d_new_item' => esc_html_x( 'Add New Template', 'Template Library', 'templately' ),
'edit_item' => esc_html_x( 'Edit Template', 'Template Library', 'templately' ),
'new_item' => esc_html_x( 'New Template', 'Template Library', 'templately' ),
'all_items' => esc_html_x( 'All Templates', 'Template Library', 'templately' ),
'view_item' => esc_html_x( 'View Template', 'Template Library', 'templately' ),
'search_items' => esc_html_x( 'Search Template', 'Template Library', 'templately' ),
'not_found' => esc_html_x( 'No Templates found', 'Template Library', 'templately' ),
'not_found_in_trash' => esc_html_x( 'No Templates found in Trash', 'Template Library', 'templately' ),
'parent_item_colon' => '',
'menu_name' => esc_html_x( 'Templates', 'Template Library', 'templately' ),
];
$args = [
'labels' => $labels,
'public' => true,
'rewrite' => false,
'menu_icon' => 'dashicons-admin-page',
'show_ui' => true,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'exclude_from_search' => true,
'capability_type' => 'post',
'hierarchical' => false,
'show_in_rest' => true,
'supports' => [ 'title', 'thumbnail', 'author', 'editor', 'elementor' ],
];
/**
* Register template library post type args.
*
* @param array $args Arguments for registering a post type.
*/
$this->post_type_object = register_post_type( self::CPT, $args );
}
/**
* Tab menu
*
* @param $tabs
*
* @return void
*/
public function admin_print_tabs( $tabs ) {
$types = templately()->theme_builder::$templates_manager->get_template_types();
$template_types = [];
$status_args = [ 'post_type' => 'templately_library' ];
$template_types['all'] = [
'url' => add_query_arg( $status_args, 'edit.php' ),
'label' => __( 'All', 'templately' )
];
foreach ( $types as $type_name => $type ) {
if( $type::get_property( 'builder' ) === false ) {
continue;
}
$status_args['type'] = $type_name;
$template_types[ $type_name ] = [
'url' => add_query_arg( $status_args, 'edit.php' ),
'label' => call_user_func( [ $type, 'get_title' ] )
];
}
$this->builder::$views->get( 'builder/tabs', [ 'tabs' => $tabs, 'template_types' => $template_types ] );
}
/**
* Retrieves items.
*
* @param array $args
*
* @return array
*/
public function get_items( array $args = [] ): array {
$template_types = [];
if ( ! empty( $args['type'] ) ) {
$template_types = $args['type'];
unset( $args['type'] );
}
$defaults_args = [
'post_type' => self::CPT,
'post_status' => 'publish',
'posts_per_page' => - 1,
'orderby' => 'title',
'order' => 'ASC',
];
if ( ! empty( $template_types ) ) {
$defaults_args['meta_query'] = [
[
'key' => self::TYPE_META_KEY,
'value' => $template_types,
]
];
}
$args = wp_parse_args( $args, $defaults_args );
$items = new WP_Query( $args );
return $items->posts;
}
}