PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.5.2
WP Coder – Insert & Manage Code Snippets v4.5.2
4.5.2 4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 All 40 releases
← All changes | includes/snippets/class-snippet-disabled.php +42 -8 3.4 → 4.5.2 View file →
@@ -3,10 +3,16 @@
3 3 defined( 'ABSPATH' ) || exit;
4 4
5 5 class WPCoder_Lite_Disabled_Snippets {
6 6
7 + /**
8 + * @var false|mixed|null
9 + */
10 + private $options;
11 +
7 12 public function __construct() {
8 13 $options = get_option( '_wp_coder_snippets', [] );
14 + $this->options = $options;
9 15
10 16 if ( array_key_exists( 'disable_gutenberg', $options ) ) {
11 17 add_filter( 'gutenberg_can_edit_post', '__return_false', 5 );
12 18 add_filter( 'use_block_editor_for_post', '__return_false', 5 );
@@ -32,12 +38,11 @@
32 38 add_filter( 'xmlrpc_enabled', '__return_false' );
33 39 }
34 40
35 41 if ( array_key_exists( 'disable_admin_bar', $options ) ) {
36 - add_filter( 'show_admin_bar', '__return_false' );
42 + add_filter( 'show_admin_bar', [ $this, 'disable_admin_bar' ] );
37 43 }
38 44
39 -
40 45 if ( array_key_exists( 'disable_automatic_updates', $options ) ) {
41 46 // Disable core auto-updates
42 47 add_filter( 'auto_update_core', '__return_false' );
43 48 // Disable auto-updates for plugins.
@@ -159,17 +164,17 @@
159 164 add_filter( 'comment_form_default_fields', [ $this, 'comment_from_website' ], 150 );
160 165 }
161 166
162 167 if ( array_key_exists( 'disable_self_pingbacks', $options ) ) {
163 - add_action( 'pre_ping', [$this, 'self_pingbacks']);
168 + add_action( 'pre_ping', [ $this, 'self_pingbacks' ] );
164 169 }
165 170
166 171 if ( array_key_exists( 'disable_wlwmanifest_link', $options ) ) {
167 - remove_action('wp_head', 'wlwmanifest_link');
172 + remove_action( 'wp_head', 'wlwmanifest_link' );
168 173 }
169 174
170 175 if ( array_key_exists( 'disable_embeds', $options ) ) {
171 - add_action( 'init', [$this, 'disable_embeds'], 9999);
176 + add_action( 'init', [ $this, 'disable_embeds' ], 9999 );
172 177 }
173 178
174 179 if ( array_key_exists( 'disable_lazy_load', $options ) ) {
175 180 add_filter( 'wp_lazy_loading_enabled', '__return_false' );
@@ -175,9 +180,9 @@
175 180 add_filter( 'wp_lazy_loading_enabled', '__return_false' );
176 181 }
177 182
178 183 if ( array_key_exists( 'disable_wp_shortlink', $options ) ) {
179 - remove_action('wp_head', 'wp_shortlink_wp_head' );
184 + remove_action( 'wp_head', 'wp_shortlink_wp_head' );
180 185 }
181 186
182 187 if ( array_key_exists( 'disable_admin_pass_reset_email', $options ) ) {
183 188 remove_action( 'after_password_reset', 'wp_password_change_notification' );
@@ -182,9 +187,20 @@
182 187 if ( array_key_exists( 'disable_admin_pass_reset_email', $options ) ) {
183 188 remove_action( 'after_password_reset', 'wp_password_change_notification' );
184 189 }
185 190
191 + if ( array_key_exists( 'disable_trackbacks_pingbacks', $options ) ) {
192 + add_filter('xmlrpc_methods', static function($methods) {
193 + unset($methods['pingback.ping']);
194 + return $methods;
195 + });
196 + }
186 197
198 + if ( array_key_exists( 'disable_comments_html', $options ) ) {
199 + remove_filter('comment_text', 'make_clickable', 9);
200 + add_filter('pre_comment_content', 'wp_strip_all_tags');
201 + }
202 +
187 203 }
188 204
189 205 public function disable_embeds(): void {
190 206 // Remove the REST API endpoint.
@@ -206,8 +222,9 @@
206 222 if ( false !== strpos( $rewrite, 'embed=true' ) ) {
207 223 unset( $rules[ $rule ] );
208 224 }
209 225 }
226 +
210 227 return $rules;
211 228 } );
212 229 // Remove filter of the oEmbed result before any HTTP requests are made.
213 230 remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
@@ -212,9 +229,9 @@
212 229 // Remove filter of the oEmbed result before any HTTP requests are made.
213 230 remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
214 231 }
215 232
216 - public function self_pingbacks(&$links): void {
233 + public function self_pingbacks( &$links ): void {
217 234
218 235 $home = get_option( 'home' );
219 236 foreach ( $links as $l => $link ) {
220 237 if ( 0 === strpos( $link, $home ) ) {
@@ -234,9 +251,9 @@
234 251 public function disable_feed(): void {
235 252 wp_die(
236 253 sprintf(
237 254 // Translators: Placeholders for the homepage link.
238 - esc_html__( 'No feed available, please visit our %1$shomepage%2$s!', 'wpcoder' ),
255 + esc_html__( 'No feed available, please visit our %1$shomepage%2$s!', 'wp-coder' ),
239 256 ' <a href="' . esc_url( home_url( '/' ) ) . '">',
240 257 '</a>'
241 258 )
242 259 );
@@ -317,8 +334,25 @@
317 334 // For attachment without a parent redirect to homepage.
318 335 wp_safe_redirect( get_bloginfo( 'wpurl' ), 302 );
319 336 }
320 337 exit;
338 + }
339 +
340 + public function disable_admin_bar( $show_admin_bar ): bool {
341 + $admin_bar = false;
342 +
343 + $user = wp_get_current_user();
344 +
345 + if ( ! empty( $user->roles ) ) {
346 + foreach ( $user->roles as $role ) {
347 + if ( array_key_exists( 'disable_admin_bar_user_' . $role, $this->options ) ) {
348 + $admin_bar = true;
349 + break;
350 + }
351 + }
352 + }
353 +
354 + return $admin_bar;
321 355 }
322 356
323 357
324 358 }