PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.1.1
Post Grid Gutenberg Blocks – PostX v5.1.1
5.1.1 5.1.0 5.0.41 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 All 240 releases
ultimate-post / classes / Options.php

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

259 lines 8.7 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( 'admin_footer', array( $this, 'sync_addon_submenu_visibility' ) );
35 add_action( 'in_admin_header', array( $this, 'remove_all_notices' ) );
36 add_filter( 'plugin_row_meta', array( $this, 'plugin_settings_meta' ), 10, 2 );
37 add_filter( 'plugin_action_links_' . ULTP_BASE, array( $this, 'plugin_action_links_callback' ) );
38 }
39
40
41 /**
42 * Adds extra links to the plugin row meta on the plugins page.
43 *
44 * @param array $links Existing plugin meta links.
45 * @param string $file Plugin file path.
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 * Adds quick action links below the plugin name.
69 *
70 * @param array $links Default plugin action links.
71 * @return array Modified plugin action links.
72 */
73 public function plugin_action_links_callback( $links ) {
74 $setting_link = array(
75 'ultp_options' => '<a href="' . esc_url( admin_url( 'admin.php?page=ultp-settings#startersites' ) ) . '">' . esc_html__( 'Starter Sites', 'ultimate-post' ) . '</a>',
76 );
77
78 // The "Upgrade to Pro" / "Renew License" link is added after this by
79 // includes/notice/class-promo-links.php.
80 return array_merge( $setting_link, $links );
81 }
82
83
84 /**
85 * Add admin menu option page and submenus.
86 *
87 * @since v.1.0.0
88 * @return void No return value.
89 */
90 public static function menu_page_callback() {
91 $ultp_menu_icon = 'data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MCA0OC4zIj4NCiAgPGRlZnM+DQogICAgPHN0eWxlPg0KICAgICAgLmNscy0xIHsNCiAgICAgICAgZmlsbDogI2E3YWFhZDsNCiAgICAgIH0NCiAgICA8L3N0eWxlPg0KICA8L2RlZnM+DQogIDx0aXRsZT5Qb3N0eCBJY29uIGNtcHJzc2QgU1ZHPC90aXRsZT4NCiAgPGc+DQogICAgPHBhdGggY2xhc3M9ImNscy0xIiBkPSJNMTguODEsOXY4LjlIOC4x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ywwLDAsMSwyOC4xNiwyNC4xM1oiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTAuODUpIi8+DQogIDwvZz4NCjwvc3ZnPg0K';
92 $menupage_cap = apply_filters( 'ultp_menu_page_capability', 'manage_options' );
93 add_menu_page(
94 __( 'PostX', 'ultimate-post' ),
95 __( 'PostX', 'ultimate-post' ),
96 $menupage_cap,
97 'ultp-settings',
98 array( self::class, 'ultp_dashboard' ),
99 $ultp_menu_icon,
100 58.5
101 );
102
103 add_submenu_page(
104 'ultp-settings',
105 __( 'PostX Dashboard', 'ultimate-post' ),
106 __( 'Getting Started', 'ultimate-post' ),
107 $menupage_cap,
108 'ultp-settings'
109 );
110
111 $menu_lists = array(
112 'startersites' => esc_html__( 'Starter Sites', 'ultimate-post' ),
113 'builder' => esc_html__( 'Site Builder', 'ultimate-post' ),
114 'saved-templates' => esc_html__( 'Saved Templates', 'ultimate-post' ),
115 'custom-font' => esc_html__( 'Custom Font', 'ultimate-post' ),
116 'addons' => esc_html__( 'Add-ons', 'ultimate-post' ),
117 'blocks' => esc_html__( 'Blocks', 'ultimate-post' ),
118 'settings' => esc_html__( 'Settings', 'ultimate-post' ),
119 );
120 if ( defined( 'ULTP_PRO_VER' ) ) {
121 $menu_lists['license'] = esc_html__( 'License ', 'ultimate-post' );
122 }
123
124 foreach ( $menu_lists as $key => $val ) {
125 add_submenu_page(
126 'ultp-settings',
127 $val,
128 $val,
129 $menupage_cap,
130 'ultp-settings#' . $key,
131 array( __CLASS__, 'render_main' )
132 );
133 }
134 add_submenu_page(
135 'ultp-settings',
136 esc_html__( 'Initial Setup', 'ultimate-post' ),
137 esc_html__( 'Initial Setup', 'ultimate-post' ),
138 $menupage_cap,
139 'ultp-setup-wizard',
140 array( __CLASS__, 'ultp_wizard_page' )
141 );
142
143 // The "Upgrade to Pro" / "Renew License" item is added last by includes/notice/class-promo-links.php.
144
145 add_theme_page(
146 __( 'Starter Sites', 'ultimate-post' ),
147 __( 'Starter Sites', 'ultimate-post' ),
148 $menupage_cap,
149 'ultp-startersites',
150 array( self::class, 'handle_external_redirects' )
151 );
152 }
153
154 /**
155 * Sync addon-backed WordPress submenu items with addon enabled status.
156 *
157 * @since v.4.1.7
158 * @return void No return value.
159 */
160 public function sync_addon_submenu_visibility() {
161 $settings = ultimate_post()->get_setting();
162 $submenus = array(
163 'builder' => 'ultp_builder',
164 'saved-templates' => 'ultp_templates',
165 'custom-font' => 'ultp_custom_font',
166 );
167
168 foreach ( $submenus as $slug => $setting_key ) {
169 $submenus[ $slug ] = isset( $settings[ $setting_key ] ) && $settings[ $setting_key ] !== 'false';
170 }
171 ?>
172 <script>
173 ( function() {
174 const postxAddonSubmenus = <?php echo wp_json_encode( $submenus ); ?>;
175
176 Object.keys( postxAddonSubmenus ).forEach( function( slug ) {
177 const link = document.querySelector( '#adminmenu a[href*="page=ultp-settings#' + slug + '"]' );
178 const item = link ? link.closest( 'li' ) : null;
179
180 if ( ! item ) {
181 return;
182 }
183
184 item.id = 'postx-submenu-' + slug;
185 item.style.display = postxAddonSubmenus[ slug ] ? '' : 'none';
186 } );
187 }() );
188 </script>
189 <?php
190 }
191
192 /**
193 * Handle external redirects for menu and pro links.
194 *
195 * @since v.1.0.0
196 * @return void No return value.
197 */
198 public function handle_external_redirects() {
199 if (empty($_GET['page'])) { // @codingStandardsIgnoreLine
200 return;
201 }
202 $_page = sanitize_key( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug.
203 if ('ultp-startersites' === $_page) { // @codingStandardsIgnoreLine
204 wp_safe_redirect( admin_url( 'admin.php?page=ultp-settings#startersites' ) );
205 exit;
206 } else if ('go_postx_pro' === $_page) { // @codingStandardsIgnoreLine
207 wp_redirect( // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Intentional redirect to the fixed wpxpo.com pricing URL.
208 Xpo::generate_utm_link(
209 array(
210 'utmKey' => 'dashboard_go_pro',
211 )
212 )
213 );
214 die();
215 }
216 }
217
218 /**
219 * Render the wizard page.
220 *
221 * @since v.2.4.4
222 */
223 public static function ultp_wizard_page() {
224 ?>
225 <div class="ultp-wizard-page-wrap" id="ultp-wizard-page"></div>
226 <?php
227 }
228
229 /**
230 * Render the dashboard page.
231 *
232 * @since v.1.0.0
233 * @return void No return value.
234 */
235 public static function ultp_dashboard() {
236 echo '<div id="ultp-dashboard"></div>';
237 }
238
239 /**
240 * Remove all notifications from menu page.
241 *
242 * @since v.1.0.0
243 * @return void No return value.
244 */
245 public static function remove_all_notices() {
246 if (isset($_GET['page'])) { // @codingStandardsIgnoreLine
247 $page = sanitize_key($_GET['page']); // @codingStandardsIgnoreLine
248 if (
249 $page === 'ultp-settings' ||
250 $page === 'ultp-license' ||
251 $page === 'ultp-setup-wizard'
252 ) {
253 remove_all_actions( 'admin_notices' );
254 remove_all_actions( 'all_admin_notices' );
255 }
256 }
257 }
258 }
259