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
803 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>ℹ</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>★</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">✚ <?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">▶ <?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 nudge-show-more is-enabled" 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 | <a id="enable-svg-upload-show-moreless" class="nudge-show-more-less show-more-less show-more" href="#">Expand ▼</a> |
| 71 | <div class="nudge-wrapper-show-more"> |
| 72 | <div class="nudge-content"> |
| 73 | <div class="nudge-primary"> |
| 74 | <h4>Sponsor ASE from as little as USD 1, monthly or one-time</h4> |
| 75 | <div class="nudge-info"> |
| 76 | <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> |
| 77 | <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> |
| 78 | </div> |
| 79 | <div class="nudge-ctas"> |
| 80 | <a href="https://bowo.io/asenha-sp-gth-ndg" class="button button-primary sponsorship-button monthly" target="_blank">Sponsor Monthly</a> |
| 81 | <a href="https://bowo.io/asenha-sp-ppl-ndg" class="button sponsorship-button one-time" target="_blank">Sponsor One-Time</a> |
| 82 | <a href="#" id="have-sponsored" class="asenha-have-sponsored">I've sponsored ASE</a> |
| 83 | </div> |
| 84 | <div class="nudge-stats"> |
| 85 | <p class="nudge-description">ASE has consumed more than <a href="https://bowo.io/asenha-sp-ndg-chnlg" target="_blank">250 hours of dev time</a>. At v5.2.8 (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> |
| 86 | </div> |
| 87 | </div> |
| 88 | <div class="nudge-secondary"> |
| 89 | <h4>Give ASE your 5-star review or provide detailed feedback</h4> |
| 90 | <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> |
| 91 | <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. 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> |
| 92 | <p class="nudge-description">Or, if you find something is lacking or not working as you expect it to, you can provide a good and detailed <a href="https://bowo.io/asenha-fdbk-ndg" target="_blank">feature request or feedback</a>, which is much more appreciated than a 4-star review or less. This is how we can work together to improve ASE.</p> |
| 93 | </div> |
| 94 | </div> |
| 95 | <a href="https://bowo.io/asenha-bw-ndg" target="_blank" class="nudge-photo-link"><img src="<?php |
| 96 | echo esc_attr( ASENHA_URL . 'assets/img/bowo.jpg' ) ; |
| 97 | ?>" class="nudge-photo" /></a> |
| 98 | <h3>Thank you!</h3> |
| 99 | <p class="nudge-description nudge-closing">I hope you continue to benefit from ASE. ~<a href="https://bowo.io/asenha-bw-ndg" target="_blank">Bowo</a></p> |
| 100 | <div class="dismiss-sponsorship-nudge"><a href="#" id="sponsorship-nudge-dismiss" class="asenha-sponsorship-nudge-dismiss">Dismiss this notice</a></div> |
| 101 | </div> |
| 102 | </div> |
| 103 | <form action="options.php" method="post"> |
| 104 | <div class="asenha-vertical-tabs"> |
| 105 | <div class="asenha-tab-buttons"> |
| 106 | <input id="tab-content-management" type="radio" name="tabs" checked><label for="tab-content-management">Content Management</label> |
| 107 | <input id="tab-admin-interface" type="radio" name="tabs"><label for="tab-admin-interface">Admin Interface</label> |
| 108 | <input id="tab-login-logout" type="radio" name="tabs"><label for="tab-login-logout">Log In | Log Out</label> |
| 109 | <input id="tab-custom-code" type="radio" name="tabs"><label for="tab-custom-code">Custom Code</label> |
| 110 | <input id="tab-disable-components" type="radio" name="tabs"><label for="tab-disable-components">Disable Components</label> |
| 111 | <input id="tab-security" type="radio" name="tabs"><label for="tab-security">Security</label> |
| 112 | <input id="tab-optimizations" type="radio" name="tabs"><label for="tab-optimizations">Optimizations</label> |
| 113 | <input id="tab-utilities" type="radio" name="tabs"><label for="tab-utilities">Utilities</label> |
| 114 | </div> |
| 115 | <div class="asenha-tab-contents"> |
| 116 | <section class="asenha-fields fields-content-management"> |
| 117 | <table class="form-table" role="presentation"> |
| 118 | <tbody></tbody> |
| 119 | </table> |
| 120 | </section> |
| 121 | <section class="asenha-fields fields-admin-interface"> |
| 122 | <table class="form-table" role="presentation"> |
| 123 | <tbody></tbody> |
| 124 | </table> |
| 125 | </section> |
| 126 | <section class="asenha-fields fields-login-logout"> |
| 127 | <table class="form-table" role="presentation"> |
| 128 | <tbody></tbody> |
| 129 | </table> |
| 130 | </section> |
| 131 | <section class="asenha-fields fields-custom-code"> |
| 132 | <table class="form-table" role="presentation"> |
| 133 | <tbody></tbody> |
| 134 | </table> |
| 135 | </section> |
| 136 | <section class="asenha-fields fields-disable-components"> |
| 137 | <table class="form-table" role="presentation"> |
| 138 | <tbody></tbody> |
| 139 | </table> |
| 140 | </section> |
| 141 | <section class="asenha-fields fields-security"> |
| 142 | <table class="form-table" role="presentation"> |
| 143 | <tbody></tbody> |
| 144 | </table> |
| 145 | </section> |
| 146 | <section class="asenha-fields fields-optimizations"> |
| 147 | <table class="form-table" role="presentation"> |
| 148 | <tbody></tbody> |
| 149 | </table> |
| 150 | </section> |
| 151 | <section class="asenha-fields fields-utilities"> |
| 152 | <table class="form-table" role="presentation"> |
| 153 | <tbody></tbody> |
| 154 | </table> |
| 155 | </section> |
| 156 | </div> |
| 157 | </div> |
| 158 | <div style="display:none;"><!-- Hide to prevent flash of fields appearing at the bottom of the page --> |
| 159 | <?php |
| 160 | settings_fields( ASENHA_ID ); |
| 161 | ?> |
| 162 | <?php |
| 163 | do_settings_sections( ASENHA_SLUG ); |
| 164 | ?> |
| 165 | <?php |
| 166 | submit_button( |
| 167 | 'Save Changes', |
| 168 | // Button copy |
| 169 | 'primary', |
| 170 | // Type: 'primary', 'small', or 'large' |
| 171 | 'submit', |
| 172 | // The 'name' attribute |
| 173 | true, |
| 174 | // Whether to wrap in <p> tag |
| 175 | array( |
| 176 | 'id' => 'asenha-submit', |
| 177 | ) |
| 178 | ); |
| 179 | ?> |
| 180 | </div> |
| 181 | </form> |
| 182 | </div> |
| 183 | |
| 184 | <div class="asenha-footer"> |
| 185 | </div> |
| 186 | |
| 187 | <div id="asenha-sponsor" class="cta-modal-content sponsorship" style="display:none;"> |
| 188 | <div class="sponsorship-content"> |
| 189 | <div class="sponsorship-header"> |
| 190 | <div class="sponsorship-image"> |
| 191 | <img src="<?php |
| 192 | echo esc_attr( ASENHA_URL . 'assets/img/undraw_Programming_re_kg9v.png' ) ; |
| 193 | ?>" /> |
| 194 | </div> |
| 195 | <h2>Thank you for your interest in sponsoring!</h2> |
| 196 | </div> |
| 197 | <div class="sponsorship-content-sections"> |
| 198 | <div class="sponsorship-info"> |
| 199 | <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> |
| 200 | </div> |
| 201 | <div class="sponsorship-methods"> |
| 202 | <p class="sponsorship-amount">Sponsorship can be <strong>as little as USD 1</strong>, monthly or one-time.</p> |
| 203 | <div class="sponsorship-method sponsor-via-github"> |
| 204 | <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> |
| 205 | </div> |
| 206 | <div class="sponsorship-method sponsor-via-paypal"> |
| 207 | <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> |
| 208 | </div> |
| 209 | </div> |
| 210 | </div> |
| 211 | <p>More about me and my work at <a href="https://bowo.io/asenha-bw-sp" target="_blank">bowo.io</a>.</p> |
| 212 | </div> |
| 213 | </div> |
| 214 | </div> |
| 215 | <?php |
| 216 | // Record the number of times changes were saved as well as the date of last save |
| 217 | $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() ); |
| 218 | $changes_saved = ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ? true : false ); |
| 219 | |
| 220 | if ( $changes_saved ) { |
| 221 | $current_date = date( 'Y-m-d', time() ); |
| 222 | |
| 223 | if ( !isset( $asenha_stats['first_save_date'] ) ) { |
| 224 | $asenha_stats['first_save_date'] = $current_date; |
| 225 | $asenha_stats['last_save_date'] = $current_date; |
| 226 | $asenha_stats['save_count'] = 1; |
| 227 | $asenha_stats['have_sponsored'] = false; |
| 228 | $asenha_stats['sponsorship_nudge_dismissed'] = false; |
| 229 | $asenha_stats['sponsorship_nudge_last_shown_date'] = ''; |
| 230 | $asenha_stats['sponsorship_nudge_last_shown_save_count'] = 0; |
| 231 | } else { |
| 232 | $asenha_stats['last_save_date'] = $current_date; |
| 233 | $save_count = $asenha_stats['save_count']; |
| 234 | $save_count++; |
| 235 | $asenha_stats['save_count'] = $save_count; |
| 236 | } |
| 237 | |
| 238 | update_option( ASENHA_SLUG_U . '_stats', $asenha_stats ); |
| 239 | } |
| 240 | |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Suppress all notices, then add notice for successful settings update |
| 245 | * |
| 246 | * @since 1.1.0 |
| 247 | */ |
| 248 | function asenha_suppress_notices() |
| 249 | { |
| 250 | global $plugin_page ; |
| 251 | // Suppress all notices |
| 252 | if ( ASENHA_SLUG === $plugin_page ) { |
| 253 | remove_all_actions( 'admin_notices' ); |
| 254 | } |
| 255 | // Add notice for successful settings update |
| 256 | if ( isset( $_GET['page'] ) && ASENHA_SLUG == $_GET['page'] && isset( $_GET['settings-updated'] ) && true == $_GET['settings-updated'] ) { |
| 257 | ?> |
| 258 | <script> |
| 259 | jQuery(document).ready( function() { |
| 260 | jQuery('.asenha-changes-saved').fadeIn(400).delay(2500).fadeOut(400); |
| 261 | }); |
| 262 | </script> |
| 263 | |
| 264 | <?php |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Suppress all generic notices on the plugin settings page |
| 270 | * |
| 271 | * @since 2.7.0 |
| 272 | */ |
| 273 | function asenha_suppress_generic_notices() |
| 274 | { |
| 275 | global $plugin_page ; |
| 276 | // Suppress all notices |
| 277 | if ( ASENHA_SLUG === $plugin_page ) { |
| 278 | remove_all_actions( 'all_admin_notices' ); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Enqueue admin scripts |
| 284 | * |
| 285 | * @since 1.0.0 |
| 286 | */ |
| 287 | function asenha_admin_scripts( $hook_suffix ) |
| 288 | { |
| 289 | global |
| 290 | $wp_version, |
| 291 | $pagenow, |
| 292 | $typenow, |
| 293 | $taxnow, |
| 294 | $hook_suffix |
| 295 | ; |
| 296 | $current_screen = get_current_screen(); |
| 297 | // Get all WP Enhancements options, default to empty array in case it's not been created yet |
| 298 | $options = get_option( 'admin_site_enhancements', array() ); |
| 299 | // For main page of this plugin |
| 300 | |
| 301 | if ( is_asenha() ) { |
| 302 | wp_enqueue_style( |
| 303 | 'asenha-jbox', |
| 304 | ASENHA_URL . 'assets/css/jBox.all.min.css', |
| 305 | array(), |
| 306 | ASENHA_VERSION |
| 307 | ); |
| 308 | wp_enqueue_script( |
| 309 | 'asenha-jbox', |
| 310 | ASENHA_URL . 'assets/js/jBox.all.min.js', |
| 311 | array(), |
| 312 | ASENHA_VERSION, |
| 313 | false |
| 314 | ); |
| 315 | wp_enqueue_script( |
| 316 | 'asenha-jsticky', |
| 317 | ASENHA_URL . 'assets/js/jquery.jsticky.mod.min.js', |
| 318 | array( 'jquery' ), |
| 319 | ASENHA_VERSION, |
| 320 | false |
| 321 | ); |
| 322 | wp_enqueue_script( |
| 323 | 'asenha-js-cookie', |
| 324 | ASENHA_URL . 'assets/js/js.cookie.min.js', |
| 325 | array(), |
| 326 | ASENHA_VERSION, |
| 327 | false |
| 328 | ); |
| 329 | // jQuery UI Sortables. In use, e.g. for Admin Interface >> Admin Menu Organizer |
| 330 | // Re-register and re-enqueue jQuery UI Core and plugins required for sortable, draggable and droppable when ordering menu items |
| 331 | wp_deregister_script( 'jquery-ui-core' ); |
| 332 | wp_register_script( |
| 333 | 'jquery-ui-core', |
| 334 | get_site_url() . '/wp-includes/js/jquery/ui/core.min.js', |
| 335 | array( 'jquery' ), |
| 336 | ASENHA_VERSION, |
| 337 | false |
| 338 | ); |
| 339 | wp_enqueue_script( 'jquery-ui-core' ); |
| 340 | |
| 341 | if ( version_compare( $wp_version, '5.6.0', '>=' ) ) { |
| 342 | wp_deregister_script( 'jquery-ui-mouse' ); |
| 343 | wp_register_script( |
| 344 | 'jquery-ui-mouse', |
| 345 | get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js', |
| 346 | array( 'jquery-ui-core' ), |
| 347 | ASENHA_VERSION, |
| 348 | false |
| 349 | ); |
| 350 | wp_enqueue_script( 'jquery-ui-mouse' ); |
| 351 | } else { |
| 352 | wp_deregister_script( 'jquery-ui-widget' ); |
| 353 | wp_register_script( |
| 354 | 'jquery-ui-widget', |
| 355 | get_site_url() . '/wp-includes/js/jquery/ui/widget.min.js', |
| 356 | array( 'jquery' ), |
| 357 | ASENHA_VERSION, |
| 358 | false |
| 359 | ); |
| 360 | wp_enqueue_script( 'jquery-ui-widget' ); |
| 361 | wp_deregister_script( 'jquery-ui-mouse' ); |
| 362 | wp_register_script( |
| 363 | 'jquery-ui-mouse', |
| 364 | get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js', |
| 365 | array( 'jquery-ui-core', 'jquery-ui-widget' ), |
| 366 | ASENHA_VERSION, |
| 367 | false |
| 368 | ); |
| 369 | wp_enqueue_script( 'jquery-ui-mouse' ); |
| 370 | } |
| 371 | |
| 372 | wp_deregister_script( 'jquery-ui-sortable' ); |
| 373 | wp_register_script( |
| 374 | 'jquery-ui-sortable', |
| 375 | get_site_url() . '/wp-includes/js/jquery/ui/sortable.min.js', |
| 376 | array( 'jquery-ui-mouse' ), |
| 377 | ASENHA_VERSION, |
| 378 | false |
| 379 | ); |
| 380 | wp_enqueue_script( 'jquery-ui-sortable' ); |
| 381 | wp_deregister_script( 'jquery-ui-draggable' ); |
| 382 | wp_register_script( |
| 383 | 'jquery-ui-draggable', |
| 384 | get_site_url() . '/wp-includes/js/jquery/ui/draggable.min.js', |
| 385 | array( 'jquery-ui-mouse' ), |
| 386 | ASENHA_VERSION, |
| 387 | false |
| 388 | ); |
| 389 | wp_enqueue_script( 'jquery-ui-draggable' ); |
| 390 | wp_deregister_script( 'jquery-ui-droppable' ); |
| 391 | wp_register_script( |
| 392 | 'jquery-ui-droppable', |
| 393 | get_site_url() . '/wp-includes/js/jquery/ui/droppable.min.js', |
| 394 | array( 'jquery-ui-draggable' ), |
| 395 | ASENHA_VERSION, |
| 396 | false |
| 397 | ); |
| 398 | wp_enqueue_script( 'jquery-ui-droppable' ); |
| 399 | // Script to set behaviour and actions of the sortable menu |
| 400 | wp_enqueue_script( |
| 401 | 'asenha-custom-admin-menu', |
| 402 | ASENHA_URL . 'assets/js/custom-admin-menu.js', |
| 403 | array( 'jquery-ui-draggable' ), |
| 404 | ASENHA_VERSION, |
| 405 | false |
| 406 | ); |
| 407 | // CodeMirror. In use, e.g. for Utilities >> Enable Custom Admin / Frontend CSS / ads.txt / app-ads.txt |
| 408 | wp_enqueue_style( |
| 409 | 'asenha-codemirror', |
| 410 | ASENHA_URL . 'assets/css/codemirror/codemirror.min.css', |
| 411 | array(), |
| 412 | ASENHA_VERSION |
| 413 | ); |
| 414 | wp_enqueue_script( |
| 415 | 'asenha-codemirror', |
| 416 | ASENHA_URL . 'assets/js/codemirror/codemirror.min.js', |
| 417 | array( 'jquery' ), |
| 418 | ASENHA_VERSION, |
| 419 | true |
| 420 | ); |
| 421 | wp_enqueue_script( |
| 422 | 'asenha-codemirror-htmlmixed-mode', |
| 423 | ASENHA_URL . 'assets/js/codemirror/htmlmixed.js', |
| 424 | array( 'asenha-codemirror' ), |
| 425 | ASENHA_VERSION, |
| 426 | true |
| 427 | ); |
| 428 | wp_enqueue_script( |
| 429 | 'asenha-codemirror-xml-mode', |
| 430 | ASENHA_URL . 'assets/js/codemirror/xml.js', |
| 431 | array( 'asenha-codemirror' ), |
| 432 | ASENHA_VERSION, |
| 433 | true |
| 434 | ); |
| 435 | wp_enqueue_script( |
| 436 | 'asenha-codemirror-javascript-mode', |
| 437 | ASENHA_URL . 'assets/js/codemirror/javascript.js', |
| 438 | array( 'asenha-codemirror' ), |
| 439 | ASENHA_VERSION, |
| 440 | true |
| 441 | ); |
| 442 | wp_enqueue_script( |
| 443 | 'asenha-codemirror-css-mode', |
| 444 | ASENHA_URL . 'assets/js/codemirror/css.js', |
| 445 | array( 'asenha-codemirror' ), |
| 446 | ASENHA_VERSION, |
| 447 | true |
| 448 | ); |
| 449 | wp_enqueue_script( |
| 450 | 'asenha-codemirror-markdown-mode', |
| 451 | ASENHA_URL . 'assets/js/codemirror/markdown.js', |
| 452 | array( 'asenha-codemirror' ), |
| 453 | ASENHA_VERSION, |
| 454 | true |
| 455 | ); |
| 456 | // DataTables. In use, e.g. for Security >> Limit Login Attempts |
| 457 | wp_enqueue_style( |
| 458 | 'asenha-datatables', |
| 459 | ASENHA_URL . 'assets/css/datatables/datatables.min.css', |
| 460 | array(), |
| 461 | ASENHA_VERSION |
| 462 | ); |
| 463 | wp_enqueue_script( |
| 464 | 'asenha-datatables', |
| 465 | ASENHA_URL . 'assets/js/datatables/datatables.min.js', |
| 466 | array( 'jquery' ), |
| 467 | ASENHA_VERSION, |
| 468 | false |
| 469 | ); |
| 470 | // Main style and script for the admin page |
| 471 | wp_enqueue_style( |
| 472 | 'asenha-admin-page', |
| 473 | ASENHA_URL . 'assets/css/admin-page.css', |
| 474 | array( 'asenha-jbox', 'asenha-codemirror', 'asenha-datatables' ), |
| 475 | ASENHA_VERSION |
| 476 | ); |
| 477 | wp_enqueue_script( |
| 478 | 'asenha-admin-page', |
| 479 | ASENHA_URL . 'assets/js/admin-page.js', |
| 480 | array( |
| 481 | 'asenha-jsticky', |
| 482 | 'asenha-jbox', |
| 483 | 'asenha-js-cookie', |
| 484 | 'asenha-codemirror-htmlmixed-mode', |
| 485 | 'asenha-codemirror-xml-mode', |
| 486 | 'asenha-codemirror-javascript-mode', |
| 487 | 'asenha-codemirror-css-mode', |
| 488 | 'asenha-codemirror-markdown-mode', |
| 489 | 'asenha-datatables', |
| 490 | 'asenha-custom-admin-menu' |
| 491 | ), |
| 492 | ASENHA_VERSION, |
| 493 | false |
| 494 | ); |
| 495 | } |
| 496 | |
| 497 | // Enqueue on all wp-admin |
| 498 | wp_enqueue_style( |
| 499 | 'asenha-wp-admin', |
| 500 | ASENHA_URL . 'assets/css/wp-admin.css', |
| 501 | array(), |
| 502 | ASENHA_VERSION |
| 503 | ); |
| 504 | // Content Management >> Show IDs, for list tables in wp-admin, e.g. All Posts page |
| 505 | if ( false !== strpos( $current_screen->base, 'edit' ) || false !== strpos( $current_screen->base, 'users' ) || false !== strpos( $current_screen->base, 'upload' ) ) { |
| 506 | wp_enqueue_style( |
| 507 | 'asenha-list-table', |
| 508 | ASENHA_URL . 'assets/css/list-table.css', |
| 509 | array(), |
| 510 | ASENHA_VERSION |
| 511 | ); |
| 512 | } |
| 513 | // Content Management >> Enable Media Replacement |
| 514 | |
| 515 | if ( $current_screen->base == 'upload' || $current_screen->id == 'attachment' ) { |
| 516 | // wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 517 | // wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 518 | wp_enqueue_style( |
| 519 | 'asenha-media-replace', |
| 520 | ASENHA_URL . 'assets/css/media-replace.css', |
| 521 | array(), |
| 522 | ASENHA_VERSION |
| 523 | ); |
| 524 | wp_enqueue_script( |
| 525 | 'asenha-media-replace', |
| 526 | ASENHA_URL . 'assets/js/media-replace.js', |
| 527 | array(), |
| 528 | ASENHA_VERSION, |
| 529 | false |
| 530 | ); |
| 531 | } |
| 532 | |
| 533 | // Content Management >> Hide Admin Notices |
| 534 | |
| 535 | if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) { |
| 536 | wp_enqueue_style( |
| 537 | 'asenha-jbox', |
| 538 | ASENHA_URL . 'assets/css/jBox.all.min.css', |
| 539 | array(), |
| 540 | ASENHA_VERSION |
| 541 | ); |
| 542 | wp_enqueue_script( |
| 543 | 'asenha-jbox', |
| 544 | ASENHA_URL . 'assets/js/jBox.all.min.js', |
| 545 | array(), |
| 546 | ASENHA_VERSION, |
| 547 | false |
| 548 | ); |
| 549 | wp_enqueue_style( |
| 550 | 'asenha-hide-admin-notices', |
| 551 | ASENHA_URL . 'assets/css/hide-admin-notices.css', |
| 552 | array(), |
| 553 | ASENHA_VERSION |
| 554 | ); |
| 555 | wp_enqueue_script( |
| 556 | 'asenha-hide-admin-notices', |
| 557 | ASENHA_URL . 'assets/js/hide-admin-notices.js', |
| 558 | array( 'asenha-jbox' ), |
| 559 | ASENHA_VERSION, |
| 560 | false |
| 561 | ); |
| 562 | } |
| 563 | |
| 564 | // Utilities >> Multiple User Roles |
| 565 | if ( array_key_exists( 'multiple_user_roles', $options ) && $options['multiple_user_roles'] ) { |
| 566 | if ( 'user-edit.php' == $hook_suffix || 'user-new.php' == $hook_suffix ) { |
| 567 | // Only replace roles dropdown with checkboxes for users that can assign roles to other users, e.g. administrators |
| 568 | if ( current_user_can( 'promote_users', get_current_user_id() ) ) { |
| 569 | wp_enqueue_script( |
| 570 | 'asenha-multiple-user-roles', |
| 571 | ASENHA_URL . 'assets/js/multiple-user-roles.js', |
| 572 | array( 'jquery' ), |
| 573 | ASENHA_VERSION, |
| 574 | false |
| 575 | ); |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | // Pass on ASENHA stats to admin-page.js to determine whether to show sponsorship nudge |
| 580 | $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() ); |
| 581 | $current_date = date( 'Y-m-d', time() ); |
| 582 | $show_sponsorship_nudge = false; |
| 583 | $asenha_stats_localized = array( |
| 584 | 'firstSaveDate' => '', |
| 585 | 'lastSaveDate' => '', |
| 586 | 'saveCount' => 0, |
| 587 | 'showSponsorshipNudge' => false, |
| 588 | ); |
| 589 | |
| 590 | if ( !empty($asenha_stats) ) { |
| 591 | $have_sponsored = $asenha_stats['have_sponsored']; |
| 592 | $changes_saved = ( isset( $_GET['settings-updated'] ) && 'true' == $_GET['settings-updated'] ? true : false ); |
| 593 | // Compensate for redirect from settings-updated=true URL |
| 594 | |
| 595 | if ( $changes_saved ) { |
| 596 | $save_count = $asenha_stats['save_count'] + 1; |
| 597 | } else { |
| 598 | $save_count = $asenha_stats['save_count']; |
| 599 | } |
| 600 | |
| 601 | $saves_to_nudge_sponsorship = 10; |
| 602 | |
| 603 | if ( $save_count < $saves_to_nudge_sponsorship ) { |
| 604 | $save_count_modulo = -1; |
| 605 | } else { |
| 606 | $save_count_modulo = $save_count % $saves_to_nudge_sponsorship; |
| 607 | } |
| 608 | |
| 609 | // User have not sponsored ASE |
| 610 | if ( false === $have_sponsored ) { |
| 611 | // Sponsorship nudge have not been dismissed |
| 612 | |
| 613 | if ( false === $asenha_stats['sponsorship_nudge_dismissed'] ) { |
| 614 | // Show sponsorship nudge after every x saves |
| 615 | |
| 616 | if ( $save_count_modulo >= 0 ) { |
| 617 | $show_sponsorship_nudge = true; |
| 618 | } else { |
| 619 | $show_sponsorship_nudge = false; |
| 620 | } |
| 621 | |
| 622 | |
| 623 | if ( $show_sponsorship_nudge && $save_count_modulo >= 0 ) { |
| 624 | $asenha_stats['sponsorship_nudge_last_shown_date'] = $current_date; |
| 625 | $asenha_stats['sponsorship_nudge_last_shown_save_count'] = $save_count; |
| 626 | update_option( ASENHA_SLUG_U . '_stats', $asenha_stats ); |
| 627 | } |
| 628 | |
| 629 | } else { |
| 630 | |
| 631 | if ( $save_count_modulo == 0 ) { |
| 632 | |
| 633 | if ( $save_count > $asenha_stats['sponsorship_nudge_last_shown_save_count'] ) { |
| 634 | $asenha_stats['sponsorship_nudge_dismissed'] = false; |
| 635 | update_option( ASENHA_SLUG_U . '_stats', $asenha_stats ); |
| 636 | $show_sponsorship_nudge = true; |
| 637 | } else { |
| 638 | $show_sponsorship_nudge = false; |
| 639 | } |
| 640 | |
| 641 | } else { |
| 642 | $show_sponsorship_nudge = false; |
| 643 | } |
| 644 | |
| 645 | } |
| 646 | |
| 647 | } |
| 648 | $asenha_stats_localized = array( |
| 649 | 'firstSaveDate' => $asenha_stats['first_save_date'], |
| 650 | 'lastSaveDate' => $asenha_stats['last_save_date'], |
| 651 | 'saveCount' => $save_count, |
| 652 | 'showSponsorshipNudge' => $show_sponsorship_nudge, |
| 653 | ); |
| 654 | } |
| 655 | |
| 656 | wp_localize_script( 'asenha-admin-page', 'asenhaStats', $asenha_stats_localized ); |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * Enqueue public scripts |
| 661 | * |
| 662 | * @since 3.9.0 |
| 663 | */ |
| 664 | function asenha_public_scripts( $hook_suffix ) |
| 665 | { |
| 666 | // Get all WP Enhancements options, default to empty array in case it's not been created yet |
| 667 | $options = get_option( 'admin_site_enhancements', array() ); |
| 668 | |
| 669 | if ( array_key_exists( 'enable_external_permalinks', $options ) ) { |
| 670 | $enable_external_permalinks = $options['enable_external_permalinks']; |
| 671 | } else { |
| 672 | $enable_external_permalinks = false; |
| 673 | } |
| 674 | |
| 675 | |
| 676 | if ( $enable_external_permalinks ) { |
| 677 | wp_enqueue_script( |
| 678 | 'asenha-public', |
| 679 | ASENHA_URL . 'assets/js/public.js', |
| 680 | array( 'jquery' ), |
| 681 | ASENHA_VERSION, |
| 682 | false |
| 683 | ); |
| 684 | wp_localize_script( 'asenha-public', 'phpVars', array( |
| 685 | 'externalPermalinksEnabled' => $enable_external_permalinks, |
| 686 | ) ); |
| 687 | } |
| 688 | |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * Add 'Access now' plugin action link. |
| 693 | * |
| 694 | * @since 1.0.0 |
| 695 | */ |
| 696 | function asenha_plugin_action_links( $links ) |
| 697 | { |
| 698 | $settings_link = '<a href="tools.php?page=' . ASENHA_SLUG . '">Configure now</a>'; |
| 699 | array_unshift( $links, $settings_link ); |
| 700 | return $links; |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Modify footer text |
| 705 | * |
| 706 | * @since 1.0.0 |
| 707 | */ |
| 708 | function asenha_footer_text() |
| 709 | { |
| 710 | if ( is_asenha() ) { |
| 711 | ?> |
| 712 | <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>. |
| 713 | <?php |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * Change WP version number text in footer |
| 719 | * |
| 720 | * @since 4.8.3 |
| 721 | */ |
| 722 | function asenha_footer_version_text() |
| 723 | { |
| 724 | ?> |
| 725 | Also by Bowo → <a href="https://bowo.io/asenha-wpn" target="_blank">WordPress Newsboard</a>: The latest from 100+ sources |
| 726 | <?php |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * Check if current screen is this plugin's main page |
| 731 | * |
| 732 | * @since 1.0.0 |
| 733 | */ |
| 734 | function is_asenha() |
| 735 | { |
| 736 | $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] ); |
| 737 | // e.g. /wp-admin/index.php?page=page-slug |
| 738 | |
| 739 | if ( strpos( $request_uri, 'page=' . ASENHA_SLUG ) !== false ) { |
| 740 | return true; |
| 741 | // Yes, this is the plugin's main page |
| 742 | } else { |
| 743 | return false; |
| 744 | // Nope, this is NOT the plugin's page |
| 745 | } |
| 746 | |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * Mark that user have sponsored ASE |
| 751 | * |
| 752 | * @since 5.2.7 |
| 753 | */ |
| 754 | function asenha_have_sponsored() |
| 755 | { |
| 756 | |
| 757 | if ( isset( $_REQUEST ) ) { |
| 758 | $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() ); |
| 759 | $asenha_stats['have_sponsored'] = true; |
| 760 | $asenha_stats['sponsorship_nudge_dismissed'] = true; |
| 761 | $success = update_option( ASENHA_SLUG_U . '_stats', $asenha_stats ); |
| 762 | |
| 763 | if ( $success ) { |
| 764 | echo json_encode( array( |
| 765 | 'success' => true, |
| 766 | ) ) ; |
| 767 | } else { |
| 768 | echo json_encode( array( |
| 769 | 'success' => false, |
| 770 | ) ) ; |
| 771 | } |
| 772 | |
| 773 | } |
| 774 | |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * Dismiss sponsorship nudge |
| 779 | * |
| 780 | * @since 5.2.7 |
| 781 | */ |
| 782 | function asenha_dismiss_sponsorship_nudge() |
| 783 | { |
| 784 | |
| 785 | if ( isset( $_REQUEST ) ) { |
| 786 | $asenha_stats = get_option( ASENHA_SLUG_U . '_stats', array() ); |
| 787 | $asenha_stats['sponsorship_nudge_dismissed'] = true; |
| 788 | $success = update_option( ASENHA_SLUG_U . '_stats', $asenha_stats ); |
| 789 | |
| 790 | if ( $success ) { |
| 791 | echo json_encode( array( |
| 792 | 'success' => true, |
| 793 | ) ) ; |
| 794 | } else { |
| 795 | echo json_encode( array( |
| 796 | 'success' => false, |
| 797 | ) ) ; |
| 798 | } |
| 799 | |
| 800 | } |
| 801 | |
| 802 | } |
| 803 |