first commit

This commit is contained in:
User A0264400
2026-04-01 23:20:16 +03:00
commit a766acdc90
23071 changed files with 4933189 additions and 0 deletions

View File

@@ -0,0 +1,178 @@
<?php
/**
* Admin boot
*
* @author Alex Kovalev <alex.kovalevv@gmail.com>, Github: https://github.com/alexkovalevv
* @copyright Webcraftic 25.05.2017
* @version 1.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Массово проходится по комментарием в базе данных и отключает, какждый индивидуально.
*/
function wbcr_cmp_enter_permanent_mode() {
global $wpdb;
if ( ! WCM_Plugin::app()->getPopulateOption( 'disable_comments_permanent' ) ) {
return;
}
$types = wbcr_cmp_get_disabled_post_types();
if ( empty( $types ) ) {
return;
}
if ( WCM_Plugin::app()->isNetworkActive() ) {
// NOTE: this can be slow on large networks!
$blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id
FROM $wpdb->blogs
WHERE site_id = %d
AND public = '1'
AND archived = '0'
AND deleted = '0'", $wpdb->siteid ) );
foreach ( $blogs as $id ) {
switch_to_blog( $id );
wbcr_close_comments_in_db( $types );
restore_current_blog();
}
} else {
wbcr_close_comments_in_db( $types );
}
}
add_action( 'wbcr/factory/pages/impressive/after_form_save', 'wbcr_cmp_enter_permanent_mode' );
add_action( 'wbcr_clearfy_configurated_quick_mode', 'wbcr_cmp_enter_permanent_mode' );
/**
* Закрывает комментарии в базе данных
*
* @param $types
*/
function wbcr_close_comments_in_db( $types ) {
global $wpdb;
$bits = implode( ', ', array_pad( [], count( $types ), '%s' ) );
$wpdb->query( $wpdb->prepare( "UPDATE `$wpdb->posts`
SET `comment_status` = 'closed', ping_status = 'closed'
WHERE `post_type`
IN ( $bits )", $types ) );
}
if ( ! defined( 'LOADING_COMMENTS_PLUS_AS_ADDON' ) ) {
function wbcr_cmp_set_plugin_meta( $links, $file ) {
if ( $file == WCM_PLUGIN_BASE ) {
$url = 'https://clearfy.pro';
if ( get_locale() == 'ru_RU' ) {
$url = 'https://ru.clearfy.pro';
}
$url .= '?utm_source=wordpress.org&utm_campaign=' . WCM_Plugin::app()->getPluginName();
$links[] = '<a href="' . $url . '" style="color: #FF5722;font-weight: bold;" target="_blank">' . __( 'Get ultimate plugin free', 'comments-plus' ) . '</a>';
}
return $links;
}
add_filter( 'plugin_row_meta', 'wbcr_cmp_set_plugin_meta', 10, 2 );
/**
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
*
* @param string $page_url
* @param string $plugin_name
*
* @return string
*/
function wbcr_cmp_rating_widget_url( $page_url, $plugin_name ) {
if ( ! defined( 'LOADING_COMMENTS_PLUS_AS_ADDON' ) && ( $plugin_name == WCM_Plugin::app()->getPluginName() ) ) {
return 'https://goo.gl/v4QkW5';
}
return $page_url;
}
add_filter( 'wbcr_factory_pages_480_imppage_rating_widget_url', 'wbcr_cmp_rating_widget_url', 10, 2 );
/**
* Удаляем лишние виджеты из правого сайдбара в интерфейсе плагина
*
* - Виджет с премиум рекламой
* - Виджет с рейтингом
* - Виджет с маркерами информации
*/
add_filter( 'wbcr/factory/pages/impressive/widgets', function ( $widgets, $position, $plugin ) {
if ( WCM_Plugin::app()->getPluginName() == $plugin->getPluginName() && 'right' == $position ) {
unset( $widgets['business_suggetion'] );
unset( $widgets['rating_widget'] );
unset( $widgets['info_widget'] );
}
return $widgets;
}, 20, 3 );
} else {
function wbcr_cmp_group_options( $options ) {
$options[] = [
'name' => 'disable_comments',
'title' => __( 'Disable comments on the entire site', 'comments-plus' ),
'tags' => [ 'disable_all_comments' ],
'values' => [ 'disable_all_comments' => 'disable_comments' ]
];
$options[] = [
'name' => 'disable_comments_for_post_types',
'title' => __( 'Select post types', 'comments-plus' ),
'tags' => []
];
$options[] = [
'name' => 'disable_comments_extra_post_types',
'title' => __( 'Custom post types', 'comments-plus' ),
'tags' => []
];
$options[] = [
'name' => 'disable_comments_permanent',
'title' => __( 'Use persistent mode', 'comments-plus' ),
'tags' => []
];
$options[] = [
'name' => 'comment_text_convert_links_pseudo',
'title' => __( 'Replace external links in comments on the JavaScript code', 'comments-plus' ),
'tags' => [ 'recommended', 'seo_optimize' ]
];
$options[] = [
'name' => 'pseudo_comment_author_link',
'title' => __( 'Replace external links from comment authors on the JavaScript code', 'comments-plus' ),
'tags' => [ 'recommended', 'seo_optimize' ]
];
$options[] = [
'name' => 'remove_url_from_comment_form',
'title' => __( 'Remove field "site" in comment form', 'comments-plus' ),
'tags' => []
];
return $options;
}
add_filter( "wbcr_clearfy_group_options", 'wbcr_cmp_group_options' );
function wbcr_cmp_allow_quick_mods( $mods ) {
$mods['disable_all_comments'] = [
'title' => __( 'One click disable all comments', 'comments-plus' ),
'icon' => 'dashicons-testimonial'
];
return $mods;
}
add_filter( "wbcr_clearfy_allow_quick_mods", 'wbcr_cmp_allow_quick_mods' );
}

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,233 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Страница общих настроек для этого плагина.
*
* Может быть использована только, если этот плагин используется как отдельный плагин, а не как аддон
* дя плагина Clearfy. Если плагин загружен, как аддон для Clearfy, эта страница не будет подключена.
*
* Поддерживает режим работы с мультисаймами. Вы можете увидеть эту страницу в панели настройки сети.
*
* @author Alex Kovalev <alex.kovalevv@gmail.com>, Github: https://github.com/alexkovalevv
*
* @copyright (c) 2018 Webraftic Ltd
*/
class WbcrCmp_CommentsPage extends WBCR\Factory_Templates_134\Pages\PageBase {
/**
* {@inheritDoc}
*
* @var string
*/
public $id = "comments";
/**
* {@inheritDoc}
*
* @var string
*/
public $page_menu_dashicon = 'dashicons-testimonial';
/**
* {@inheritDoc}
*
* @var bool
*/
public $available_for_multisite = true;
/**
* {@inheritDoc}
*
* @since 1.1.0
* @var bool
*/
public $show_right_sidebar_in_options = true;
/**
* WbcrCmp_CommentsPage constructor.
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
*
* @param \Wbcr_Factory480_Plugin $plugin
*/
public function __construct( Wbcr_Factory480_Plugin $plugin ) {
$this->menu_title = __( 'Disable comments', 'comments-plus' );
$this->page_menu_short_description = __( 'Manage site comments', 'comments-plus' );
if ( ! defined( 'LOADING_COMMENTS_PLUS_AS_ADDON' ) ) {
$this->internal = false;
$this->menu_target = 'options-general.php';
$this->add_link_to_plugin_actions = true;
$this->show_search_options_form = false;
}
parent::__construct( $plugin );
}
/*public function getMenuTitle() {
return defined( 'LOADING_COMMENTS_PLUS_AS_ADDON' ) ? __( 'Comments', 'comments-plus' ) : __( 'General', 'comments-plus' );
}*/
/**
* {@inheritDoc}
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
* @return string
*/
public function getPageTitle() {
return defined( 'LOADING_COMMENTS_PLUS_AS_ADDON' ) ? __( 'Comments', 'comments-plus' ) : __( 'General', 'comments-plus' );
}
/**
* {@inheritDoc}
*
* @since 1.0.0
* @return mixed[]
*/
public function getPageOptions() {
$options = [];
$options[] = [
'type' => 'html',
'html' => '<div class="wbcr-factory-page-group-header"><strong>' . __( 'Global disabling of comments', 'comments-plus' ) . '</strong><p>' . __( 'What is the difference between these and native WordPress functions? WordPress disables comments only for new posts! Using the functions below, you can disable comments globally, even for old posts, and you can choose which post types comments to disable. The plugin also disables the comment functionality itself, which creates a certain load on the site.', 'comments-plus' ) . '</p></div>'
];
$args = [ 'public' => true ];
if ( $this->plugin->isNetworkActive() ) {
$args['_builtin'] = true;
}
$types = get_post_types( $args, 'objects' );
/*foreach( array_keys( $types ) as $type ) {
if( ! in_array( $type, $this->modified_types ) && ! post_type_supports( $type, 'comments' ) ) // the type doesn't support comments anyway
unset( $types[$type] );
}*/
$post_types = [];
foreach ( $types as $type_name => $type ) {
$post_types[] = [ $type_name, $type->label ];
}
$options[] = [
'type' => 'dropdown',
'name' => 'disable_comments',
'way' => 'buttons',
'title' => __( 'Disable comments', 'comments-plus' ),
'data' => [
[ 'enable_comments', __( 'Not disable', 'comments-plus' ) ],
[
'disable_comments',
__( 'Everywhere', 'comments-plus' ),
sprintf( __( 'You can delete all comments in the database by clicking on this link (<a href="%s">cleaning comments in database</a>).', 'comments-plus' ), admin_url( 'admin.php?page=delete_comments-' . $this->plugin->getPluginName() ) )
],
[
'disable_certain_post_types_comments',
__( 'On certain post types', 'comments-plus' ),
sprintf( __( 'You can delete all comments for the selected post types. Select the post types below and save the settings. After that, click the link (<a href="%s">delete all comments for the selected post types in database</a>).', 'comments-plus' ), admin_url( 'admin.php?page=delete_comments-' . $this->plugin->getPluginName() ) )
]
],
'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'grey' ],
'hint' => __( 'Everywhere - Warning: This option is global and will affect your entire site. Use it only if you want to disable comments everywhere. A complete description of what this option does is available here', 'comments-plus' ) . '<br><br>' . __( 'On certain post types - Disabling comments will also disable trackbacks and pingbacks. All comment-related fields will also be hidden from the edit/quick-edit screens of the affected posts. These settings cannot be overridden for individual posts.', 'comments-plus' ),
'default' => 'enable_comments',
'events' => [
'disable_certain_post_types_comments' => [
'show' => '.factory-control-disable_comments_for_post_types, #wbcr-clearfy-comments-base-options,.factory-control-disable_comments_permanent,.factory-control-disable_comments_extra_post_types'
],
'enable_comments' => [
'show' => '#wbcr-clearfy-comments-base-options',
'hide' => '.factory-control-disable_comments_for_post_types,.factory-control-disable_comments_permanent,.factory-control-disable_comments_extra_post_types'
],
'disable_comments' => [
'show' => '.factory-control-disable_comments_permanent',
'hide' => '.factory-control-disable_comments_for_post_types, #wbcr-clearfy-comments-base-options,.factory-control-disable_comments_extra_post_types'
]
]
];
$options[] = [
'type' => 'list',
'way' => 'checklist',
'name' => 'disable_comments_for_post_types',
'title' => __( 'Select post types', 'comments-plus' ),
'data' => $post_types,
'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'grey' ],
'hint' => __( 'Select the post types for which comments will be disabled', 'comments-plus' ),
'default' => 'post,page,attachment'
];
if ( $this->plugin->isNetworkActive() ) {
$options[] = [
'type' => 'textbox',
'name' => 'disable_comments_extra_post_types',
'title' => __( 'Custom post types', 'comments-plus' ),
'data' => $post_types,
'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'grey' ],
'hint' => __( 'Only the built-in post types appear above. If you want to disable comments on other custom post types on the entire network, you can supply a comma-separated list of post types below (use the slug that identifies the post type).', 'comments-plus' ),
'default' => ''
];
}
$options[] = [
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'disable_comments_permanent',
'title' => __( 'Use persistent mode', 'comments-plus' ),
'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'grey' ],
'hint' => __( 'This will make persistent changes to your database &mdash; comments will remain closed even if you later disable the plugin! You should not use it if you only want to disable comments temporarily.', 'comments-plus' ),
'default' => false
];
$options[] = [
'type' => 'div',
'id' => 'wbcr-clearfy-comments-base-options',
'items' => [
[
'type' => 'html',
'html' => '<div class="wbcr-factory-page-group-header"><strong>' . __( 'General settings for comments', 'comments-plus' ) . '</strong><p>' . __( 'These settings will help you improve SEO and reduce the amount of spam.', 'comments-plus' ) . '</p></div>'
],
[
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'remove_url_from_comment_form',
'title' => __( 'Remove field "site" in comment form', 'comments-plus' ),
'layout' => [ 'hint-type' => 'icon', 'hint-icon-color' => 'grey' ],
'hint' => __( 'Tired of spam in the comments? Do visitors leave "blank" comments for the sake of a link to their site?', 'comments-plus' ) . '<br><b>Clearfy: </b>' . __( 'Removes the "Site" field from the comment form.', 'comments-plus' ) . '<br>--<br><span class="wbcr-factory-light-orange-color"> *' . __( 'Works with the standard comment form, if the form is manually written in your theme-it probably will not work!', 'comments-plus' ) . '</span>',
'default' => false
],
[
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'comment_text_convert_links_pseudo',
'title' => __( 'Replace external links in comments on the JavaScript code', 'comments-plus' ),
'layout' => [ 'hint-type' => 'icon' ],
'hint' => __( 'Superfluous external links from comments, which can be typed from a dozen and more for one article, do not bring anything good for promotion.', 'comments-plus' ) . '<br><br><b>Clearfy: </b>' . sprintf( __( 'Replaces the links of this kind of %s, on links of this kind %s', 'comments-plus' ), '<code>a href="http://yourdomain.com" rel="nofollow"</code>', '<code>span data-uri="http://yourdomain.com"</code>' ),
'default' => false
],
[
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'pseudo_comment_author_link',
'title' => __( 'Replace external links from comment authors on the JavaScript code', 'comments-plus' ),
'layout' => [ 'hint-type' => 'icon' ],
'hint' => __( 'Up to 90 percent of comments in the blog can be left for the sake of an external link. Even nofollow from page weight loss here does not help.', 'comments-plus' ) . '<br><br><b>Clearfy: </b>' . __( 'Replaces the links of the authors of comments on the JavaScript code, it is impossible to distinguish it from usual links.', 'comments-plus' ) . '<br>--<br><i>' . __( 'In some Wordpress topics this may not work.', 'comments-plus' ) . '</i>',
'default' => false
]
]
];
$formOptions = [];
$formOptions[] = [
'type' => 'form-group',
'items' => $options,
//'cssClass' => 'postbox'
];
return apply_filters( 'wbcr_cmp_comments_form_options', $formOptions );
}
}

View File

@@ -0,0 +1,513 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Страница общих настроек для этого плагина.
*
* Может быть использована только, если этот плагин используется как отдельный плагин, а не как аддон
* дя плагина Clearfy. Если плагин загружен, как аддон для Clearfy, эта страница не будет подключена.
*
* Поддерживает режим работы с мультисаймами. Вы можете увидеть эту страницу в панели настройки сети.
*
* @author Alex Kovalev <alex.kovalevv@gmail.com>, Github: https://github.com/alexkovalevv
*
* @copyright (c) 2018 Webraftic Ltd
*/
class WbcrCmp_DeleteCommentsPage extends WBCR\Factory_Templates_134\Pages\PageBase {
/**
* {@inheritDoc}
*
* @var string
*/
public $id = "delete_comments";
/**
* {@inheritDoc}
*
* @var string
*/
public $type = "page";
/**
* {@inheritDoc}
*
* @var string
*/
public $page_parent_page = "comments";
/**
* {@inheritDoc}
*
* @var string
*/
public $page_menu_dashicon = 'dashicons-testimonial';
/**
* {@inheritDoc}
*
* @var bool
*/
public $available_for_multisite = true;
/**
* {@inheritDoc}
*
* @since 1.1.0
* @var bool
*/
public $show_right_sidebar_in_options = true;
/**
* WbcrCmp_DeleteCommentsPage constructor.
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
*
* @param \Wbcr_Factory480_Plugin $plugin
*/
public function __construct( Wbcr_Factory480_Plugin $plugin ) {
$this->menu_title = __( 'Comments cleaner', 'comments-plus' );
parent::__construct( $plugin );
}
/**
* {@inheritDoc}
*
* @param $notices
* @param Wbcr_Factory480_Plugin $plugin
*
* @return array
* @see libs\factory\pages\themplates\FactoryPages480_ImpressiveThemplate
*/
public function getActionNotices( $notices ) {
$notices[] = [
'conditions' => [
'wbcr_cmp_clear_comments' => 1
],
'type' => 'success',
'message' => __( 'All comments have been deleted.', 'comments-plus' )
];
$notices[] = [
'conditions' => [
'wbcr_cmp_clear_comments_error' => 1,
'wbcr_cmp_code' => 'interal_error'
],
'type' => 'danger',
'message' => __( 'An error occurred while trying to delete comments. Internal error occured. Please try again later.', 'comments-plus' )
];
return $notices;
}
public function getStats() {
if ( WCM_Plugin::app()->isNetworkActive() ) {
$stats = $this->getMultisiteStats();
} else {
$stats = $this->getSiteStats();
}
return $stats;
}
public function getMultisiteStats() {
$stats = [];
foreach ( WCM_Plugin::app()->getActiveSites() as $site ) {
switch_to_blog( $site->blog_id );
$site_stats = $this->getSiteStats();
$stats = $this->mergeStats( $stats, $site_stats );
restore_current_blog();
}
return $stats;
}
public function mergeStats( $current_stats, $new_stats ) {
if ( ! isset( $current_stats['stat_data'] ) ) {
$current_stats['stat_data'] = $new_stats['stat_data'];
} else {
$comment_fields = [ 'total_comments', 'order_notes_count', 'spamcount', 'unpcount', 'trashcount' ];
foreach ( $comment_fields as $comment_field ) {
if ( is_null( $current_stats['stat_data'][0]->$comment_field ) ) {
$current_stats['stat_data'][0]->$comment_field = 0;
}
if ( is_null( $new_stats['stat_data'][0]->$comment_field ) ) {
$new_stats['stat_data'][0]->$comment_field = 0;
}
if ( $new_stats['stat_data'][0]->$comment_field ) {
$current_stats['stat_data'][0]->$comment_field = $current_stats['stat_data'][0]->$comment_field + $new_stats['stat_data'][0]->$comment_field;
}
}
}
if ( ! isset( $current_stats['post_types'] ) ) {
$current_stats['post_types'] = $new_stats['post_types'];
} else {
foreach ( $new_stats['post_types'] as $post_type_key => $post_type ) {
if ( array_key_exists( $post_type_key, $current_stats['post_types'] ) ) {
$current_stats['post_types'][ $post_type_key ]['comments_count'] += $new_stats['post_types'][ $post_type_key ]['comments_count'];
} else {
$current_stats['post_types'][ $post_type_key ] = $new_stats['post_types'][ $post_type_key ];
}
}
}
return $current_stats;
}
public function getSiteStats() {
global $wpdb;
$stat_data = $wpdb->get_results( "SELECT count(*) as total_comments,
SUM(comment_type='order_note') as order_notes_count,
SUM(comment_approved='spam') as spamcount,
SUM(comment_approved='0') as unpcount,
SUM(comment_approved='trash') as trashcount
FROM {$wpdb->prefix}comments" );
$stat_data_by_post_type = $wpdb->get_results( "SELECT
SUM(comment_count) as type_comments_count, post_type
FROM $wpdb->posts
GROUP BY post_type" );
$types = get_post_types( [ 'public' => true ], 'objects' );
$post_types = [];
foreach ( (array) $types as $type_name => $type ) {
$comments_count = 0;
if ( ! empty( $stat_data_by_post_type ) ) {
foreach ( (array) $stat_data_by_post_type as $post_type_stat_value ) {
if ( $post_type_stat_value->post_type == $type_name ) {
$comments_count = $post_type_stat_value->type_comments_count;
}
}
}
$post_types[ $type_name ] = [ 'label' => $type->label, 'comments_count' => $comments_count ];
}
return [
'stat_data' => $stat_data,
'post_types' => $post_types
];
}
/**
* Prints the content of the page
*
* @see libs\factory\pages\themplates\FactoryPages480_ImpressiveThemplate
*/
public function showPageContent() {
$stats = $this->getStats();
$stat_data = $stats['stat_data'];
$post_types = $stats['post_types'];
?>
<script>
/**
* Select all types by one click.
*/
jQuery(document).ready(function($) {
updateCommentsCounter();
var allTypesCheckbox = $('#wbcr-cmp-all-types-checkbox');
allTypesCheckbox.click(function() {
$('.wbcr-cmp-post-type-checkbox').prop("checked", $(this).prop("checked"));
updateCommentsCounter()
});
$('.wbcr-cmp-post-type-checkbox').click(function() {
if( !$(this).prop("checked") ) {
allTypesCheckbox.prop("checked", false);
}
updateCommentsCounter();
});
$('input[name="wbcr_cmp_delete_order_notes"]').click(function() {
updateCommentsCounter();
});
$('.wbcr-cmp-delete-comments-button').click(function() {
var confrimDelete = confirm('<?php _e( 'Are you sure you want to delete comments from the database without restoring?', 'comments-plus' ); ?>');
if( !confrimDelete ) {
return false;
}
$(this).submit();
});
function updateCommentsCounter() {
var commentsCount = 0;
$('.wbcr-cmp-post-type-checkbox:checked, input[name="wbcr_cmp_delete_order_notes"]:checked').each(function() {
commentsCount += $(this).data('comments-number');
});
$('.wbcr-cmp-delete-comments-button').val('<?php _e( 'Delete ', 'comments-plus' ) ?>(' + commentsCount + ')');
}
});
</script>
<div class="wbcr-factory-page-group-header" style="margin-top:0;">
<strong><?php _e( 'Comments clearing tools', 'comments-plus' ) ?></strong>
<p>
<?php _e( 'These functions can be useful for global disabling comments or bulk cleaning spam comments.', 'comments-plus' ) ?>
</p>
</div>
<form method="post" action="<?= $this->getActionUrl( 'delete-all-comments' ) ?>" style="padding: 20px;">
<h5><?php _e( 'Remove all comments', 'comments-plus' ); ?></h5>
<p><?php _e( 'You can delete all comments in your database with one click.', 'comments-plus' ); ?></p>
<p><strong><?php _e( 'Choose post types', 'comments-plus' ); ?></strong>
<div style="height:150px; width:400px; padding:10px 10px 0; background: #fff; border:1px solid #ccc; overflow-y: scroll; overflow-x:hidden;">
<p>
<label>
<input type="checkbox" id="wbcr-cmp-all-types-checkbox" name="wbcr_cmp_post_type[]" value="all" checked/> <?php _e( 'Select all', 'comments-plus' ); ?>
</label>
</p>
<?php foreach ( (array) $post_types as $key => $type ): ?>
<p>
<label>
<input type="checkbox" data-comments-number="<?= $type['comments_count'] ?>" class="wbcr-cmp-post-type-checkbox" name="wbcr_cmp_post_type[]" value="<?= esc_attr( $key ) ?>" checked/> <?= $type['label'] ?>
(<?= $type['comments_count'] ?>)
</label>
</p>
<?php endforeach; ?>
</div>
<?php if ( class_exists( 'WooCommerce' ) ):
?>
<p style="margin:15px 0 0">
<label>
<input type="checkbox" data-comments-number="<?= $stat_data[0]->order_notes_count ?>" name="wbcr_cmp_delete_order_notes" value="1"/> <?php printf( __( 'Delete Woocommerce order notices? (%d)', 'comments-plus' ), $stat_data[0]->order_notes_count ); ?>
</label>
</p>
<?php endif;
?>
<p style="margin-top:15px;">
<input type="submit" name="wbcr_cmp_delete_all" class="button button-default wbcr-cmp-delete-comments-button" value="<?php printf( __( 'Delete (%s)', 'comments-plus' ), $stat_data[0]->total_comments ); ?>">
</p>
<?php wp_nonce_field( $this->getResultId() . '_delete_all_comments' ) ?>
</form>
<div style="padding: 20px;">
<hr/>
<h5><?php _e( 'Remove spam comments', 'comments-plus' ); ?></h5>
<p><?php _e( 'You can remove only spam comments from the database with one click.', 'comments-plus' ); ?></p>
<a href="<?= wp_nonce_url( $this->getActionUrl( 'delete-spam-comments' ), $this->getResultId() . '_delete_spam_comments' ) ?>" class="button button-default wbcr-cmp-delete-comments-button">
<?php printf( __( 'Delete (%d)', 'comments-plus' ), $stat_data[0]->spamcount ); ?>
</a>
<hr/>
<h5><?php _e( 'Remove unapproved comments', 'comments-plus' ); ?></h5>
<p><?php _e( 'You can remove only unapproved comments from the database with one click.', 'comments-plus' ); ?></p>
<a href="<?= wp_nonce_url( $this->getActionUrl( 'delete-unaproved-comments' ), $this->getResultId() . '_delete_unaproved_comments' ) ?>" class="button button-default wbcr-cmp-delete-comments-button">
<?php printf( __( 'Delete (%d)', 'comments-plus' ), $stat_data[0]->unpcount ); ?>
</a>
<hr/>
<h5><?php _e( 'Remove trashed comments', 'comments-plus' ); ?></h5>
<p><?php _e( 'You can remove only trashed comments from the database with one click.', 'comments-plus' ); ?></p>
<a href="<?= wp_nonce_url( $this->getActionUrl( 'delete-trash-comments' ), $this->getResultId() . '_delete_trash_comments' ) ?>" class="button button-default wbcr-cmp-delete-comments-button">
<?php printf( __( 'Delete (%d)', 'comments-plus' ), $stat_data[0]->trashcount ); ?>
</a>
</div>
<?php
}
/**
* @return bool
*/
protected function deleteAllComments() {
global $wpdb;
$delete_order_notes = $this->request->post( 'wbcr_cmp_delete_order_notes', false, 'intval' );
if ( $wpdb->query( "TRUNCATE $wpdb->commentmeta" ) != false ) {
$delete_all_sql = "TRUNCATE $wpdb->comments";
if ( class_exists( 'WooCommerce' ) ) {
if ( ! $delete_order_notes ) {
$delete_all_sql = "DELETE FROM $wpdb->comments WHERE comment_type != 'order_note'";
}
}
if ( $wpdb->query( $delete_all_sql ) != false ) {
$wpdb->query( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0" );
$wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
$wpdb->query( "OPTIMIZE TABLE $wpdb->comments" );
return true;
}
}
return false;
}
/**
* @param string $post_type
*
* @return bool
*/
protected function deleteCommentsByPostType( $post_type = 'post' ) {
global $wpdb;
$delete_order_notes = $this->request->post( 'wbcr_cmp_delete_order_notes', false, 'intval' );
$wpdb->query( "DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '%s'" );
$delete_certain_sql = "DELETE comments FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '%s'";
if ( class_exists( 'WooCommerce' ) ) {
if ( ! $delete_order_notes ) {
$delete_certain_sql .= " and comment_type != 'order_note'";
}
}
$wpdb->query( $wpdb->prepare( $delete_certain_sql, $post_type ) );
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '%s'", $post_type ) );
return true;
}
/**
* @param $post_types
*
* @return bool
*/
protected function deleteCommentsByPostTypes( $post_types ) {
global $wpdb;
if ( empty( $post_types ) || ! is_array( $post_types ) ) {
return false;
}
foreach ( $post_types as $post_type ) {
$this->deleteCommentsByPostType( $post_type );
}
$wpdb->query( "OPTIMIZE TABLE $wpdb->commentmeta" );
$wpdb->query( "OPTIMIZE TABLE $wpdb->comments" );
return true;
}
/**
* This action deletes all comments from the database without restoring.
*/
public function deleteAllCommentsAction() {
check_admin_referer( $this->getResultId() . '_delete_all_comments' );
if ( isset( $_POST['wbcr_cmp_delete_all'] ) ) {
$post_types = $this->request->post( 'wbcr_cmp_post_type', [], true );
$result = false;
if ( empty( $post_types ) || in_array( 'all', $post_types ) ) {
if ( WCM_Plugin::app()->isNetworkActive() ) {
foreach ( WCM_Plugin::app()->getActiveSites() as $site ) {
switch_to_blog( $site->blog_id );
$result = $this->deleteAllComments();
restore_current_blog();
}
} else {
$result = $this->deleteAllComments();
}
} else {
if ( WCM_Plugin::app()->isNetworkActive() ) {
foreach ( WCM_Plugin::app()->getActiveSites() as $site ) {
switch_to_blog( $site->blog_id );
$result = $this->deleteCommentsByPostTypes( $post_types );
restore_current_blog();
}
} else {
$result = $this->deleteCommentsByPostTypes( $post_types );
}
}
if ( $result ) {
$this->redirectToAction( 'index', [
'wbcr_cmp_clear_comments' => '1'
] );
} else {
$this->redirectToAction( 'index', [
'wbcr_cmp_clear_comments_error' => '1',
'wbcr_cmp_code' => 'interal_error',
] );
}
}
$this->redirectToAction( 'index' );
}
/**
* The basic function of deleting comments.
*
* @param int|string $type
*/
public function deleteComments( $type = 0 ) {
if ( in_array( $type, [ 'spam', 'trash', 0 ] ) ) {
if ( WCM_Plugin::app()->isNetworkActive() ) {
foreach ( WCM_Plugin::app()->getActiveSites() as $site ) {
switch_to_blog( $site->blog_id );
$this->deleteCommentsByType( $type );
restore_current_blog();
}
} else {
$this->deleteCommentsByType( $type );
}
$this->redirectToAction( 'index', [
'wbcr_cmp_clear_comments' => '1'
] );
}
}
/**
* @param int $type
*
* @return false|int
*/
private function deleteCommentsByType( $type = 0 ) {
global $wpdb;
$wpdb->query( "DELETE cmeta
FROM $wpdb->commentmeta cmeta
INNER JOIN {$wpdb->comments} comments ON cmeta.comment_id=comments.comment_ID
WHERE comment_approved='{$type}'" );
$res = $wpdb->query( "DELETE FROM {$wpdb->comments} WHERE comment_approved='{$type}'" );
if ( $res ) {
$wpdb->query( "OPTIMIZE TABLE {$wpdb->comments}" );
$wpdb->query( "OPTIMIZE TABLE {$wpdb->commentmeta}" );
}
return $res;
}
/**
* This action deletes spam comments
*/
public function deleteSpamCommentsAction() {
check_admin_referer( $this->getResultId() . '_delete_spam_comments' );
$this->deleteComments( 'spam' );
}
/**
* This action deletes unaproved comments
*/
public function deleteUnaprovedCommentsAction() {
check_admin_referer( $this->getResultId() . '_delete_unaproved_comments' );
$this->deleteComments();
}
/**
* This action deletes trash comments
*/
public function deleteTrashCommentsAction() {
check_admin_referer( $this->getResultId() . '_delete_trash_comments' );
$this->deleteComments( 'trash' );
}
}

View File

@@ -0,0 +1,24 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Рекламная страница.
*
* Используется для рекламы плагина Clearfy. Пользователь может изучить все возможности плагина Clearfy
* и перейти на лендинг плагина, чтобы скачать и попробовать его.
*
* Может быть использована только, если этот плагин используется как отдельный плагин, а не как аддон
* для плагина Clearfy. Если плагин загружен, как аддон для Clearfy, эта страница не будет подключена.
*
* НЕ поддерживает режим работы с мультисаймами!
*
* @author Alex Kovalev <alex.kovalevv@gmail.com>, Github: https://github.com/alexkovalevv
*
* @copyright (c) 2018 Webraftic Ltd
*/
class WbcrCmp_MoreFeaturesPage extends \WBCR\Factory_Templates_134\Pages\MoreFeatures {
}

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.