wpr-conditions-manager.php
5 days ago
wpr-editor-hooks.php
5 days ago
wpr-render-templates.php
5 days ago
wpr-templates-actions.php
5 days ago
wpr-templates-category-filter.php
5 days ago
wpr-templates-library.php
5 days ago
wpr-templates-loop.php
5 days ago
wpr-templates-modal-popups.php
5 days ago
wpr-templates-shortcode.php
5 days ago
wpr-templates-library.php
138 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly. |
| 5 | } |
| 6 | |
| 7 | use WprAddons\Admin\Includes\WPR_Render_Templates; |
| 8 | use WprAddons\Admin\Includes\WPR_Templates_Shortcode; |
| 9 | use WprAddons\Admin\Includes\WPR_Templates_Modal_Popups; |
| 10 | use WprAddons\Admin\Includes\WPR_Templates_Actions; |
| 11 | use WprAddons\Admin\Templates\Library\WPR_Templates_Library_Blocks; |
| 12 | use WprAddons\Admin\Templates\Library\WPR_Templates_Library_Sections; |
| 13 | use WprAddons\Admin\Templates\Library\WPR_Templates_Library_Pages; |
| 14 | use WprAddons\Admin\Templates\Library\WPR_Templates_Library_Popups; |
| 15 | use WprAddons\Classes\Utilities; |
| 16 | |
| 17 | /** |
| 18 | * WPR_Templates_Library setup |
| 19 | * |
| 20 | * @since 1.0 |
| 21 | */ |
| 22 | class WPR_Templates_Library { |
| 23 | |
| 24 | /** |
| 25 | ** Constructor |
| 26 | */ |
| 27 | public function __construct() { |
| 28 | |
| 29 | // Register CPTs |
| 30 | add_action( 'init', [ $this, 'register_templates_library_cpt' ] ); |
| 31 | add_action( 'template_redirect', [ $this, 'block_template_frontend' ] ); |
| 32 | add_action( 'current_screen', [ $this, 'redirect_to_options_page' ] ); |
| 33 | |
| 34 | // Templates Shortcode |
| 35 | new WPR_Templates_Shortcode(); |
| 36 | |
| 37 | // Init Popups |
| 38 | new WPR_Templates_Modal_Popups(); |
| 39 | |
| 40 | // Init Theme Builder |
| 41 | new WPR_Render_Templates(); |
| 42 | |
| 43 | // Template Actions |
| 44 | new WPR_Templates_Actions(); |
| 45 | |
| 46 | // Add Blocks to Library |
| 47 | new WPR_Templates_Library_Blocks(); |
| 48 | |
| 49 | // Add Sections to Library |
| 50 | new WPR_Templates_Library_Sections(); |
| 51 | |
| 52 | // Add Pages to Library |
| 53 | new WPR_Templates_Library_Pages(); |
| 54 | |
| 55 | // Add Popups to Library |
| 56 | new WPR_Templates_Library_Popups(); |
| 57 | |
| 58 | // Enable Elementor for 'wpr_templates' |
| 59 | $this->add_elementor_cpt_support(); |
| 60 | |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | ** Register Templates Library |
| 65 | */ |
| 66 | public function redirect_to_options_page() { |
| 67 | if ( get_current_screen()->post_type == 'wpr_templates' && isset($_GET['action']) && $_GET['action'] == 'edit' ) { |
| 68 | $elementor_template_type = isset($_GET['post']) ? sanitize_text_field(wp_unslash($_GET['post'])) : ''; |
| 69 | |
| 70 | if ( 'wpr-popups' === Utilities::get_elementor_template_type( $elementor_template_type ) ) { |
| 71 | wp_redirect('admin.php?page=wpr-popups'); |
| 72 | } else { |
| 73 | wp_redirect('admin.php?page=wpr-theme-builder'); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public function register_templates_library_cpt() { |
| 79 | |
| 80 | $args = array( |
| 81 | 'label' => esc_html__( 'Royal Templates', 'wpr-addons' ), |
| 82 | 'public' => true, |
| 83 | 'rewrite' => false, |
| 84 | 'show_ui' => true, |
| 85 | 'show_in_menu' => false, |
| 86 | 'show_in_nav_menus' => false, |
| 87 | 'exclude_from_search' => true, |
| 88 | 'capability_type' => 'post', |
| 89 | 'hierarchical' => false, |
| 90 | ); |
| 91 | |
| 92 | register_post_type( 'wpr_templates', $args ); |
| 93 | |
| 94 | $tax_args = [ |
| 95 | 'hierarchical' => true, |
| 96 | 'show_ui' => true, |
| 97 | 'show_in_nav_menus' => false, |
| 98 | 'show_admin_column' => true, |
| 99 | 'query_var' => is_admin(), |
| 100 | 'rewrite' => false, |
| 101 | 'public' => false, |
| 102 | ]; |
| 103 | |
| 104 | register_taxonomy( 'wpr_template_type', 'wpr_templates', $tax_args ); |
| 105 | |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | ** Don't display on the frontend for non edit_posts capable users |
| 110 | */ |
| 111 | public function block_template_frontend() { |
| 112 | if ( is_singular( 'wpr_templates' ) && ! current_user_can( 'edit_posts' ) ) { |
| 113 | wp_redirect( site_url(), 301 ); |
| 114 | die; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | *** Add elementor support for wpr_templates. |
| 120 | **/ |
| 121 | function add_elementor_cpt_support() { |
| 122 | if ( ! is_admin() ) { |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | $cpt_support = get_option( 'elementor_cpt_support' ); |
| 127 | |
| 128 | if ( ! $cpt_support ) { |
| 129 | update_option( 'elementor_cpt_support', ['post', 'page', 'wpr_templates'] ); |
| 130 | } elseif ( ! in_array( 'wpr_templates', $cpt_support ) ) { |
| 131 | $cpt_support[] = 'wpr_templates'; |
| 132 | update_option( 'elementor_cpt_support', $cpt_support ); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | } |
| 137 | |
| 138 | new WPR_Templates_Library(); |