PluginProbe
WowAddons – Product Addons and Product Options With Custom Fields / trunk
WowAddons – Product Addons and Product Options With Custom Fields vtrunk
1.7.2 1.7.1 1.7.0 1.6.21 1.6.20 1.6.19 1.6.18 1.6.17 1.6.16 1.6.15 1.6.14 1.6.13 1.6.12 1.6.11 1.6.10 1.6.9 1.6.8 1.6.7 1.6.6 1.5.10 1.5.11 1.5.2 1.5.3 1.5.4 1.5.5 All 57 releases
product-addons / includes / class-initialization.php

class-initialization.php in WowAddons – Product Addons and Product Options With Custom Fields trunk, at includes/class-initialization.php

213 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore
2 /**
3 * Initialization Action.
4 *
5 * @package PRAD
6 * @since 1.0.0
7 */
8 namespace PRAD\Includes;
9
10 use PRAD\Includes\Admin\Notice;
11 use PRAD\Includes\Admin\Options;
12 use PRAD\Includes\Admin\OurPlugins;
13 use PRAD\Includes\Admin\Product\ProductEdit;
14 use PRAD\Includes\Common\Hooks;
15 use PRAD\Includes\Common\SafeMathEvaluator;
16 use PRAD\Includes\Compatibility\Compatibility;
17 use PRAD\Includes\Compatibility\ShopCompatibilty;
18 use PRAD\Includes\Order\CartPage;
19 use PRAD\Includes\Order\CheckoutPage;
20 use PRAD\Includes\Restapi\RequestApi;
21
22 use PRAD\Includes\Cron\Cleanup;
23
24 defined( 'ABSPATH' ) || exit;
25
26 /**
27 * Initialization class.
28 */
29 class Initialization {
30
31 /**
32 * Setup class.
33 *
34 * @since v.1.0.0
35 */
36 public function __construct() {
37 $this->requires();
38 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_callback' ) );
39 add_action( 'activated_plugin', array( $this, 'activation_redirect' ) );
40 }
41
42 /**
43 * Necessary Requires Class
44 *
45 * @since v.1.0.0
46 * @return void
47 */
48 public function requires() {
49
50 new Deactive();
51 new PostType();
52 new Analytics();
53 new Xpo();
54
55 new Options();
56 new Notice();
57
58 new ProductEdit();
59 new OurPlugins();
60
61 new CartPage();
62 new CheckoutPage();
63
64 new Hooks();
65 new RequestApi();
66 new Compatibility();
67 new ShopCompatibilty();
68 new SafeMathEvaluator();
69
70 new Cleanup();
71 }
72
73
74 /**
75 * Only Backend CSS and JS Scripts
76 *
77 * @since v.1.0.0
78 * @return void
79 */
80 public function admin_scripts_callback() {
81 global $pagenow;
82 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; //phpcs:ignore
83
84 product_addons()->enqueue_style( 'prad-admin-style', 'prad-admin' );
85 product_addons()->enqueue_script( 'prad-admin-script', 'prad-admin' );
86
87 if ( 'admin.php' === $pagenow ) {
88 wp_localize_script(
89 'prad-admin-script',
90 'prad_admin',
91 array()
92 );
93 if ( 'prad-dashboard' === $page ) {
94 $user_info = get_userdata( get_current_user_id() );
95
96 // Styles.
97 product_addons()->enqueue_style( 'prad-editor-css', 'wowaddons' );
98 product_addons()->enqueue_style( 'prad-editor-css2', 'style-wowaddons' );
99 product_addons()->enqueue_style( 'prad-block-css', 'wowaddons-blocks' );
100
101 // Scripts.
102 product_addons()->enqueue_script( 'prad-editor-script', 'wowaddons' );
103 product_addons()->enqueue_script( 'prad-date-script', 'wowdate-min' );
104
105 wp_enqueue_media();
106 wp_localize_script(
107 'prad-editor-script',
108 'pradBackendData',
109 array_merge(
110 array(
111 'url' => PRAD_URL,
112 'db_url' => admin_url( 'admin.php?page=prad-dashboard#' ),
113 'ajax' => admin_url( 'admin-ajax.php' ),
114 'version' => PRAD_VER,
115 'isActive' => product_addons()->is_lc_active(),
116 'isExpired' => Xpo::is_lc_expired(),
117 'license' => get_option( 'edd_prad_license_key' ),
118 'nonce' => wp_create_nonce( 'prad-nonce' ),
119 'decimal_sep' => get_option( 'woocommerce_price_decimal_sep', '.' ),
120 'num_decimals' => get_option( 'woocommerce_price_num_decimals', '2' ),
121 'currency_pos' => get_option( 'woocommerce_currency_pos', 'left' ),
122 'currencySymbol' => function_exists( 'get_woocommerce_currency_symbol' ) ? get_woocommerce_currency_symbol() : '$',
123 'characterText' => Xpo::get_prad_settings_item( 'characterText', 'Character' ),
124 'wordText' => Xpo::get_prad_settings_item( 'wordText', 'Word' ),
125 'userInfo' => array(
126 'name' => $user_info->first_name ? $user_info->first_name . ( $user_info->last_name ? ' ' . $user_info->last_name : '' ) : $user_info->user_login,
127 'email' => $user_info->user_email,
128 ),
129 'isFreshInstall' => self::is_fresh_install(),
130 'helloBar' => Notice::get_hellobar_config(),
131 'uploadFileTypes' => product_addons()->prad_get_upload_allowed_file_types(),
132 'pradAttributes' => product_addons()->prad_get_attributes(),
133 'date_format' => get_option( 'date_format' ),
134 ),
135 Xpo::get_wow_products_details()
136 )
137 );
138 wp_set_script_translations( 'prad-editor-script', 'product-addons', PRAD_PATH . 'languages/' );
139 }
140 }
141
142 if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) && 'product' === get_post_type() ) {
143 product_addons()->enqueue_style( 'prad-product-edit-style', 'style-prad-product-edit' );
144 product_addons()->enqueue_script( 'prad-product-edit-script', 'prad-product-edit' );
145
146 wp_localize_script(
147 'prad-product-edit-script',
148 'pradBackendData',
149 array(
150 'url' => PRAD_URL,
151 'db_url' => admin_url( 'admin.php?page=prad-dashboard#' ),
152 'ajax' => admin_url( 'admin-ajax.php' ),
153 'version' => PRAD_VER,
154 'nonce' => wp_create_nonce( 'prad-nonce' ),
155 'product_id' => get_the_ID(),
156 )
157 );
158 }
159 }
160
161 /**
162 * Check if the user has never created an option list.
163 *
164 * Used to show the onboarding get-started screen and trimmed
165 * header on the dashboard for brand-new users.
166 *
167 * @since v.1.6.17
168 *
169 * @return bool
170 */
171 public static function is_fresh_install() {
172 if ( 'yes' === get_option( 'prad_first_option_created', '' ) ) {
173 return false;
174 }
175
176 $existing = get_posts(
177 array(
178 'post_type' => 'prad_option',
179 'post_status' => 'any',
180 'posts_per_page' => 1,
181 'fields' => 'ids',
182 )
183 );
184
185 if ( ! empty( $existing ) ) {
186 // Existing users from before the flag existed: backfill it.
187 update_option( 'prad_first_option_created', 'yes' );
188 return false;
189 }
190
191 return true;
192 }
193
194 /**
195 * Redirect After Active Plugin
196 *
197 * @since v.1.0.0
198 *
199 * @param string $plugin Plugin name.
200 *
201 * @return NULL
202 */
203 public function activation_redirect( $plugin ) {
204 if ( 'product-addons/product-addons.php' === $plugin ) {
205 if ( wp_doing_ajax() || is_network_admin() || isset( $_GET['activate-multi'] ) || isset( $_POST['action'] ) && 'activate-selected' == $_POST['action'] ) { // phpcs:ignore
206 return;
207 }
208 $tab = self::is_fresh_install() ? 'lists' : 'dashboard';
209 exit( wp_safe_redirect( admin_url( 'admin.php?page=prad-dashboard#' . $tab ) ) ); // phpcs:ignore
210 }
211 }
212 }
213