Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/25/2018 03:48:20 AM (7 years ago)
Author:
imath
Message:

BP Nouveau: Improve Messages UI extensibility

In BP Nouveau, the Messages UI is a Backbone based one. This means current legacy hooks inserted into the JS templates are a bit more different to use for plugin developers as it requires them to use JavaScript to get the data models. If the current AJAX requests still need a way to be extended to fetch extra data such as specific Messages metas, this commit is a first step to help plugin developers to insert content into the Messages UI without changing their habits about using the PHP Messages template global variables to get data about the Messages loop. This is done by introducing the back compatibility function bp_nouveau_messages_catch_hook_content(). This function is used during the AJAX requests that are fetching messages for a specific thread. As a start, 2 legacy hooks have been moved from the JS Template level to this higher level :

  • bp_before_message_content
  • bp_after_message_content

If actions are attached to these hooks their outputs will be caught using the buffer and will be "transported" as new properties, respectively beforeContent and afterContent, of the JSON reply that is used by the Messages UI. If these 2 properties are set and populated, their content will be output inside the corresponding JS templates.

Props pareshradadiya

See #7847 (Trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/messages/functions.php

    r12119 r12121  
    439439    );
    440440}
     441
     442/**
     443 * Fires Messages Legacy hooks to catch the content and add them
     444 * as extra keys to the JSON Messages UI reply.
     445 *
     446 * @since 3.0.1
     447 *
     448 * @param array $hooks The list of hooks to fire.
     449 * @return array       An associative containing the caught content.
     450 */
     451function bp_nouveau_messages_catch_hook_content( $hooks = array() ) {
     452    $content = array();
     453
     454    ob_start();
     455    foreach ( $hooks as $js_key => $hook ) {
     456        if ( ! has_action( $hook ) ) {
     457            continue;
     458        }
     459
     460        // Fire the hook.
     461        do_action( $hook );
     462
     463        // Catch the sanitized content.
     464        $content[ $js_key ] = bp_strip_script_and_style_tags( ob_get_contents() );
     465
     466        // Clean the buffer.
     467        ob_clean();
     468    }
     469    ob_end_clean();
     470
     471    return $content;
     472}
Note: See TracChangeset for help on using the changeset viewer.