function ingredients_meta() {
add_meta_box( 'ingredients_meta',
__('Ингредиенты'),
'ingredients_meta_callback',
'recipes',
'advanced',
'default' );
}
add_action('add_meta_boxes', 'ingredients_meta');
function ingredients_meta_callback( $post ) {
echo _e('<p>Требуемые Ингредиенты для приготовления</p>');
wp_nonce_field( basename(__FILE__), 'ingredients_nonce');
$ingredients_stored_meta = get_post_meta( $post->ID );
wp_editor($ingredients_stored_meta['ingredients-recipes-original'][0], 'ingredients-recipes-original', array(
'wpautop' => 1,
'media_buttons' => 1,
'textarea_name' => 'ingredients-recipes-original', //нужно указывать!
'textarea_rows' => 20,
'tabindex' => null,
'editor_css' => '',
'editor_class' => '',
'teeny' => 0,
'dfw' => 0,
'tinymce' => 1,
'quicktags' => 1,
'drag_drop_upload' => false
) );
}
function ingredients_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'ingredients_nonce' ] ) && wp_verify_nonce( $_POST[ 'ingredients_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and sanitizes/saves if needed
if( isset( $_POST[ 'ingredients-recipes-original' ] ) ) {
update_post_meta( $post_id, 'ingredients-recipes-original', sanitize_text_field( $_POST[ 'ingredients-recipes-original' ] ) );
}
}
add_action( 'save_post', 'ingredients_meta_save' );
function ingredients_meta() {
add_meta_box( 'ingredients_meta',
__('Ингредиенты'),
'ingredients_meta_callback',
'recipes',
'advanced',
'default' );
}
add_action('add_meta_boxes', 'ingredients_meta');
function ingredients_meta_callback( $post ) {
echo _e('<p>Требуемые Ингредиенты для приготовления</p>');
wp_nonce_field( basename(__FILE__), 'ingredients_nonce');
$ingredients_stored_meta = get_post_meta( $post->ID );
wp_editor($ingredients_stored_meta['ingredients-recipes-original'][0], 'ingredients-recipes-original', array(
'wpautop' => 1,
'media_buttons' => 1,
'textarea_name' => 'ingredients-recipes-original', //нужно указывать!
'textarea_rows' => 20,
'tabindex' => null,
'editor_css' => '',
'editor_class' => '',
'teeny' => 0,
'dfw' => 0,
'tinymce' => 1,
'quicktags' => 1,
'drag_drop_upload' => false
) );
}
function ingredients_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'ingredients_nonce' ] ) && wp_verify_nonce( $_POST[ 'ingredients_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and sanitizes/saves if needed
if( isset( $_POST[ 'ingredients-recipes-original' ] ) ) {
update_post_meta( $post_id, 'ingredients-recipes-original', $_POST[ 'ingredients-recipes-original' ] );
}
}
add_action( 'save_post', 'ingredients_meta_save' );