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
362 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', // Parent page/menu |
| 12 | 'Admin and Site Enhancements', // Browser tab/window title |
| 13 | 'Enhancements', // Sube menu title |
| 14 | 'manage_options', // Minimal user capabililty |
| 15 | ASENHA_SLUG, // Page slug. Shows up in URL. |
| 16 | 'asenha_add_settings_page' |
| 17 | ); |
| 18 | |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Create the settings page of the plugin |
| 23 | * |
| 24 | * @since 1.0.0 |
| 25 | */ |
| 26 | function asenha_add_settings_page() { |
| 27 | ?> |
| 28 | <div class="wrap asenha"> |
| 29 | |
| 30 | <div id="asenha-header" class="asenha-header"> |
| 31 | <div class="asenha-header-left"> |
| 32 | <h1 class="asenha-heading"><?php echo get_admin_page_title(); ?> <small><?php esc_html_e( 'by', 'admin-site-enhancements' ); ?> <a href="https://bowo.io" target="_blank">bowo.io</a></small></h1> |
| 33 | <!-- <a href="https://wordpress.org/plugins/admin-site-enhancements/" target="_blank" class="asenha-header-action"><span>ℹ</span> <?php // esc_html_e( 'Info', 'admin-site-enhancements' ); ?></a> --> |
| 34 | <a href="https://wordpress.org/plugins/admin-site-enhancements/#reviews" target="_blank" class="asenha-header-action"><span>★</span> <?php esc_html_e( 'Review', 'admin-site-enhancements' ); ?></a> |
| 35 | <a href="https://wordpress.org/support/plugin/admin-site-enhancements/" target="_blank" class="asenha-header-action">✚ <?php esc_html_e( 'Feedback', 'admin-site-enhancements' ); ?></a> |
| 36 | <a href="https://paypal.me/qriouslad" target="_blank" class="asenha-header-action">♥ <?php esc_html_e( 'Donate', 'admin-site-enhancements' ); ?></a> |
| 37 | </div> |
| 38 | <div class="asenha-header-right"> |
| 39 | <a class="button button-primary asenha-save-button">Save Changes</a> |
| 40 | <div class="asenha-changes-saved" style="display:none;">Changes have been saved.</div> |
| 41 | </div> |
| 42 | </div> |
| 43 | |
| 44 | <div class="asenha-body"> |
| 45 | <form action="options.php" method="post"> |
| 46 | <div class="asenha-vertical-tabs"> |
| 47 | <div class="asenha-tab-buttons"> |
| 48 | <input id="tab-content-management" type="radio" name="tabs" checked><label for="tab-content-management">Content Management</label> |
| 49 | <input id="tab-admin-interface" type="radio" name="tabs"><label for="tab-admin-interface">Admin Interface</label> |
| 50 | <input id="tab-login-logout" type="radio" name="tabs"><label for="tab-login-logout">Log In | Log Out</label> |
| 51 | <input id="tab-custom-code" type="radio" name="tabs"><label for="tab-custom-code">Custom Code</label> |
| 52 | <input id="tab-disable-components" type="radio" name="tabs"><label for="tab-disable-components">Disable Components</label> |
| 53 | <input id="tab-security" type="radio" name="tabs"><label for="tab-security">Security</label> |
| 54 | <input id="tab-optimizations" type="radio" name="tabs"><label for="tab-optimizations">Optimizations</label> |
| 55 | <input id="tab-utilities" type="radio" name="tabs"><label for="tab-utilities">Utilities</label> |
| 56 | </div> |
| 57 | <div class="asenha-tab-contents"> |
| 58 | <section class="asenha-fields fields-content-management"> |
| 59 | <table class="form-table" role="presentation"> |
| 60 | <tbody></tbody> |
| 61 | </table> |
| 62 | </section> |
| 63 | <section class="asenha-fields fields-admin-interface"> |
| 64 | <table class="form-table" role="presentation"> |
| 65 | <tbody></tbody> |
| 66 | </table> |
| 67 | </section> |
| 68 | <section class="asenha-fields fields-login-logout"> |
| 69 | <table class="form-table" role="presentation"> |
| 70 | <tbody></tbody> |
| 71 | </table> |
| 72 | </section> |
| 73 | <section class="asenha-fields fields-custom-code"> |
| 74 | <table class="form-table" role="presentation"> |
| 75 | <tbody></tbody> |
| 76 | </table> |
| 77 | </section> |
| 78 | <section class="asenha-fields fields-disable-components"> |
| 79 | <table class="form-table" role="presentation"> |
| 80 | <tbody></tbody> |
| 81 | </table> |
| 82 | </section> |
| 83 | <section class="asenha-fields fields-security"> |
| 84 | <table class="form-table" role="presentation"> |
| 85 | <tbody></tbody> |
| 86 | </table> |
| 87 | </section> |
| 88 | <section class="asenha-fields fields-optimizations"> |
| 89 | <table class="form-table" role="presentation"> |
| 90 | <tbody></tbody> |
| 91 | </table> |
| 92 | </section> |
| 93 | <section class="asenha-fields fields-utilities"> |
| 94 | <table class="form-table" role="presentation"> |
| 95 | <tbody></tbody> |
| 96 | </table> |
| 97 | </section> |
| 98 | </div> |
| 99 | </div> |
| 100 | <div style="display:none;"><!-- Hide to prevent flash of fields appearing at the bottom of the page --> |
| 101 | <?php settings_fields( ASENHA_ID ); ?> |
| 102 | <?php do_settings_sections( ASENHA_SLUG ); ?> |
| 103 | <?php submit_button( |
| 104 | 'Save Changes', // Button copy |
| 105 | 'primary', // Type: 'primary', 'small', or 'large' |
| 106 | 'submit', // The 'name' attribute |
| 107 | true, // Whether to wrap in <p> tag |
| 108 | array( 'id' => 'asenha-submit' ), // additional attributes |
| 109 | ); ?> |
| 110 | </div> |
| 111 | </form> |
| 112 | </div> |
| 113 | |
| 114 | <div class="asenha-footer"> |
| 115 | </div> |
| 116 | |
| 117 | </div> |
| 118 | <?php |
| 119 | |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Suppress all notices, then add notice for successful settings update |
| 124 | * |
| 125 | * @since 1.1.0 |
| 126 | */ |
| 127 | function asenha_suppress_notices() { |
| 128 | |
| 129 | global $plugin_page; |
| 130 | |
| 131 | // Suppress all notices |
| 132 | |
| 133 | if ( ASENHA_SLUG === $plugin_page ) { |
| 134 | |
| 135 | remove_all_actions( 'admin_notices' ); |
| 136 | |
| 137 | } |
| 138 | |
| 139 | // Add notice for successful settings update |
| 140 | |
| 141 | if ( |
| 142 | isset( $_GET[ 'page' ] ) |
| 143 | && ASENHA_SLUG == $_GET[ 'page' ] |
| 144 | && isset( $_GET[ 'settings-updated' ] ) |
| 145 | && true == $_GET[ 'settings-updated' ] |
| 146 | ) { |
| 147 | ?> |
| 148 | <script> |
| 149 | jQuery(document).ready( function() { |
| 150 | jQuery('.asenha-changes-saved').fadeIn(400).delay(2500).fadeOut(400); |
| 151 | }); |
| 152 | </script> |
| 153 | |
| 154 | <?php |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Suppress all generic notices on the plugin settings page |
| 160 | * |
| 161 | * @since 2.7.0 |
| 162 | */ |
| 163 | function asenha_suppress_generic_notices() { |
| 164 | |
| 165 | global $plugin_page; |
| 166 | |
| 167 | // Suppress all notices |
| 168 | |
| 169 | if ( ASENHA_SLUG === $plugin_page ) { |
| 170 | |
| 171 | remove_all_actions( 'all_admin_notices' ); |
| 172 | |
| 173 | } |
| 174 | |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Enqueue admin scripts |
| 179 | * |
| 180 | * @since 1.0.0 |
| 181 | */ |
| 182 | function asenha_admin_scripts( $hook_suffix ) { |
| 183 | |
| 184 | global $wp_version; |
| 185 | |
| 186 | $current_screen = get_current_screen(); |
| 187 | |
| 188 | // Get all WP Enhancements options, default to empty array in case it's not been created yet |
| 189 | $options = get_option( 'admin_site_enhancements', array() ); |
| 190 | |
| 191 | // For main page of this plugin |
| 192 | |
| 193 | if ( is_asenha() ) { |
| 194 | wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 195 | wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 196 | wp_enqueue_script( 'asenha-jsticky', ASENHA_URL . 'assets/js/jquery.jsticky.mod.min.js', array( 'jquery' ), ASENHA_VERSION, false ); |
| 197 | wp_enqueue_script( 'asenha-js-cookie', ASENHA_URL . 'assets/js/js.cookie.min.js', array(), ASENHA_VERSION, false ); |
| 198 | |
| 199 | // jQuery UI Sortables. In use, e.g. for Admin Interface >> Admin Menu Organizer |
| 200 | // Re-register and re-enqueue jQuery UI Core and plugins required for sortable, draggable and droppable when ordering menu items |
| 201 | wp_deregister_script( 'jquery-ui-core' ); |
| 202 | wp_register_script( 'jquery-ui-core', get_site_url() . '/wp-includes/js/jquery/ui/core.min.js', array( 'jquery' ), ASENHA_VERSION, false ); |
| 203 | wp_enqueue_script( 'jquery-ui-core' ); |
| 204 | |
| 205 | if ( version_compare( $wp_version, '5.6.0', '>=' ) ) { |
| 206 | |
| 207 | wp_deregister_script( 'jquery-ui-mouse' ); |
| 208 | wp_register_script( 'jquery-ui-mouse', get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js', array( 'jquery-ui-core' ), ASENHA_VERSION, false ); |
| 209 | wp_enqueue_script( 'jquery-ui-mouse' ); |
| 210 | |
| 211 | } else { |
| 212 | |
| 213 | wp_deregister_script( 'jquery-ui-widget' ); |
| 214 | wp_register_script( 'jquery-ui-widget', get_site_url() . '/wp-includes/js/jquery/ui/widget.min.js', array( 'jquery' ), ASENHA_VERSION, false ); |
| 215 | wp_enqueue_script( 'jquery-ui-widget' ); |
| 216 | |
| 217 | wp_deregister_script( 'jquery-ui-mouse' ); |
| 218 | wp_register_script( 'jquery-ui-mouse', get_site_url() . '/wp-includes/js/jquery/ui/mouse.min.js', array( 'jquery-ui-core', 'jquery-ui-widget' ), ASENHA_VERSION, false ); |
| 219 | wp_enqueue_script( 'jquery-ui-mouse' ); |
| 220 | |
| 221 | } |
| 222 | |
| 223 | wp_deregister_script( 'jquery-ui-sortable' ); |
| 224 | wp_register_script( 'jquery-ui-sortable', get_site_url() . '/wp-includes/js/jquery/ui/sortable.min.js', array( 'jquery-ui-mouse' ), ASENHA_VERSION, false ); |
| 225 | wp_enqueue_script( 'jquery-ui-sortable' ); |
| 226 | |
| 227 | wp_deregister_script( 'jquery-ui-draggable' ); |
| 228 | wp_register_script( 'jquery-ui-draggable', get_site_url() . '/wp-includes/js/jquery/ui/draggable.min.js', array( 'jquery-ui-mouse' ), ASENHA_VERSION, false ); |
| 229 | wp_enqueue_script( 'jquery-ui-draggable' ); |
| 230 | |
| 231 | wp_deregister_script( 'jquery-ui-droppable' ); |
| 232 | wp_register_script( 'jquery-ui-droppable', get_site_url() . '/wp-includes/js/jquery/ui/droppable.min.js', array( 'jquery-ui-draggable' ), ASENHA_VERSION, false ); |
| 233 | wp_enqueue_script( 'jquery-ui-droppable' ); |
| 234 | |
| 235 | // Script to set behaviour and actions of the sortable menu |
| 236 | wp_enqueue_script( 'asenha-custom-admin-menu', ASENHA_URL . 'assets/js/custom-admin-menu.js', array( 'jquery-ui-draggable' ), ASENHA_VERSION, false ); |
| 237 | |
| 238 | // CodeMirror. In use, e.g. for Utilities >> Enable Custom Admin / Frontend CSS / ads.txt / app-ads.txt |
| 239 | wp_enqueue_style( 'asenha-codemirror', ASENHA_URL . 'assets/css/codemirror/codemirror.min.css', array(), ASENHA_VERSION ); |
| 240 | wp_enqueue_script( 'asenha-codemirror', ASENHA_URL . 'assets/js/codemirror/codemirror.min.js', array(), ASENHA_VERSION, true ); |
| 241 | wp_enqueue_script( 'asenha-codemirror-htmlmixed-mode', ASENHA_URL . 'assets/js/codemirror/htmlmixed.js', array( 'asenha-codemirror' ), ASENHA_VERSION, true ); |
| 242 | wp_enqueue_script( 'asenha-codemirror-xml-mode', ASENHA_URL . 'assets/js/codemirror/xml.js', array( 'asenha-codemirror' ), ASENHA_VERSION, true ); |
| 243 | wp_enqueue_script( 'asenha-codemirror-javascript-mode', ASENHA_URL . 'assets/js/codemirror/javascript.js', array( 'asenha-codemirror' ), ASENHA_VERSION, true ); |
| 244 | wp_enqueue_script( 'asenha-codemirror-css-mode', ASENHA_URL . 'assets/js/codemirror/css.js', array( 'asenha-codemirror' ), ASENHA_VERSION, true ); |
| 245 | wp_enqueue_script( 'asenha-codemirror-markdown-mode', ASENHA_URL . 'assets/js/codemirror/markdown.js', array( 'asenha-codemirror' ), ASENHA_VERSION, true ); |
| 246 | |
| 247 | // DataTables. In use, e.g. for Security >> Limit Login Attempts |
| 248 | wp_enqueue_style( 'asenha-datatables', ASENHA_URL . 'assets/css/datatables/datatables.min.css', array(), ASENHA_VERSION ); |
| 249 | wp_enqueue_script( 'asenha-datatables', ASENHA_URL . 'assets/js/datatables/datatables.min.js', array( 'jquery' ), ASENHA_VERSION, false ); |
| 250 | |
| 251 | // Main style and script for the admin page |
| 252 | wp_enqueue_style( 'asenha-admin-page', ASENHA_URL . 'assets/css/admin-page.css', array( 'asenha-jbox', 'asenha-codemirror', 'asenha-datatables' ), ASENHA_VERSION ); |
| 253 | wp_enqueue_script( 'asenha-admin-page', ASENHA_URL . 'assets/js/admin-page.js', array( 'asenha-jsticky', 'asenha-jbox', 'asenha-js-cookie', 'asenha-codemirror-htmlmixed-mode', 'asenha-codemirror-xml-mode', 'asenha-codemirror-javascript-mode', 'asenha-codemirror-css-mode', 'asenha-codemirror-markdown-mode', 'asenha-datatables', 'asenha-custom-admin-menu' ), ASENHA_VERSION, false ); |
| 254 | } |
| 255 | |
| 256 | // Enqueue on all wp-admin |
| 257 | |
| 258 | wp_enqueue_style( 'asenha-wp-admin', ASENHA_URL . 'assets/css/wp-admin.css', array(), ASENHA_VERSION ); |
| 259 | |
| 260 | // Content Management >> Show IDs, for list tables in wp-admin, e.g. All Posts page |
| 261 | |
| 262 | if ( ( false !== strpos( $current_screen->base, 'edit' ) ) // List tables for pages, posts, taxonomies |
| 263 | || ( false !== strpos( $current_screen->base, 'users' ) ) // Users list table |
| 264 | || ( false !== strpos( $current_screen->base, 'upload' ) ) // Media list table |
| 265 | ) { |
| 266 | wp_enqueue_style( 'asenha-list-table', ASENHA_URL . 'assets/css/list-table.css', array(), ASENHA_VERSION ); |
| 267 | } |
| 268 | |
| 269 | // Content Management >> Enable Media Replacement |
| 270 | |
| 271 | if ( ( $current_screen->base == 'upload' ) // Media list table |
| 272 | || ( $current_screen->id == 'attachment' ) // Media edit page |
| 273 | ) { |
| 274 | // wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 275 | // wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 276 | wp_enqueue_style( 'asenha-media-replace', ASENHA_URL . 'assets/css/media-replace.css', array(), ASENHA_VERSION ); |
| 277 | wp_enqueue_script( 'asenha-media-replace', ASENHA_URL . 'assets/js/media-replace.js', array(), ASENHA_VERSION, false ); |
| 278 | } |
| 279 | |
| 280 | // Content Management >> Hide Admin Notices |
| 281 | if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) { |
| 282 | wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 283 | wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 284 | wp_enqueue_style( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/css/hide-admin-notices.css', array(), ASENHA_VERSION ); |
| 285 | wp_enqueue_script( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/js/hide-admin-notices.js', array( 'asenha-jbox' ), ASENHA_VERSION, false ); |
| 286 | } |
| 287 | |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Enqueue public scripts |
| 292 | * |
| 293 | * @since 3.9.0 |
| 294 | */ |
| 295 | function asenha_public_scripts( $hook_suffix ) { |
| 296 | |
| 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 | if ( array_key_exists( 'enable_external_permalinks', $options ) ) { |
| 300 | $enable_external_permalinks = $options['enable_external_permalinks']; |
| 301 | } else { |
| 302 | $enable_external_permalinks = false; |
| 303 | } |
| 304 | |
| 305 | wp_enqueue_script( 'asenha-public', ASENHA_URL . 'assets/js/public.js', array( 'jquery' ), ASENHA_VERSION, false ); |
| 306 | wp_localize_script( |
| 307 | 'asenha-public', |
| 308 | 'phpVars', |
| 309 | array( |
| 310 | 'externalPermalinksEnabled' => $enable_external_permalinks, |
| 311 | ) |
| 312 | ); |
| 313 | |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Add 'Access now' plugin action link. |
| 318 | * |
| 319 | * @since 1.0.0 |
| 320 | */ |
| 321 | |
| 322 | function asenha_plugin_action_links( $links ) { |
| 323 | |
| 324 | $settings_link = '<a href="tools.php?page=' . ASENHA_SLUG . '">Configure now</a>'; |
| 325 | |
| 326 | array_unshift($links, $settings_link); |
| 327 | |
| 328 | return $links; |
| 329 | |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Modify footer text |
| 334 | * |
| 335 | * @since 1.0.0 |
| 336 | */ |
| 337 | function asenha_footer_text() { |
| 338 | |
| 339 | if ( is_asenha() ) { |
| 340 | ?> |
| 341 | <a href="https://wordpress.org/plugins/admin-site-enhancements/" target="_blank">Admin Site Enhancements</a> is on <a href="https://github.com/qriouslad/admin-site-enhancements" target="_blank">github</a>. |
| 342 | <?php |
| 343 | } |
| 344 | |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Check if current screen is this plugin's main page |
| 349 | * |
| 350 | * @since 1.0.0 |
| 351 | */ |
| 352 | function is_asenha() { |
| 353 | |
| 354 | $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] ); // e.g. /wp-admin/index.php?page=page-slug |
| 355 | |
| 356 | if ( strpos( $request_uri, 'page=' . ASENHA_SLUG ) !== false ) { |
| 357 | return true; // Yes, this is the plugin's main page |
| 358 | } else { |
| 359 | return false; // Nope, this is NOT the plugin's page |
| 360 | } |
| 361 | |
| 362 | } |