| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Customize Admin |
| 4 |
Plugin URI: https://vanderwijk.com/wordpress/wordpress-customize-admin-plugin/ |
| 5 |
Description: This plugin allows you to customize the appearance and branding of the WordPress admin interface. |
| 6 |
Version: 1.9.1 |
| 7 |
Author: Johan van der Wijk |
| 8 |
Author URI: https://vanderwijk.com |
| 9 |
Text Domain: customize-admin-plugin |
| 10 |
Domain Path: /languages |
| 11 |
|
| 12 |
Release notes: Options page layout changes and WordPress v6.3 compatibility tested. |
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify |
| 15 |
it under the terms of the GNU General Public License as published by |
| 16 |
the Free Software Foundation; either version 2 of the License, or |
| 17 |
(at your option) any later version. |
| 18 |
|
| 19 |
This program is distributed in the hope that it will be useful, |
| 20 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
GNU General Public License for more details. |
| 23 |
|
| 24 |
You should have received a copy of the GNU General Public License |
| 25 |
along with this program; if not, write to the Free Software |
| 26 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 |
*/ |
| 28 |
|
| 29 |
if ( ! defined( 'ABSPATH' ) ) die ( 'Error!' ); |
| 30 |
|
| 31 |
// Load the required files needed for the plugin to run in the proper order and add needed functions to the required hooks. |
| 32 |
function ca_plugin_init () { |
| 33 |
load_plugin_textdomain ( 'customize-admin-plugin', false, 'customize-admin/languages' ); |
| 34 |
} |
| 35 |
add_action ( 'plugins_loaded', 'ca_plugin_init' ); |
| 36 |
|
| 37 |
function ca_enqueue_scripts () { |
| 38 |
if ( 'settings_page_customize-admin/customize-admin-options' !== get_current_screen ()->id ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
wp_register_script ( 'ca-color-picker', WP_PLUGIN_URL . '/customize-admin/js/color-picker.js', array ( 'jquery' ) ); |
| 43 |
wp_enqueue_script ( 'ca-color-picker' ); |
| 44 |
wp_enqueue_script ( 'wp-color-picker' ); |
| 45 |
|
| 46 |
wp_enqueue_media (); |
| 47 |
wp_register_script ( 'ca-media-upload', WP_PLUGIN_URL . '/customize-admin/js/media-upload.js', array ( 'jquery' ) ); |
| 48 |
wp_enqueue_script ( 'ca-media-upload' ); |
| 49 |
|
| 50 |
// Enqueue code editor and settings for manipulating CSS |
| 51 |
$settings = wp_enqueue_code_editor ( array ( 'type' => 'text/css' ) ); |
| 52 |
|
| 53 |
// Return if the editor was not enqueued. |
| 54 |
if ( false === $settings ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
wp_add_inline_script ( |
| 59 |
'code-editor', |
| 60 |
sprintf( |
| 61 |
'jQuery( function () { wp.codeEditor.initialize ( "ca_custom_css", %s ); } );', |
| 62 |
wp_json_encode ( $settings ) |
| 63 |
) |
| 64 |
); |
| 65 |
} |
| 66 |
add_action ( 'admin_enqueue_scripts', 'ca_enqueue_scripts' ); |
| 67 |
|
| 68 |
function ca_enqueue_styles () { |
| 69 |
if ( 'settings_page_customize-admin/customize-admin-options' !== get_current_screen ()->id ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
wp_enqueue_style ( 'wp-color-picker' ); |
| 74 |
} |
| 75 |
add_action ( 'admin_print_styles', 'ca_enqueue_styles' ); |
| 76 |
|
| 77 |
// URL for the logo on the login screen |
| 78 |
function ca_logo_url($url) { |
| 79 |
if ( get_option ( 'ca_logo_url' ) != '' ) { |
| 80 |
return esc_url( get_option ( 'ca_logo_url' ) ); |
| 81 |
} else { |
| 82 |
return esc_url( get_bloginfo( 'url' ) ); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
// CSS for custom logo on the login screen |
| 87 |
function ca_logo_file () { |
| 88 |
if ( get_option ( 'ca_logo_file' ) != '' ) { |
| 89 |
echo '<style>.login h1 a { background-image: url("' . esc_url ( get_option ( 'ca_logo_file' ) ) . '"); background-size: contain; width: 320px; }</style>'; |
| 90 |
} else { |
| 91 |
echo '<style>.login h1 a { background-image: url("' . plugins_url( 'vanderwijk.png' , __FILE__ ) . '"); background-size: contain; width: 320px; }</style>'; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
// CSS for custom background color |
| 96 |
function ca_login_background_color () { |
| 97 |
if ( get_option ( 'ca_login_background_color' ) != '' ) { |
| 98 |
echo '<style>body { background-color: ' . esc_html ( get_option ( 'ca_login_background_color' ) ) . '!important; } </style>'; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
// CSS for custom CSS |
| 103 |
function ca_custom_css () { |
| 104 |
if ( get_option ( 'ca_custom_css' ) != '' ) { |
| 105 |
echo '<style>'. strip_tags( get_option ( 'ca_custom_css' ) ) . '</style>'; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
// Remove the generator meta tag |
| 110 |
function ca_remove_meta_generator () { |
| 111 |
if ( get_option ( 'ca_remove_meta_generator' ) != '' ) { |
| 112 |
remove_action ( 'wp_head', 'wp_generator' ); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
// Remove the RSD meta tag |
| 117 |
function ca_remove_meta_rsd () { |
| 118 |
if ( get_option ( 'ca_remove_meta_rsd' ) != '' ) { |
| 119 |
remove_action ( 'wp_head', 'rsd_link' ); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
// Remove the WLW meta tag |
| 124 |
function ca_remove_meta_wlw () { |
| 125 |
if ( get_option ( 'ca_remove_meta_wlw' ) != '' ) { |
| 126 |
remove_action ( 'wp_head', 'wlwmanifest_link' ); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
// Remove the RSS feed links |
| 131 |
function ca_remove_rss_links () { |
| 132 |
if ( get_option ( 'ca_remove_rss_links' ) != '' ) { |
| 133 |
remove_action ( 'wp_head', 'feed_links', 2 ); //removes feeds |
| 134 |
remove_action ( 'wp_head', 'feed_links_extra', 3 ); //removes comment feed links |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
add_action ( |
| 139 |
'wp_dashboard_setup', |
| 140 |
function () { |
| 141 |
global $wp_meta_boxes; |
| 142 |
|
| 143 |
// Remove WordPress Site Health Status widget from dashboard |
| 144 |
if ( get_option ( 'ca_remove_dashboard_site_health_status' ) != '' ) { |
| 145 |
unset ( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_site_health'] ); |
| 146 |
} |
| 147 |
|
| 148 |
// Remove At a Glance widget from dashboard |
| 149 |
if ( get_option ( 'ca_remove_dashboard_at_a_glance' ) != '' ) { |
| 150 |
unset ( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now'] ); |
| 151 |
} |
| 152 |
|
| 153 |
// Remove Activity widget from dashboard |
| 154 |
if ( get_option ( 'ca_remove_dashboard_activity' ) != '' ) { |
| 155 |
unset ( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity'] ); |
| 156 |
} |
| 157 |
|
| 158 |
// Remove Plugins widget from dashboard |
| 159 |
if ( get_option ( 'ca_remove_dashboard_plugins' ) != '' ) { |
| 160 |
unset ( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'] ); |
| 161 |
} |
| 162 |
|
| 163 |
// Remove Quick Draft widget from dashboard |
| 164 |
if ( get_option ( 'ca_remove_dashboard_quick_press' ) != '' ) { |
| 165 |
unset ( $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] ); |
| 166 |
} |
| 167 |
|
| 168 |
// Remove WordPress Site News widget from dashboard |
| 169 |
if ( get_option ( 'ca_remove_dashboard_wordpress_news' ) != '' ) { |
| 170 |
unset ( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] ); |
| 171 |
} |
| 172 |
|
| 173 |
// Remove WordPress Other News widget from dashboard |
| 174 |
if ( get_option ( 'ca_remove_dashboard_wordpress_other' ) != '' ) { |
| 175 |
unset ( $wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary'] ); |
| 176 |
} |
| 177 |
|
| 178 |
} |
| 179 |
); |
| 180 |
|
| 181 |
add_filter ( 'login_headerurl', 'ca_logo_url' ); |
| 182 |
add_action ( 'login_head', 'ca_logo_file' ); |
| 183 |
add_action ( 'login_head', 'ca_login_background_color' ); |
| 184 |
add_action ( 'login_head', 'ca_custom_css' ); |
| 185 |
|
| 186 |
add_action ( 'init', 'ca_remove_meta_generator' ); |
| 187 |
add_action ( 'init', 'ca_remove_meta_rsd' ); |
| 188 |
add_action ( 'init', 'ca_remove_meta_wlw' ); |
| 189 |
add_action ( 'init', 'ca_remove_rss_links' ); |
| 190 |
|
| 191 |
require_once ( 'customize-admin-options.php' ); |