_x( 'Custom Data', 'post type general name', 'acd' ), 'singular_name' => _x( 'Custom Data', 'post type singular name', 'acd' ), 'menu_name' => _x( 'Custom Data', 'admin menu', 'acd' ), 'name_admin_bar' => _x( 'Custom Data', 'add new on admin bar', 'acd' ), 'add_new' => _x( 'Add New', 'Custom Data', 'acd' ), 'add_new_item' => __( 'Add New Data', 'acd' ), 'new_item' => __( 'New Data', 'acd' ), 'edit_item' => __( 'Edit Data', 'acd' ), 'view_item' => __( 'View Data', 'acd' ), 'all_items' => __( 'All Data', 'acd' ), 'search_items' => __( 'Search Data', 'acd' ), 'parent_item_colon' => __( 'Parent Data:', 'acd' ), 'not_found' => __( 'No Data found.', 'acd' ), 'not_found_in_trash' => __( 'No Data found in Trash.', 'acd' ) ); $args = array( 'labels' => $labels, 'description' => __( 'Description', 'acd' ), 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => false, 'taxonomies' => array(), 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => true, 'menu_position' => 99, // 20: below Pages // https://developer.wordpress.org/resource/dashicons/#megaphone 'menu_icon' => 'dashicons-media-spreadsheet', 'supports' => array( 'title', 'thumbnail', 'custom-fields' ) ); register_post_type( 'acd-data', $args ); } /** * Adds the meta box container. */ public function add_meta_box( $post_type ) { // Limit meta box to certain post types. $post_types = array( 'acd-data' ); if ( in_array( $post_type, $post_types ) ) { add_meta_box( 'acd_meta_box', __( 'Custom Data', 'acd' ), array( $this, 'render_meta_box_content' ), $post_type, 'advanced', 'high' ); } } /** * Save the meta when the post is saved. * * @param int $post_id The ID of the post being saved. */ public function save( $post_id ) { /* * We need to verify this came from the our screen and with proper authorization, * because save_post can be triggered at other times. */ // Check if our nonce is set. if ( ! isset( $_POST['acd_inner_custom_box_nonce'] ) ) { return $post_id; } $nonce = $_POST['acd_inner_custom_box_nonce']; // Verify that the nonce is valid. if ( ! wp_verify_nonce( $nonce, 'acd_inner_custom_box' ) ) { return $post_id; } /* * If this is an autosave, our form has not been submitted, * so we don't want to do anything. */ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } /* OK, it's safe for us to save the data now. */ // Sanitize the user input. // $data = sanitize_textarea_field( $_POST['acd_data'] ); $type = sanitize_text_field( $_POST['acd_type'] ); // $data = $_POST['acd_data']; $data = sanitize_post_field( 'post_content', $_POST['acd_data'], $post_id, 'edit' ); // Update the meta field. update_post_meta( $post_id, '_acd_data', $data ); update_post_meta( $post_id, '_acd_type', $type ); } /** * Render Meta Box content. * * @param WP_Post $post The post object. */ public function render_meta_box_content( $post ) { // Add an nonce field so we can check for it later. wp_nonce_field( 'acd_inner_custom_box', 'acd_inner_custom_box_nonce' ); // Use get_post_meta to retrieve an existing value from the database. $type = sanitize_text_field( get_post_meta( $post->ID, '_acd_type', true ) ); // $data = get_post_meta( $post->ID, '_acd_data', true ); $data = sanitize_post_field( 'post_content', get_post_meta( $post->ID, '_acd_data', true ), $post->ID, 'edit' ); // Display the form, using the current value. $type_options = array( '' => 'Text', 'br' => 'Automatically add br', 'list' => 'List', 'thumbnail' => 'Thumbnail', 'script' => 'Script' ); ?>

: [select your-list acd-data:ID; ?> ], [checkbox your-check acd-data:ID; ?> ], [radio your-radio acd-data:ID; ?> ]