Beispiel #1
0
function wck_cfc_create_box()
{
    global $wpdb;
    /* get post types */
    $args = array('public' => true);
    $output = 'objects';
    // or objects
    $post_types = get_post_types($args, $output);
    $post_type_names = array();
    foreach ($post_types as $post_type) {
        if ($post_type->name != 'attachment' && $post_type->name != 'wck-meta-box') {
            $post_type_names[] = $post_type->name;
        }
    }
    /* get page templates */
    $templates = wck_get_page_templates();
    /* set up the fields array */
    $cfc_box_args_fields = array(array('type' => 'text', 'title' => 'Meta name', 'description' => 'The name of the meta field. It is the name by which you will query the data in the frontend. Must be unique, only lowercase letters, no spaces and no special characters.', 'required' => true), array('type' => 'select', 'title' => 'Post Type', 'options' => $post_type_names, 'default-option' => true, 'description' => 'What post type the meta box should be attached to', 'required' => true), array('type' => 'select', 'title' => 'Repeater', 'options' => array('false', 'true'), 'default' => 'false', 'description' => 'Whether the box supports just one entry or if it is a repeater field. By default it is a single field.'), array('type' => 'select', 'title' => 'Sortable', 'options' => array('true', 'false'), 'default' => 'false', 'description' => 'Whether the entries are sortable or not. Thsi is valid for repeater fields.'), array('type' => 'text', 'title' => 'Post ID', 'description' => 'ID of a post on which the meta box should appear.'));
    if (!empty($templates)) {
        $cfc_box_args_fields[] = array('type' => 'select', 'title' => 'Page Template', 'options' => $templates, 'default-option' => true, 'description' => 'If post type is "page" you can further select a page templete. The meta box will only appear  on the page that has that selected page template.');
    }
    /* set up the box arguments */
    $args = array('metabox_id' => 'wck-cfc-args', 'metabox_title' => 'Meta Box Arguments', 'post_type' => 'wck-meta-box', 'meta_name' => 'wck_cfc_args', 'meta_array' => $cfc_box_args_fields, 'sortable' => false, 'single' => true);
    /* create the box */
    new WCK_CFC_Wordpress_Creation_Kit($args);
    /* set up the fields array */
    $cfc_box_fields_fields = array(array('type' => 'text', 'title' => 'Field Title', 'description' => 'Title of the field. A slug will automatically be generated.', 'required' => true), array('type' => 'select', 'title' => 'Field Type', 'options' => array('text', 'textarea', 'select', 'checkbox', 'radio', 'upload'), 'default-option' => true, 'description' => 'The field type', 'required' => true), array('type' => 'textarea', 'title' => 'Description', 'description' => 'The description of the field.'), array('type' => 'select', 'title' => 'Required', 'options' => array('false', 'true'), 'default' => 'false', 'description' => 'Whether the field is required or not'), array('type' => 'text', 'title' => 'Default Value', 'description' => 'Default value of the field. For Checkboxes if there are multiple values separete them with a ","'), array('type' => 'text', 'title' => 'Options', 'description' => 'Options for field types "select", "checkbox" and "radio". For multiple options separete them with a ","'), array('type' => 'radio', 'title' => 'Attach upload to post', 'description' => 'Whether or not the uploads should be attached to the post', 'options' => array('yes', 'no')));
    /* set up the box arguments */
    $args = array('metabox_id' => 'wck-cfc-fields', 'metabox_title' => 'Meta Box Fields', 'post_type' => 'wck-meta-box', 'meta_name' => 'wck_cfc_fields', 'meta_array' => $cfc_box_fields_fields);
    /* create the box */
    new WCK_CFC_Wordpress_Creation_Kit($args);
}
Beispiel #2
0
function wck_cfc_create_box()
{
    global $wpdb;
    /* get post types */
    $public_cpt_arg = apply_filters('wck_cfc_public_cpt_arg', true);
    $args = array('public' => $public_cpt_arg);
    $output = 'objects';
    // or objects
    $post_types = get_post_types($args, $output);
    $post_type_names = array();
    if (!empty($post_types)) {
        foreach ($post_types as $post_type) {
            if ($post_type->name != 'attachment' && $post_type->name != 'wck-meta-box' && $post_type->name != 'wck-frontend-posting' && $post_type->name != 'wck-option-page' && $post_type->name != 'wck-option-field' && $post_type->name != 'wck-swift-template') {
                $post_type_names[] = $post_type->name;
            }
        }
    }
    /* add CPTC registered with WCK that are not public */
    if ($public_cpt_arg) {
        $cpts = get_option('wck_cptc');
        if (!empty($cpts)) {
            foreach ($cpts as $cpt) {
                if ($cpt['public'] == 'false') {
                    $post_type_names[] = $cpt['post-type'];
                }
            }
        }
    }
    /* get page templates */
    $templates = wck_get_page_templates();
    /* set up the fields array */
    $cfc_box_args_fields = array(array('type' => 'text', 'title' => __('Meta name', 'wck'), 'description' => __('The name of the meta field. It is the name by which you will query the data in the frontend. Must be unique, only lowercase letters, no spaces and no special characters.', 'wck'), 'required' => true), array('type' => 'select', 'title' => __('Post Type', 'wck'), 'options' => $post_type_names, 'default-option' => true, 'description' => __('What post type the meta box should be attached to', 'wck'), 'required' => true), array('type' => 'select', 'title' => __('Repeater', 'wck'), 'options' => array('false', 'true'), 'default' => 'false', 'description' => __('Whether the box supports just one entry or if it is a repeater field. By default it is a single field.', 'wck')), array('type' => 'select', 'title' => __('Sortable', 'wck'), 'options' => array('true', 'false'), 'default' => 'false', 'description' => __('Whether the entries are sortable or not. This is valid for repeater fields.', 'wck')), array('type' => 'text', 'title' => __('Post ID', 'wck'), 'description' => __('ID of a post on which the meta box should appear. You can also input multiple IDs and separate them with ","', 'wck')));
    /* only in pro version */
    if (function_exists('wck_nr_add_repeater_boxes')) {
        $nested_arg = array(array('type' => 'select', 'title' => __('Nested', 'wck'), 'options' => array('true', 'false'), 'default' => 'false', 'description' => __('Set to true if you want this metabox to be a nested repeater inside another repeater.', 'wck')));
        array_splice($cfc_box_args_fields, 1, 0, $nested_arg);
    }
    if (!empty($templates)) {
        $cfc_box_args_fields[] = array('type' => 'select', 'title' => __('Page Template', 'wck'), 'options' => $templates, 'default-option' => true, 'description' => __('If post type is "page" you can further select a page templete. The meta box will only appear  on the page that has that selected page template.', 'wck'));
    }
    /* set up the box arguments */
    $args = array('metabox_id' => 'wck-cfc-args', 'metabox_title' => __('Meta Box Arguments', 'wck'), 'post_type' => 'wck-meta-box', 'meta_name' => 'wck_cfc_args', 'meta_array' => $cfc_box_args_fields, 'sortable' => false, 'single' => true);
    /* create the box */
    new Wordpress_Creation_Kit($args);
    /* set up field types */
    $field_types = array('text', 'textarea', 'select', 'checkbox', 'radio', 'upload', 'wysiwyg editor', 'datepicker', 'country select', 'user select', 'cpt select');
    $field_types = apply_filters('wck_field_types', $field_types);
    /* setup post types */
    $post_types = get_post_types(array('public' => true), 'names');
    /* set up the fields array */
    $cfc_box_fields_fields = apply_filters('wck_cfc_box_fields_fields', array(array('type' => 'text', 'title' => __('Field Title', 'wck'), 'description' => __('Title of the field. A slug will automatically be generated.', 'wck'), 'required' => true), array('type' => 'select', 'title' => __('Field Type', 'wck'), 'options' => $field_types, 'default-option' => true, 'description' => __('The field type', 'wck'), 'required' => true), array('type' => 'textarea', 'title' => __('Description', 'wck'), 'description' => 'The description of the field.'), array('type' => 'select', 'title' => __('Required', 'wck'), 'options' => array('false', 'true'), 'default' => 'false', 'description' => __('Whether the field is required or not', 'wck')), array('type' => 'select', 'title' => __('CPT', 'wck'), 'options' => $post_types, 'default' => 'post', 'description' => __('Select what custom post type should be used in the CPT Select.', 'wck')), array('type' => 'text', 'title' => __('Default Value', 'wck'), 'description' => __('Default value of the field. For Checkboxes if there are multiple values separate them with a ",". For an Upload field input an attachment id.', 'wck')), array('type' => 'text', 'title' => __('Options', 'wck'), 'description' => __('Options for field types "select", "checkbox" and "radio". For multiple options separate them with a ",". You can use the following structure if you want the label to be different from the value: %LabelOne%valueone,%LabelTwo%valuetwo,%LabelThree%valuethree', 'wck')), array('type' => 'checkbox', 'title' => __('Attach upload to post', 'wck'), 'description' => __('Uploads will be attached to the post if this is checked', 'wck'), 'options' => array('yes'), 'default' => 'yes')));
    /* set up the box arguments */
    $args = array('metabox_id' => 'wck-cfc-fields', 'metabox_title' => __('Meta Box Fields', 'wck'), 'post_type' => 'wck-meta-box', 'meta_name' => 'wck_cfc_fields', 'meta_array' => $cfc_box_fields_fields);
    /* create the box */
    new Wordpress_Creation_Kit($args);
}