class-advanced-import-admin.php
3 weeks ago
class-advanced-import-template.php
3 months ago
class-advanced-import-tracking.php
3 weeks ago
class-elementor-import.php
3 weeks ago
class-reset.php
3 weeks ago
index.php
5 years ago
class-advanced-import-template.php
180 lines
| 1 | <?php // phpcs:ignore Class file names should be based on the class name with "class-" prepended. |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | /** |
| 7 | * Theme Menu Page. |
| 8 | * |
| 9 | * @link https://www.acmeit.org/ |
| 10 | * @since 1.0.0 |
| 11 | * |
| 12 | * @package Wp_Block_Theme_Boilerplate |
| 13 | * @subpackage Wp_Block_Theme_Boilerplate/Advanced_Import_Admin_Template |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Class used to add theme menu page and content on it. |
| 18 | * |
| 19 | * @package Wp_Block_Theme_Boilerplate |
| 20 | * @subpackage Wp_Block_Theme_Boilerplate/Advanced_Import_Admin_Template |
| 21 | * @author codersantosh <codersantosh@gmail.com> |
| 22 | */ |
| 23 | class Advanced_Import_Admin_Template { |
| 24 | |
| 25 | /** |
| 26 | * Current added Menu hook_suffix |
| 27 | * |
| 28 | * @since 1.0.0 |
| 29 | * @access public |
| 30 | * @var string $hook_suffix Store current added Menu hook_suffix. |
| 31 | */ |
| 32 | private $hook_suffix; |
| 33 | |
| 34 | /** |
| 35 | * Id of this class. |
| 36 | * |
| 37 | * @since 1.0.0 |
| 38 | * @access public |
| 39 | * @var string $id Store id of this class. |
| 40 | */ |
| 41 | private $id = 'advanced-import-template'; |
| 42 | |
| 43 | /** |
| 44 | * API url. |
| 45 | * |
| 46 | * @since 1.4.6 |
| 47 | * @access protected |
| 48 | */ |
| 49 | protected $api_url = 'https://demo.patternswp.com/wp-json/patternswp-demo-setup/v1/acmeit-demos'; |
| 50 | |
| 51 | /** |
| 52 | * Empty Constructor |
| 53 | */ |
| 54 | private function __construct() {} |
| 55 | |
| 56 | /** |
| 57 | * Gets an instance of this object. |
| 58 | * Prevents duplicate instances which avoid artefacts and improves performance. |
| 59 | * |
| 60 | * @static |
| 61 | * @access public |
| 62 | * @since 1.0.0 |
| 63 | * @return object |
| 64 | */ |
| 65 | public static function instance() { |
| 66 | // Store the instance locally to avoid private static replication. |
| 67 | static $instance = null; |
| 68 | |
| 69 | // Only run these methods if they haven't been ran previously. |
| 70 | if ( null === $instance ) { |
| 71 | $instance = new self(); |
| 72 | } |
| 73 | |
| 74 | // Always return the instance. |
| 75 | return $instance; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Initialize the class. |
| 80 | * |
| 81 | * @access public |
| 82 | * @return void |
| 83 | */ |
| 84 | public function run() { |
| 85 | add_action( 'admin_menu', array( $this, 'add_theme_menu' ) ); |
| 86 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_resources' ) ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Add Theme Page Menu page. |
| 91 | * |
| 92 | * @access public |
| 93 | * |
| 94 | * @since 1.0.0 |
| 95 | */ |
| 96 | public function add_theme_menu() { |
| 97 | $this->hook_suffix[] = add_theme_page( esc_html__( 'Template Import', 'advanced-import' ), esc_html__( 'Template Import', 'advanced-import' ), 'edit_theme_options', $this->id, array( $this, 'info_screen' ) ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Register the CSS/JavaScript Resources for the admin menu. |
| 102 | * |
| 103 | * @access public |
| 104 | * Use Condition to Load it Only When it is Necessary |
| 105 | * |
| 106 | * @param string $hook_suffix The current admin page. |
| 107 | * |
| 108 | * @since 1.0.0 |
| 109 | */ |
| 110 | public function enqueue_resources( $hook_suffix ) { |
| 111 | if ( ! is_array( $this->hook_suffix ) || ! in_array( $hook_suffix, $this->hook_suffix, true ) ) { |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | advanced_import_admin()->wp_enqueue_styles(); |
| 116 | advanced_import_admin()->wp_enqueue_scripts(); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Add menu page. |
| 121 | * |
| 122 | * @see templates/theme-info.php |
| 123 | * |
| 124 | * @access public |
| 125 | * |
| 126 | * @since 1.0.0 |
| 127 | */ |
| 128 | public function info_screen() { |
| 129 | do_action( 'advanced_import_before_demo_import_screen' ); |
| 130 | |
| 131 | echo '<div class="ai-body">'; |
| 132 | |
| 133 | advanced_import_admin()->get_header(); |
| 134 | |
| 135 | echo '<div class="ai-content">'; |
| 136 | echo '<div class="ai-content-blocker hidden">'; |
| 137 | echo '<div class="ai-notification-title"><p>' . esc_html__( 'Processing... Please do not refresh this page or do not go to other url!', 'advanced-import' ) . '</p></div>'; |
| 138 | echo '<div id="ai-demo-popup"></div>'; |
| 139 | echo '</div>'; |
| 140 | $this->init_demo_import(); |
| 141 | echo '</div>'; |
| 142 | echo '</div>';/*ai-body*/ |
| 143 | do_action( 'advanced_import_after_demo_import_screen' ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * 1st step of demo import view |
| 148 | * Upload Zip file |
| 149 | * Demo List |
| 150 | */ |
| 151 | public function init_demo_import() { |
| 152 | |
| 153 | $author_template_lists = apply_filters( 'advanced_import_template_lists', array() ); |
| 154 | $args = apply_filters( 'advanced_import_template_api_args', array() ); |
| 155 | $url = add_query_arg( $args, $this->api_url ); |
| 156 | |
| 157 | $acmeit_template_lists = advanced_import_get_api_data( $url ); |
| 158 | |
| 159 | advanced_import_admin()->demo_lists = array_merge( $author_template_lists, $acmeit_template_lists ); |
| 160 | $demo_lists = advanced_import_admin()->demo_lists; |
| 161 | |
| 162 | $total_demo = is_array( $demo_lists ) ? count( $demo_lists ) : 0; |
| 163 | if ( $total_demo >= 1 ) { |
| 164 | advanced_import_admin()->demo_list( $demo_lists, $total_demo, false ); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Return instance of Advanced_Import_Admin_Template class |
| 171 | * |
| 172 | * @since 1.0.0 |
| 173 | * |
| 174 | * @return Advanced_Import_Admin_Template |
| 175 | */ |
| 176 | function advanced_import_admin_template() { //phpcs:ignore |
| 177 | return Advanced_Import_Admin_Template::instance(); |
| 178 | } |
| 179 | advanced_import_admin_template()->run(); |
| 180 |