From 23cb97cf6c5c4121b26505bae410ef2f098c073f Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Tue, 7 Nov 2017 16:24:43 +0200 Subject: [PATCH] - UM Woocommerce compatibility; - make "Shop" page restricted; --- includes/admin/core/class-admin-metabox.php | 9 +++++++-- includes/admin/core/um-admin-filters-fields.php | 12 ++++++++++++ includes/core/class-access.php | 3 +-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index c385ea17..1374d1f7 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -103,8 +103,13 @@ if ( ! class_exists( 'Admin_Metabox' ) ) { //restrict content metabox $post_types = um_get_option( 'restricted_access_post_metabox' ); if ( ! empty( $post_types[ $current_screen->id ] ) ) { - add_action( 'add_meta_boxes', array(&$this, 'add_metabox_restrict_content'), 1 ); - add_action( 'save_post', array( &$this, 'save_metabox_restrict_content' ), 10, 2 ); + + $hide_metabox = apply_filters( 'um_restrict_content_hide_metabox', false ); + + if ( ! $hide_metabox ) { + add_action( 'add_meta_boxes', array(&$this, 'add_metabox_restrict_content'), 1 ); + add_action( 'save_post', array( &$this, 'save_metabox_restrict_content' ), 10, 2 ); + } if ( $current_screen->id == 'attachment' ) { add_action( 'add_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 ); diff --git a/includes/admin/core/um-admin-filters-fields.php b/includes/admin/core/um-admin-filters-fields.php index 8b625c0d..c8b553cf 100644 --- a/includes/admin/core/um-admin-filters-fields.php +++ b/includes/admin/core/um-admin-filters-fields.php @@ -131,3 +131,15 @@ return $break; } + + + + add_filter( 'um_restrict_content_hide_metabox', 'um_hide_metabox_restrict_content_shop', 10, 1 ); + function um_hide_metabox_restrict_content_shop( $hide ) { + if ( function_exists( 'wc_get_page_id' ) && ! empty( $_GET['post'] ) && + $_GET['post'] == wc_get_page_id( 'shop' ) ) { + return true; + } + + return $hide; + } diff --git a/includes/core/class-access.php b/includes/core/class-access.php index e03793b6..9f97d8ff 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -203,7 +203,7 @@ if ( ! class_exists( 'Access' ) ) { * @return array */ function filter_protected_posts( $posts, $query ) { - $filtered_posts = array(); + $filtered_posts = array(); //if empty if ( empty( $posts ) ) @@ -213,7 +213,6 @@ if ( ! class_exists( 'Access' ) ) { //other filter foreach ( $posts as $post ) { - $restriction = $this->get_post_privacy_settings( $post ); if ( ! $restriction ) { $filtered_posts[] = $post;