-
Notifications
You must be signed in to change notification settings - Fork 0
/
hide-reviews-for-woocommerce.php
108 lines (84 loc) · 3.28 KB
/
hide-reviews-for-woocommerce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
Plugin Name: Hide Reviews for WooCommerce
Plugin URI: http://sfndesign.ca/
Description: Hides all reviews in WooCommerce if you choose not to use the stars as ratings
Version: 1.0
Author: SFNdesign, Curtis McHale
Author URI: http://sfndesign.ca
License: GPLv2 or later
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Hide_Reviews_For_Woocommerce{
function __construct(){
add_action( 'widgets_init', array( $this, 'kill_wc_ratings_widgets' ), 11 );
add_filter( 'woocommerce_product_tabs', array( $this, 'kill_wc_reviews_tab' ), 98 );
add_action( 'admin_notices', array( $this, 'check_required_plugins' ) );
} // construct
/**
* Removes WC widgets we do not want
*
* @since 1.0
* @author SFNdesign, Curtis McHale
*
* @uses get_option() Gets option from the wp_options table give string
* @uses unregister_widget() Unregisters the named widget
*/
public function kill_wc_ratings_widgets(){
$review_setting = get_option( 'woocommerce_enable_review_rating' );
if ( 'no' === $review_setting ){
unregister_widget( 'WC_Widget_Top_Rated_Products' );
unregister_widget( 'WC_Widget_Recent_Reviews' );
}
} // kill_wc_ratings_widgets
/**
* Removes the WooCommerce Reviews
*
* @since 1.0
* @author SFNdesign, Curtis McHale
*
* @param array $tabs required The tabs array
* @uses get_option() Gets option from the wp_options table give string
* @return array $tabs Our modified tabs array
*/
public function kill_wc_reviews_tab( $tabs ){
$review_setting = get_option( 'woocommerce_enable_review_rating' );
if ( 'no' === $review_setting ){
unset( $tabs['reviews'] );
}
return $tabs;
} // kill_wc_reviews_tab
/**
* Checks for WooCommerce and GF and kills our plugin if they aren't both active
*
* @uses function_exists Checks for the function given string
* @uses deactivate_plugins Deactivates plugins given string or array of plugins
*
* @action admin_notices Provides WordPress admin notices
*
* @since 1.0
* @author SFNdesign, Curtis McHale
*/
public function check_required_plugins(){
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ){ ?>
<div id="message" class="error">
<p>Hide Reviews for WooCommerce expects WooCommerce to be active. This plugin has been deactivated.</p>
</div>
<?php
deactivate_plugins( '/hide-reviews-for-woocommerce/hide-reviews-for-woocommerce.php' );
} // if woocommerce
} // check_required_plugins
} // Hide_Reviews_For_Woocommerce
$GLOBALS['hiderevwc'] = new Hide_Reviews_For_Woocommerce();