PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 5.2.7
Admin and Site Enhancements (ASE) v5.2.7
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / settings.php
admin-site-enhancements Last commit date
assets 3 years ago classes 3 years ago includes 3 years ago vendor 3 years ago LICENSE.md 3 years ago README.md 3 years ago admin-site-enhancements.php 3 years ago bootstrap.php 3 years ago settings.php 3 years ago
settings.php
794 lines
1 <?php
2
3 /**
4 * Register admin menu
5 *
6 * @since 1.0.0
7 */
8 function asenha_register_admin_menu()
9 {
10 add_submenu_page(
11 'tools.php',
12 // Parent page/menu
13 'Admin and Site Enhancements',
14 // Browser tab/window title
15 'Enhancements',
16 // Sube menu title
17 'manage_options',
18 // Minimal user capabililty
19 ASENHA_SLUG,
20 // Page slug. Shows up in URL.
21 'asenha_add_settings_page'
22 );
23 }
24
25 /**
26 * Create the settings page of the plugin
27 *
28 * @since 1.0.0
29 */
30 function asenha_add_settings_page()
31 {
32 ?>
33 <div class="wrap asenha">
34
35 <div id="asenha-header" class="asenha-header">
36 <div class="asenha-header-left">
37 <h1 class="asenha-heading"><?php
38 echo get_admin_page_title() ;
39 ?> <small><?php
40 esc_html_e( 'by', 'admin-site-enhancements' );
41 ?> <a href="https://bowo.io/asenha-bw" target="_blank">Bowo</a></small></h1>
42 <!-- <a href="https://wordpress.org/plugins/admin-site-enhancements/" target="_blank" class="asenha-header-action"><span>&#8505;</span> <?php
43 // esc_html_e( 'Info', 'admin-site-enhancements' );
44 ?></a> -->
45 </div>
46 <div class="asenha-header-right">
47 <a href="https://bowo.io/asenha-rvw" target="_blank" class="asenha-header-action"><span>&starf;</span> <?php
48 esc_html_e( 'Review', 'admin-site-enhancements' );
49 ?></a>
50 <a href="https://bowo.io/asenha-fdbk" target="_blank" class="asenha-header-action">&#10010; <?php
51 esc_html_e( 'Feedback', 'admin-site-enhancements' );
52 ?></a>
53 <a href="https://bowo.io/asenha-trnslt" target="_blank" class="asenha-header-action">&#9654; <?php
54 esc_html_e( 'Translate', 'admin-site-enhancements' );
55 ?></a>
56 <div id="plugin-sponsor" class="button button-primary plugin-sponsor">
57 <?php
58 esc_html_e( 'Sponsor', 'admin-site-enhancements' );
59 ?>
60 </div>
61 <a class="button button-primary asenha-save-button">Save Changes</a>
62 <div class="asenha-changes-saved" style="display:none;">Changes have been saved.</div>
63 </div>
64 </div>
65
66 <div class="asenha-body">
67 <div class="asenha-sponsorship-nudge" style="display: none;">
68 <h3>Looks like some of these enhancements have been useful for your site?</h3>
69 <p class="nudge-description">Please consider supporting Admin and Site Enhancements (ASE).</p>
70 <div class="nudge-content">
71 <div class="nudge-primary">
72 <h4>Sponsor ASE from as little as USD 1, monthly or one-time</h4>
73 <div class="nudge-info">
74 <p class="nudge-description user-quote">“A very very useful plugin. I have made a little sponsorship and encourage other users to do the same as it is so much deserved. Thank you Bowo! ~<a href="https://wordpress.org/support/topic/very-very-useful-54/" target="_blank">@pgrand83</a></p>
75 <p class="nudge-description">Please consider sponsoring ASE's ongoing development and maintenance so it can remain functional and useful for years to come. Thank you!</p>
76 </div>
77 <div class="nudge-ctas">
78 <a href="https://bowo.io/asenha-sp-gth-ndg" class="button button-primary sponsorship-button monthly" target="_blank">Sponsor Monthly</a>
79 <a href="https://bowo.io/asenha-sp-ppl-ndg" class="button sponsorship-button one-time" target="_blank">Sponsor One-Time</a>
80 <a href="#" id="have-sponsored" class="asenha-have-sponsored">I've sponsored ASE</a>
81 </div>
82 <div class="nudge-stats">
83 <p class="nudge-description">ASE has required more than <a href="https://bowo.io/asenha-sp-ndg-chnlg" target="_blank">250 hours of dev time</a>. At v5.2.7 (released on June 26, 2023) and 4,000+ active installs, there have been <a href="https://bowo.io/asenha-sp-gth-ndg" target="_blank">4 monthly sponsors</a> and <a href="https://bowo.io/asenha-sp-ppl-ndg" target="_blank">16 one-time sponsors</a>. You can be one today!</p>
84 </div>
85 </div>
86 <div class="nudge-secondary">
87 <h4>Give ASE your 5-star review or provide detailed feedback</h4>
88 <p class="nudge-description user-quote">“Simply the best! Still looking for the sixth star for you. Don’t stop developing… We are supporting you! ~<a href="https://wordpress.org/support/topic/too-good-to-be-true-22/" target="_blank">@springbreak</a></p>
89 <p class="nudge-description">If financial sponsorship is not something you can provide at the moment, you can always <a href="https://bowo.io/asenha-rvw-ndg" target="_blank">add a quick, 5-star review</a> to support ASE. Or, <a href="https://bowo.io/asenha-fdbk-ndg" target="_blank">provide your feature request or feedback</a> so it is worthy of a 5-star review for a future release.</p>
90 <p class="nudge-description">A good and detailed feature request or feedback is much more appreciated than a less-than-5-star review. ASE aims for nothing less than excellence. It has received <a href="https://bowo.io/asenha-rvw-ndg" target="_blank">50+ 5-star reviews</a> so far. Help make it 100, or more!</p>
91 </div>
92 </div>
93 <h3>Thank you!</h3>
94 <p class="nudge-description">I hope you continue to benefit from ASE. ~<a href="https://bowo.io/asenha-bw-ndg" target="_blank">Bowo</a></p>
95 <div class="dismiss-sponsorship-nudge"><a href="#" id="sponsorship-nudge-dismiss" class="asenha-sponsorship-nudge-dismiss">Dismiss this notice</a></div>
96 </div>
97 <form action="options.php" method="post">
98 <div class="asenha-vertical-tabs">
99 <div class="asenha-tab-buttons">
100 <input id="tab-content-management" type="radio" name="tabs" checked><label for="tab-content-management">Content Management</label>
101 <input id="tab-admin-interface" type="radio" name="tabs"><label for="tab-admin-interface">Admin Interface</label>
102 <input id="tab-login-logout" type="radio" name="tabs"><label for="tab-login-logout">Log In | Log Out</label>
103 <input id="tab-custom-code" type="radio" name="tabs"><label for="tab-custom-code">Custom Code</label>
104 <input id="tab-disable-components" type="radio" name="tabs"><label for="tab-disable-components">Disable Components</label>
105 <input id="tab-security" type="radio" name="tabs"><label for="tab-security">Security</label>
106 <input id="tab-optimizations" type="radio" name="tabs"><label for="tab-optimizations">Optimizations</label>
107 <input id="tab-utilities" type="radio" name="tabs"><label for="tab-utilities">Utilities</label>
108 </div>
109 <div class="asenha-tab-contents">
110 <section class="asenha-fields fields-content-management">
111 <table class="form-table" role="presentation">
112 <tbody></tbody>
113 </table>
114 </section>
115 <section class="asenha-fields fields-admin-interface">
116 <table class="form-table" role="presentation">
117 <tbody></tbody>
118 </table>
119 </section>
120 <section class="asenha-fields fields-login-logout">
121 <table class="form-table" role="presentation">
122 <tbody></tbody>
123 </table>
124 </section>
125 <section class="asenha-fields fields-custom-code">
126 <table class="form-table" role="presentation">
127 <tbody></tbody>
128 </table>
129 </section>
130 <section class="asenha-fields fields-disable-components">
131 <table class="form-table" role="presentation">
132 <tbody></tbody>
133 </table>
134 </section>
135 <section class="asenha-fields fields-security">
136 <table class="form-table" role="presentation">
137 <tbody></tbody>
138 </table>
139 </section>
140 <section class="asenha-fields fields-optimizations">
141 <table class="form-table" role="presentation">
142 <tbody></tbody>
143 </table>
144 </section>
145 <section class="asenha-fields fields-utilities">
146 <table class="form-table" role="presentation">
147 <tbody></tbody>
148 </table>
149 </section>
150 </div>
151 </div>
152 <div style="display:none;"><!-- Hide to prevent flash of fields appearing at the bottom of the page -->
153 <?php
154 settings_fields( ASENHA_ID );
155 ?>
156 <?php
157 do_settings_sections( ASENHA_SLUG );
158 ?>
159 <?php
160 submit_button(
161 'Save Changes',
162 // Button copy
163 'primary',
164 // Type: 'primary', 'small', or 'large'
165 'submit',
166 // The 'name' attribute
167 true,
168 // Whether to wrap in <p> tag
169 array(
170 'id' => 'asenha-submit',
171 )
172 );
173 ?>
174 </div>
175 </form>
176 </div>
177
178 <div class="asenha-footer">
179 </div>
180
181 <div id="asenha-sponsor" class="cta-modal-content sponsorship" style="display:none;">
182 <div class="sponsorship-content">
183 <div class="sponsorship-header">
184 <div class="sponsorship-image">
185 <img src="<?php
186 echo esc_attr( ASENHA_URL . 'assets/img/undraw_Programming_re_kg9v.png' ) ;
187 ?>" />
188 </div>
189 <h2>Thank you for your interest in sponsoring!</h2>
190 </div>
191 <div class="sponsorship-content-sections">
192 <div class="sponsorship-info">
193 <p class="sponsorship-description">I love building <strong>useful and free <a href="https://bowo.io/asenha-other-plugins" target="_blank">plugins</a></strong>. Your sponsorship will help justify the time and effort I spend in <strong>developing and maintaining this plugin</strong>, so it can remain functional and be more useful for <strong>your personal project(s), paid dev work, client site(s) and/or agency workflow</strong>... hopefully for years to come.</p>
194 </div>
195 <div class="sponsorship-methods">
196 <p class="sponsorship-amount">Sponsorship can be <strong>as little as USD 1</strong>, monthly or one-time.</p>
197 <div class="sponsorship-method sponsor-via-github">
198 <a href="https://bowo.io/asenha-sp-gth" target="_blank" class="button button-primary button-hero sponsorship-button monthly">Monthly Sponsorship via Github <span class="dashicons dashicons-arrow-right-alt2"></span></a>
199 </div>
200 <div class="sponsorship-method sponsor-via-paypal">
201 <a href="https://bowo.io/asenha-sp-ppl" target="_blank" class="button button-hero sponsorship-button one-time">One-time Sponsorship via PayPal <span class="dashicons dashicons-arrow-right-alt2"></span></a>
202 </div>
203 </div>
204 </div>
205 <p>More about me and my work at <a href="https://bowo.io/asenha-bw-sp" target="_blank">bowo.io</a>.</p>
206 </div>
207 </div>
208 </div>
209 <?php
210 // Record the number of times changes were saved as well as the date of last save
211 $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() );
212 $changes_saved = ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ? true : false );
213
214 if ( $changes_saved ) {
215 $current_date = date( 'Y-m-d', time() );
216
217 if ( !isset( $asenha_stats['first_save_date'] ) ) {
218 $asenha_stats['first_save_date'] = $current_date;
219 $asenha_stats['last_save_date'] = $current_date;
220 $asenha_stats['save_count'] = 1;
221 $asenha_stats['have_sponsored'] = false;
222 $asenha_stats['sponsorship_nudge_dismissed'] = false;
223 $asenha_stats['sponsorship_nudge_last_shown_date'] = '';
224 $asenha_stats['sponsorship_nudge_last_shown_save_count'] = 0;
225 } else {
226 $asenha_stats['last_save_date'] = $current_date;
227 $save_count = $asenha_stats['save_count'];
228 $save_count++;
229 $asenha_stats['save_count'] = $save_count;
230 }
231
232 update_option( ASENHA_SLUG_U . '_stats', $asenha_stats );
233 }
234
235 }
236
237 /**
238 * Suppress all notices, then add notice for successful settings update
239 *
240 * @since 1.1.0
241 */
242 function asenha_suppress_notices()
243 {
244 global $plugin_page ;
245 // Suppress all notices
246 if ( ASENHA_SLUG === $plugin_page ) {
247 remove_all_actions( 'admin_notices' );
248 }
249 // Add notice for successful settings update
250 if ( isset( $_GET['page'] ) && ASENHA_SLUG == $_GET['page'] && isset( $_GET['settings-updated'] ) && true == $_GET['settings-updated'] ) {
251 ?>
252 <script>
253 jQuery(document).ready( function() {
254 jQuery('.asenha-changes-saved').fadeIn(400).delay(2500).fadeOut(400);
255 });
256 </script>
257
258 <?php
259 }
260 }
261
262 /**
263 * Suppress all generic notices on the plugin settings page
264 *
265 * @since 2.7.0
266 */
267 function asenha_suppress_generic_notices()
268 {
269 global $plugin_page ;
270 // Suppress all notices
271 if ( ASENHA_SLUG === $plugin_page ) {
272 remove_all_actions( 'all_admin_notices' );
273 }
274 }
275
276 /**
277 * Enqueue admin scripts
278 *
279 * @since 1.0.0
280 */
281 function asenha_admin_scripts( $hook_suffix )
282 {
283 global
284 $wp_version,
285 $pagenow,
286 $typenow,
287 $taxnow,
288 $hook_suffix
289 ;
290 $current_screen = get_current_screen();
291 // Get all WP Enhancements options, default to empty array in case it's not been created yet
292 $options = get_option( 'admin_site_enhancements', array() );
293 // For main page of this plugin
294
295 if ( is_asenha() ) {
296 wp_enqueue_style(
297 'asenha-jbox',
298 ASENHA_URL . 'assets/css/jBox.all.min.css',
299 array(),
300 ASENHA_VERSION
301 );
302 wp_enqueue_script(
303 'asenha-jbox',
304 ASENHA_URL . 'assets/js/jBox.all.min.js',
305 array(),
306 ASENHA_VERSION,
307 false
308 );
309 wp_enqueue_script(
310 'asenha-jsticky',
311 ASENHA_URL . 'assets/js/jquery.jsticky.mod.min.js',
312 array( 'jquery' ),
313 ASENHA_VERSION,
314 false
315 );
316 wp_enqueue_script(
317 'asenha-js-cookie',
318 ASENHA_URL . 'assets/js/js.cookie.min.js',
319 array(),
320 ASENHA_VERSION,
321 false
322 );
323 // jQuery UI Sortables. In use, e.g. for Admin Interface >> Admin Menu Organizer
324 // Re-register and re-enqueue jQuery UI Core and plugins required for sortable, draggable and droppable when ordering menu items
325 wp_deregister_script( 'jquery-ui-core' );
326 wp_register_script(
327 'jquery-ui-core',
328 get_site_url() . '/wp-includes/js/jquery/ui/core.min.js',
329 array( 'jquery' ),
330 ASENHA_VERSION,
331 false
332 );
333 wp_enqueue_script( 'jquery-ui-core' );
334
335 if ( version_compare( $wp_version, '5.6.0', '>=' ) ) {
336 wp_deregister_script( 'jquery-ui-mouse' );
337 wp_register_script(
338 'jquery-ui-mouse',
339 get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js',
340 array( 'jquery-ui-core' ),
341 ASENHA_VERSION,
342 false
343 );
344 wp_enqueue_script( 'jquery-ui-mouse' );
345 } else {
346 wp_deregister_script( 'jquery-ui-widget' );
347 wp_register_script(
348 'jquery-ui-widget',
349 get_site_url() . '/wp-includes/js/jquery/ui/widget.min.js',
350 array( 'jquery' ),
351 ASENHA_VERSION,
352 false
353 );
354 wp_enqueue_script( 'jquery-ui-widget' );
355 wp_deregister_script( 'jquery-ui-mouse' );
356 wp_register_script(
357 'jquery-ui-mouse',
358 get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js',
359 array( 'jquery-ui-core', 'jquery-ui-widget' ),
360 ASENHA_VERSION,
361 false
362 );
363 wp_enqueue_script( 'jquery-ui-mouse' );
364 }
365
366 wp_deregister_script( 'jquery-ui-sortable' );
367 wp_register_script(
368 'jquery-ui-sortable',
369 get_site_url() . '/wp-includes/js/jquery/ui/sortable.min.js',
370 array( 'jquery-ui-mouse' ),
371 ASENHA_VERSION,
372 false
373 );
374 wp_enqueue_script( 'jquery-ui-sortable' );
375 wp_deregister_script( 'jquery-ui-draggable' );
376 wp_register_script(
377 'jquery-ui-draggable',
378 get_site_url() . '/wp-includes/js/jquery/ui/draggable.min.js',
379 array( 'jquery-ui-mouse' ),
380 ASENHA_VERSION,
381 false
382 );
383 wp_enqueue_script( 'jquery-ui-draggable' );
384 wp_deregister_script( 'jquery-ui-droppable' );
385 wp_register_script(
386 'jquery-ui-droppable',
387 get_site_url() . '/wp-includes/js/jquery/ui/droppable.min.js',
388 array( 'jquery-ui-draggable' ),
389 ASENHA_VERSION,
390 false
391 );
392 wp_enqueue_script( 'jquery-ui-droppable' );
393 // Script to set behaviour and actions of the sortable menu
394 wp_enqueue_script(
395 'asenha-custom-admin-menu',
396 ASENHA_URL . 'assets/js/custom-admin-menu.js',
397 array( 'jquery-ui-draggable' ),
398 ASENHA_VERSION,
399 false
400 );
401 // CodeMirror. In use, e.g. for Utilities >> Enable Custom Admin / Frontend CSS / ads.txt / app-ads.txt
402 wp_enqueue_style(
403 'asenha-codemirror',
404 ASENHA_URL . 'assets/css/codemirror/codemirror.min.css',
405 array(),
406 ASENHA_VERSION
407 );
408 wp_enqueue_script(
409 'asenha-codemirror',
410 ASENHA_URL . 'assets/js/codemirror/codemirror.min.js',
411 array( 'jquery' ),
412 ASENHA_VERSION,
413 true
414 );
415 wp_enqueue_script(
416 'asenha-codemirror-htmlmixed-mode',
417 ASENHA_URL . 'assets/js/codemirror/htmlmixed.js',
418 array( 'asenha-codemirror' ),
419 ASENHA_VERSION,
420 true
421 );
422 wp_enqueue_script(
423 'asenha-codemirror-xml-mode',
424 ASENHA_URL . 'assets/js/codemirror/xml.js',
425 array( 'asenha-codemirror' ),
426 ASENHA_VERSION,
427 true
428 );
429 wp_enqueue_script(
430 'asenha-codemirror-javascript-mode',
431 ASENHA_URL . 'assets/js/codemirror/javascript.js',
432 array( 'asenha-codemirror' ),
433 ASENHA_VERSION,
434 true
435 );
436 wp_enqueue_script(
437 'asenha-codemirror-css-mode',
438 ASENHA_URL . 'assets/js/codemirror/css.js',
439 array( 'asenha-codemirror' ),
440 ASENHA_VERSION,
441 true
442 );
443 wp_enqueue_script(
444 'asenha-codemirror-markdown-mode',
445 ASENHA_URL . 'assets/js/codemirror/markdown.js',
446 array( 'asenha-codemirror' ),
447 ASENHA_VERSION,
448 true
449 );
450 // DataTables. In use, e.g. for Security >> Limit Login Attempts
451 wp_enqueue_style(
452 'asenha-datatables',
453 ASENHA_URL . 'assets/css/datatables/datatables.min.css',
454 array(),
455 ASENHA_VERSION
456 );
457 wp_enqueue_script(
458 'asenha-datatables',
459 ASENHA_URL . 'assets/js/datatables/datatables.min.js',
460 array( 'jquery' ),
461 ASENHA_VERSION,
462 false
463 );
464 // Main style and script for the admin page
465 wp_enqueue_style(
466 'asenha-admin-page',
467 ASENHA_URL . 'assets/css/admin-page.css',
468 array( 'asenha-jbox', 'asenha-codemirror', 'asenha-datatables' ),
469 ASENHA_VERSION
470 );
471 wp_enqueue_script(
472 'asenha-admin-page',
473 ASENHA_URL . 'assets/js/admin-page.js',
474 array(
475 'asenha-jsticky',
476 'asenha-jbox',
477 'asenha-js-cookie',
478 'asenha-codemirror-htmlmixed-mode',
479 'asenha-codemirror-xml-mode',
480 'asenha-codemirror-javascript-mode',
481 'asenha-codemirror-css-mode',
482 'asenha-codemirror-markdown-mode',
483 'asenha-datatables',
484 'asenha-custom-admin-menu'
485 ),
486 ASENHA_VERSION,
487 false
488 );
489 }
490
491 // Enqueue on all wp-admin
492 wp_enqueue_style(
493 'asenha-wp-admin',
494 ASENHA_URL . 'assets/css/wp-admin.css',
495 array(),
496 ASENHA_VERSION
497 );
498 // Content Management >> Show IDs, for list tables in wp-admin, e.g. All Posts page
499 if ( false !== strpos( $current_screen->base, 'edit' ) || false !== strpos( $current_screen->base, 'users' ) || false !== strpos( $current_screen->base, 'upload' ) ) {
500 wp_enqueue_style(
501 'asenha-list-table',
502 ASENHA_URL . 'assets/css/list-table.css',
503 array(),
504 ASENHA_VERSION
505 );
506 }
507 // Content Management >> Enable Media Replacement
508
509 if ( $current_screen->base == 'upload' || $current_screen->id == 'attachment' ) {
510 // wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION );
511 // wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false );
512 wp_enqueue_style(
513 'asenha-media-replace',
514 ASENHA_URL . 'assets/css/media-replace.css',
515 array(),
516 ASENHA_VERSION
517 );
518 wp_enqueue_script(
519 'asenha-media-replace',
520 ASENHA_URL . 'assets/js/media-replace.js',
521 array(),
522 ASENHA_VERSION,
523 false
524 );
525 }
526
527 // Content Management >> Hide Admin Notices
528
529 if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
530 wp_enqueue_style(
531 'asenha-jbox',
532 ASENHA_URL . 'assets/css/jBox.all.min.css',
533 array(),
534 ASENHA_VERSION
535 );
536 wp_enqueue_script(
537 'asenha-jbox',
538 ASENHA_URL . 'assets/js/jBox.all.min.js',
539 array(),
540 ASENHA_VERSION,
541 false
542 );
543 wp_enqueue_style(
544 'asenha-hide-admin-notices',
545 ASENHA_URL . 'assets/css/hide-admin-notices.css',
546 array(),
547 ASENHA_VERSION
548 );
549 wp_enqueue_script(
550 'asenha-hide-admin-notices',
551 ASENHA_URL . 'assets/js/hide-admin-notices.js',
552 array( 'asenha-jbox' ),
553 ASENHA_VERSION,
554 false
555 );
556 }
557
558 // Utilities >> Multiple User Roles
559 if ( array_key_exists( 'multiple_user_roles', $options ) && $options['multiple_user_roles'] ) {
560 if ( 'user-edit.php' == $hook_suffix || 'user-new.php' == $hook_suffix ) {
561 // Only replace roles dropdown with checkboxes for users that can assign roles to other users, e.g. administrators
562 if ( current_user_can( 'promote_users', get_current_user_id() ) ) {
563 wp_enqueue_script(
564 'asenha-multiple-user-roles',
565 ASENHA_URL . 'assets/js/multiple-user-roles.js',
566 array( 'jquery' ),
567 ASENHA_VERSION,
568 false
569 );
570 }
571 }
572 }
573 // Pass on ASENHA stats to admin-page.js to determine whether to show sponsorship nudge
574 $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() );
575 $current_date = date( 'Y-m-d', time() );
576 $show_sponsorship_nudge = false;
577 $asenha_stats_localized = array(
578 'firstSaveDate' => '',
579 'lastSaveDate' => '',
580 'saveCount' => 0,
581 'daysSinceLastSaveDate' => 0,
582 'showSponsorshipNudge' => false,
583 );
584
585 if ( !empty($asenha_stats) ) {
586 $have_sponsored = $asenha_stats['have_sponsored'];
587 $changes_saved = ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ? true : false );
588 // Compensate for redirect from settings-updated=true URL
589
590 if ( $changes_saved ) {
591 $save_count = $asenha_stats['save_count'] + 1;
592 } else {
593 $save_count = $asenha_stats['save_count'];
594 }
595
596 $saves_to_nudge_sponsorship = 10;
597
598 if ( $save_count < $saves_to_nudge_sponsorship ) {
599 $save_count_modulo = -1;
600 } else {
601 $save_count_modulo = $save_count % $saves_to_nudge_sponsorship;
602 }
603
604 // User have not sponsored ASE
605 if ( false === $have_sponsored ) {
606 // Sponsorship nudge have not been dismissed
607
608 if ( false === $asenha_stats['sponsorship_nudge_dismissed'] ) {
609 // Show sponsorship nudge after every x saves
610
611 if ( $save_count_modulo >= 0 ) {
612 $show_sponsorship_nudge = true;
613 } else {
614 $show_sponsorship_nudge = false;
615 }
616
617
618 if ( $show_sponsorship_nudge && $save_count_modulo >= 0 ) {
619 $asenha_stats['sponsorship_nudge_last_shown_date'] = $current_date;
620 $asenha_stats['sponsorship_nudge_last_shown_save_count'] = $save_count;
621 update_option( ASENHA_SLUG_U . '_stats', $asenha_stats );
622 }
623
624 } else {
625
626 if ( $save_count_modulo == 0 ) {
627
628 if ( $save_count > $asenha_stats['sponsorship_nudge_last_shown_save_count'] ) {
629 $asenha_stats['sponsorship_nudge_dismissed'] = false;
630 update_option( ASENHA_SLUG_U . '_stats', $asenha_stats );
631 $show_sponsorship_nudge = true;
632 } else {
633 $show_sponsorship_nudge = false;
634 }
635
636 } else {
637 $show_sponsorship_nudge = false;
638 }
639
640 }
641
642 }
643 $asenha_stats_localized = array(
644 'firstSaveDate' => $asenha_stats['first_save_date'],
645 'lastSaveDate' => $asenha_stats['last_save_date'],
646 'saveCount' => $save_count,
647 'showSponsorshipNudge' => $show_sponsorship_nudge,
648 );
649 }
650
651 wp_localize_script( 'asenha-admin-page', 'asenhaStats', $asenha_stats_localized );
652 }
653
654 /**
655 * Enqueue public scripts
656 *
657 * @since 3.9.0
658 */
659 function asenha_public_scripts( $hook_suffix )
660 {
661 // Get all WP Enhancements options, default to empty array in case it's not been created yet
662 $options = get_option( 'admin_site_enhancements', array() );
663
664 if ( array_key_exists( 'enable_external_permalinks', $options ) ) {
665 $enable_external_permalinks = $options['enable_external_permalinks'];
666 } else {
667 $enable_external_permalinks = false;
668 }
669
670 wp_enqueue_script(
671 'asenha-public',
672 ASENHA_URL . 'assets/js/public.js',
673 array( 'jquery' ),
674 ASENHA_VERSION,
675 false
676 );
677 wp_localize_script( 'asenha-public', 'phpVars', array(
678 'externalPermalinksEnabled' => $enable_external_permalinks,
679 ) );
680 }
681
682 /**
683 * Add 'Access now' plugin action link.
684 *
685 * @since 1.0.0
686 */
687 function asenha_plugin_action_links( $links )
688 {
689 $settings_link = '<a href="tools.php?page=' . ASENHA_SLUG . '">Configure now</a>';
690 array_unshift( $links, $settings_link );
691 return $links;
692 }
693
694 /**
695 * Modify footer text
696 *
697 * @since 1.0.0
698 */
699 function asenha_footer_text()
700 {
701 if ( is_asenha() ) {
702 ?>
703 <a href="https://bowo.io/asenha-dotorg" target="_blank">Admin Site Enhancements</a> is on <a href="https://bowo.io/asenha-gthb" target="_blank">github</a>.
704 <?php
705 }
706 }
707
708 /**
709 * Change WP version number text in footer
710 *
711 * @since 4.8.3
712 */
713 function asenha_footer_version_text()
714 {
715 ?>
716 Also by Bowo &#8594; <a href="https://bowo.io/asenha-wpn" target="_blank">WordPress Newsboard</a>: The latest from 100+ sources
717 <?php
718 }
719
720 /**
721 * Check if current screen is this plugin's main page
722 *
723 * @since 1.0.0
724 */
725 function is_asenha()
726 {
727 $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] );
728 // e.g. /wp-admin/index.php?page=page-slug
729
730 if ( strpos( $request_uri, 'page=' . ASENHA_SLUG ) !== false ) {
731 return true;
732 // Yes, this is the plugin's main page
733 } else {
734 return false;
735 // Nope, this is NOT the plugin's page
736 }
737
738 }
739
740 /**
741 * Mark that user have sponsored ASE
742 *
743 * @since 5.2.7
744 */
745 function asenha_have_sponsored()
746 {
747
748 if ( isset( $_REQUEST ) ) {
749 $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() );
750 $asenha_stats['have_sponsored'] = true;
751 $asenha_stats['sponsorship_nudge_dismissed'] = true;
752 $success = update_option( ASENHA_SLUG_U . '_stats', $asenha_stats );
753
754 if ( $success ) {
755 echo json_encode( array(
756 'success' => true,
757 ) ) ;
758 } else {
759 echo json_encode( array(
760 'success' => false,
761 ) ) ;
762 }
763
764 }
765
766 }
767
768 /**
769 * Dismiss sponsorship nudge
770 *
771 * @since 5.2.7
772 */
773 function asenha_dismiss_sponsorship_nudge()
774 {
775
776 if ( isset( $_REQUEST ) ) {
777 $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() );
778 $asenha_stats['sponsorship_nudge_dismissed'] = true;
779 $success = update_option( ASENHA_SLUG_U . '_stats', $asenha_stats );
780
781 if ( $success ) {
782 echo json_encode( array(
783 'success' => true,
784 ) ) ;
785 } else {
786 echo json_encode( array(
787 'success' => false,
788 ) ) ;
789 }
790
791 }
792
793 }
794