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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 / classes / class-disable-components.php
admin-site-enhancements / classes Last commit date
class-activation.php 3 years ago class-admin-interface.php 3 years ago class-common-methods.php 3 years ago class-content-management.php 3 years ago class-deactivation.php 3 years ago class-disable-components.php 3 years ago class-security.php 3 years ago class-settings-fields-render.php 3 years ago class-settings-sanitization.php 3 years ago class-settings-sections-fields.php 3 years ago class-utilities.php 3 years ago
class-disable-components.php
262 lines
1 <?php
2
3 namespace ASENHA\CLasses;
4 use WP_Error;
5
6 /**
7 * Class related to the Disable Components feature
8 *
9 * @since 2.2.0
10 */
11 class Disable_Components {
12
13 /**
14 * Disable comments for post types
15 *
16 * @since 2.7.0
17 */
18 public function disable_comments_for_post_types_edit() {
19
20 $options = get_option( ASENHA_SLUG_U );
21 $disable_comments_for = $options['disable_comments_for'];
22
23 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
24 if ( $is_commenting_disabled ) {
25 remove_post_type_support( $post_type_slug, 'comments' );
26 remove_post_type_support( $post_type_slug, 'trackbacks' );
27 remove_meta_box( 'commentstatusdiv', $post_type_slug, 'normal' );
28 remove_meta_box( 'commentstatusdiv', $post_type_slug, 'side' );
29 remove_meta_box( 'commentsdiv', $post_type_slug, 'normal' );
30 remove_meta_box( 'commentsdiv', $post_type_slug, 'side' );
31 }
32 }
33
34 }
35
36 /**
37 * Hide existing comments from the frontend post
38 *
39 * @since 2.7.0
40 */
41 public function hide_existing_comments_on_frontend( $comments, $post_id ) {
42 $options = get_option( ASENHA_SLUG_U );
43 $disable_comments_for = $options['disable_comments_for'];
44 $current_post_type = get_post_type();
45
46 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
47 if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) {
48 return array(); // return an empty array instead of the existing comments array
49 } else {
50 return $comments;
51 }
52 }
53 }
54
55 /**
56 * Close commenting on the frontend
57 *
58 * @since 2.7.0
59 */
60 public function close_commenting_on_frontend() {
61 $options = get_option( ASENHA_SLUG_U );
62 $disable_comments_for = $options['disable_comments_for'];
63 $current_post_type = get_post_type();
64
65 foreach ( $disable_comments_for as $post_type_slug => $is_commenting_disabled ) {
66 if ( ( $current_post_type === $post_type_slug ) && $is_commenting_disabled ) {
67 return false; // close commenting
68 } else {
69 return true; // keep commenting open
70 }
71 }
72 }
73
74 /**
75 * Disable Gutenberg in wp-admin for some or all post types
76 *
77 * @since 2.8.0
78 */
79 public function disable_gutenberg_for_post_types_admin() {
80
81 // Get current page's post type from WP core globals and query parameters
82
83 global $pagenow, $typenow;
84
85 $post_type = null;
86
87 if ( 'edit.php' === $pagenow ) { // on the list table screen, $typenow returns correct post type
88
89 $post_type = $typenow;
90
91 } elseif ( 'post.php' === $pagenow ) { // on the edit screen, $typenow is empty, so we detect it
92
93 $post_type = get_post_type( $_GET['post'] );
94
95 } elseif ( 'post-new.php' === $pagenow ) { // on the add new screen, best to get post type from GET parameter
96
97 $post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : 'post';
98
99 } else {}
100
101 // Check if Gutenberg feature is enabled for the site
102
103 // Before/after WP v5.0.0 via feature plugin
104 $gutenberg = function_exists( 'gutenberg_register_scripts_and_styles' );
105
106 // Since WP v5.0.0, gutenberg is in core
107 $block_editor = has_action( 'enqueue_block_assets' );
108
109 // Gutenberg feature is not enabled for the site
110 if ( ! $gutenberg && ( false === $block_editor ) ) {
111 return; // do nothing
112 }
113
114 // Assemble single-dimensional array of post types for which Gutenberg should be disabled
115 $options = get_option( ASENHA_SLUG_U );
116 $disable_gutenberg_for = $options['disable_gutenberg_for'];
117 $post_types_for_disable_gutenberg = array();
118
119 foreach( $disable_gutenberg_for as $post_type_slug => $is_gutenberg_disabled ) {
120 if ( $is_gutenberg_disabled ) {
121 $post_types_for_disable_gutenberg[] = $post_type_slug;
122 }
123 }
124
125 // Selectively disable Gutenberg
126 if ( in_array( $post_type, $post_types_for_disable_gutenberg ) ) {
127
128 // For WP v5.0.0 upwards
129 add_filter( 'use_block_editor_for_post_type', '__return_false', 100 );
130
131 // If Gutenberg feature plugin is activated
132 if ( $gutenberg ) {
133 add_filter( 'gutenberg_can_edit_post_type', '__return_false', 100 );
134 $this->remove_all_gutenberg_hook();
135 }
136
137 }
138
139 }
140
141 /**
142 * Remove Gutenberg hooks added via feature plugin.
143 *
144 * @link https://plugins.trac.wordpress.org/browser/classic-editor/tags/1.6.2/classic-editor.php#L138
145 * @since 2.8.0
146 */
147 public function remove_all_gutenberg_hooks() {
148
149 remove_action( 'admin_menu', 'gutenberg_menu' );
150 remove_action( 'admin_init', 'gutenberg_redirect_demo' );
151
152 // Gutenberg 5.3+
153 remove_action( 'wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles' );
154 remove_action( 'admin_enqueue_scripts', 'gutenberg_register_scripts_and_styles' );
155 remove_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
156 remove_action( 'rest_api_init', 'gutenberg_register_rest_widget_updater_routes' );
157 remove_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' );
158 remove_action( 'admin_print_scripts', 'gutenberg_block_editor_admin_print_scripts' );
159 remove_action( 'admin_print_footer_scripts', 'gutenberg_block_editor_admin_print_footer_scripts' );
160 remove_action( 'admin_footer', 'gutenberg_block_editor_admin_footer' );
161 remove_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' );
162 remove_action( 'admin_notices', 'gutenberg_build_files_notice' );
163
164 remove_filter( 'load_script_translation_file', 'gutenberg_override_translation_file' );
165 remove_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
166 remove_filter( 'default_content', 'gutenberg_default_demo_content' );
167 remove_filter( 'default_title', 'gutenberg_default_demo_title' );
168 remove_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' );
169 remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' );
170
171 // Previously used, compat for older Gutenberg versions.
172 remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );
173 remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
174 remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );
175
176 remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' );
177 remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' );
178 remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' );
179
180 remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save' );
181 remove_action( 'submitpost_box', 'gutenberg_intercept_meta_box_render' );
182 remove_action( 'submitpage_box', 'gutenberg_intercept_meta_box_render' );
183 remove_action( 'edit_page_form', 'gutenberg_intercept_meta_box_render' );
184 remove_action( 'edit_form_advanced', 'gutenberg_intercept_meta_box_render' );
185 remove_filter( 'redirect_post_location', 'gutenberg_meta_box_save_redirect' );
186 remove_filter( 'filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes' );
187
188 remove_filter( 'body_class', 'gutenberg_add_responsive_body_class' );
189 remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' ); // old
190 remove_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' );
191 remove_filter( 'register_post_type_args', 'gutenberg_filter_post_type_labels' );
192 }
193
194 /**
195 * Disable Gutenberg styles and scripts on the front end for all or some post types
196 *
197 * @since 2.8.0
198 */
199 public function disable_gutenberg_for_post_types_frontend() {
200
201 $post = get_queried_object();
202 $post_type = $post->post_type;
203
204 // Assemble single-dimensional array of post types for which Gutenberg should be disabled
205 $options = get_option( ASENHA_SLUG_U );
206 $disable_gutenberg_for = $options['disable_gutenberg_for'];
207 $post_types_for_disable_gutenberg = array();
208
209 foreach( $disable_gutenberg_for as $post_type_slug => $is_gutenberg_disabled ) {
210 if ( $is_gutenberg_disabled ) {
211 $post_types_for_disable_gutenberg[] = $post_type_slug;
212 }
213 }
214
215 // Selectively disable for the selected post types
216 if ( in_array( $post_type, $post_types_for_disable_gutenberg ) ) {
217
218 global $wp_styles;
219
220 // As needed, exclude some block styles from dequeuing
221 $keep_enqueued = array(); // e.g. array( 'wp-block-navigation' );
222
223 foreach ( $wp_styles->queue as $handle ) {
224
225 // For all stye handles that starts with 'wp-block'
226 if ( false !== strpos( $handle, 'wp-block' ) ) {
227
228 if ( ! in_array( $handle, $keep_enqueued ) ) {
229 wp_dequeue_style( $handle );
230 }
231
232 }
233
234 }
235
236 // Additional dequeuing
237 wp_dequeue_style( 'core-block-supports' );
238 wp_dequeue_style( 'global-styles' ); // theme.json
239 wp_dequeue_style( 'classic-theme-styles' ); // classic theme
240
241 }
242
243 }
244
245 /**
246 * Disable REST API for non-authenticated users. This is for WP v4.7 or later.
247 *
248 * @since 2.9.0
249 */
250 public function disable_rest_api() {
251
252 return new WP_Error(
253 'rest_api_authentication_required',
254 'The REST API has been restricted to authenticated users.',
255 array(
256 'status' => rest_authorization_required_code()
257 )
258 );
259
260 }
261
262 }