Skip to content

Commit d475108

Browse files
v0.5.3 (#67)
1 parent f09808c commit d475108

File tree

10 files changed

+279
-71
lines changed

10 files changed

+279
-71
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
### Changelog
22

3+
#### 0.5.3
4+
- Fix `typeof` typo in `disable-blog-customizer.js` from 0.5.2 updates for #59.
5+
- Fix uninstall error to allow for the plugin to be deleted correctly.
6+
- Only fire comment related admin functions if comments are supported.
7+
- Limit the `get_comment_count` function to query only post types supporting comments. This allows for the post types to be modified via the `dwpb_post_types_supporting_comments` filter and avoids large queries on post types that aren't relevant (e.g. shop_order in WooCommerce). Closes #65
8+
- Add caching to the `dwpb_post_types_with_feature` function.
9+
- Create a plugin integration framework - simple class with "plugin active" checks and related integration functions, including the preexisting WooCommerce (version <= 2.6.2) comment count integration.
10+
- Add a Disable Comments integration, utilizing the `dwpb_post_types_supporting_comments` to turn off all Disable Blog comment-related functions if Disable Comments is active.
11+
312
#### 0.5.2
413
- Test up to WP 6.1.1
514
- Increase minimum PHP to v7.4

assets/js/disable-blog-customizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
wp.customize.bind( 'ready', function() {
55

66
// Replace the default text in the homepage settings with the new version.
7-
if ( typeof dwpbCustomizer.homepageSettingsText !== 'undefined' && wp.customize.section("static_front_page") !== 'undefined' ) {
7+
if ( typeof dwpbCustomizer.homepageSettingsText !== 'undefined' && typeof wp.customize.section("static_front_page") !== 'undefined' ) {
88
wp.customize.section("static_front_page").container.find(".customize-section-description")[0].innerText = dwpbCustomizer.homepageSettingsText;
99
} // end if
1010

disable-blog.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
* Plugin Name: Disable Blog
1616
* Plugin URI: https://wordpress.org/plugins/disable-blog/
1717
* Description: Go blog-less with WordPress. This plugin disables all blog-related functionality (by hiding, removing, and redirecting).
18-
* Version: 0.5.2
19-
* Author: Joshua Nelson
18+
* Version: 0.5.3
19+
* Author: Joshua David Nelson
2020
* Author URI: http://joshuadnelson.com
2121
* License: GPL-2.0+
2222
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@@ -59,7 +59,7 @@ function deactivate_disable_blog() {
5959
define( 'DWPB_DIR', dirname( __FILE__ ) );
6060
define( 'DWPB_URL', plugins_url( '/', __FILE__ ) );
6161
define( 'DWPB_PLUGIN_NAME', 'disable-blog' );
62-
define( 'DWPB_VERSION', '0.5.2' );
62+
define( 'DWPB_VERSION', '0.5.3' );
6363

6464
/**
6565
* The core plugin class that is used to define everything.

includes/class-disable-blog-admin.php

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ public function enqueue_scripts() {
852852
*
853853
* @since 0.4.8
854854
* @param string $page the page slug.
855-
* @return boolean
855+
* @return bool
856856
*/
857857
public function is_admin_page( $page ) {
858858

@@ -899,27 +899,6 @@ public function filter_wp_count_comments( $comments, $post_id ) {
899899

900900
}
901901

902-
/**
903-
* Turn the comments object back into an array if WooCommerce is active.
904-
*
905-
* This is only necessary for version of WooCommerce prior to 2.6.3, where it failed
906-
* to check/convert the $comment object into an array.
907-
*
908-
* @since 0.4.3
909-
* @param object $comments the array of comments.
910-
* @param int $post_id the post id.
911-
* @return array
912-
*/
913-
public function filter_woocommerce_comment_count( $comments, $post_id ) {
914-
915-
if ( 0 === $post_id && class_exists( 'WC_Comments' ) && function_exists( 'WC' ) && version_compare( WC()->version, '2.6.2', '<=' ) ) {
916-
$comments = (array) $comments;
917-
}
918-
919-
return $comments;
920-
921-
}
922-
923902
/**
924903
* Alter the comment counts on the admin comment table to remove comments associated with posts.
925904
*
@@ -951,25 +930,14 @@ public function filter_admin_table_comment_count( $views ) {
951930
* @since 0.4.0
952931
* @since 0.4.3 Removed Unused "count" function.
953932
* @see get_comment_count()
933+
* @see https://developer.wordpress.org/reference/functions/esc_sql/
954934
* @return array
955935
*/
956936
public function get_comment_counts() {
957937

958938
global $wpdb;
959939

960-
// Grab the comments that are not associated with 'post' post_type.
961-
$totals = (array) $wpdb->get_results(
962-
"SELECT comment_approved, COUNT( * ) AS total
963-
FROM {$wpdb->comments}
964-
WHERE comment_post_ID in (
965-
SELECT ID
966-
FROM {$wpdb->posts}
967-
WHERE post_type != 'post'
968-
AND post_status = 'publish')
969-
GROUP BY comment_approved",
970-
ARRAY_A
971-
);
972-
940+
// Set up the counts, we'll be adding to this array.
973941
$comment_count = array(
974942
'moderated' => 0,
975943
'approved' => 0,
@@ -981,6 +949,35 @@ public function get_comment_counts() {
981949
'all' => 0,
982950
);
983951

952+
// Get the post types that support comments.
953+
$supported_post_types = dwpb_post_types_with_feature( 'comments' );
954+
955+
// Return an array of empty counts if there are no post types that support comments.
956+
if ( empty( $supported_post_types ) || ! is_array( $supported_post_types ) ) {
957+
return $comment_count;
958+
}
959+
960+
// Sanitizing the post type strings.
961+
$sanitized_post_types = (array) array_map( 'esc_sql', $supported_post_types );
962+
963+
// Implode the post types into a string for the query.
964+
$in_post_types = implode( "','", $sanitized_post_types );
965+
966+
// Grab the comments that are associated with supported post types only.
967+
// @codingStandardsIgnoreStart -- The get_results function doesn't need a wpdb->prepare here because $in_post_types is sanitized above.
968+
$totals = (array) $wpdb->get_results(
969+
"SELECT comment_approved, COUNT( * ) AS total
970+
FROM {$wpdb->comments}
971+
WHERE comment_post_ID in (
972+
SELECT ID
973+
FROM {$wpdb->posts}
974+
WHERE post_type in ('{$in_post_types}')
975+
AND post_status = 'publish')
976+
GROUP BY comment_approved",
977+
ARRAY_A
978+
);
979+
// @codingStandardsIgnoreEnd
980+
984981
foreach ( $totals as $row ) {
985982
switch ( $row['comment_approved'] ) {
986983
case 'trash':
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
/**
3+
* Integrations with other plugins.
4+
*
5+
* @link https://github.com/joshuadavidnelson/disable-blog
6+
* @since 0.5.3
7+
* @package Disable_Blog
8+
* @subpackage Disable_Blog_Integrations
9+
*/
10+
11+
/**
12+
* Integrations with other plugins.
13+
*
14+
* @since 0.5.3
15+
*/
16+
class Disable_Blog_Integrations {
17+
18+
/**
19+
* The ID of this plugin.
20+
*
21+
* @since 0.5.3
22+
* @access private
23+
* @var string $plugin_name The ID of this plugin.
24+
*/
25+
private $plugin_name;
26+
27+
/**
28+
* The version of this plugin.
29+
*
30+
* @since 0.5.3
31+
* @access private
32+
* @var string $version The current version of this plugin.
33+
*/
34+
private $version;
35+
36+
/**
37+
* Initialize the class and set its properties.
38+
*
39+
* @since 0.5.3
40+
* @param string $plugin_name The name of the plugin.
41+
* @param string $version The version of this plugin.
42+
*/
43+
public function __construct( $plugin_name, $version ) {
44+
45+
$this->plugin_name = $plugin_name;
46+
$this->version = $version;
47+
48+
}
49+
50+
/**
51+
* Check if the plugin is active.
52+
*
53+
* A wrapper function of is_plugin_active to call wp-admin/includes/plugin.php as needed.
54+
*
55+
* @since 0.5.3
56+
* @see https://developer.wordpress.org/reference/functions/is_plugin_active/
57+
* @param string $plugin the plugin path.
58+
* @return bool
59+
*/
60+
public function is_plugin_active( $plugin ) {
61+
62+
// Check if the is_plugin_active function is available.
63+
if ( ! function_exists( 'is_plugin_active' ) ) {
64+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
65+
}
66+
67+
// Check if the the plugin is active.
68+
if ( is_plugin_active( $plugin ) ) {
69+
return true;
70+
}
71+
72+
return false;
73+
74+
}
75+
76+
/**
77+
* Check if the Disable Comments plugin is active.
78+
*
79+
* @since 0.5.3
80+
* @return bool
81+
*/
82+
public function is_disable_comments_active() {
83+
84+
// Check if the Disable Comments plugin is active.
85+
if ( $this->is_plugin_active( 'disable-comments/disable-comments.php' ) || class_exists( 'Disable_Comments' ) ) {
86+
return true;
87+
}
88+
89+
return false;
90+
91+
}
92+
93+
/**
94+
* Check if WooCommerce is active.
95+
*
96+
* @since 0.5.3
97+
* @return bool
98+
*/
99+
public function is_woocommerce_active() {
100+
101+
// Check if the Disable Comments plugin is active.
102+
if ( $this->is_plugin_active( 'woocommerce/woocommerce.php' ) || function_exists( 'WC' ) ) {
103+
return true;
104+
}
105+
106+
return false;
107+
108+
}
109+
110+
/**
111+
* Turn the comments object back into an array if WooCommerce is active.
112+
*
113+
* This is only necessary for version of WooCommerce prior to 2.6.3, where it failed
114+
* to check/convert the $comment object into an array.
115+
*
116+
* @since 0.4.3
117+
* @since 0.5.3 Moved to the Disable_Blog_Integrations class.
118+
* @param object $comments the array of comments.
119+
* @param int $post_id the post id.
120+
* @return array
121+
*/
122+
public function filter_woocommerce_comment_count( $comments, $post_id ) {
123+
124+
if ( 0 === $post_id && function_exists( 'WC' ) && version_compare( WC()->version, '2.6.2', '<=' ) ) {
125+
$comments = (array) $comments;
126+
}
127+
128+
return $comments;
129+
130+
}
131+
132+
}

0 commit comments

Comments
 (0)