Option to disable reviews globally

This commit is contained in:
Mike Jolley 2017-06-08 15:26:30 +01:00
parent b4040b1335
commit 5ee38c54c2
10 changed files with 89 additions and 42 deletions

View File

@ -273,6 +273,15 @@ jQuery( function ( $ ) {
}
}).change();
// Revies.
$( 'input#woocommerce_enable_reviews' ).change(function() {
if ( $( this ).is( ':checked' ) ) {
$( '#woocommerce_enable_review_rating' ).closest( 'tr' ).show();
} else {
$( '#woocommerce_enable_review_rating' ).closest( 'tr' ).hide();
}
}).change();
// Attribute term table
$( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' );

File diff suppressed because one or more lines are too long

View File

@ -33,7 +33,7 @@ class WC_Admin_Dashboard {
* Init dashboard widgets.
*/
public function init() {
if ( current_user_can( 'publish_shop_orders' ) ) {
if ( current_user_can( 'publish_shop_orders' ) && post_type_supports( 'product', 'comments' ) ) {
wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce recent reviews', 'woocommerce' ), array( $this, 'recent_reviews' ) );
}
wp_add_dashboard_widget( 'woocommerce_dashboard_status', __( 'WooCommerce status', 'woocommerce' ), array( $this, 'status_widget' ) );

View File

@ -168,9 +168,8 @@ class WC_Admin_Meta_Boxes {
global $post;
// Comments/Reviews
if ( isset( $post ) && ( 'publish' == $post->post_status || 'private' == $post->post_status ) ) {
if ( isset( $post ) && ( 'publish' == $post->post_status || 'private' == $post->post_status ) && post_type_supports( 'product', 'comments' ) ) {
remove_meta_box( 'commentsdiv', 'product', 'normal' );
add_meta_box( 'commentsdiv', __( 'Reviews', 'woocommerce' ), 'post_comment_meta_box', 'product', 'normal' );
}
}

View File

@ -33,17 +33,19 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
</div>
<div class="options_group reviews">
<?php
woocommerce_wp_checkbox( array(
'id' => '_reviews_allowed',
'value' => $product_object->get_reviews_allowed( 'edit' ) ? 'open' : 'closed',
'label' => __( 'Enable reviews', 'woocommerce' ),
'cbvalue' => 'open',
) );
do_action( 'woocommerce_product_options_reviews' );
?>
</div>
<?php if ( post_type_supports( 'product', 'comments' ) ) : ?>
<div class="options_group reviews">
<?php
woocommerce_wp_checkbox( array(
'id' => '_reviews_allowed',
'value' => $product_object->get_reviews_allowed( 'edit' ) ? 'open' : 'closed',
'label' => __( 'Enable reviews', 'woocommerce' ),
'cbvalue' => 'open',
) );
do_action( 'woocommerce_product_options_reviews' );
?>
</div>
<?php endif; ?>
<?php do_action( 'woocommerce_product_options_advanced' ); ?>
</div>

View File

@ -466,6 +466,36 @@ class WC_Settings_Products extends WC_Settings_Page {
'id' => 'product_rating_options',
),
array(
'title' => __( 'Enable reviews', 'woocommerce' ),
'desc' => __( 'Enable product reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_reviews',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),
array(
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_label',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'title' => __( 'Product ratings', 'woocommerce' ),
'desc' => __( 'Enable star rating on reviews', 'woocommerce' ),
@ -486,27 +516,6 @@ class WC_Settings_Products extends WC_Settings_Page {
'autoload' => false,
),
array(
'title' => __( 'Verified owners', 'woocommerce' ),
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_label',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'product_rating_options',

View File

@ -22,6 +22,7 @@ class WC_Comments {
*/
public static function init() {
// Rating posts
add_filter( 'comments_open', array( __CLASS__, 'comments_open' ), 10, 2 );
add_filter( 'preprocess_comment', array( __CLASS__, 'check_comment_rating' ), 0 );
add_action( 'comment_post', array( __CLASS__, 'add_comment_rating' ), 1 );
add_action( 'comment_moderation_recipients', array( __CLASS__, 'comment_moderation_recipients' ), 10, 2 );
@ -53,6 +54,21 @@ class WC_Comments {
add_action( 'comment_post', array( __CLASS__, 'add_comment_purchase_verification' ) );
}
/**
* See if comments are open.
*
* @since 3.1.0
* @param bool $open
* @param int $post_id
* @return bool
*/
public static function comments_open( $open, $post_id ) {
if ( 'product' === get_post_type( $post_id ) && ! post_type_supports( 'product', 'comments' ) ) {
$open = false;
}
return $open;
}
/**
* Exclude order comments from queries and RSS.
*

View File

@ -249,6 +249,11 @@ class WC_Post_types {
do_action( 'woocommerce_register_post_type' );
$permalinks = wc_get_permalink_structure();
$supports = array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'publicize', 'wpcom-markdown' );
if ( 'yes' === get_option( 'woocommerce_enable_reviews', 'yes' ) ) {
$supports[] = 'comments';
}
register_post_type( 'product',
apply_filters( 'woocommerce_register_post_type_product',
@ -289,7 +294,7 @@ class WC_Post_types {
'hierarchical' => false, // Hierarchical causes memory issues - WP loads all records!
'rewrite' => $permalinks['product_rewrite_slug'] ? array( 'slug' => $permalinks['product_rewrite_slug'], 'with_front' => false, 'feeds' => true ) : false,
'query_var' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', 'publicize', 'wpcom-markdown' ),
'supports' => $supports,
'has_archive' => ( $shop_page_id = wc_get_page_id( 'shop' ) ) && get_post( $shop_page_id ) ? urldecode( get_page_uri( $shop_page_id ) ) : 'shop',
'show_in_nav_menus' => true,
'show_in_rest' => true,

View File

@ -909,7 +909,9 @@ if ( ! function_exists( 'woocommerce_template_single_rating' ) ) {
* @subpackage Product
*/
function woocommerce_template_single_rating() {
wc_get_template( 'single-product/rating.php' );
if ( post_type_supports( 'product', 'comments' ) ) {
wc_get_template( 'single-product/rating.php' );
}
}
}
if ( ! function_exists( 'woocommerce_template_single_price' ) ) {
@ -1251,7 +1253,9 @@ if ( ! function_exists( 'woocommerce_review_display_rating' ) ) {
* @return void
*/
function woocommerce_review_display_rating() {
wc_get_template( 'single-product/review-rating.php' );
if ( post_type_supports( 'product', 'comments' ) ) {
wc_get_template( 'single-product/review-rating.php' );
}
}
}

View File

@ -43,9 +43,12 @@ function wc_register_widgets() {
register_widget( 'WC_Widget_Product_Search' );
register_widget( 'WC_Widget_Product_Tag_Cloud' );
register_widget( 'WC_Widget_Products' );
register_widget( 'WC_Widget_Rating_Filter' );
register_widget( 'WC_Widget_Recent_Reviews' );
register_widget( 'WC_Widget_Recently_Viewed' );
register_widget( 'WC_Widget_Top_Rated_Products' );
if ( post_type_supports( 'product', 'comments' ) ) {
register_widget( 'WC_Widget_Top_Rated_Products' );
register_widget( 'WC_Widget_Recent_Reviews' );
register_widget( 'WC_Widget_Rating_Filter' );
}
}
add_action( 'widgets_init', 'wc_register_widgets' );