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 / admin / class-options.php

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

299 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php //phpcs:ignore
2 /**
3 * Options Action.
4 *
5 * @package PRAD\Options
6 * @since v.1.0.0
7 */
8
9 namespace PRAD\Includes\Admin;
10
11 defined( 'ABSPATH' ) || exit;
12
13 use PRAD\Includes\Xpo;
14
15 /**
16 * Options class.
17 */
18 class Options {
19
20 /**
21 * Setup class.
22 *
23 * @since v.1.0.0
24 */
25 public function __construct() {
26 add_action( 'admin_init', array( $this, 'handle_external_redirects' ) );
27 add_action( 'admin_menu', array( $this, 'menu_page_callback' ) );
28 add_action( 'in_admin_header', array( $this, 'remove_all_notices' ) );
29
30 add_filter( 'plugin_action_links_' . PRAD_BASE, array( $this, 'plugin_action_links_callback' ) );
31 add_filter( 'plugin_row_meta', array( $this, 'plugin_settings_meta' ), 10, 2 );
32 }
33
34 /**
35 * Adds quick action links below the plugin name.
36 * **YOU NEED TO CUSTOMIZE THIS FUNCTION**
37 *
38 * @param array $links Default plugin action links.
39 * @return array Modified plugin action links.
40 */
41 public function plugin_action_links_callback( $links ) {
42 $offer_config = array(
43 array(
44 'start' => '2026-05-07 00:00 Asia/Dhaka',
45 'end' => '2026-05-21 23:59 Asia/Dhaka',
46 'text' => __(
47 'Flash Sale - Up to 50% OFF',
48 'product-addons'
49 ),
50 'utmKey' => 'plugin_meta',
51 ),
52 array(
53 'start' => '2026-05-22 00:00 Asia/Dhaka',
54 'end' => '2026-06-01 23:59 Asia/Dhaka',
55 'text' => __(
56 'Surprise Sale - Up to 55% OFF',
57 'product-addons'
58 ),
59 'utmKey' => 'plugin_meta',
60 ),
61 array(
62 'start' => '2026-06-02 00:00 Asia/Dhaka',
63 'end' => '2026-06-20 23:59 Asia/Dhaka',
64 'text' => __(
65 'Massive Sale - Up to 50% OFF',
66 'product-addons'
67 ),
68 'utmKey' => 'plugin_meta',
69 ),
70 array(
71 'start' => '2026-07-06 00:00 Asia/Dhaka',
72 'end' => '2026-08-01 23:59 Asia/Dhaka',
73 'text' => __(
74 'Summer Sale - Up to 50% OFF',
75 'product-addons'
76 ),
77 'utmKey' => 'plugin_meta_summer_db',
78 ),
79 array(
80 'start' => '2026-09-02 00:00 Asia/Dhaka',
81 'end' => '2026-10-10 23:59 Asia/Dhaka',
82 'text' => __(
83 'Get Pro at $52',
84 'product-addons'
85 ),
86 'utmKey' => 'plugin_meta_base_price',
87 ),
88 );
89
90 $setting_link = array(
91 'prad_options' => '<a href="' . esc_url( admin_url( 'admin.php?page=prad-dashboard#lists' ) ) . '">' . esc_html__( 'Create Options', 'product-addons' ) . '</a>',
92 );
93
94 $upgrade_link = array();
95
96 // Free user or expired license user.
97 if ( ! defined( 'PRAD_PRO_VER' ) || Xpo::is_lc_expired() ) {
98
99 if ( Xpo::is_lc_expired() ) {
100 $text = esc_html__( 'Renew License', 'product-addons' );
101 $url = 'https://account.wpxpo.com/checkout/?edd_license_key=' . Xpo::get_lc_key() . '&renew=1';
102 } else {
103
104 $text = esc_html__( 'Upgrade to Pro', 'product-addons' );
105 $url = Xpo::generate_utm_link(
106 array(
107 'utmKey' => 'plugin_meta',
108 )
109 );
110
111 foreach ( $offer_config as $offer ) {
112 $current_time = gmdate( 'U' );
113 $notice_start = gmdate( 'U', strtotime( $offer['start'] ) );
114 $notice_end = gmdate( 'U', strtotime( $offer['end'] ) );
115 if ( $current_time >= $notice_start && $current_time <= $notice_end ) {
116 $url = Xpo::generate_utm_link(
117 array(
118 'utmKey' => $offer['utmKey'],
119 )
120 );
121 $text = $offer['text'];
122 break;
123 }
124 }
125 }
126
127 $upgrade_link['prad_pro'] = '<a style="color: #e83838; font-weight: bold;" target="_blank" href="' . esc_url( $url ) . '">' . $text . '</a>';
128 }
129
130 return array_merge( $setting_link, $links, $upgrade_link );
131 }
132
133 /**
134 * Adds extra links to the plugin row meta on the plugins page.
135 * **YOU NEED TO CUSTOMIZE THIS FUNCTION**
136 *
137 * @param array $links Existing plugin meta links.
138 * @param string $file Plugin file path.
139 * @return array Modified plugin meta links.
140 */
141 public function plugin_settings_meta( $links, $file ) {
142 if ( strpos( $file, 'product-addons.php' ) !== false ) {
143 $new_links = array(
144 'prad_docs' => '<a href="https://wpxpo.com/docs/wowaddons/?utm_source=db-wowaddons-plugin&utm_medium=doc&utm_campaign=wowaddons-dashboard" target="_blank">' . esc_html__( 'Docs', 'product-addons' ) . '</a>',
145 'prad_support' => '<a href="https://www.wpxpo.com/contact/" target="_blank">' . esc_html__( 'Support', 'product-addons' ) . '</a>',
146 );
147 $links = array_merge( $links, $new_links );
148 }
149 return $links;
150 }
151
152 /**
153 * Admin Menu Option Page
154 *
155 * @since v.1.0.0
156 * @return void
157 */
158 public static function menu_page_callback() {
159 $menupage_cap = Xpo::prad_old_view_permisson_handler();
160
161 add_menu_page(
162 __( 'WowAddons', 'product-addons' ),
163 __( 'WowAddons', 'product-addons' ),
164 $menupage_cap,
165 'prad-dashboard',
166 array( self::class, 'tab_page_content' ),
167 PRAD_URL . '/assets/img/wowaddons-icon-square.svg',
168 58.5
169 );
170
171 add_submenu_page(
172 'prad-dashboard',
173 __( 'WowAddons Dashboard', 'product-addons' ),
174 __( 'Dashboard', 'product-addons' ),
175 $menupage_cap,
176 'prad-dashboard'
177 );
178
179 $menu_lists = array();
180 $menu_lists['lists'] = esc_html__( 'Option Set', 'product-addons' );
181 $menu_lists['analytics'] = esc_html__( 'Analytics', 'product-addons' );
182 $menu_lists['settings'] = esc_html__( 'Settings', 'product-addons' );
183
184 add_submenu_page(
185 'edit.php?post_type=product',
186 __( 'WowAddons', 'product-addons' ),
187 __( 'WowAddons', 'product-addons' ),
188 $menupage_cap,
189 'wowaddons-page',
190 array( __CLASS__, 'render_main' )
191 );
192
193 if ( defined( 'PRAD_PRO_VER' ) ) {
194 $menu_lists['license'] = esc_html__( 'License', 'product-addons' );
195 }
196 foreach ( $menu_lists as $key => $val ) {
197 add_submenu_page(
198 'prad-dashboard',
199 $val,
200 $val,
201 $menupage_cap,
202 'prad-dashboard#' . $key,
203 array( __CLASS__, 'render_main' )
204 );
205 }
206
207 $pro_link = '';
208 $pro_link_text = '';
209 if ( Xpo::is_lc_expired() ) {
210 $license_key = Xpo::get_lc_key();
211 $pro_link = 'https://account.wpxpo.com/checkout/?edd_license_key=' . $license_key . '&renew=1';
212 $pro_link_text = __( 'Renew License', 'product-addons' );
213 } elseif ( ! Xpo::is_lc_active() ) {
214 $pro_link = Xpo::generate_utm_link(
215 array(
216 'utmKey' => 'sub_menu',
217 )
218 );
219 $pro_link_text = __( 'Upgrade to Pro!', 'product-addons' );
220
221 $is_offer_running = true;
222 if ( $is_offer_running ) {
223 $current_time = gmdate( 'U' );
224 $start = '2026-01-01 00:00 Asia/Dhaka';
225 $end = '2026-02-15 23:59 Asia/Dhaka';
226 $notice_start = gmdate( 'U', strtotime( $start ) );
227 $notice_end = gmdate( 'U', strtotime( $end ) );
228 if ( $current_time >= $notice_start && $current_time <= $notice_end ) {
229 $pro_link_text = esc_html__( 'New Year Offer!', 'product-addons' );
230 }
231 }
232 }
233
234 if ( ! empty( $pro_link ) ) {
235 ob_start();
236 ?>
237 <a href="<?php echo esc_url( $pro_link ); ?>" target="_blank" class="prad-go-pro">
238 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
239 <path d="M2.86 6.553a.5.5 0 01.823-.482l3.02 2.745c.196.178.506.13.64-.098L9.64 4.779a.417.417 0 01.72 0l2.297 3.939a.417.417 0 00.64.098l3.02-2.745a.5.5 0 01.823.482l-1.99 8.63a.833.833 0 01-.813.646H5.663a.833.833 0 01-.812-.646L2.86 6.553z" stroke="currentColor" stroke-width="1.5"></path>
240 </svg>
241 <span><?php echo esc_html( $pro_link_text ); ?></span>
242 </a>
243 <?php
244 $submenu_content = ob_get_clean();
245
246 add_submenu_page(
247 'prad-dashboard',
248 '',
249 $submenu_content,
250 $menupage_cap,
251 'prad-pro',
252 array( self::class, 'handle_external_redirects' )
253 );
254
255 }
256 }
257
258 /**
259 * Go to Pro URL Redirect
260 *
261 * @since v.1.0.0
262 * @return NULL
263 */
264 public function handle_external_redirects() {
265 if ( empty( $_GET['page'] ) ) { // @codingStandardsIgnoreLine
266 return;
267 }
268 if ( 'go_prad_pro' === sanitize_text_field( $_GET['page'] ) ) { // @codingStandardsIgnoreLine
269 wp_safe_redirect( 'https://www.wpxpo.com/product/wowaddons/' );
270 die();
271 }
272 }
273
274 /**
275 * Initial Plugin Setting
276 *
277 * @since v.1.0.0
278 * @return void
279 */
280 public static function tab_page_content() {
281 echo wp_kses( '<div id="prad-dashboard-wrap"></div>', apply_filters( 'prad_allowed_html_tags', array() ) );// phpcs:ignore
282 }
283
284 /**
285 * Remove All Notification From Menu Page
286 *
287 * @since v.1.0.0
288 * @return void
289 */
290 public static function remove_all_notices() {
291 $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash($_GET['page']) ) : ''; // phpcs:ignore
292 if ( 'prad-dashboard' === $page ) {
293 remove_all_actions( 'admin_notices' );
294 remove_all_actions( 'all_admin_notices' );
295 remove_all_actions( 'in_admin_header' );
296 }
297 }
298 }
299