我尝试在WordPress中安装TinyMCE插件。这一切都有效,但仅适用于管理员。我已经使用wp_editor()函数嵌入了TinyMCE文本编辑器,该函数旨在为访问者显示。但我不明白如何更改代码,让每个人都可以看到(也是网站的访问者)。 PHP代码是:
<?php
if ( ! defined( 'ABSPATH' ) )
die( "Can't load this file directly" );
class Extra_Plugins_Buttons
{
function __construct() {
add_action( 'admin_init', array( $this, 'action_admin_init' ) );
}
function action_admin_init() {
// only hook up these filters if we're in the admin panel, and the current user has permission
// to edit posts and pages
add_filter( 'mce_buttons_3', array( $this, 'filter_mce_button3' ) );
add_filter( 'mce_buttons_4', array( $this, 'filter_mce_button4' ) );
add_filter( 'mce_external_plugins', array( $this, 'filter_mce_plugin' ) );
}
function filter_mce_button3( $buttons ) {
// add a separation before our button, here our button's id is "mygallery_button"
array_push( $buttons
,'jbimages'
);
return $buttons;
}
function filter_mce_plugin( $plugins ) {
// this plugin file will work the magic of our button
$plugins['jbimages'] = get_template_directory_uri() . '/inc/editor/jbimages/plugin.min.js';
return $plugins;
}
}
$mygallery = new Extra_Plugins_Buttons();
答案 0 :(得分:0)
您需要将admin_init更改为init。 init将适用于admin和前端。
在构造函数中,将admin_int更改为init或使用构造函数将代码替换为下面的代码。
function __construct() {
add_action( 'init', array( $this, 'action_admin_init' ) );
}