'ctcc_gallery_metabox', 'title' => __( 'Cookie Consent', 'uk-cookie-consent' ), 'callback' => 'meta_box_callback', 'screens' => array( 'page', 'post' ), 'context' => 'side', 'priority' => 'default', 'fields' => array ( array ( 'ID' => 'ctcc_exclude', 'name' => 'ctcc_exclude', 'title' => __( 'Exclude from cookie notice', 'uk-cookie-consent' ), 'type' => 'checkbox', 'class' => '' ), ), ), ); return $metaboxes; } /* * Register the metabox * @since 1.0.0 */ public function add_meta_box() { $metaboxes = $this->metaboxes(); foreach ( $metaboxes as $metabox ) { add_meta_box ( $metabox['ID'], $metabox['title'], array ( $this, 'meta_box_callback' ), $metabox['screens'], $metabox['context'], $metabox['priority'], $metabox['fields'] ); } } /* * Metabox callbacks * @since 1.0.0 */ public function meta_box_callback ( $post, $fields ) { wp_nonce_field ( 'save_metabox_data', 'ctcc_metabox_nonce' ); if ( $fields['args'] ) { foreach ( $fields['args'] as $field ) { switch ( $field['type'] ) { case 'checkbox': $this -> metabox_checkbox_output ( $post, $field ); break; } } } } /* * Metabox callback for checkbox * @since 1.0.0 */ public function metabox_checkbox_output( $post, $field ) { $field_value = 0; // First check if we're on the post-new screen global $pagenow; if ( in_array ( $pagenow, array( 'post-new.php' ) ) ) { // This is a new post screen so we can apply the default value $field_value = $field['default']; } else { $custom = get_post_custom ( $post->ID ); if ( isset ( $custom[$field['ID']][0] ) ) { $field_value = $custom[$field['ID']][0]; } } ?>
metaboxes(); foreach ( $metaboxes as $metabox ) { if ( $metabox['fields'] ) { foreach ( $metabox['fields'] as $field ) { if ( $field['type'] != 'divider' ) { if ( isset ( $_POST[$field['name']] ) ) { if ( $field['type'] == 'wysiwyg' ) { $data = $_POST[$field['name']]; } else { $data = sanitize_text_field ( $_POST[$field['name']] ); } update_post_meta ( $post_id, $field['ID'], $data ); } else { delete_post_meta ( $post_id, $field['ID'] ); } } } } } } } }