Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if( have_rows('custom_post_types', 'option') ):
- while( have_rows('custom_post_types', 'option') ) : the_row();
- // ACF Custom Label Declarations
- $cpt_name_plural = '"name" => ' . esc_html__( '"' . get_sub_field('cpt_name_plural') . '"' );
- $cpt_name_single = '"singular_name" => ' . esc_html__( '"' . get_sub_field('cpt_name_single') . '"' );
- $cpt_label_add_new = '"add_new" => ' . esc_html__( '"' . get_sub_field('cpt_label_add_new') . '"' );
- $cpt_label_add_new_item = '"add_new_item" => ' . esc_html__( '"' . get_sub_field('cpt_label_add_new_item') . '"' );
- $cpt_label_edit_item = '"edit_item" => ' . esc_html__( '"' . get_sub_field('cpt_label_edit_item') . '"' );
- $cpt_label_new_item = '"new_item" => ' . esc_html__( '"' . get_sub_field('cpt_label_new_item') . '"' );
- $cpt_label_view_item = '"view_item" => ' . esc_html__( '"' . get_sub_field('cpt_label_view_item') . '"' );
- $cpt_label_search_items = '"search_items" => ' . esc_html__( '"' . get_sub_field('cpt_label_search_items') . '"' );
- $cpt_label_not_found = '"not_found" => ' . esc_html__( '"' . get_sub_field('cpt_label_not_found') . '"' );
- $cpt_label_not_found_in_trash = '"not_found_in_trash" => ' . esc_html__( '"' . get_sub_field('cpt_label_not_found_in_trash') . '"' );
- $cpt_label_parent_item_colon = '"parent_item_colon" => ' . esc_html__( '"' . get_sub_field('cpt_label_parent_item_colon') . '"' );
- $cpt_label_all_items = '"all_items" => ' . esc_html__( '"' . get_sub_field('cpt_label_all_items') . '"' );
- $cpt_label_archives = '"archives" => ' . esc_html__( '"' . get_sub_field('cpt_label_archives') . '"' );
- $cpt_label_attributes = '"attributes" => ' . esc_html__( '"' . get_sub_field('cpt_label_attributes') . '"' );
- $cpt_label_insert_into_item = '"insert_into_item" => ' . esc_html__( '"' . get_sub_field('cpt_label_insert_into_item') . '"' );
- $cpt_label_uploaded_to_this_item = '"uploaded_to_this_item" => ' . esc_html__( '"' . get_sub_field('cpt_label_uploaded_to_this_item') . '"' );
- $cpt_label_featured_image = '"featured_image" => ' . esc_html__( '"' . get_sub_field('cpt_label_featured_image') . '"' );
- $cpt_label_set_featured_image = '"set_featured_image" => ' . esc_html__( '"' . get_sub_field('cpt_label_set_featured_image') . '"' );
- $cpt_label_remove_featured_image = '"remove_featured_image" => ' . esc_html__( '"' . get_sub_field('cpt_label_remove_featured_image') . '"' );
- $cpt_label_use_featured_image = '"use_featured_image" => ' . esc_html__( '"' . get_sub_field('cpt_label_use_featured_image') . '"' );
- $cpt_label_menu_name = '"menu_name" => ' . esc_html__( '"' . get_sub_field('cpt_label_menu_name') . '"' );
- $cpt_label_filter_items_list = '"filter_items_list" => ' . esc_html__( '"' . get_sub_field('cpt_label_filter_items_list') . '"' );
- $cpt_label_filter_by_date = '"filter_by_date" => ' . esc_html__( '"' . get_sub_field('cpt_label_filter_by_date') . '"' );
- $cpt_label_items_list_navigation = '"items_list_navigation" => ' . esc_html__( '"' . get_sub_field('cpt_label_items_list_navigation') . '"' );
- $cpt_label_items_list = '"items_list" => ' . esc_html__( '"' . get_sub_field('cpt_label_items_list') . '"' );
- $cpt_label_item_published = '"item_published" => ' . esc_html__( '"' . get_sub_field('cpt_label_item_published') . '"' );
- $cpt_label_item_published_privately = '"item_published_privately" => ' . esc_html__( '"' . get_sub_field('cpt_label_item_published_privately') . '"' );
- $cpt_label_item_reverted_to_draft = '"item_reverted_to_draft" => ' . esc_html__( '"' . get_sub_field('cpt_label_item_reverted_to_draft') . '"' );
- $cpt_label_item_scheduled = '"item_scheduled" => ' . esc_html__( '"' . get_sub_field('cpt_label_item_scheduled') . '"' );
- $cpt_label_item_updated = '"item_updated" => ' . esc_html__( '"' . get_sub_field('cpt_label_item_updated') . '"' );
- $cpt_label_item_link = '"item_link" => ' . esc_html__( '"' . get_sub_field('cpt_label_item_link') . '"' );
- $cpt_label_item_link_description = '"item_link_description" => ' . esc_html__( '"' . get_sub_field('cpt_label_item_link_description') . '"' );
- // ACF Custom Args Declarations
- $arg_label = '"label" => "' . get_sub_field('cpt_name_plural') . '"';
- $arg_description = '"description" => "' . get_sub_field('cpt_description') . '"';
- $arg_has_archive = '"has_archive" => ' . get_sub_field('cpt_archive_page_requirement');
- $arg_exclude_from_search = '"exclude_from_search" => ' . get_sub_field('cpt_search_results');
- $arg_rewrite_slug = '"rewrite" => [ "slug" => "' . get_sub_field('cpt_slug') . '", "with_front" => true ]';
- $arg_menu_position = '"menu_position" => ' . get_sub_field('cpt_menu_position');
- $arg_menu_icon = '"menu_icon" => "' . get_sub_field('cpt_dashicon') . '"';
- // ACF Custom Args Declarations
- $register_slug = '"' . get_sub_field('cpt_slug') . '"';
- // Start the Custom Fields Loop
- function register_my_cpts() {
- if( get_sub_field('cpt_custom_labels') ):
- $labels = [
- $cpt_name_plural,
- $cpt_name_single,
- $cpt_label_add_new,
- $cpt_label_add_new_item,
- $cpt_label_edit_item,
- $cpt_label_new_item,
- $cpt_label_view_item,
- $cpt_label_search_items,
- $cpt_label_not_found,
- $cpt_label_not_found_in_trash,
- $cpt_label_parent_item_colon,
- $cpt_label_all_items,
- $cpt_label_archives,
- $cpt_label_attributes,
- $cpt_label_insert_into_item,
- $cpt_label_uploaded_to_this_item,
- $cpt_label_featured_image,
- $cpt_label_set_featured_image,
- $cpt_label_remove_featured_image,
- $cpt_label_use_featured_image,
- $cpt_label_menu_name,
- $cpt_label_filter_items_list,
- $cpt_label_filter_by_date,
- $cpt_label_items_list_navigation,
- $cpt_label_items_list,
- $cpt_label_item_published,
- $cpt_label_item_published_privately,
- $cpt_label_item_reverted_to_draft,
- $cpt_label_item_scheduled,
- $cpt_label_item_updated,
- $cpt_label_item_link,
- $cpt_label_item_link_description,
- ];
- else:
- $labels = [
- "name" => esc_html__( "name" ),
- "singular_name" => esc_html__( "singular_name" ),
- "add_new" => esc_html__( "add_new" ),
- "add_new_item" => esc_html__( "add_new_item" ),
- "edit_item" => esc_html__( "edit_item" ),
- "new_item" => esc_html__( "new_item" ),
- "view_item" => esc_html__( "view_item" ),
- "search_items" => esc_html__( "search_items" ),
- "not_found" => esc_html__( "not_found" ),
- "not_found_in_trash" => esc_html__( "not_found_in_trash" ),
- "parent_item_colon" => esc_html__( "parent_item_colon" ),
- "all_items" => esc_html__( "all_items" ),
- "archives" => esc_html__( "archives" ),
- "attributes" => esc_html__( "attributes" ),
- "insert_into_item" => esc_html__("insert_into_item" ),
- "uploaded_to_this_item" => esc_html__( "uploaded_to_this_item" ),
- "featured_image" => esc_html__( "featured_image" ),
- "set_featured_image" => esc_html__( "set_featured_image" ),
- "remove_featured_image" => esc_html__( "remove_featured_image" ),
- "use_featured_image" => esc_html__( "use_featured_image" ),
- "menu_name" => esc_html__( "menu_name" ),
- "filter_items_list" => esc_html__( "filter_items_list" ),
- "filter_by_date" => esc_html__( "filter_by_date" ),
- "items_list_navigation" => esc_html__( "items_list_navigation" ),
- "items_list" => esc_html__( "items_list" ),
- "item_published" => esc_html__( "item_published" ),
- "item_published_privately" => esc_html__( "item_published_privately" ),
- "item_reverted_to_draft" => esc_html__( "item_reverted_to_draft" ),
- "item_scheduled" => esc_html__( "item_scheduled" ),
- "item_updated" => esc_html__( "item_updated" ),
- "item_link" => esc_html__( "item_link" ),
- "item_link_description" => esc_html__( "item_link_description" ),
- ];
- endif;
- $args = [
- $arg_label,
- "labels" => $labels,
- $arg_description,
- "public" => true,
- "publicly_queryable" => true,
- "show_ui" => true,
- "show_in_rest" => true,
- "rest_base" => "",
- "rest_controller_class" => "WP_REST_Posts_Controller",
- "rest_namespace" => "wp/v2",
- $arg_has_archive,
- "show_in_menu" => true,
- "show_in_nav_menus" => true,
- "delete_with_user" => false,
- $arg_exclude_from_search,
- "capability_type" => "post",
- "map_meta_cap" => true,
- "hierarchical" => false,
- "can_export" => false,
- $arg_rewrite_slug,
- "query_var" => true,
- $arg_menu_position,
- $arg_menu_icon,
- "supports" => [ "title", "editor" ],
- "show_in_graphql" => false,
- ];
- register_post_type( $register_slug, $args );
- }
- add_action( 'init', 'register_my_cpts' );
- endwhile;
- endif;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement