__('Custom Boxes', 'customizing'), 'singular_name' => __('Custom Box', 'customizing'), 'add_new_item' => __('Add New Custom Box', 'customizing'), 'edit_item' => __('Edit Custom Box', 'customizing'), 'new_item' => __('New Custom Box', 'customizing'), 'view_item' => __('View Custom Box', 'customizing'), 'view_items' => __('View Custom Boxes', 'customizing'), 'search_items' => __('Search Custom Boxes', 'customizing'), 'not_found' => __('No custom boxes found.', 'customizing'), 'not_found_in_trash' => __('No custom boxes found in trash.', 'customizing'), 'all_items' => __('All Custom Boxes', 'customizing'), ); $args=array( 'labels' => $labels, 'description' => __('Custom Meta Boxes', 'customizing'), 'public' => false, 'show_ui' => true, 'show_in_menu' => 'customizing', 'supports' => array('title'), ); register_post_type('cff-custom-box', $args); } if(current_user_can('manage_options')) add_action('cff-init', 'cff_custom_boxes'); /** @brief Inits the custom boxes interface fields. @since 1.0.0 */ function cff_custom_boxes_fields() { $fields=array( array( 'id' => 'cff-id', 'label' => __('ID', 'customizing'), 'type' => 'text', 'oninput' => 'cff_slugify_self(this)', 'classes' => 'cff-slug-field', 'required' => true, 'description' => __('Meta box ID (used in the "id" attribute for the meta box).'), 'span' => 100, ), array( 'id' => 'cff-context', 'label' => __('Context', 'customizing'), 'type' => 'select', 'options' => array( 'normal' => 'Normal', 'side' => 'Side', 'advanced' => 'Advanced', ), 'description' => __('The context within the screen where the boxes should display.', 'customizing'), 'span' => 50, ), array( 'id' => 'cff-priority', 'label' => __('Priority', 'customizing'), 'type' => 'select', 'options' => array( 'default' => 'Default', 'high' => 'High', 'low' => 'Low', ), 'description' => __('The priority within the context where the boxes should show.', 'customizing'), 'span' => 50, ), ); $custom_box=array( 'id' => 'details', 'title' => __('Details', 'customizing'), 'type' => 'cff-custom-box', 'fields' => $fields, ); cff_add_meta_box($custom_box); $fields_settings=cff_fields_settings(); $custom_box=array( 'id' => 'fields', 'title' => __('Fields', 'customizing'), 'type' => 'cff-custom-box', 'fields' => array( $fields_settings, ), ); cff_add_meta_box($custom_box); $post_types=get_post_types(array('public' => true), 'objects'); foreach($post_types as $key => $post_type) $post_types[$key]=$post_type->label; $fields=array( array( 'id' => 'cff-post-types', //'label' => __('Post Types', 'customizing'), 'type' => 'options', 'options' => $post_types, 'multiple' => true, 'description' => __('Post types associated with this box.', 'customizing'), 'span' => 100, ), ); $custom_box=array( 'id' => 'post-types', 'title' => __('Post Types', 'customizing'), 'type' => 'cff-custom-box', 'fields' => $fields, 'context' => 'side', ); cff_add_meta_box($custom_box); } if(current_user_can('manage_options')) add_action('admin_init', 'cff_custom_boxes_fields'); /** @brief Gets the meta box args from the post. @param mixed $custom_box The custom box post. @since 1.3.0 */ function cff_get_custom_box($custom_box) { $args=array(); $data=cff_get_post_meta($custom_box->ID); $args['id']=$data['cff-id']; $args['title']=$custom_box->post_title; $args['type']=$data['cff-post-types']; $args['context']=$data['cff-context']; $args['priority']=$data['cff-priority']; $fields=array(); foreach($data['cff-fields'] as $field) { $field+=$field['attributes']; $fields[]=$field; } $args['fields']=$fields; return $args; } /** @brief Inits the custom boxes from the database. @since 1.0.0 */ function cff_add_custom_boxes() { $custom_boxes=get_posts(array('post_type' => 'cff-custom-box')); foreach($custom_boxes as $custom_box) { $args=cff_get_custom_box($custom_box); cff_add_meta_box($args); } } add_action('cff-init', 'cff_add_custom_boxes'); ?>