__('Custom Types', 'customizing'), 'singular_name' => __('Custom Type', 'customizing'), 'add_new_item' => __('Add New Custom Type', 'customizing'), 'edit_item' => __('Edit Custom Type', 'customizing'), 'new_item' => __('New Custom Type', 'customizing'), 'view_item' => __('View Custom Type', 'customizing'), 'view_items' => __('View Custom Types', 'customizing'), 'search_items' => __('Search Custom Types', 'customizing'), 'not_found' => __('No custom types found.', 'customizing'), 'not_found_in_trash' => __('No custom types found in trash.', 'customizing'), 'all_items' => __('All Custom Types', 'customizing'), ); $args=array( 'labels' => $labels, 'description' => __('Custom Post Types', 'customizing'), 'public' => false, 'show_ui' => true, 'show_in_menu' => 'customizing', 'supports' => array('title'), ); register_post_type('cff-custom-type', $args); } if(current_user_can('manage_options')) add_action('cff-init', 'cff_custom_types'); /** @brief Inits the custom types interface fields. @since 1.0.0 */ function cff_custom_types_fields() { $fields=array( array( 'id' => 'cff-singular-name', 'label' => __('Singular Name', 'customizing'), 'type' => 'text', 'oninput' => 'cff_slugify_sibling(this, ".cff-slug-field")', 'placeholder' => __('Post/ Page', 'customizing'), 'description' => __('Name for one object of this post type.', 'customizing'), 'span' => 50, ), array( 'id' => 'cff-slug', 'label' => __('Slug', 'customizing'), 'type' => 'text', 'pattern' => '[a-z][a-z0-9-]{0,19}', 'oninput' => 'cff_slugify_self(this)', 'classes' => 'cff-slug-field', 'required' => true, 'description' => __('Max 20 English characters, cannot contain capital letters, underscores or spaces.', 'customizing'), 'span' => 50 ), array( 'id' => 'cff-capability-type', 'label' => __('Capability Type', 'customizing'), 'type' => 'text', 'pattern' => '[a-z][a-z0-9-]{0,19}', 'oninput' => 'cff_slugify_self(this)', 'placeholder' => __('post', 'customizing'), 'description' => __('The string to use to build the read, edit, and delete capabilities.', 'customizing'), 'span' => 50 ), array( 'id' => 'cff-capability-type-plural', 'label' => __('Capability Type Plural', 'customizing'), 'type' => 'text', 'pattern' => '[a-z][a-z0-9-]{0,19}', 'oninput' => 'cff_slugify_self(this)', 'placeholder' => __('posts', 'customizing'), 'description' => __('The string to use to build all capabilities in the plural.', 'customizing'), 'span' => 50 ), array( 'id' => 'cff-description', 'label' => __('Description', 'customizing'), 'type' => 'textarea', 'description' => __('A short descriptive summary for the post type.', 'customizing'), 'span' => 100, ), ); $custom_box=array( 'id' => 'details', 'title' => __('Details', 'customizing'), 'type' => 'cff-custom-type', 'fields' => $fields, ); cff_add_meta_box($custom_box); $fields=array( array( 'id' => 'cff-add-new', 'label' => __('Add New', 'customizing'), 'type' => 'text', 'placeholder' => __('Add New', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-add-new-item', 'label' => __('Add New Item', 'customizing'), 'type' => 'text', 'placeholder' => __('Add New Post/ Page', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-edit-item', 'label' => __('Edit Item', 'customizing'), 'type' => 'text', 'placeholder' => __('Edit Post/ Page', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-new-item', 'label' => __('New Item', 'customizing'), 'type' => 'text', 'placeholder' => __('New Post/ Page', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-view-item', 'label' => __('View Item', 'customizing'), 'type' => 'text', 'placeholder' => __('View Post/ Page', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-view-items', 'label' => __('View Items', 'customizing'), 'type' => 'text', 'placeholder' => __('View Posts/ Pages', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-search-items', 'label' => __('Search Items', 'customizing'), 'type' => 'text', 'placeholder' => __('Search Posts/ Pages', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-not-found', 'label' => __('Not Found', 'customizing'), 'type' => 'text', 'placeholder' => __('No posts/ pages found', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-not-found-in-trash', 'label' => __('Not Found in Trash', 'customizing'), 'type' => 'text', 'placeholder' => __('No posts/ pages found in trash', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-parent-item-colon', 'label' => __('Parent Item Colon', 'customizing'), 'type' => 'text', 'placeholder' => __('Parent Page:', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-all-items', 'label' => __('All Items', 'customizing'), 'type' => 'text', 'placeholder' => __('All Posts/ Pages', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-archives', 'label' => __('Archives', 'customizing'), 'type' => 'text', 'placeholder' => __('Post/ Page Archives', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-attributes', 'label' => __('Attributes', 'customizing'), 'type' => 'text', 'placeholder' => __('Post/ Page Attributes', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-insert-into-item', 'label' => __('Insert into Item', 'customizing'), 'type' => 'text', 'placeholder' => __('Insert into Post/ Page', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-uploaded-to-this-item', 'label' => __('Uploaded to this Item', 'customizing'), 'type' => 'text', 'placeholder' => __('Uploaded to this post/ page', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-featured-image', 'label' => __('Featured Image', 'customizing'), 'type' => 'text', 'placeholder' => __('Featured Image', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-set-featured-image', 'label' => __('Set Featured Image', 'customizing'), 'type' => 'text', 'placeholder' => __('Set Featured Image', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-remove-featured-image', 'label' => __('Remove Featured Image', 'customizing'), 'type' => 'text', 'placeholder' => __('Remove Featured Image', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-use-featured-image', 'label' => __('Use Featured Image', 'customizing'), 'type' => 'text', 'placeholder' => __('Use Featured Image', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-menu-name', 'label' => __('Menu Name', 'customizing'), 'type' => 'text', 'placeholder' => __('Posts/ Pages', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-filter-items-list', 'label' => __('Filter Items List', 'customizing'), 'type' => 'text', 'placeholder' => __('Filter Posts List', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-items-list-navigation', 'label' => __('Items List Navigation', 'customizing'), 'type' => 'text', 'placeholder' => __('Posts List Navigation', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-items-list', 'label' => __('Items List', 'customizing'), 'type' => 'text', 'placeholder' => __('Posts List', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-name-admin-bar', 'label' => __('Name Admin Bar', 'customizing'), 'type' => 'text', 'placeholder' => __('Post/ Page', 'customizing'), 'span' => 25, ), ); $custom_box=array( 'id' => 'labels', 'title' => __('Labels', 'customizing'), 'type' => 'cff-custom-type', 'fields' => $fields, ); cff_add_meta_box($custom_box); global $menu; $options=array(); $options['true']=__('Show as a Top Level Menu', 'customizing'); foreach($menu as $details) if($details[0]) $options[$details[2]]=__('Show as a Submenu of ', 'customizing').explode('"', $details[0])[0]; $options['false']=__('Don\'t Show in the Menu', 'customizing'); $menu_icons=cff_get_menu_icons(); $fields=array( array( 'id' => 'cff-public', 'label' => __('Public', 'customizing'), 'type' => 'checkbox', 'value' => true, 'description' => __('Controls how the type is visible to authors and readers.', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-exclude-from-search', 'label' => __('Exclude from Search', 'customizing'), 'type' => 'checkbox', 'description' => __('Whether to exclude posts with this post type from front end search results.', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-publicly-queryable', 'label' => __('Publicly Queryable', 'customizing'), 'type' => 'checkbox', 'value' => true, 'description' => __('Whether queries can be performed on the front end for this post type.', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-show-ui', 'label' => __('Show User Interface', 'customizing'), 'type' => 'checkbox', 'value' => true, 'description' => __('Whether to generate a default UI for managing this post type in the admin.', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-show-in-nav-menus', 'label' => __('Show in Navigation Menus', 'customizing'), 'type' => 'checkbox', 'value' => true, 'description' => __('Whether this post type is available for selection in navigation menus.', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-show-in-menu', 'label' => __('Show in Menu', 'customizing'), 'type' => 'select', 'options' => $options, 'value' => 'true', 'description' => __('Where to show the post type in the admin menu. "Show User Interface" must be checked.', 'customizing'), 'span' => 50, ), array( 'id' => 'cff-show-in-admin-bar', 'label' => __('Show in Admin Bar', 'customizing'), 'type' => 'checkbox', 'value' => true, 'description' => __('Whether to make this post type available in the WordPress admin bar.', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-menu-position', 'label' => __('Menu Position', 'customizing'), 'type' => 'select', 'options' => array( 5 => __('Below Posts', 'customizing'), 10 => __('Below Media', 'customizing'), 15 => __('Below Links', 'customizing'), 20 => __('Below Pages', 'customizing'), 25 => __('Below Comments', 'customizing'), 60 => __('Below First Separator', 'customizing'), 65 => __('Below Plugins', 'customizing'), 70 => __('Below Users', 'customizing'), 75 => __('Below Tools', 'customizing'), 80 => __('Below Settings', 'customizing'), 100 => __('Below Second Separator', 'customizing'), ), 'value' => 25, 'description' => __('The position in the menu order this post type should appear. '. '"Show as a Top Level Menu" must be selected in "Show in Menu".', 'customizing'), 'span' => 50, ), array( 'id' => 'cff-menu-icon', 'label' => __('Menu Icon', 'customizing'), 'type' => 'options', 'options' => $menu_icons, 'value' => 'dashicons-admin-post', 'classes' => 'cff-dashicons-field', 'description' => __('The url to the icon to be used for this menu or the name of the icon from the iconfont.', 'customizing'), 'span' => 100, ), array( 'id' => 'cff-hierarchical', 'label' => __('Hierarchical', 'customizing'), 'type' => 'checkbox', 'description' => __('Whether the post type is hierarchical (e.g. page).', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-has-archive', 'label' => __('Has Archive', 'customizing'), 'type' => 'checkbox', 'description' => __('Enables post type archives.', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-can-export', 'label' => __('Can Export', 'customizing'), 'type' => 'checkbox', 'value' => true, 'description' => __('Can this post type be exported.', 'customizing'), 'span' => 25, ), array( 'id' => 'cff-show-in-rest', 'label' => __('Show in REST', 'customizing'), 'type' => 'checkbox', 'description' => __('Whether to expose this post type in the REST API.', 'customizing'), 'span' => 25, ), ); $custom_box=array( 'id' => 'options', 'title' => __('Options', 'customizing'), 'type' => 'cff-custom-type', 'fields' => $fields, ); cff_add_meta_box($custom_box); $fields=array( array( 'id' => 'cff-supports', //'label' => __('Supports', 'customizing'), 'type' => 'options', 'options' => array( 'title' => __('Title', 'customizing'), 'editor' => __('Content Editor', 'customizing'), 'author' => __('Author', 'customizing'), 'thumbnail' => __('Featured Image', 'customizing'), 'excerpt' => __('Excerpt', 'customizing'), 'trackbacks' => __('Trackbacks', 'customizing'), 'custom-fields' => __('Custom Fields', 'customizing'), 'comments' => __('Comments', 'customizing'), 'revisions' => __('Revisions', 'customizing'), 'page-attributes' => __('Page Attributes', 'customizing'), 'post-formats' => __('Post Formats', 'customizing'), ), 'value' => array('title', 'editor'), 'multiple' => true, 'description' => __('Basic WordPress editing fields.', 'customizing'), 'span' => 100, ), ); $custom_box=array( 'id' => 'supports', 'title' => __('Supports', 'customizing'), 'type' => 'cff-custom-type', 'fields' => $fields, 'context' => 'side', ); cff_add_meta_box($custom_box); $taxonomies=get_taxonomies(array('public' => true), 'objects'); foreach($taxonomies as $key => $value) $taxonomies[$key]=$value->label; $fields=array( array( 'id' => 'cff-taxonomies', //'label' => __('Taxonomies', 'customizing'), 'type' => 'options', 'options' => $taxonomies, 'multiple' => true, 'description' => __('Taxonomies associated with this post type.', 'customizing'), 'span' => 100, ), ); $custom_box=array( 'id' => 'taxonomies', 'title' => __('Taxonomies', 'customizing'), 'type' => 'cff-custom-type', 'fields' => $fields, 'context' => 'side', ); cff_add_meta_box($custom_box); } if(current_user_can('manage_options')) add_action('admin_init', 'cff_custom_types_fields'); /** @brief Inits the custom types from the database. @since 1.0.0 */ function cff_add_custom_types() { $custom_types=get_posts(array('post_type' => 'cff-custom-type')); foreach($custom_types as $custom_type) { $data=cff_get_post_meta($custom_type->ID); //var_dump($data); $slug=$data['cff-slug']; $indexes=array( 'singular_name' => 'cff-singular-name', 'add_new' => 'cff-add-new', 'add_new_item' => 'cff-add-new-item', 'edit_item' => 'cff-edit-item', 'new_item' => 'cff-new-item', 'view_item' => 'cff-view-item', 'view_items' => 'cff-view-items', 'search_items' => 'cff-search-items', 'not_found' => 'cff-not-found', 'not_found_in_trash' => 'cff-not-found-in-trash', 'parent_item_colon' => 'cff-parent-item-colon', 'all_items' => 'cff-all-items', 'archives' => 'cff-archives', 'attributes' => 'cff-attributes', 'insert_into_item' => 'cff-insert-into-item', 'uploaded_to_this_item' => 'cff-uploaded-to-this-item', 'featured_image' => 'cff-featured-image', 'set_featured_image' => 'cff-set-featured-image', 'remove_featured_image' => 'cff-remove-featured-image', 'use_featured_image' => 'cff-use-featured-image', 'menu_name' => 'cff-menu-name', 'filter_items_list' => 'cff-filter-items-list', 'items_list_navigation' => 'cff-items-list-navigation', 'items_list' => 'cff-items-list', 'name_admin_bar' => 'cff-name-admin-bar', ); $labels=array(); $labels['name']=$custom_type->post_title; foreach($indexes as $key => $value) if($data[$value]) $labels[$key]=$data[$value]; $args=array(); $args['labels']=$labels; $args['description']=$data['cff-description']; $args['public']=(bool)$data['cff-public']; $args['exclude_from_search']=(bool)$data['cff-exclude-from-search']; $args['publicly_queryable']=(bool)$data['cff-publicly-queryable']; $args['show_ui']=(bool)$data['cff-show-ui']; $args['show_in_nav_menus']=(bool)$data['cff-show-in-nav-menus']; $show_in_menu=$data['cff-show-in-menu']; if($show_in_menu==='true') $show_in_menu=true; if($show_in_menu==='false') $show_in_menu=false; $args['show_in_menu']=$show_in_menu; $args['show_in_admin_bar']=(bool)$data['cff-show-in-admin-bar']; $args['menu_position']=(int)$data['cff-menu-position']; $menu_icon=$data['cff-menu-icon']; if(!$menu_icon) $menu_icon=null; $args['menu_icon']=$menu_icon; $capability_type=$data['cff-capability-type']; if($capability_type) { $capability_type_plural=$data['cff-capability-type-plural']; if(!$capability_type_plural) $capability_type_plural=$capability_type.'s'; $args['capability_type']=array( $capability_type, $capability_type_plural ); $args['map_meta_cap']=true; } $args['hierarchical']=(bool)$data['cff-hierarchical']; $supports=$data['cff-supports']; if(!$supports) $supports=false; $args['supports']=$supports; $args['has_archive']=(bool)$data['cff-has-archive']; $args['can_export']=(bool)$data['cff-can-export']; $args['show_in_rest']=(bool)$data['cff-show-in-rest']; $args['taxonomies']=$data['cff-taxonomies']; register_post_type($slug, $args); } } add_action('cff-init', 'cff_add_custom_types'); ?>