PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / security-tweaks / disable-trackback.php

disable-trackback.php in Defender Security – Malware Scanner, Login Security & Firewall 3.0.1, at src/component/security-tweaks/disable-trackback.php

125 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_Defender\Component\Security_Tweaks;
4
5 use Calotes\Base\Component;
6
7 /**
8 * Class Disable_Trackback
9 * @package WP_Defender\Component\Security_Tweaks
10 */
11 class Disable_Trackback extends Component {
12 public $slug = 'disable-trackback';
13 public $resolved = false;
14
15 /**
16 * Check whether the issue has been resolved or not.
17 *
18 * @return bool
19 */
20 public function check() {
21 return $this->resolved;
22 }
23
24 /**
25 * Here is the code for processing, if the return is true, we add it to resolve list, WP_Error if any error.
26 *
27 * @return bool|\WP_Error
28 */
29 public function process() {
30 return $this->update_site_trackback();
31 }
32
33 /**
34 * This is for un-do stuff that has be done in @process.
35 *
36 * @return bool|\WP_Error
37 */
38 public function revert() {
39 return $this->update_site_trackback( true );
40 }
41
42 /**
43 * Update site ping status and pingback flag.
44 *
45 * @param bool $revert Set true to revert changes. Default value: false.
46 *
47 * @return bool
48 */
49 private function update_site_trackback( $revert = false ) {
50 global $wpdb;
51
52 $flag = $revert ? 1 : 0;
53 $status = $revert ? 'open' : 'closed';
54 $ping_status = 'default_ping_status';
55 $pingback_flag = 'default_pingback_flag';
56
57 if ( ! is_multisite() ) {
58 update_option( $ping_status, $status );
59 update_option( $pingback_flag, $flag );
60
61 $this->change_posts_ping_status( $wpdb, $revert );
62
63 return true;
64 }
65
66 $blog_ids = wp_list_pluck( get_sites(), 'blog_id' );
67
68 foreach ( $blog_ids as $blog_id ) {
69 update_blog_option( $blog_id, $ping_status, $status );
70 update_blog_option( $blog_id, $pingback_flag, $flag );
71
72 $this->change_posts_ping_status( $wpdb, $revert, $blog_id );
73 }
74
75 return true;
76 }
77
78 /**
79 * Update the post ping status.
80 *
81 * @param bool $revert Set to true to revert changes.
82 * @param int $blog_id The blog id if multisite.
83 *
84 * @return void
85 */
86 private function change_posts_ping_status( $wpdb, $revert = false, $blog_id = 0 ) {
87 $ping_status = $revert ? 'open' : 'closed';
88 $post_type_to_ignore = [ 'wd_ip_lockout', 'wd_iplockout_log' ];
89 $post_type_to_ignore = "'" . implode( "','", $post_type_to_ignore ) . "'";
90
91 if ( $blog_id ) {
92 $wpdb->set_blog_id( $blog_id );
93 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET `ping_status` = %s WHERE `post_status` != %s AND `post_type` NOT IN(%s)", $ping_status, 'inherit', $post_type_to_ignore ) );
94 } else {
95 $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET `ping_status` = %s WHERE `post_status` != %s AND `post_type` NOT IN(%s)", $ping_status, 'inherit', $post_type_to_ignore ) );
96 }
97 }
98
99 /**
100 * Shield up.
101 *
102 * @return void
103 */
104 public function shield_up() {
105 $this->resolved = true;
106 }
107
108 /**
109 * Return a summary data of this tweak.
110 *
111 * @return array
112 */
113 public function to_array() {
114 return [
115 'slug' => $this->slug,
116 'title' => __( 'Disable trackbacks and pingbacks', 'wpdef' ),
117 'errorReason' => __( 'Trackbacks and pingbacks are currently enabled.', 'wpdef' ),
118 'successReason' => __( 'Trackbacks and pingbacks are disabled, nice work!', 'wpdef' ),
119 'misc' => [],
120 'bulk_description' => __( 'Trackbacks and pingbacks can lead to DDos attacks and tons of spam comments. If you don’t require this feature, we recommend turning it off.', 'wpdef' ),
121 'bulk_title' => 'Trackbacks and pingbacks'
122 ];
123 }
124 }
125