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 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 / bootstrap.php
admin-site-enhancements Last commit date
assets 3 years ago classes 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
bootstrap.php
264 lines
1 <?php
2
3 // We're using the singleton design pattern
4 // https://code.tutsplus.com/articles/design-patterns-in-wordpress-the-singleton-pattern--wp-31621
5 // https://carlalexander.ca/singletons-in-wordpress/
6 // https://torquemag.io/2016/11/singletons-wordpress-good-evil/
7
8 /**
9 * Main class of the plugin used to add functionalities
10 *
11 * @since 1.0.0
12 */
13 class Admin_Site_Enhancements {
14
15 // Refers to a single instance of this class
16 private static $instance = null;
17
18 /**
19 * Creates or returns a single instance of this class
20 *
21 * @return Admin_Site_Enhancements a single instance of this class
22 * @since 1.0.0
23 */
24 public static function get_instance() {
25
26 if ( null == self::$instance ) {
27
28 self::$instance = new self;
29
30 }
31
32 return self::$instance;
33
34 }
35
36 /**
37 * Initialize plugin functionalities
38 */
39 private function __construct() {
40
41 // Setup admin menu, admin page, settings, settings sections, sections fields, admin scripts, plugin action links, etc.
42
43 // Register admin menu and add the settings page.
44 add_action( 'admin_menu', 'asenha_register_admin_menu' );
45
46 // Register plugin settings
47
48 // Instantiate object for registration of settings section and fields
49 $settings = new ASENHA\Classes\Settings_Sections_Fields;
50
51 add_action( 'admin_init', [ $settings, 'register_sections_fields' ] );
52
53 // Suppress all notices on the plugin's main page. Then add notification for successful settings update.
54 add_action( 'admin_notices', 'asenha_suppress_notices', 5 );
55
56 // Enqueue admin scripts and styles only on the plugin's main page
57 add_action( 'admin_enqueue_scripts', 'asenha_admin_scripts' );
58
59 // Instantiate object for common methods
60 $common_methods = new ASENHA\Classes\Common_Methods;
61
62 // Load CodeMirror. In use, e.g. for Utilities >> Enable Custom Admin / Frontend CSS
63 add_action( 'admin_enqueue_scripts', [ $common_methods, 'enqueue_codemirror_assets' ] );
64
65 // Load DataTables. In use, e.g. for Security >> Limit Login Attempts
66 add_action( 'admin_enqueue_scripts', [ $common_methods, 'enqueue_datatables_assets' ] );
67
68 // Add action links in plugins page
69 add_filter( 'plugin_action_links_' . ASENHA_SLUG . '/' . ASENHA_SLUG . '.php', 'asenha_plugin_action_links' );
70
71 // Update footer text
72 add_filter( 'admin_footer_text', 'asenha_footer_text' );
73
74 // Selectively enable enhancements based on options value
75
76 // Get all WP Enhancements options, default to empty array in case it's not been created yet
77 $options = get_option( ASENHA_SLUG_U, array() );
78
79 // ===== CONTENT MANAGEMENT =====
80
81 // Instantiate object for Content Management features
82 $content_management = new ASENHA\Classes\Content_Management;
83
84 // Content Management >> Enable Page and Post Duplication
85 if ( array_key_exists( 'enable_duplication', $options ) && $options['enable_duplication'] ) {
86 add_action( 'admin_action_asenha_enable_duplication', [ $content_management, 'asenha_enable_duplication' ] );
87 add_filter( 'page_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 );
88 add_filter( 'post_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 );
89 }
90
91 // Content Management >> Enable Media Replacement
92 if ( array_key_exists( 'enable_media_replacement', $options ) && $options['enable_media_replacement'] ) {
93 add_filter( 'media_row_actions', [ $content_management, 'modify_media_list_table_edit_link' ], 10, 2 );
94 add_filter( 'attachment_fields_to_edit', [ $content_management, 'add_media_replacement_button' ] );
95 add_action( 'edit_attachment', [ $content_management, 'replace_media' ] );
96 add_filter( 'post_updated_messages', [ $content_management, 'attachment_updated_custom_message' ] );
97 }
98
99 // Content Management >> Enhance List Tables
100 if ( array_key_exists( 'enhance_list_tables', $options ) && $options['enhance_list_tables'] ) {
101
102 // Show Featured Image Column
103 if ( array_key_exists( 'show_featured_image_column', $options ) && $options['show_featured_image_column'] ) {
104 add_action( 'admin_init', [ $content_management, 'show_featured_image_column' ] );
105 }
106
107 // Show Excerpt Column
108 if ( array_key_exists( 'show_excerpt_column', $options ) && $options['show_excerpt_column'] ) {
109 add_action( 'admin_init', [ $content_management, 'show_excerpt_column' ] );
110 }
111
112 // Show ID Column
113 if ( array_key_exists( 'show_id_column', $options ) && $options['show_id_column'] ) {
114 add_action( 'admin_init', [ $content_management, 'show_id_column' ] );
115 }
116
117 // Hide Comments Column
118 if ( array_key_exists( 'hide_comments_column', $options ) && $options['hide_comments_column'] ) {
119 add_action( 'admin_init', [ $content_management, 'hide_comments_column' ] );
120 }
121
122 // Hide Post Tags Column
123 if ( array_key_exists( 'hide_post_tags_column', $options ) && $options['hide_post_tags_column'] ) {
124 add_action( 'admin_init', [ $content_management, 'hide_post_tags_column' ] );
125 }
126
127 // Show Custom Taxonomy Filters
128 if ( array_key_exists( 'show_custom_taxonomy_filters', $options ) && $options['show_custom_taxonomy_filters'] ) {
129 add_action( 'restrict_manage_posts', [ $content_management, 'show_custom_taxonomy_filters' ] );
130 }
131
132 }
133
134 // ===== ADMIN INTERFACE =====
135
136 // Instantiate object for Admin Interface features
137 $admin_interface = new ASENHA\Classes\Admin_Interface;
138
139 // Admin Interface >> Hide Admin Notices
140 if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) {
141 add_action( 'all_admin_notices', [ $admin_interface, 'admin_notices_wrapper' ] );
142 add_action( 'admin_bar_menu', [ $admin_interface, 'admin_notices_menu' ] );
143 add_action( 'admin_enqueue_scripts', [ $admin_interface, 'admin_notices_menu_inline_css' ] ); // wp-admin
144 }
145
146 // Admin Interface >> Hide Admin Bar
147 if ( array_key_exists( 'hide_admin_bar', $options ) && $options['hide_admin_bar'] && array_key_exists( 'hide_admin_bar_for', $options ) && isset( $options['hide_admin_bar_for'] ) ) {
148 add_filter( 'show_admin_bar', [ $admin_interface, 'hide_admin_bar_for_roles' ] );
149 }
150
151 // Admin Interface >> View Admin as Role
152 if ( array_key_exists( 'view_admin_as_role', $options ) && $options['view_admin_as_role'] ) {
153 add_action( 'admin_bar_menu', [ $admin_interface, 'view_admin_as_admin_bar_menu' ], 8 ); // Priority 8 so it is next to username section
154 add_action( 'init', [ $admin_interface, 'role_switcher_to_view_admin_as' ] );
155 add_action( 'wp_die_handler', [ $admin_interface, 'custom_error_page_on_switch_failure' ] );
156 }
157
158 // Admin Interface >> Hide or Modify Elements
159 if ( array_key_exists( 'hide_modify_elements', $options ) && $options['hide_modify_elements'] ) {
160 add_filter( 'admin_bar_menu', [ $admin_interface, 'modify_admin_bar_menu' ], 5 ); // priority 5 to execute earlier than the normal 10
161 }
162
163 // Admin Interface >> Customize Admin Menu
164
165 // Load jQuery UI sortables scripts regardless of whether Customize Admin Menu is enabled or not. This is needed to enable sorting upon clicking the feature toggle.
166 add_action( 'admin_enqueue_scripts', [ $admin_interface, 'enqueue_jquery_ui_sortables_scripts' ] );
167
168 if ( array_key_exists( 'customize_admin_menu', $options ) && $options['customize_admin_menu'] ) {
169 // add_action( 'wp_ajax_save_custom_menu_order', [ $admin_interface, 'save_custom_menu_order' ] );
170 // add_action( 'wp_ajax_save_hidden_menu_items', [ $admin_interface, 'save_hidden_menu_items' ] );
171 add_filter( 'custom_menu_order', '__return_true' );
172 add_filter( 'menu_order', [ $admin_interface, 'render_custom_menu_order' ] );
173 add_action( 'admin_menu', [ $admin_interface, 'hide_menu_items' ], 999 );
174 add_action( 'admin_menu', [ $admin_interface, 'add_hidden_menu_toggle' ] );
175 add_action( 'admin_enqueue_scripts', [ $admin_interface, 'enqueue_toggle_hidden_menu_script' ] );
176 }
177
178 // ===== SECURITY =====
179
180 // Instantiate object for Security features
181 $security = new ASENHA\Classes\Security;
182
183 // Security >> Change Login URL
184 if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) {
185 if ( array_key_exists( 'custom_login_slug', $options ) && ! empty( $options['custom_login_slug'] ) ) {
186 add_action( 'init', [ $security, 'redirect_on_custom_login_url' ] );
187 add_action( 'login_head', [ $security, 'redirect_on_default_login_urls' ] );
188 add_action( 'wp_login_failed', [ $security, 'redirect_to_custom_login_url_on_login_fail' ] );
189 add_action( 'wp_logout', [ $security, 'redirect_to_custom_login_url_on_logout_success' ] );
190 add_action( 'wp_login', [ $security, 'redirect_to_dashboard' ], 10, 2 );
191 }
192 }
193
194 // Security >> Limit Login Attempts
195 if ( array_key_exists( 'limit_login_attempts', $options ) && $options['limit_login_attempts'] ) {
196 add_filter( 'authenticate', [ $security, 'maybe_allow_login' ], 999, 3 ); // Very low priority so it is processed last
197 add_action( 'login_enqueue_scripts', [ $security, 'maybe_hide_login_form' ] );
198 add_action( 'wp_login_failed', [ $security, 'log_failed_login' ], 5 ); // Higher priority than one in Change Login URL
199 add_action( 'wp_login_errors', [ $security, 'login_error_handler' ], 999, 2 );
200 add_filter( 'login_message', [ $security, 'add_failed_login_message' ] );
201 add_action( 'wp_login', [ $security, 'clear_failed_login_log' ] );
202 }
203
204 // Security >> Obfuscate Author Slugs
205 if ( array_key_exists( 'obfuscate_author_slugs', $options ) && $options['obfuscate_author_slugs'] ) {
206 add_action( 'pre_get_posts', [ $security, 'alter_author_query' ], 10 );
207 add_filter( 'author_link', [ $security, 'alter_author_link' ], 10, 3 );
208 add_filter( 'rest_prepare_user', [ $security, 'alter_json_users' ], 10, 3 );
209 }
210
211 // ===== UTILITIES ======
212
213 // Instantiate object for Utilities features
214 $utilities = new ASENHA\Classes\Utilities;
215
216 // Utilities >> Redirect After Login
217 if ( array_key_exists( 'redirect_after_login', $options ) && $options['redirect_after_login'] ) {
218 if ( array_key_exists( 'redirect_after_login_to_slug', $options ) && ! empty( $options['redirect_after_login_to_slug'] ) ) {
219 if ( array_key_exists( 'redirect_after_login_for', $options ) && ! empty( $options['redirect_after_login_for'] ) ) {
220 add_filter( 'wp_login', [ $utilities, 'redirect_for_roles_after_login' ], 5, 2 );
221 }
222 }
223 }
224
225 // Utilities >> Redirect After Logout
226 if ( array_key_exists( 'redirect_after_logout', $options ) && $options['redirect_after_logout'] ) {
227 if ( array_key_exists( 'redirect_after_logout_to_slug', $options ) && ! empty( $options['redirect_after_logout_to_slug'] ) ) {
228 if ( array_key_exists( 'redirect_after_logout_for', $options ) && ! empty( $options['redirect_after_logout_for'] ) ) {
229 add_action( 'wp_logout', [ $utilities, 'redirect_after_logout' ], 5, 1 ); // load earlier than Change Login URL add_action
230 }
231 }
232 }
233
234 // Utilities >> Redirect 404 to Homepage
235 if ( array_key_exists( 'redirect_404_to_homepage', $options ) && $options['redirect_404_to_homepage'] ) {
236 add_filter( 'wp', [ $utilities, 'redirect_404_to_homepage' ] );
237 }
238
239 // Utilities >> Enable Custom Admin / Frontend CSS
240
241 if ( array_key_exists( 'enable_custom_admin_css', $options ) && $options['enable_custom_admin_css'] ) {
242 add_filter( 'admin_enqueue_scripts', [ $utilities, 'custom_admin_css' ] );
243 }
244
245 if ( array_key_exists( 'enable_custom_frontend_css', $options ) && $options['enable_custom_frontend_css'] ) {
246 add_filter( 'wp_enqueue_scripts', [ $utilities, 'custom_frontend_css' ] );
247 }
248
249 // ===== DISABLE COMPONENTS ======
250
251 // Instantiate object for Disable Components features
252 $disable_components = new ASENHA\Classes\Disable_Components;
253
254 // Disable Components >> Disable XML-RPC
255 if ( array_key_exists( 'disable_xmlrpc', $options ) && $options['disable_xmlrpc'] ) {
256 add_filter( 'xmlrpc_enabled', '__return_false' );
257 add_filter( 'wp_xmlrpc_server_class', [ $disable_components, 'maybe_disable_xmlrpc' ] );
258 }
259
260 }
261
262 }
263
264 Admin_Site_Enhancements::get_instance();