PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / admin / setup.php

setup.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/admin/setup.php

118 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine\Admin;
4
5 use StoreEngine\Assets;
6 use StoreEngine\Utils\Helper;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class Setup {
13 const PAGE_ID = 'storeengine-setup';
14
15 private ?Assets $assets;
16
17 public static function init() {
18 $self = new self();
19 $self->assets = new Assets();
20 if ( $self->is_current() ) {
21 add_action( 'admin_init', [ $self, 'admin_init' ], 0 );
22 }
23 add_action( 'admin_menu', [ $self, 'register_admin_menu' ] );
24 }
25
26 public function register_admin_menu() {
27 add_submenu_page(
28 'options-writing.php', // make it hidden
29 __( 'StoreEngine Setup', 'storeengine' ),
30 __( 'StoreEngine Setup', 'storeengine' ),
31 'manage_options',
32 self::PAGE_ID
33 );
34 }
35
36
37 public function admin_init() {
38 do_action( 'storeengine/admin/setup/init', $this );
39
40 $this->enqueue_assets();
41
42 // Setup default heartbeat options
43 add_filter( 'heartbeat_settings', function ( $settings ) {
44 $settings['interval'] = 15;
45
46 return $settings;
47 } );
48
49 $this->render();
50 die;
51 }
52
53 public function is_current() {
54 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
55 return ( ! empty( $_GET['page'] ) && self::PAGE_ID === $_GET['page'] );
56 }
57
58 public function get_setup_scripts_data() {
59 return apply_filters(
60 'storeengine/admin/setup_scripts_data',
61 array_merge(
62 $this->assets->get_backend_script_data(),
63 [
64 'admin_url' => admin_url(),
65 'customize_url' => add_query_arg(
66 'return',
67 admin_url( 'admin.php?page=storeengine-settings&path=general' ),
68 admin_url( 'customize.php' )
69 ),
70 ]
71 )
72 );
73 }
74
75
76 private function enqueue_assets() {
77 wp_enqueue_style(
78 'storeengine-admin-icon',
79 STOREENGINE_ASSETS_URI . 'library/icons/storeengine-icons.css',
80 [ 'wp-components' ],
81 filemtime(
82 STOREENGINE_ASSETS_DIR_PATH .
83 'library/icons/storeengine-icons.css'
84 ),
85 );
86 if ( Helper::is_plugin_active( 'ablocks/ablocks.php' ) ) {
87 $Assets = new \ABlocks\Assets();
88 $Assets->demo_template_importer_scripts();
89 }
90
91 $dependencies = include STOREENGINE_ASSETS_DIR_PATH . sprintf( 'build/setup.%s.asset.php', STOREENGINE_VERSION );
92 wp_enqueue_style( 'storeengine-admin-style', STOREENGINE_ASSETS_URI . 'build/setup.css', array( 'wp-components' ), $dependencies['version'], 'all' );
93 wp_add_inline_style( 'storeengine-admin-style', $this->assets->get_dynamic_css() );
94 wp_enqueue_script( 'updates' );
95 // Load the JS-translation companion so w.org language packs apply here.
96 $this->assets->register_i18n_strings();
97 wp_enqueue_script(
98 'storeengine-setup-scripts',
99 STOREENGINE_ASSETS_URI . sprintf( 'build/setup.%s.js', STOREENGINE_VERSION ),
100 array_merge( (array) $dependencies['dependencies'], wp_script_is( 'storeengine-i18n', 'registered' ) ? [ 'storeengine-i18n' ] : [] ),
101 $dependencies['version'],
102 true
103 );
104 wp_localize_script( 'storeengine-setup-scripts', 'StoreEngineGlobal', $this->get_setup_scripts_data() );
105 wp_set_script_translations(
106 'storeengine-setup-scripts',
107 'storeengine',
108 STOREENGINE_ROOT_DIR_PATH . 'i18n/languages'
109 );
110 // Enqueue emoji styles to prevent deprecation notices
111 wp_enqueue_emoji_styles();
112 }
113
114 private function render() {
115 require STOREENGINE_ROOT_DIR_PATH . 'includes/admin/views/setup.php';
116 }
117 }
118