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

Hide Subscription feature if plugin not activated #56

Merged
merged 4 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions includes/classes/Feature/ElasticPressLabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function output_feature_box_settings() {
$settings = wp_parse_args( $settings, $this->default_settings );

foreach ( $this->subfeatures as $subfeature ) {
if ( ! $subfeature->is_available && ! $subfeature->is_active ) {
continue;
}

$this->subfeature_field(
$subfeature->slug,
$subfeature->title,
Expand Down Expand Up @@ -189,9 +193,11 @@ private function register_subfeatures() {

$this->add_to_subfeatures(
array(
'slug' => $subfeature->slug,
'title' => $subfeature->title,
'description' => $description,
'slug' => $subfeature->slug,
'title' => $subfeature->title,
'description' => $description,
'is_available' => method_exists( $subfeature, 'is_available' ) ? $subfeature->is_available() : true,
'is_active' => $subfeature->is_active(),
)
);

Expand Down
15 changes: 14 additions & 1 deletion includes/classes/Feature/WooCommerceSubscriptionSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ public function requirements_status() {

$woocommerce_feature = \ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' );
$protected_content_feature = \ElasticPress\Features::factory()->get_registered_feature( 'protected_content' );
if ( ! $woocommerce_feature->is_active() || ! $protected_content_feature->is_active() ) {

if ( ! $this->is_subscription_plugin_activated() ) {
$status->code = 2;
$status->message = esc_html__( 'This feature requires the WooCommerce Subscriptions plugin to be activated.', 'elasticpress-labs' );
} elseif ( ! $woocommerce_feature->is_active() || ! $protected_content_feature->is_active() ) {
$status->code = 2;
$status->message = esc_html__( 'This feature requires the WooCommerce and Protected Content features to be enabled.', 'elasticpress-labs' );
} else {
Expand All @@ -143,4 +147,13 @@ public function requirements_status() {

return $status;
}

/**
* Check if WooCommerce Subscriptions plugin is activated.
*
* @return bool
*/
public function is_subscription_plugin_activated() : bool {
return is_plugin_active( 'woocommerce-subscriptions/woocommerce-subscriptions.php' ) && class_exists( '\WC_Subscriptions' );
}
}