admin-site-enhancements
Last commit date
assets
3 years ago
classes
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
273 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-disable-components" type="radio" name="tabs"><label for="tab-disable-components">Disable Components</label> |
| 51 | <input id="tab-security" type="radio" name="tabs"><label for="tab-security">Security</label> |
| 52 | <input id="tab-utilities" type="radio" name="tabs"><label for="tab-utilities">Utilities</label> |
| 53 | </div> |
| 54 | <div class="asenha-tab-contents"> |
| 55 | <section class="asenha-fields fields-content-management"> |
| 56 | <table class="form-table" role="presentation"> |
| 57 | <tbody></tbody> |
| 58 | </table> |
| 59 | </section> |
| 60 | <section class="asenha-fields fields-admin-interface"> |
| 61 | <table class="form-table" role="presentation"> |
| 62 | <tbody></tbody> |
| 63 | </table> |
| 64 | </section> |
| 65 | <section class="asenha-fields fields-disable-components"> |
| 66 | <table class="form-table" role="presentation"> |
| 67 | <tbody></tbody> |
| 68 | </table> |
| 69 | </section> |
| 70 | <section class="asenha-fields fields-security"> |
| 71 | <table class="form-table" role="presentation"> |
| 72 | <tbody></tbody> |
| 73 | </table> |
| 74 | </section> |
| 75 | <section class="asenha-fields fields-utilities"> |
| 76 | <table class="form-table" role="presentation"> |
| 77 | <tbody></tbody> |
| 78 | </table> |
| 79 | </section> |
| 80 | </div> |
| 81 | </div> |
| 82 | <div style="display:none;"><!-- Hide to prevent flash of fields appearing at the bottom of the page --> |
| 83 | <?php settings_fields( ASENHA_ID ); ?> |
| 84 | <?php do_settings_sections( ASENHA_SLUG ); ?> |
| 85 | <?php submit_button( |
| 86 | 'Save Changes', // Button copy |
| 87 | 'primary', // Type: 'primary', 'small', or 'large' |
| 88 | 'submit', // The 'name' attribute |
| 89 | true, // Whether to wrap in <p> tag |
| 90 | array( 'id' => 'asenha-submit' ), // additional attributes |
| 91 | ); ?> |
| 92 | </div> |
| 93 | </form> |
| 94 | </div> |
| 95 | |
| 96 | <div class="asenha-footer"> |
| 97 | </div> |
| 98 | |
| 99 | </div> |
| 100 | <?php |
| 101 | |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Suppress all notices, then add notice for successful settings update |
| 106 | * |
| 107 | * @since 1.1.0 |
| 108 | */ |
| 109 | function asenha_suppress_notices() { |
| 110 | |
| 111 | global $plugin_page; |
| 112 | |
| 113 | // Suppress all notices |
| 114 | |
| 115 | if ( ASENHA_SLUG === $plugin_page ) { |
| 116 | |
| 117 | remove_all_actions( 'admin_notices' ); |
| 118 | |
| 119 | } |
| 120 | |
| 121 | // Add notice for successful settings update |
| 122 | |
| 123 | if ( |
| 124 | isset( $_GET[ 'page' ] ) |
| 125 | && ASENHA_SLUG == $_GET[ 'page' ] |
| 126 | && isset( $_GET[ 'settings-updated' ] ) |
| 127 | && true == $_GET[ 'settings-updated' ] |
| 128 | ) { |
| 129 | ?> |
| 130 | <script> |
| 131 | jQuery(document).ready( function() { |
| 132 | jQuery('.asenha-changes-saved').fadeIn(400).delay(2500).fadeOut(400); |
| 133 | }); |
| 134 | </script> |
| 135 | |
| 136 | <?php |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Suppress all generic notices on the plugin settings page |
| 142 | * |
| 143 | * @since 2.7.0 |
| 144 | */ |
| 145 | function asenha_suppress_generic_notices() { |
| 146 | |
| 147 | global $plugin_page; |
| 148 | |
| 149 | // Suppress all notices |
| 150 | |
| 151 | if ( ASENHA_SLUG === $plugin_page ) { |
| 152 | |
| 153 | remove_all_actions( 'all_admin_notices' ); |
| 154 | |
| 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Enqueue admin scripts |
| 161 | * |
| 162 | * @since 1.0.0 |
| 163 | */ |
| 164 | function asenha_admin_scripts( $hook_suffix ) { |
| 165 | |
| 166 | $current_screen = get_current_screen(); |
| 167 | |
| 168 | // Get all WP Enhancements options, default to empty array in case it's not been created yet |
| 169 | $options = get_option( 'admin_site_enhancements', array() ); |
| 170 | |
| 171 | // For main page of this plugin |
| 172 | |
| 173 | if ( is_asenha() ) { |
| 174 | wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 175 | wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 176 | wp_enqueue_script( 'asenha-jsticky', ASENHA_URL . 'assets/js/jquery.jsticky.mod.min.js', array( 'jquery' ), ASENHA_VERSION, false ); |
| 177 | wp_enqueue_script( 'asenha-js-cookie', ASENHA_URL . 'assets/js/js.cookie.min.js', array(), ASENHA_VERSION, false ); |
| 178 | |
| 179 | // CodeMirror. In use, e.g. for Utilities >> Enable Custom Admin / Frontend CSS |
| 180 | wp_enqueue_style( 'asenha-codemirror', ASENHA_URL . 'assets/css/codemirror/codemirror.min.css', array(), ASENHA_VERSION ); |
| 181 | wp_enqueue_script( 'asenha-codemirror', ASENHA_URL . 'assets/js/codemirror/codemirror.min.js', array(), ASENHA_VERSION, true ); |
| 182 | wp_enqueue_script( 'asenha-codemirror-css-mode', ASENHA_URL . 'assets/js/codemirror/css.js', array( 'asenha-codemirror' ), ASENHA_VERSION, true ); // CSS mode |
| 183 | |
| 184 | // DataTables. In use, e.g. for Security >> Limit Login Attempts |
| 185 | wp_enqueue_style( 'asenha-datatables', ASENHA_URL . 'assets/css/datatables/datatables.min.css', array(), ASENHA_VERSION ); |
| 186 | wp_enqueue_script( 'asenha-datatables', ASENHA_URL . 'assets/js/datatables/datatables.min.js', array( 'jquery' ), ASENHA_VERSION, false ); |
| 187 | |
| 188 | // Main style and script for the admin page |
| 189 | wp_enqueue_style( 'asenha-admin-page', ASENHA_URL . 'assets/css/admin-page.css', array( 'asenha-jbox', 'asenha-codemirror', 'asenha-datatables' ), ASENHA_VERSION ); |
| 190 | wp_enqueue_script( 'asenha-admin-page', ASENHA_URL . 'assets/js/admin-page.js', array( 'asenha-jsticky', 'asenha-jbox', 'asenha-js-cookie', 'asenha-codemirror-css-mode', 'asenha-datatables' ), ASENHA_VERSION, false ); |
| 191 | } |
| 192 | |
| 193 | // Enqueue on all wp-admin |
| 194 | |
| 195 | wp_enqueue_style( 'asenha-wp-admin', ASENHA_URL . 'assets/css/wp-admin.css', array(), ASENHA_VERSION ); |
| 196 | |
| 197 | // Content Management >> Show IDs, for list tables in wp-admin, e.g. All Posts page |
| 198 | |
| 199 | if ( ( false !== strpos( $current_screen->base, 'edit' ) ) // List tables for pages, posts, taxonomies |
| 200 | || ( false !== strpos( $current_screen->base, 'users' ) ) // Users list table |
| 201 | || ( false !== strpos( $current_screen->base, 'upload' ) ) // Media list table |
| 202 | ) { |
| 203 | wp_enqueue_style( 'asenha-list-table', ASENHA_URL . 'assets/css/list-table.css', array(), ASENHA_VERSION ); |
| 204 | } |
| 205 | |
| 206 | // Content Management >> Enable Media Replacement |
| 207 | |
| 208 | if ( ( $current_screen->base == 'upload' ) // Media list table |
| 209 | || ( $current_screen->id == 'attachment' ) // Media edit page |
| 210 | ) { |
| 211 | // wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 212 | // wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 213 | wp_enqueue_style( 'asenha-media-replace', ASENHA_URL . 'assets/css/media-replace.css', array(), ASENHA_VERSION ); |
| 214 | wp_enqueue_script( 'asenha-media-replace', ASENHA_URL . 'assets/js/media-replace.js', array(), ASENHA_VERSION, false ); |
| 215 | } |
| 216 | |
| 217 | // Content Management >> Hide Admin Notices |
| 218 | if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) { |
| 219 | wp_enqueue_style( 'asenha-jbox', ASENHA_URL . 'assets/css/jBox.all.min.css', array(), ASENHA_VERSION ); |
| 220 | wp_enqueue_script( 'asenha-jbox', ASENHA_URL . 'assets/js/jBox.all.min.js', array(), ASENHA_VERSION, false ); |
| 221 | wp_enqueue_style( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/css/hide-admin-notices.css', array(), ASENHA_VERSION ); |
| 222 | wp_enqueue_script( 'asenha-hide-admin-notices', ASENHA_URL . 'assets/js/hide-admin-notices.js', array( 'asenha-jbox' ), ASENHA_VERSION, false ); |
| 223 | } |
| 224 | |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Add 'Access now' plugin action link. |
| 229 | * |
| 230 | * @since 1.0.0 |
| 231 | */ |
| 232 | |
| 233 | function asenha_plugin_action_links( $links ) { |
| 234 | |
| 235 | $settings_link = '<a href="tools.php?page=' . ASENHA_SLUG . '">Configure now</a>'; |
| 236 | |
| 237 | array_unshift($links, $settings_link); |
| 238 | |
| 239 | return $links; |
| 240 | |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Modify footer text |
| 245 | * |
| 246 | * @since 1.0.0 |
| 247 | */ |
| 248 | function asenha_footer_text() { |
| 249 | |
| 250 | if ( is_asenha() ) { |
| 251 | ?> |
| 252 | <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>. |
| 253 | <?php |
| 254 | } |
| 255 | |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Check if current screen is this plugin's main page |
| 260 | * |
| 261 | * @since 1.0.0 |
| 262 | */ |
| 263 | function is_asenha() { |
| 264 | |
| 265 | $request_uri = sanitize_text_field( $_SERVER['REQUEST_URI'] ); // e.g. /wp-admin/index.php?page=page-slug |
| 266 | |
| 267 | if ( strpos( $request_uri, 'page=' . ASENHA_SLUG ) !== false ) { |
| 268 | return true; // Yes, this is the plugin's main page |
| 269 | } else { |
| 270 | return false; // Nope, this is NOT the plugin's page |
| 271 | } |
| 272 | |
| 273 | } |