Skip to content

Commit

Permalink
Merge pull request #237 from Codeinwp/fix/featured_plugins
Browse files Browse the repository at this point in the history
fix: featured available on in some free plugins
  • Loading branch information
preda-bogdan authored Jun 25, 2024
2 parents 47e67d9 + 9bc0688 commit 061916f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Modules/Featured_plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public function can_load( $product ) {
return false;
}

$slug = $product->get_slug();
// only load for products that contain "pro" in the slug.
if ( strpos( $slug, 'pro' ) === false ) {
if ( $product->is_wordpress_available() ) {
return false;
}

Expand Down
31 changes: 31 additions & 0 deletions tests/featured-plugins-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,32 @@ public static function wpTearDownAfterClass() {
self::delete_user( self::$admin_id );
}

/**
* Utility method to change the value of a protected property.
*
* @param \ThemeisleSDK\Product $object The object.
* @param string $property The property name.
* @param mixed $new_value The new value.
*
* @return void
* @throws ReflectionException Throws an exception if the property does not exist.
*/
private function set_protected_property( $object, $property, $new_value ) {
$reflection = new ReflectionClass( $object );
$property = $reflection->getProperty( $property );
$property->setAccessible( true );
$property->setValue( $object, $new_value );
}

/**
* Test plugin not loading without config.
*/
public function test_plugin_not_loading_if_not_pro() {
$plugin = dirname( __FILE__ ) . '/sample_products/sample_plugin/plugin_file.php';
$plugin_product = new \ThemeisleSDK\Product( $plugin );

$this->set_protected_property( $plugin_product, 'wordpress_available', true );

$this->assertFalse( ( new \ThemeisleSDK\Modules\Featured_Plugins() )->can_load( $plugin_product ) );
}

Expand All @@ -117,6 +136,18 @@ public function test_plugin_loading_for_pro() {
$this->assertTrue( ( new \ThemeisleSDK\Modules\Featured_Plugins() )->can_load( $plugin_product ) );
}

/**
* Test plugin not loading for slugs that contain pro as part of a word. Eg. Product.
*/
public function test_plugin_loading_for_words_w_pro() {
$plugin = dirname( __FILE__ ) . '/sample_products/sample_pro_plugin/plugin_file.php';
$plugin_product = new \ThemeisleSDK\Product( $plugin );

$this->set_protected_property( $plugin_product, 'wordpress_available', true );

$this->assertFalse( ( new \ThemeisleSDK\Modules\Featured_Plugins() )->can_load( $plugin_product ) );
}

/**
* Test plugin not loading for pro if disabled.
*/
Expand Down

0 comments on commit 061916f

Please sign in to comment.