' . sprintf(__('Note: The Disable Comments plugin is currently active, and comments are completely disabled on: %s. Many of the settings below will not be applicable for those post types.', 'disable-comments'), implode(__(', ', 'disable-comments'), $names)) . '
';
}
}
/**
* Return context-aware settings page URL
*/
private function settings_page_url()
{
$base = $this->networkactive && is_network_admin() ? network_admin_url('settings.php') : admin_url('options-general.php');
return add_query_arg('page', DC_PLUGIN_SLUG, $base);
}
/**
* Return context-aware tools page URL
*/
private function tools_page_url()
{
$base = $this->networkactive && is_network_admin() ? network_admin_url('settings.php') : admin_url('tools.php');
return add_query_arg('page', 'disable_comments_tools', $base);
}
public function setup_notice()
{
$current_screen = get_current_screen()->id;
if (!in_array($current_screen, ['dashboard-network', 'dashboard'])) {
return;
}
$hascaps = $this->networkactive && is_network_admin() ? current_user_can('manage_network_plugins') : current_user_can('manage_options');
if($this->networkactive && !is_network_admin() && !$this->options['sitewide_settings']){
$hascaps = false;
}
if ($hascaps) {
$this->setup_notice_flag = true;
// translators: %s: URL to Disabled Comment settings page.
echo '';
}
}
public function filter_admin_menu()
{
global $pagenow;
if ($pagenow == 'comment.php' || $pagenow == 'edit-comments.php') {
wp_die(__('Comments are closed.', 'disable-comments'), '', array('response' => 403));
}
remove_menu_page('edit-comments.php');
if (!$this->discussion_settings_allowed()) {
if ($pagenow == 'options-discussion.php') {
wp_die(__('Comments are closed.', 'disable-comments'), '', array('response' => 403));
}
remove_submenu_page('options-general.php', 'options-discussion.php');
}
}
public function filter_dashboard()
{
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
public function admin_css()
{
echo '';
}
public function filter_existing_comments($comments, $post_id)
{
$post_type = get_post_type($post_id);
return ($this->is_remove_everywhere() || $this->is_post_type_disabled($post_type) ? array() : $comments);
}
public function filter_comment_status($open, $post_id)
{
$post_type = get_post_type($post_id);
return ($this->is_remove_everywhere() || $this->is_post_type_disabled($post_type) ? false : $open);
}
public function filter_comments_number($count, $post_id)
{
$post_type = get_post_type($post_id);
return ($this->is_remove_everywhere() || $this->is_post_type_disabled($post_type) ? 0 : $count);
}
public function disable_rc_widget()
{
unregister_widget('WP_Widget_Recent_Comments');
/**
* The widget has added a style action when it was constructed - which will
* still fire even if we now unregister the widget... so filter that out
*/
add_filter('show_recent_comments_widget_style', '__return_false');
}
public function set_plugin_meta($links, $file)
{
static $plugin;
$plugin = plugin_basename(__FILE__);
if ($file == $plugin) {
$links[] = '
' . sprintf(__('The Disable Comments plugin is active, but isn\'t configured to do anything yet. Visit the configuration page to choose which post types to disable comments on.', 'disable-comments'), esc_attr($this->settings_page_url())) . '