<?php
namespace Elementor\LearnDash;

defined('ABSPATH') || exit;

class WKFE_PRO_LD_CPT {
    public function __construct() {
        add_action('init',[$this,'ld_post_type'],0);
        add_action('admin_menu',[$this,'cpt_admin_menu']);
    }
    
    public function ld_post_type() {
        $labels = array(
            'name'                  => _x( 'Learndash Templates', 'Post type general name', 'widgetkit-pro' ),
            'singular_name'         => _x( 'Learndash Template', 'Post type singular name', 'widgetkit-pro' ),
            'menu_name'             => _x( 'Learndash Templates', 'Admin Menu text', 'widgetkit-pro' ),
            'name_admin_bar'        => _x( 'Learndash Template', 'Add New on Toolbar', 'widgetkit-pro' ),
            'add_new'               => __( 'Add New', 'widgetkit-pro' ),
            'add_new_item'          => __( 'Add New Learndash Template', 'widgetkit-pro' ),
            'new_item'              => __( 'New Learndash Template', 'widgetkit-pro' ),
            'edit_item'             => __( 'Edit Learndash Template', 'widgetkit-pro' ),
            'view_item'             => __( 'View Learndash Template', 'widgetkit-pro' ),
            'all_items'             => __( 'All Learndash Templates', 'widgetkit-pro' ),
            'search_items'          => __( 'Search Learndash Templates', 'widgetkit-pro' ),
            'parent_item_colon'     => __( 'Parent Learndash Templates:', 'widgetkit-pro' ),
            'not_found'             => __( 'No Learndash Templates found.', 'widgetkit-pro' ),
            'not_found_in_trash'    => __( 'No Learndash Templates found in Trash.', 'widgetkit-pro' )
        );
     
        $args = array(
            'labels'             => $labels,
            'public'             => true,
            'publicly_queryable' => true,
            'show_in_menu'        => false,
            'show_in_nav_menus'   => false,
            'exclude_from_search' => true,
            'query_var'          => true,
            'rewrite'            => array( 'slug' => 'wkfe-ld-template' ),
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'supports'           => array( 'title','elementor' ),
        );
     
        register_post_type( 'wkfe-ld-template', $args );

        flush_rewrite_rules();
    }

    public function cpt_admin_menu() {
        if( class_exists('SFWD_LMS') ) {
            add_submenu_page('widgetkit-settings', esc_html__('Learndash Templates', 'widgetkit-pro'), esc_html__('Learndash Templates', 'widgetkit-pro'), 'manage_options', 'edit.php?post_type=wkfe-ld-template');
        }
    }
}

new WKFE_PRO_LD_CPT();