Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/18/2015 10:54:46 PM (9 years ago)
Author:
djpaul
Message:

Activity: fix @mentions in wp-admin post editor.

If the screen loads with the text editor visible, bp_mentions is attached to the text editor as expected, but loadMentionsInTinyMCE uses up its tries and gives up trying to attach the iframe, so when you switch to the visual editor, ` doesn't work.

This change removes the looped loadMentionsInTinyMCE approach and instead hooks into TinyMCE configuration to specify an init callback, where we then load bp_mentions.

Fixes #6487 (trunk). Props dcavins, imath, DJPaul.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-cssjs.php

    r9819 r10054  
    4242    }
    4343
     44    // If the script has been enqueued, let's attach our mentions TinyMCE init callback.
     45    add_filter( 'tiny_mce_before_init', 'bp_add_mentions_on_tinymce_init', 10, 2 );
     46
    4447    /**
    4548     * Fires at the end of the Activity Mentions script.
     
    5457add_action( 'bp_enqueue_scripts', 'bp_activity_mentions_script' );
    5558add_action( 'bp_admin_enqueue_scripts', 'bp_activity_mentions_script' );
     59
     60/**
     61 * Bind the mentions listener to a wp_editor instance when TinyMCE initializes.
     62 *
     63 * @since BuddyPress (2.3.3)
     64 *
     65 * @param array  $settings   An array with TinyMCE config.
     66 * @param string $editor_id Unique editor identifier, e.g. 'content'.
     67 *
     68 * @return array  $mceInit   An array with TinyMCE config.
     69 */
     70function bp_add_mentions_on_tinymce_init( $settings, $editor_id ) {
     71    // We only apply the mentions init to the visual post editor in the WP dashboard.
     72    if ( 'content' === $editor_id ) {
     73        $settings['init_instance_callback'] = 'window.bp.mentions.tinyMCEinit';
     74    }
     75
     76    return $settings;
     77}
Note: See TracChangeset for help on using the changeset viewer.