Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle inactive woocommerce #1437

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions includes/plugins/class-woocommerce-memberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public static function filter_lists( $lists ) {
if ( ! is_array( $lists ) || empty( $lists ) ) {
return $lists;
}
if ( ! function_exists( 'wc_memberships_is_post_content_restricted' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so apparently this happens if woo memberships is active but woocommerce is not.

I think it's best to fix the check on the init method, that checks class_exists( 'WC_Memberships_Loader' ). If Woo and/or Woo memberships is not active, the hooks should not even be initalized

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added in acacf58

return $lists;
}
$lists = array_filter(
$lists,
function ( $list ) {
Expand All @@ -87,15 +90,15 @@ function ( $list ) {
return false;
}

$is_post_restricted = wc_memberships_is_post_content_restricted( $list_object->get_id() );
$is_post_restricted = \wc_memberships_is_post_content_restricted( $list_object->get_id() );

if ( ! $is_post_restricted ) {
return true;
}

$user_id = self::$user_id_in_scope ?? get_current_user_id();

return wc_memberships_user_can( $user_id, 'view', [ 'post' => $list_object->get_id() ] );
return \wc_memberships_user_can( $user_id, 'view', [ 'post' => $list_object->get_id() ] );
}
);
return array_values( $lists );
Expand Down