I am trying to use multiple wp_editor_meta_box
to my posts for custom post_meta
but the problem is when I use the same codes for each of them there is an error
Fatal error: Cannot redeclare wp_editor_meta_box() (previously declared in C:\xampp\htdocs\aria\wp-content\themes\ariadl\functions.php:100) in C:\xampp\htdocs\aria\wp-content\themes\ariadl\functions.php on line 175
these are my codes :
/* Define the custom box */
add_action( 'add_meta_boxes', 'myplugin2_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin2_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin2_add_custom_box() {
add_meta_box( 'wp_editor_test_2_box', 'اطلاعات سیستم مورد نیاز', 'wp_editor_meta_box' );
}
/* Prints the box content */
function wp_editor_meta_box( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_2', false );
wp_editor( $field_value[0], '_wp_editor_test_2' );
}
/* When the post is saved, saves our custom data */
function myplugin2_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_2'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_2', $_POST['_wp_editor_test_2'] );
}
}
/* Define the custom box */
add_action( 'add_meta_boxes', 'myplugin1_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin1_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin1_add_custom_box() {
add_meta_box( 'wp_editor_test_3_box', 'راهنمای نصب', 'wp_editor_meta_box' );
}
/* Prints the box content */
function wp_editor_meta_box( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin1_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_3', false );
wp_editor( $field_value[0], '_wp_editor_test_3' );
}
/* When the post is saved, saves our custom data */
function myplugin1_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin1_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin1_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_3'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_3', $_POST['_wp_editor_test_3'] );
}
}
/* Define the custom box */
add_action( 'add_meta_boxes', 'myplugin_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin_add_custom_box() {
add_meta_box( 'wp_editor_test_1_box', 'اطلاعات باکس دانلود >> در این قسمت می توانید لینک های دانلود مطلب مورد نظر را با متن دلخواه قرار دهید.در هر خط یه لینک قرار دهید', 'wp_editor_meta_box' );
}
/* Prints the box content */
function wp_editor_meta_box( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_1', false );
wp_editor( $field_value[0], '_wp_editor_test_1' );
}
/* When the post is saved, saves our custom data */
function myplugin_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_1'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_1', $_POST['_wp_editor_test_1'] );
}
}
I am trying to use multiple wp_editor_meta_box
to my posts for custom post_meta
but the problem is when I use the same codes for each of them there is an error
Fatal error: Cannot redeclare wp_editor_meta_box() (previously declared in C:\xampp\htdocs\aria\wp-content\themes\ariadl\functions.php:100) in C:\xampp\htdocs\aria\wp-content\themes\ariadl\functions.php on line 175
these are my codes :
/* Define the custom box */
add_action( 'add_meta_boxes', 'myplugin2_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin2_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin2_add_custom_box() {
add_meta_box( 'wp_editor_test_2_box', 'اطلاعات سیستم مورد نیاز', 'wp_editor_meta_box' );
}
/* Prints the box content */
function wp_editor_meta_box( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_2', false );
wp_editor( $field_value[0], '_wp_editor_test_2' );
}
/* When the post is saved, saves our custom data */
function myplugin2_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_2'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_2', $_POST['_wp_editor_test_2'] );
}
}
/* Define the custom box */
add_action( 'add_meta_boxes', 'myplugin1_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin1_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin1_add_custom_box() {
add_meta_box( 'wp_editor_test_3_box', 'راهنمای نصب', 'wp_editor_meta_box' );
}
/* Prints the box content */
function wp_editor_meta_box( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin1_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_3', false );
wp_editor( $field_value[0], '_wp_editor_test_3' );
}
/* When the post is saved, saves our custom data */
function myplugin1_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin1_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin1_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_3'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_3', $_POST['_wp_editor_test_3'] );
}
}
/* Define the custom box */
add_action( 'add_meta_boxes', 'myplugin_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin_add_custom_box() {
add_meta_box( 'wp_editor_test_1_box', 'اطلاعات باکس دانلود >> در این قسمت می توانید لینک های دانلود مطلب مورد نظر را با متن دلخواه قرار دهید.در هر خط یه لینک قرار دهید', 'wp_editor_meta_box' );
}
/* Prints the box content */
function wp_editor_meta_box( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_1', false );
wp_editor( $field_value[0], '_wp_editor_test_1' );
}
/* When the post is saved, saves our custom data */
function myplugin_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_1'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_1', $_POST['_wp_editor_test_1'] );
}
}
Share
Improve this question
edited Mar 27, 2019 at 14:13
fightstarr20
1,1358 gold badges26 silver badges47 bronze badges
asked Mar 27, 2019 at 7:25
m.javad koushkim.javad koushki
54 bronze badges
1 Answer
Reset to default 1Try this. you have used same function name 3 times. It's must be dynamic names. so
<?php
/**
* Plugin Name: WP Editor in a Meta Box
* Plugin URI:
* Description: Demonstration of WP Editor in a meta box.
* Version: 1.0
* Author: goto10
* Author URI:
* License:
*/
// file name: wp_editor-in-meta-box-test.php
/* Meta box code based on http://codex.wordpress/Function_Reference/add_meta_box */
/* Define the custom box */
add_action( 'add_meta_boxes', 'myplugin2_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin2_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin2_add_custom_box() {
add_meta_box( 'wp_editor_test_2_box', 'اطلاعات سیستم مورد نیاز', 'wp_editor_meta_box2' );
}
/* Prints the box content */
function wp_editor_meta_box2( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_2', false );
wp_editor( $field_value[0], '_wp_editor_test_2' );
}
/* When the post is saved, saves our custom data */
function myplugin2_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_2'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_2', $_POST['_wp_editor_test_2'] );
}
}
add_action( 'add_meta_boxes', 'myplugin1_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin1_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin1_add_custom_box() {
add_meta_box( 'wp_editor_test_3_box', 'راهنمای نصب', 'wp_editor_meta_box3' );
}
/* Prints the box content */
function wp_editor_meta_box3( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin1_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_3', false );
wp_editor( $field_value[0], '_wp_editor_test_3' );
}
/* When the post is saved, saves our custom data */
function myplugin1_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin1_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin1_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_3'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_3', $_POST['_wp_editor_test_3'] );
}
}
add_action( 'add_meta_boxes', 'myplugin_add_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'myplugin_save_postdata' );
/* Adds a box to the main column on the Post and Page edit screens */
function myplugin_add_custom_box() {
add_meta_box( 'wp_editor_test_1_box', 'اطلاعات باکس دانلود >> در این قسمت می توانید لینک های دانلود مطلب مورد نظر را با متن دلخواه قرار دهید.در هر خط یه لینک قرار دهید', 'wp_editor_meta_box1' );
}
/* Prints the box content */
function wp_editor_meta_box1( $post ) {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
$field_value = get_post_meta( $post->ID, '_wp_editor_test_1', false );
wp_editor( $field_value[0], '_wp_editor_test_1' );
}
/* When the post is saved, saves our custom data */
function myplugin_save_postdata( $post_id ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( ( isset ( $_POST['myplugin_noncename'] ) ) && ( ! wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) ) )
return;
// Check permissions
if ( ( isset ( $_POST['post_type'] ) ) && ( 'page' == $_POST['post_type'] ) ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
}
else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
// OK, we're authenticated: we need to find and save the data
if ( isset ( $_POST['_wp_editor_test_1'] ) ) {
update_post_meta( $post_id, '_wp_editor_test_1', $_POST['_wp_editor_test_1'] );
}
}
?>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745654494a4638462.html
评论列表(0条)