PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.3
Post Grid Gutenberg Blocks – PostX v5.0.3
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.3, at classes/Options.php

274 lines 9.8 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_action_links_' . ULTP_BASE, array( $this, 'plugin_action_links_callback' ) );
36 add_filter( 'plugin_row_meta', array( $this, 'plugin_settings_meta' ), 10, 2 );
37 }
38
39
40 /**
41 * Add plugin page menu meta links.
42 *
43 * @since v.1.0.0
44 * @param ARRAY $links The existing plugin meta links.
45 * @param STRING $file The plugin file name.
46 * @return ARRAY Modified plugin meta links.
47 */
48 public function plugin_settings_meta( $links, $file ) {
49 if ( strpos( $file, 'ultimate-post.php' ) !== false ) {
50 $new_links = array(
51 'ultp_docs' => '<a href="https://wpxpo.com/docs/" target="_blank">' . esc_html__( 'Docs', 'ultimate-post' ) . '</a>',
52 'ultp_tutorial' => '<a href="https://www.youtube.com/watch?v=JZxIflYKOuM&list=PLPidnGLSR4qcAwVwIjMo1OVaqXqjUp_s4" target="_blank">' . esc_html__( 'Tutorials', 'ultimate-post' ) . '</a>',
53 'ultp_support' => '<a href="' . esc_url(
54 Xpo::generate_utm_link(
55 array(
56 'url' => 'https://www.wpxpo.com/contact/',
57 'utmKey' => 'plugin_dir_support',
58 )
59 )
60 ) . '" target="_blank">' . esc_html__( 'Support', 'ultimate-post' ) . '</a>',
61 );
62 $links = array_merge( $links, $new_links );
63 }
64 return $links;
65 }
66
67
68 /**
69 * Add settings and pro update link to plugin action links.
70 *
71 * @since v.1.0.0
72 * @param ARRAY $links The existing plugin action links.
73 * @return ARRAY Modified plugin action links.
74 */
75 public function plugin_action_links_callback( $links ) {
76 $setting_link = array();
77 $setting_link['ultp_options'] = '<a href="' . esc_url( admin_url( 'admin.php?page=ultp-settings#startersites' ) ) . '">' . esc_html__( 'Starter Sites', 'ultimate-post' ) . '</a>';
78 $upgrade_link = array();
79 if ( ! defined( 'ULTP_PRO_VER' ) || Xpo::is_lc_expired() ) {
80 $url = ! defined( 'ULTP_PRO_VER' ) ? Xpo::generate_utm_link(
81 array(
82 'utmKey' => 'plugin_dir_pro',
83 )
84 ) : 'https://account.wpxpo.com/checkout/?edd_license_key=' . Xpo::get_lc_key();
85
86 // Check if current date is between November 5th and December 10th
87 $current_date = current_time( 'Y-m-d' );
88 $start_date = date( 'Y' ) . '-11-05'; // November 5th of current year
89 $end_date = date( 'Y' ) . '-12-10'; // December 10th of current year
90 $is_promotional_period = ( $current_date >= $start_date && $current_date <= $end_date );
91
92 if ( ! defined( 'ULTP_PRO_VER' ) ) {
93 $text = $is_promotional_period ? esc_html__( 'Get 60% OFF', 'ultimate-post' ) : esc_html__( 'Switch to Pro', 'ultimate-post' );
94 } else {
95 $text = esc_html__( 'Renew License', 'ultimate-post' );
96 }
97 $upgrade_link['ultp_pro'] = '<a style="color: #e83838; font-weight: bold;" target="_blank" href="' . esc_url( $url ) . '">' . $text . '</a>';
98 }
99 return array_merge( $setting_link, $links, $upgrade_link );
100 }
101
102
103 /**
104 * Add admin menu option page and submenus.
105 *
106 * @since v.1.0.0
107 * @return void No return value.
108 */
109 public static function menu_page_callback() {
110 $ultp_menu_icon = 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MCA0OC4zIj4NCiAgPGRlZnM+DQogICAgPHN0eWxlPg0KICAgICAgLmNscy0xIHsNCiAgICAgICAgZmlsbDogI2E3YWFhZDsNCiAgICAgIH0NCiAgICA8L3N0eWxlPg0KICA8L2RlZnM+DQogIDx0aXRsZT5Qb3N0eCBJY29uIGNtcHJzc2QgU1ZHPC90aXRsZT4NCiAgPGc+DQogICAgPHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMTguODEsOXY4LjlIOC4xOUE2LjE5LDYuMTksMCwwLDAsMiwyMy43N2EzLjE2LDMuMTYsMCwwLDEtMi0yLjk0VjRBMy4xNiwzLjE2LDAsMCwxLDMuMTUuODVIMjBhMy4xOCwzLjE4LDAsMCwxLDMsMi4zMUE2LjIxLDYuMjEsMCwwLDAsMTguODEsOVoiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTAuODUpIi8+DQogICAgPHBhdGggY2xhc3M9ImNscy0xIiBkPSJNNDUsOVYyM0gzMS4xYTYuMjMsNi4yMywwLDAsMC00LjkzLTQuOTNBNS41NCw1LjU0LDAsMCwwLDI1LDE3Ljk0SDIxLjg1VjlBMy4xNSwzLjE1LDAsMCwxLDIzLjEzLDYuNWEzLjEyLDMuMTIsMCwwLDEsMS40My0uNThsLjA5LDBINDEuODNBMy4xNCwzLjE0LDAsMCwxLDQ1LDlaIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSgwIC0wLjg1KSIvPg0KICAgIDxwYXRoIGNsYXNzPSJjbHMtMSIgZD0iTTUwLDI5LjE3VjQ2YTMuMTYsMy4xNiwwLDAsMS0zLjE1LDMuMTVIMzBhMy4xOCwzLjE4LDAsMCwxLTMtMi4zMUE2LjIyLDYuMjIsMCwwLDAsMzEuMjEsNDFWMjZINDYuODVhMy4zLDMuMywwLDAsMSwxLjE0LjIxQTMuMTYsMy4xNiwwLDAsMSw1MCwyOS4xN1oiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTAuODUpIi8+DQogICAgPHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMjguMTYsMjQuMTNWNDFhMy4xMywzLjEzLDAsMCwxLTEuMjksMi41NCwzLDMsMCwwLDEtMS40Ny41OGwwLDBIOC4xOUEzLjE1LDMuMTUsMCwwLDEsNSw0MVYyNGEzLjE3LDMuMTcsMCwwLDEsMy4xNS0zSDI1YTMuMTIsMy4xMiwwLDAsMSwxLjE0LjIyLDMuMjQsMy4yNCwwLDAsMSwxLjksMi4xQTMuNjMsMy42MywwLDAsMSwyOC4xNiwyNC4xM1oiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTAuODUpIi8+DQogIDwvZz4NCjwvc3ZnPg0K';
111 $menupage_cap = apply_filters( 'ultp_menu_page_capability', 'manage_options' );
112 add_menu_page(
113 __( 'PostX', 'ultimate-post' ),
114 __( 'PostX', 'ultimate-post' ),
115 $menupage_cap,
116 'ultp-settings',
117 array( self::class, 'ultp_dashboard' ),
118 $ultp_menu_icon,
119 58.5
120 );
121
122 add_submenu_page(
123 'ultp-settings',
124 __( 'PostX Dashboard', 'ultimate-post' ),
125 __( 'Getting Started', 'ultimate-post' ),
126 $menupage_cap,
127 'ultp-settings'
128 );
129
130 $menu_lists = array(
131 'startersites' => esc_html__( 'Starter Sites', 'ultimate-post' ),
132 'builder' => esc_html__( 'Site Builder', 'ultimate-post' ),
133 'saved-templates' => esc_html__( 'Saved Templates', 'ultimate-post' ),
134 'custom-font' => esc_html__( 'Custom Font', 'ultimate-post' ),
135 'addons' => esc_html__( 'Add-ons', 'ultimate-post' ),
136 'blocks' => esc_html__( 'Blocks', 'ultimate-post' ),
137 'settings' => esc_html__( 'Settings', 'ultimate-post' ),
138 );
139 if ( defined( 'ULTP_PRO_VER' ) ) {
140 $menu_lists['license'] = esc_html__( 'License', 'ultimate-post' );
141 }
142
143 foreach ( $menu_lists as $key => $val ) {
144 add_submenu_page(
145 'ultp-settings',
146 $val,
147 $val,
148 $menupage_cap,
149 'ultp-settings#' . $key,
150 array( __CLASS__, 'render_main' )
151 );
152 }
153 add_submenu_page(
154 'ultp-settings',
155 esc_html__( 'Initial Setup', 'ultimate-post' ),
156 esc_html__( 'Initial Setup', 'ultimate-post' ),
157 $menupage_cap,
158 'ultp-setup-wizard',
159 array( __CLASS__, 'ultp_wizard_page' )
160 );
161
162 $pro_link = '';
163 $pro_link_text = '';
164 if ( ! Xpo::is_lc_active() ) {
165 $pro_link = Xpo::generate_utm_link(
166 array(
167 'utmKey' => 'sub_menu',
168 )
169 );
170 $pro_link_text = __( 'Upgrade to Pro', 'ultimate-post' );
171 } elseif ( Xpo::is_lc_expired() ) {
172 $license_key = Xpo::get_lc_key();
173 $pro_link = 'https://account.wpxpo.com/checkout/?edd_license_key=' . $license_key;
174 $pro_link_text = __( 'Renew License', 'ultimate-post' );
175 }
176
177 if ( ! empty( $pro_link ) ) {
178 ob_start();
179 ?>
180 <a href="<?php echo esc_url( $pro_link ); ?>" target="_blank" class="ultp-go-pro">
181 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
182 <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>
183 </svg>
184 <span><?php echo esc_html( $pro_link_text ); ?></span>
185 </a>
186 <?php
187 $submenu_content = ob_get_clean();
188
189 add_submenu_page(
190 'ultp-settings',
191 '',
192 $submenu_content,
193 'manage_options',
194 'ultp-pro',
195 array( self::class, 'handle_external_redirects' )
196 );
197 }
198
199 add_theme_page(
200 __( 'Starter Sites', 'ultimate-post' ),
201 __( 'Starter Sites', 'ultimate-post' ),
202 $menupage_cap,
203 'ultp-startersites',
204 array( self::class, 'handle_external_redirects' )
205 );
206 }
207
208 /**
209 * Handle external redirects for menu and pro links.
210 *
211 * @since v.1.0.0
212 * @return void No return value.
213 */
214 public function handle_external_redirects() {
215 if (empty($_GET['page'])) { // @codingStandardsIgnoreLine
216 return;
217 }
218 $_page = sanitize_key( $_GET['page'] );
219 if ('ultp-startersites' === $_page) { // @codingStandardsIgnoreLine
220 exit( wp_safe_redirect( admin_url( 'admin.php?page=ultp-settings#startersites' ) ) );
221 } else if ('go_postx_pro' === $_page) { // @codingStandardsIgnoreLine
222 wp_redirect(
223 Xpo::generate_utm_link(
224 array(
225 'utmKey' => 'dashboard_go_pro',
226 )
227 )
228 );
229 die();
230 }
231 }
232
233 /**
234 * Render the wizard page.
235 *
236 * @since v.2.4.4
237 */
238 public static function ultp_wizard_page() {
239 ?>
240 <div class="ultp-wizard-page-wrap" id="ultp-wizard-page"></div>
241 <?php
242 }
243
244 /**
245 * Render the dashboard page.
246 *
247 * @since v.1.0.0
248 * @return void No return value.
249 */
250 public static function ultp_dashboard() {
251 echo '<div id="ultp-dashboard"></div>';
252 }
253
254 /**
255 * Remove all notifications from menu page.
256 *
257 * @since v.1.0.0
258 * @return void No return value.
259 */
260 public static function remove_all_notices() {
261 if (isset($_GET['page'])) { // @codingStandardsIgnoreLine
262 $page = sanitize_key($_GET['page']); // @codingStandardsIgnoreLine
263 if (
264 $page === 'ultp-settings' ||
265 $page === 'ultp-license' ||
266 $page === 'ultp-setup-wizard'
267 ) {
268 remove_all_actions( 'admin_notices' );
269 remove_all_actions( 'all_admin_notices' );
270 }
271 }
272 }
273 }
274