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