wp_nonce_field, check_admin_referer, $post->ID — Связка не работает
-
Здравствуйте
Функции кастомного плагина:
1. Регистрирует кастомный тип записи
2. Регистрирует кастомную таксономию
3. Создает два кастомных метаполя Author, Link
4. Сохраняет кастомные метаполяПроблемы:
1. Не работает: $post->ID
Работает :get_the_ID()
2. Не работает:
wp_nonce_field(plugin_basename(__FILE__), ‘ishot_save_meta_box’);
check_admin_referer(plugin_basename(__FILE__), ‘ishot_save_meta_box’);
Работает:
wp_nonce_field()
check_admin_referer()<?php /* Plugin Name: Custom Post Type Description: This is a plugin create user post type in WordPress Version: 0.1 Author: Alexander */ add_action( 'init', 'ishot_register_ted_talks' ); function ishot_register_ted_talks() { $labels = array( 'name' => 'TED Talks', 'singular_name' => 'TED Talk', 'add_new' => 'Add New', 'add_new_item' => 'Add New Ted Talks', 'edit_item' => 'Edit Ted Talks', 'new_item' => 'New TED Talk', 'all_item' => 'All TED Talks', 'view_item' => 'View TED Talk', 'search_items' => 'Search TED Talks', 'not_found' => 'No TED Talks found', 'not_found_in_trash' => 'No TED Talks found in Trash', 'parent_item_colon' => '', 'menu_name' => 'TED Talks' ); $args = array( 'labels' => $labels, 'public' => true, 'menu_position' => 2, 'has_archive' => true, 'taxonomies' => array('ted'), 'rewrite' => array('slug' => 'ted'), 'supports' => array('title', 'editor', 'thumbnail') ); register_post_type('ted-talks', $args); } add_action('init', 'ishot_define_product_type_taxonomy'); function ishot_define_product_type_taxonomy() { register_taxonomy('ted', 'ted-talks', array( 'hierarchical' => true, 'label' => 'TED Taxonomies', 'query_var' => true, 'rewrite' => true ) ); } add_action('add_meta_boxes', 'ishot_metabox_init'); function ishot_metabox_init() { add_meta_box('ishot-meta', 'Data', 'ishot_meta_box', 'ted-talks', 'normal', 'high'); } function ishot_meta_box() { $ishot_author = get_post_meta(get_the_ID(), '_ishot_author', true); $ishot_link = get_post_meta(get_the_ID(), '_ishot_link', true); wp_nonce_field(plugin_basename(__FILE__), 'ishot_save_meta_box'); echo '<p>Name <input type="text" name="ishot_author" value="'.esc_attr($ishot_author).'" size="30"/></p>'; echo '<p>Link <input type="text" name="ishot_link" value="'.esc_attr($ishot_link).'" size="30"/></p>'; } add_action('save_post', 'ishot_save_meta_box'); function ishot_save_meta_box($post_id) { //check nonce for security check_admin_referer(plugin_basename(__FILE__), 'ishot_save_meta_box'); // save the meta box data as post meta using the post ID as a unique prefix update_post_meta( $post_id, '_ishot_author', sanitize_text_field( $_POST['ishot_author'] ) ); update_post_meta( $post_id, '_ishot_link', sanitize_text_field( $_POST['ishot_link'] ) ); }
Просмотр 4 ответов — с 1 по 4 (всего 4)
Просмотр 4 ответов — с 1 по 4 (всего 4)
- Тема «wp_nonce_field, check_admin_referer, $post->ID — Связка не работает» закрыта для новых ответов.