I went ahead and took care of this. Wasn’t as simple as I was expecting, but nothing too serious.
Here’s the exact changes made:
1.) /js/bsp_quote.js
Now checks for which editor is currently visible. This handles all cases, even if both editors are active.
jQuery(document).ready(function($) {
$('.bsp-quote-link').click(function() {
var id = $(this).attr("href").substr(1);
var data = {
'action' : 'get_status_by_ajax',
'id' : id,
'security': bsp_ajax_object.quote
}
$.post(bsp_ajax_object.ajax_url, data, function(response) {
// if tinymce editor currently visible
if( $('.mce-tinymce.mce-container.mce-panel').is(':visible') ) {
tinymce.get("bbp_reply_content").execCommand("mceInsertContent", false, response);
}
// if default text editor currently visible
if( $('textarea#bbp_reply_content').is(':visible') ) {
quote = response;
replyTextfield = $("#bbp_reply_content");
text = replyTextfield.val();
if(jQuery.trim(text) != ''){
text += "\n\n";
}
text += quote;
replyTextfield.val(text);
}
// scroll to new_post form
location.hash = "#new-post" ;
});
});
});
2.) /includes/generate_css.php
Now enqueues the bspstyle-quotes CSS file both ways – directly in tinymce (if active) and as a separate stylesheet (if text editor active). Also now includes the versioning timestamps for that file in case it gets enqueued as a separate stylesheet:
//if quotes active
if ( !empty( $bsp_style_settings_quote['quote_activate'] ) ) {
// determine which editor is currently being used
// no settings specified, using default text editor
if ( empty( $bsp_style_settings_form['Show_editorsactivate'] ) ) {
$text_editor = true;
$tinymce_editor = false;
// settings specified, set flags based on settings value
} else {
switch ( $bsp_style_settings_form['Show_editorsactivate'] ) {
case 0 :
$text_editor = true;
$tinymce_editor = false;
break;
case 1 :
$text_editor = false;
$tinymce_editor = true;
break;
case 2 :
$text_editor = true;
$tinymce_editor = true;
break;
}
}
/* add the style sheet */
$quotes_css = bsp_add_custom_editor_style();
// only if quotes css file exists
if ( $quotes_css ) {
// if tinymce being used
if ( $tinymce_editor )
add_filter( 'mce_css', 'bsp_add_custom_editor_style' );
// if default text editor being used
if ( $text_editor )
add_action( 'wp_enqueue_scripts', 'bsp_enqueue_quote_style' );
}
//and enqueue the js
add_action( 'wp_enqueue_scripts', 'bsp_enqueue_quote' );
}
//this function creates the style sheet, generated when the quotes tab is accessed.
function generate_quote_style_css() {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
global $bsp_css_location ;
ob_start(); // Capture all output (output buffering)
require ( BSP_PLUGIN_DIR . '/css/styles-quote.php' );
$css = ob_get_clean(); // Get generated CSS (output buffering)
$css_filename = 'bspstyle-quotes'.( is_multisite() ? '-'.get_current_blog_id() : '' ).'.css';
update_option( 'bsp_style_quote_generation', time(), true );
if ( !empty($bsp_css_location['activate css location'] ) && !empty( $bsp_css_location['location'] ) ) {
$location = $bsp_css_location['location'] ;
// if it starts with '/' - remove
if ( 0 === strpos( $location, '/' ) ) {
$location = substr( $location, 1, strlen( $location ) ) ;
}
// if it doesn't end with a '/' add one
if (substr( $location, strlen( $location )-1, strlen( $location ) ) !== '/' ) {
$location = $location.'/' ;
}
$path = get_home_path();
$path = $path.'/'.$location ;
file_put_contents( $path.$css_filename, $css, LOCK_EX ); // Save it
}
else
file_put_contents( BSP_PLUGIN_DIR . '/css/'.$css_filename, $css, LOCK_EX ); // Save it
}
function bsp_add_custom_editor_style() {
$css_filename = 'bspstyle-quotes'.( is_multisite() ? '-'.get_current_blog_id() : '' ).'.css';
if ( !empty( $bsp_css_location['activate css location'] ) && !empty( $bsp_css_location['location'] ) ) {
$location = $bsp_css_location['location'];
// if it starts with '/' - remove
if (0 === strpos( $location, '/' ) ) {
$location = substr( $location, 1, strlen( $location ) ) ;
}
// if it doesn't end with a '/' add one
if ( substr( $location, strlen( $location )-1, strlen( $location ) ) !== '/' ) {
$location = $location.'/' ;
}
// return custom URL location
if ( file_exists( ABSPATH.'/'.$location.$css_filename ) ) {
$location = home_url().'/'.$location ;
return $location.$css_filename;
}
} else {
// return default URL location
if ( file_exists( plugin_dir_path( dirname( __FILE__ ) ).'css/'.$css_filename ) ) {
return plugins_url( 'css/'.$css_filename, dirname( __FILE__ ) );
}
}
// return false, no file found
return false;
}
function bsp_enqueue_quote_style() {
wp_register_style( 'bsp_quotes', bsp_add_custom_editor_style(), array(), get_option( 'bsp_style_quote_generation', time() ) );
wp_enqueue_style( 'bsp_quotes' );
}
function bsp_enqueue_quote() {
wp_enqueue_script( 'bsp_quote', plugins_url('js/bsp_quote.js',dirname( __FILE__ )), array( 'jquery' ), get_option( 'bsp_version' ) );
wp_localize_script( 'bsp_quote', 'bsp_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ),'quote' => wp_create_nonce('get_id_content') ) );
}
The end result is that quotes are now working regardless of which editor you have active, and if you have BOTH editors active, the quotes functionality will happen based on which editor tab is CURRENTLY ACTIVE in the reply form.
I’m including this in the 5.2.6 release. Uploading to GitHub now. Re-download with these new changes to test it out for yourself:
https://github.com/codejp3/bbp-style-pack/archive/refs/heads/proposed-v5.2.6.zip