PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.34
Post Grid Gutenberg Blocks – PostX v5.0.34
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / Options.php

Options.php in Post Grid Gutenberg Blocks – PostX 5.0.34, at classes/Options.php

316 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Options Action.
5 *
6 * @package ULTP\Notice
7 * @since v.1.0.0
8 */
9
10 namespace ULTP;
11
12 use ULTP\Includes\Durbin\Xpo;
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * Options class.
18 *
19 * Handles plugin options and settings for Ultimate Post.
20 *
21 * @package ULTP\Options
22 * @since 4.0.0
23 */
24 class Options {
25
26 /**
27 * Setup class.
28 *
29 * @since v.1.0.0
30 */
31 public function __construct() {
32 add_action( 'admin_init', array( $this, 'handle_external_redirects' ) );
33 add_action( 'admin_menu', array( $this, 'menu_page_callback' ) );
34 add_action( 'in_admin_header', array( $this, 'remove_all_notices' ) );
35 add_filter( 'plugin_row_meta', array( $this, 'plugin_settings_meta' ), 10, 2 );
36 add_filter( 'plugin_action_links_' . ULTP_BASE, array( $this, 'plugin_action_links_callback' ) );
37 }
38
39
40 /**
41 * Adds extra links to the plugin row meta on the plugins page.
42 *
43 * @param array $links Existing plugin meta links.
44 * @param string $file Plugin file path.
45 * @return array Modified plugin meta links.
46 */
47 public function plugin_settings_meta( $links, $file ) {
48 if ( strpos( $file, 'ultimate-post.php' ) !== false ) {
49 $new_links = array(
50 'ultp_docs' => '<a href="https://wpxpo.com/docs/" target="_blank">' . esc_html__( 'Docs', 'ultimate-post' ) . '</a>',
51 'ultp_tutorial' => '<a href="https://www.youtube.com/watch?v=JZxIflYKOuM&list=PLPidnGLSR4qcAwVwIjMo1OVaqXqjUp_s4" target="_blank">' . esc_html__( 'Tutorials', 'ultimate-post' ) . '</a>',
52 'ultp_support' => '<a href="' . esc_url(
53 Xpo::generate_utm_link(
54 array(
55 'url' => 'https://www.wpxpo.com/contact/',
56 'utmKey' => 'plugin_dir_support',
57 )
58 )
59 ) . '" target="_blank">' . esc_html__( 'Support', 'ultimate-post' ) . '</a>',
60 );
61 $links = array_merge( $links, $new_links );
62 }
63 return $links;
64 }
65
66 /**
67 * Adds quick action links below the plugin name.
68 *
69 * @param array $links Default plugin action links.
70 * @return array Modified plugin action links.
71 */
72 public function plugin_action_links_callback( $links ) {
73 $offer_config = array(
74 array(
75 'start' => '2026-07-06 00:00 Asia/Dhaka',
76 'end' => '2026-08-01 23:59 Asia/Dhaka',
77 'text' => __(
78 'Summer Sale - Up to 50% OFF',
79 'ultimate-post'
80 ),
81 'utmKey' => 'summer_sale_meta',
82 ),
83 array(
84 'start' => '2026-08-02 00:00 Asia/Dhaka',
85 'end' => '2026-08-16 23:59 Asia/Dhaka',
86 'text' => __(
87 'Summer Sale - Up to 50% OFF',
88 'ultimate-post'
89 ),
90 'utmKey' => 'summer_sale_meta',
91 ),
92 );
93
94 $setting_link = array(
95 'ultp_options' => '<a href="' . esc_url( admin_url( 'admin.php?page=ultp-settings#startersites' ) ) . '">' . esc_html__( 'Starter Sites', 'ultimate-post' ) . '</a>',
96 );
97
98 $upgrade_link = array();
99
100 // Free user or expired license user.
101 if ( ! defined( 'ULTP_PRO_VER' ) || Xpo::is_lc_expired() ) {
102
103 $license_key = Xpo::get_lc_key() ?? '';
104
105 if ( Xpo::is_lc_expired() ) {
106 $text = esc_html__( 'Renew License', 'ultimate-post' );
107 $url = 'https://account.wpxpo.com/checkout/?edd_license_key=' . $license_key;
108 } else {
109
110 $text = esc_html__( 'Upgrade to Pro', 'ultimate-post' );
111 $url = Xpo::generate_utm_link(array(
112 'utmKey' => 'sub_menu',
113 ));
114
115 foreach ( $offer_config as $offer ) {
116 $current_time = gmdate( 'U' );
117 $notice_start = gmdate( 'U', strtotime( $offer['start'] ) );
118 $notice_end = gmdate( 'U', strtotime( $offer['end'] ) );
119 if ( $current_time >= $notice_start && $current_time <= $notice_end ) {
120 $url = Xpo::generate_utm_link(
121 array(
122 'utmKey' => $offer['utmKey'],
123 )
124 );
125 $text = $offer['text'];
126 break;
127 }
128 }
129 }
130
131 $upgrade_link['ultp_pro'] = '<a style="color: #0062ff; font-weight: bold;" target="_blank" href="' . esc_url( $url ) . '">' . esc_html( $text ) . '</a>';
132 }
133
134 return array_merge( $setting_link, $links, $upgrade_link );
135 }
136
137
138 /**
139 * Add admin menu option page and submenus.
140 *
141 * @since v.1.0.0
142 * @return void No return value.
143 */
144 public static function menu_page_callback() {
145 $ultp_menu_icon = 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MCA0OC4zIj4NCiAgPGRlZnM+DQogICAgPHN0eWxlPg0KICAgICAgLmNscy0xIHsNCiAgICAgICAgZmlsbDogI2E3YWFhZDsNCiAgICAgIH0NCiAgICA8L3N0eWxlPg0KICA8L2RlZnM+DQogIDx0aXRsZT5Qb3N0eCBJY29uIGNtcHJzc2QgU1ZHPC90aXRsZT4NCiAgPGc+DQogICAgPHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMTguODEsOXY4LjlIOC4xOUE2LjE5LDYuMTksMCwwLDAsMiwyMy43N2EzLjE2LDMuMTYsMCwwLDEtMi0yLjk0VjRBMy4xNiwzLjE2LDAsMCwxLDMuMTUuODVIMjBhMy4xOCwzLjE4LDAsMCwxLDMsMi4zMUE2LjIxLDYuMjEsMCwwLDAsMTguODEsOVoiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTAuODUpIi8+DQogICAgPHBhdGggY2xhc3M9ImNscy0xIiBkPSJNNDUsOVYyM0gzMS4xYTYuMjMsNi4yMywwLDAsMC00LjkzLTQuOTNBNS41NCw1LjU0LDAsMCwwLDI1LDE3Ljk0SDIxLjg1VjlBMy4xNSwzLjE1LDAsMCwxLDIzLjEzLDYuNWEzLjEyLDMuMTIsMCwwLDEsMS40My0uNThsLjA5LDBINDEuODNBMy4xNCwzLjE0LDAsMCwxLDQ1LDlaIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgwIC0wLjg1KSIvPg0KICAgIDxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTUwLDI5LjE3VjQ2YTMuMTYsMy4xNiwwLDAsMS0zLjE1LDMuMTVIMzBhMy4xOCwzLjE4LDAsMCwxLTMtMi4zMUE2LjIyLDYuMjIsMCwwLDAsMzEuMjEsNDFWMjZINDYuODVhMy4zLDMuMywwLDAsMSwxLjE0LjIxQTMuMTYsMy4xNiwwLDAsMSw1MCwyOS4xN1oiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTAuODUpIi8+DQogICAgPHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMjguMTYsMjQuMTNWNDFhMy4xMywzLjEzLDAsMCwxLTEuMjksMi41NCwzLDMsMCwwLDEtMS40Ny41OGwwLDBIOC4xOUEzLjE1LDMuMTUsMCwwLDEsNSw0MVYyNGEzLjE3LDMuMTcsMCwwLDEsMy4xNS0zSDI1YTMuMTIsMy4xMiwwLDAsMSwxLjE0LjIyLDMuMjQsMy4yNCwwLDAsMSwxLjksMi4xQTMuNjMsMy42MywwLDAsMSwyOC4xNiwyNC4xM1oiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTAuODUpIi8+DQogIDwvZz4NCjwvc3ZnPg0K';
146 $menupage_cap = apply_filters( 'ultp_menu_page_capability', 'manage_options' );
147 add_menu_page(
148 __( 'PostX', 'ultimate-post' ),
149 __( 'PostX', 'ultimate-post' ),
150 $menupage_cap,
151 'ultp-settings',
152 array( self::class, 'ultp_dashboard' ),
153 $ultp_menu_icon,
154 58.5
155 );
156
157 add_submenu_page(
158 'ultp-settings',
159 __( 'PostX Dashboard', 'ultimate-post' ),
160 __( 'Getting Started', 'ultimate-post' ),
161 $menupage_cap,
162 'ultp-settings'
163 );
164
165 $menu_lists = array(
166 'startersites' => esc_html__( 'Starter Sites', 'ultimate-post' ),
167 'builder' => esc_html__( 'Site Builder', 'ultimate-post' ),
168 'saved-templates' => esc_html__( 'Saved Templates', 'ultimate-post' ),
169 'custom-font' => esc_html__( 'Custom Font', 'ultimate-post' ),
170 'addons' => esc_html__( 'Add-ons', 'ultimate-post' ),
171 'blocks' => esc_html__( 'Blocks', 'ultimate-post' ),
172 'settings' => esc_html__( 'Settings', 'ultimate-post' ),
173 );
174 if ( defined( 'ULTP_PRO_VER' ) ) {
175 $menu_lists['license'] = esc_html__( 'License ', 'ultimate-post' );
176 }
177
178 foreach ( $menu_lists as $key => $val ) {
179 add_submenu_page(
180 'ultp-settings',
181 $val,
182 $val,
183 $menupage_cap,
184 'ultp-settings#' . $key,
185 array( __CLASS__, 'render_main' )
186 );
187 }
188 add_submenu_page(
189 'ultp-settings',
190 esc_html__( 'Initial Setup', 'ultimate-post' ),
191 esc_html__( 'Initial Setup', 'ultimate-post' ),
192 $menupage_cap,
193 'ultp-setup-wizard',
194 array( __CLASS__, 'ultp_wizard_page' )
195 );
196
197 $pro_link = '';
198 $pro_link_text = '';
199
200 // Check if current date is between November 5th and December 10th
201 $current_date = current_time( 'Y-m-d' );
202 $start_date = date( 'Y' ) . '-01-01'; // January 1st of current year
203 $end_date = date( 'Y' ) . '-02-15'; // February 15th of current year
204 $menu_pro_text_period = ( $current_date >= $start_date && $current_date <= $end_date );
205
206 if ( ! Xpo::is_lc_active() ) {
207 $pro_link = Xpo::generate_utm_link(
208 array(
209 'utmKey' => 'sub_menu',
210 )
211 );
212 $pro_link_text = $menu_pro_text_period ? __( 'New Year Offer!', 'ultimate-post' ) : __( 'Upgrade to Pro', 'ultimate-post' );
213 } elseif ( Xpo::is_lc_expired() ) {
214 $license_key = Xpo::get_lc_key();
215 $pro_link = 'https://account.wpxpo.com/checkout/?edd_license_key=' . $license_key;
216 $pro_link_text = __( 'Renew License', 'ultimate-post' );
217 }
218
219 if ( ! empty( $pro_link ) ) {
220 ob_start();
221 ?>
222 <a href="<?php echo esc_url( $pro_link ); ?>" target="_blank" class="ultp-go-pro">
223 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
224 <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>
225 </svg>
226 <span><?php echo esc_html( $pro_link_text ); ?></span>
227 </a>
228 <?php
229 $submenu_content = ob_get_clean();
230
231 add_submenu_page(
232 'ultp-settings',
233 '',
234 $submenu_content,
235 'manage_options',
236 'ultp-pro',
237 array( self::class, 'handle_external_redirects' )
238 );
239 }
240
241 add_theme_page(
242 __( 'Starter Sites', 'ultimate-post' ),
243 __( 'Starter Sites', 'ultimate-post' ),
244 $menupage_cap,
245 'ultp-startersites',
246 array( self::class, 'handle_external_redirects' )
247 );
248 }
249
250 /**
251 * Handle external redirects for menu and pro links.
252 *
253 * @since v.1.0.0
254 * @return void No return value.
255 */
256 public function handle_external_redirects() {
257 if (empty($_GET['page'])) { // @codingStandardsIgnoreLine
258 return;
259 }
260 $_page = sanitize_key( $_GET['page'] );
261 if ('ultp-startersites' === $_page) { // @codingStandardsIgnoreLine
262 exit( wp_safe_redirect( admin_url( 'admin.php?page=ultp-settings#startersites' ) ) );
263 } else if ('go_postx_pro' === $_page) { // @codingStandardsIgnoreLine
264 wp_redirect(
265 Xpo::generate_utm_link(
266 array(
267 'utmKey' => 'dashboard_go_pro',
268 )
269 )
270 );
271 die();
272 }
273 }
274
275 /**
276 * Render the wizard page.
277 *
278 * @since v.2.4.4
279 */
280 public static function ultp_wizard_page() {
281 ?>
282 <div class="ultp-wizard-page-wrap" id="ultp-wizard-page"></div>
283 <?php
284 }
285
286 /**
287 * Render the dashboard page.
288 *
289 * @since v.1.0.0
290 * @return void No return value.
291 */
292 public static function ultp_dashboard() {
293 echo '<div id="ultp-dashboard"></div>';
294 }
295
296 /**
297 * Remove all notifications from menu page.
298 *
299 * @since v.1.0.0
300 * @return void No return value.
301 */
302 public static function remove_all_notices() {
303 if (isset($_GET['page'])) { // @codingStandardsIgnoreLine
304 $page = sanitize_key($_GET['page']); // @codingStandardsIgnoreLine
305 if (
306 $page === 'ultp-settings' ||
307 $page === 'ultp-license' ||
308 $page === 'ultp-setup-wizard'
309 ) {
310 remove_all_actions( 'admin_notices' );
311 remove_all_actions( 'all_admin_notices' );
312 }
313 }
314 }
315 }
316