meta_box = array ( 'id' => $meta_box_id, 'title' => $meta_box_title, 'post_type' => $post_type, ); $this->fields = array( 'catchresponsive-layout-option', 'catchresponsive-header-image', 'catchresponsive-featured-image' ); // Add metaboxes add_action( 'add_meta_boxes', array( $this, 'add' ) ); add_action( 'save_post', array( $this, 'save' ) ); } /** * Add Meta Box for multiple post types. * * @since Catch Responsive 1.4 * * @access public */ public function add($postType) { if ( in_array( $postType, $this->meta_box['post_type'] ) ) { add_meta_box( $this->meta_box['id'], $this->meta_box['title'], array( $this, 'show' ), $postType ); } } /** * Renders metabox * * @since Catch Responsive 1.4 * * @access public */ public function show() { global $post; $layout_options = catchresponsive_metabox_layouts(); $featured_image_options = catchresponsive_metabox_featured_image_options(); $header_image_options = catchresponsive_metabox_header_featured_image_options(); // Use nonce for verification wp_nonce_field( basename( __FILE__ ), 'catchresponsive_custom_meta_box_nonce' ); // Begin the field table and loop ?>
ID, $field['id'], true ); if ( empty( $metaheader ) ){ $metaheader='default'; } ?>
ID, $field['id'], true ); if (empty( $metaimage ) ){ $metaimage='default'; } ?>
meta_box['post_type'] ) ) // Check if current post type is supported. || ( ! check_admin_referer( basename( __FILE__ ), 'catchresponsive_custom_meta_box_nonce') ) // Check nonce - Security || ( ! current_user_can( $post_type_object->cap->edit_post, $post_id ) ) ) // Check permission { return $post_id; } foreach ( $this->fields as $field ) { $old = get_post_meta( $post_id, $field, true); $new = $_POST[ $field ]; delete_post_meta( $post_id, $field ); if ( '' == $new || array() == $new ) { return; } else { if ( ! update_post_meta ($post_id, $field, sanitize_key ( $new ) ) ) { add_post_meta($post_id, $field, sanitize_key ( $new ), true ); } } } // end foreach } } $catchresponsive_metabox = new CatchResponsiveMetaBox( 'catchresponsive-options', //metabox id __( 'Catch Responsive Options', 'catch-responsive' ), //metabox title array( 'page', 'post' ) //metabox post types );