Skip to content

Commit

Permalink
release: small fixes
Browse files Browse the repository at this point in the history
- Feat: Allow affiliate url change via DB option.
- Fix: Featured plugins displaying on some non-pro products.
  • Loading branch information
preda-bogdan authored Jun 25, 2024
2 parents 24d9c93 + 061916f commit fa0b207
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
21 changes: 21 additions & 0 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function tsdk_utmify( $url, $area, $location = null ) {
$current_page = sanitize_key( str_replace( '.php', '', $current_page ) );
}
$location = $location === null ? $current_page : $location;
$is_upgrade_url = strpos( $url, '/upgrade' ) !== false;
$content = sanitize_key(
trim(
str_replace(
Expand Down Expand Up @@ -122,6 +123,26 @@ function tsdk_utmify( $url, $area, $location = null ) {
)
);

/**
* Check if there is an affiliate URL for this upgrade link, if so use it.
*/
if ( $is_upgrade_url ) {
$option_content_key = str_replace( '-', '_', $filter_key );
$theme_upgrade_option_name = 'themeisle_af_' . $option_content_key . '_themes_upgrade';
$plugin_upgrade_option_name = 'themeisle_af_' . $option_content_key . '_plugins_upgrade';

$theme_option_url = get_option( $theme_upgrade_option_name, false );
if ( ! empty( $theme_option_url ) ) {
$utmify_url = esc_url_raw( $theme_option_url );
}
$plugin_option_url = get_option( $plugin_upgrade_option_name, false );
if ( ! empty( $plugin_option_url ) ) {
$utmify_url = esc_url_raw( $plugin_option_url );
}
}



return apply_filters( 'tsdk_utmify_url_' . $filter_key, $utmify_url, $url );
}

Expand Down
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
14 changes: 12 additions & 2 deletions tests/utmify-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function ( $arguments, $url ) {
return $arguments;
},
11,
2
2
);
}

Expand All @@ -33,10 +33,14 @@ function ( $utmify_url, $url ) {
return self::AFFILIATE_URL;
},
11,
2
2
);
}

private function set_plugin_upgrade_option( $filter_key, $url ) {
update_option( 'themeisle_af_' . $filter_key . '_plugins_upgrade', $url );
}


public function test_utmify_plugin() {

Expand All @@ -61,6 +65,12 @@ public function test_utmify_plugin() {

$this->assertEquals( self::AFFILIATE_URL, $link );

$this->set_plugin_upgrade_option( 'sample_plugin', self::AFFILIATE_URL );

$link = tsdk_utmify( 'https://themeisle.com/plugins/sample-plugin/upgrade', 'area', 'location' );

$this->assertEquals( self::AFFILIATE_URL, $link );

}

}

0 comments on commit fa0b207

Please sign in to comment.