PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Modules / DisableComments / DisableComments.php

DisableComments.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.0, at Inc/Modules/DisableComments/DisableComments.php

222 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPAdminify\Inc\Modules\DisableComments;
4
5 use \Elementor;
6 use WPAdminify\Inc\Utils;
7 use WPAdminify\Inc\Classes\Multisite_Helper;
8 use WPAdminify\Inc\Admin\AdminSettings;
9 use WPAdminify\Inc\Admin\AdminSettingsModel;
10
11
12 // no direct access allowed
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * WPAdminify
19 *
20 * @package Module: Disable Comments
21 *
22 * @author Jewel Theme <support@jeweltheme.com>
23 */
24
25 class DisableComments extends AdminSettingsModel {
26
27 public $options;
28 public $disable_comments;
29
30 public function __construct() {
31 $this->options = (array) AdminSettings::get_instance()->get();
32 $this->disable_comments = $this->options['disable_comments'];
33
34
35 if (!empty($this->disable_comments['disable_comments']['enable_disable_comments'])) {
36 return;
37 }
38
39 // Disable Comments
40 add_action( 'admin_init', [ $this, 'disable_comments_settings' ] ); // Supported Hooks: 'init', 'admin_init', 'wp_loaded', 'do_meta_boxes'
41
42
43 // Close comments on the front-end
44 if (!empty($this->disable_comments['apply_for']) && in_array('close_front', $this->disable_comments['apply_for'])) {
45 add_filter( 'comments_open', '__return_false', 20, 2 );
46 add_filter( 'pings_open', '__return_false', 20, 2 );
47 }
48
49 // Remove comment notes
50 if (!empty($this->disable_comments['apply_for']) && in_array('comments_notes', $this->disable_comments['apply_for'])) {
51 add_filter('comment_form_defaults', [$this, 'remove_comments_notes']);
52 }
53
54 // Remove comments links from admin bar
55 if (!empty($this->disable_comments['apply_for']) && in_array('admin_bar', $this->disable_comments['apply_for'])) {
56 // add_action('init', [$this, 'jltma_adminify_disable_comments_admin_bar_menu']);
57 add_action( 'wp_before_admin_bar_render', [ $this, 'jltma_adminify_remove_admin_bar_menus' ], 0 );
58 }
59
60 // URL field remove from Comments
61 if (!empty($this->disable_comments['apply_for']) && in_array('comments_url_field', $this->disable_comments['apply_for'])) {
62 add_filter( 'comment_form_default_fields', [ $this,
63 'remove_url_field_comment_form' ] );
64 }
65
66 // Remove comments page in menu
67 if (!empty($this->disable_comments['apply_for']) && in_array('admin_menu', $this->disable_comments['apply_for'])) {
68 add_action( 'admin_menu', [ $this, 'remove_comments_admin_menu' ] );
69 }
70
71 // Remove "Discussion" submenu from Settings menu
72 if (!empty($this->disable_comments['apply_for']) && in_array('discussion_menu', $this->disable_comments['apply_for'])) {
73 add_action( 'admin_menu', [$this, 'remove_discussion_submenu'] );
74 }
75 }
76
77 /**
78 * Remove Discussion Submenu
79 */
80 public function remove_discussion_submenu() {
81 remove_submenu_page('options-general.php', 'options-discussion.php');
82 }
83
84 /**
85 * Remove Comments Menu
86 */
87 public function remove_comments_admin_menu(){
88 remove_menu_page('edit-comments.php');
89 }
90
91 /**
92 * Disable Comments Settings
93 *
94 * @return void
95 */
96 public function disable_comments_settings() {
97
98 // Disable support for comments and trackbacks in post types
99 $post_types = $this->disable_comments['post_types'];
100 foreach ($post_types as $post_type) {
101 if (post_type_supports($post_type, 'comments')) {
102 remove_post_type_support($post_type, 'comments');
103 remove_post_type_support($post_type, 'trackbacks');
104 \remove_meta_box('commentstatusdiv', $post_type, 'normal');
105 \remove_meta_box('commentstatusdiv', $post_type, 'side');
106 remove_meta_box('commentsdiv', $post_type, 'normal');
107 remove_meta_box('commentsdiv', $post_type, 'side');
108 remove_meta_box('trackbacksdiv', $post_type, 'normal');
109 remove_meta_box('trackbacksdiv', $post_type, 'side');
110 // wp_dequeue_script('admin-comments'); // edit-comments.js
111 }
112 }
113
114
115
116 // Remove styles for .recentcomments
117 if (!empty($this->disable_comments['apply_for']) && in_array('recentcomments', $this->disable_comments['apply_for'])) {
118 add_action('widgets_init', [$this, 'jltwp_adminify_remove_recent_comments_style']);
119 add_filter( 'show_recent_comments_widget_style', '__return_false' );
120 }
121
122 // Redirect any user trying to access comments page.
123 if (!empty($this->disable_comments['apply_for']) && in_array('menu_redirect', $this->disable_comments['apply_for'])) {
124 global $pagenow;
125 if ($pagenow === 'edit-comments.php') {
126 wp_safe_redirect(admin_url());
127 exit;
128 }
129 }
130
131 // Updated Options
132 add_filter('xmlrpc_allow_anonymous_comments', '__return_false');
133 add_filter('xmlrpc_methods', [$this, 'disable_xmlrpc_comments']);
134 add_filter('rest_endpoints', [$this, 'disable_rest_api_comments_endpoints']);
135 add_filter('rest_pre_insert_comment', [$this, 'return_blank_comment'], 10, 2);
136 }
137
138 // Remove styles for .recentcomments
139 public function jltwp_adminify_remove_recent_comments_style()
140 {
141 global $wp_widget_factory;
142 remove_action('wp_head', [$wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style']);
143 }
144
145
146 /**
147 * Return blank comment before inserting to DB
148 *
149 * @link https://plugins.trac.wordpress.org/browser/disable-comments/tags/2.4.5/disable-comments.php
150 */
151 public function return_blank_comment($prepared_comment, $request)
152 {
153 return;
154 }
155
156
157 /**
158 * Disables comments endpoint in REST API
159 *
160 * @link https://plugins.trac.wordpress.org/browser/disable-comments/tags/2.4.5/disable-comments.php
161 */
162 public function disable_rest_api_comments_endpoints($endpoints)
163 {
164 if (isset($endpoints['comments'])) {
165 unset($endpoints['comments']);
166 }
167
168 if (isset($endpoints['/wp/v2/comments'])) {
169 unset($endpoints['/wp/v2/comments']);
170 }
171
172 if (isset($endpoints['/wp/v2/comments/(?P<id>[\d]+)'])) {
173 unset($endpoints['/wp/v2/comments/(?P<id>[\d]+)']);
174 }
175
176 return $endpoints;
177 }
178
179 public function disable_xmlrpc_comments($methods)
180 {
181 unset($methods['wp.newComment']);
182 return $methods;
183 }
184
185 // Remove Comment Notes
186 public function remove_comments_notes($defaults){
187 $defaults['comment_notes_before'] = '';
188
189 return $defaults;
190 }
191
192 /* Remove from the administration bar */
193 public function jltma_adminify_remove_admin_bar_menus() {
194 global $wp_admin_bar;
195 $wp_admin_bar->remove_menu( 'comments' );
196 }
197
198 // Remove Comments Menu
199 public function jltma_adminify_disable_comments_admin_bar_menu() {
200 if ( is_admin_bar_showing() ) {
201 remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
202 }
203 }
204
205
206 /**
207 * Remove url field from comment form
208 *
209 * @param $fields
210 *
211 * @return mixed
212 */
213
214 public function remove_url_field_comment_form( $fields ) {
215
216 if ( isset( $fields['url'] ) ) {
217 unset( $fields['url'] );
218 }
219 return $fields;
220 }
221 }
222