php 在Wordpress帖子编辑器页面添加第二个TinyMCE编辑器。第二个编辑器看起来和功能完全像原始的编辑器一样

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 在Wordpress帖子编辑器页面添加第二个TinyMCE编辑器。第二个编辑器看起来和功能完全像原始的编辑器一样相关的知识,希望对你有一定的参考价值。

/* Second Post Editor TinyMCE Editor */
class SubContentEditor {

	public $meta_key = 'subcontent';
	public $meta_label = 'Right Side'; // Headline above editor
	public $post_type = array( 'page' ); // The post type in which the editor should display
	public $wpautop = true; // Automatically create paragraphs?

	function __construct() {
		add_action( 'edit_form_after_editor', array( &$this, 'edit_form_after_editor' ) );
		add_action( 'save_post', array( &$this, 'save_post' ) );
		add_action( 'init', array( &$this, 'init' ) );
	}

	public function init() {
		$this->meta_key = apply_filters( 'roman-sce-meta_key', $this->meta_key );
		$this->post_type = apply_filters( 'roman-sce-post_type', $this->post_type );
		$this->meta_label = apply_filters( 'roman-sce-meta_label', $this->meta_label );
		$this->wpautop = apply_filters( 'roman-sce-wpautop', $this->wpautop );
	}

	public function edit_form_after_editor() {
		if ( !is_admin() ) { return; }

		if ( in_array( get_post_type( $GLOBALS['post'] ), $this->post_type ) ) { return; }

		$value = $this->get_the_subcontent();

		$sc_arg = array(
			'textarea_rows' => apply_filters( 'roman-sce-row', 10 ),
			'wpautop' => $this->wpautop,
			'media_buttons' => apply_filters( 'roman-sce-media_buttons', true ),
			'tinymce' => apply_filters( 'roman-sce-tinymce', true ),
		);

		echo '<h3 class="subcontentLabel" style="margin-top:15px;">' . $this->meta_label . '</h3>';
		wp_editor( $value, 'subcontent', $sc_arg );

	}

	public function save_post( $post_id ) {
		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
			return $post_id;
		}
		if ( ! current_user_can( 'edit_post', $post_id ) ) {
			return $post_id;
		}

		if ( isset ( $_POST[ $this->meta_key ] ) ) {
			return update_post_meta( $post_id, $this->meta_key, $_POST[ $this->meta_key ] );
		}
		delete_post_meta( $post_id, $this->meta_key );

		return $post_id;
	}

	public function get_the_subcontent() {
		global $post;
		$subcontent = do_shortcode(get_post_meta( $post->ID, $this->meta_key, true ));
		if ( $this->wpautop == true ) {
			return wpautop( $subcontent );
		} else {
			return $subcontent;
		}
	}

}
$romanSCE = new SubContentEditor();

function get_the_subcontent() {
	global $romanSCE;
	return $romanSCE->get_the_subcontent();
}

/** 
  * use get_the_subcontent() where you want the content of the
  * second editor to display, just like the_content
  */
function the_subcontent() {
	echo get_the_subcontent();
}

以上是关于php 在Wordpress帖子编辑器页面添加第二个TinyMCE编辑器。第二个编辑器看起来和功能完全像原始的编辑器一样的主要内容,如果未能解决你的问题,请参考以下文章

在 Wordpress 中为自定义帖子类型添加附加页面

如何在WordPress page.php,single.php中加载style.css根目录

在 Wordpress 中从类别创建帖子的下拉菜单

WordPress 搜索仅适用于帖子,不适用于页面

php 添加此代码以将ACF字段添加到页面/帖子。务必检查wordpress仪表板顶部菜单中的屏幕选项

在wordpress中只显示5个帖子