Code Monkey home page Code Monkey logo

freemius-php-sdk's People

Contributors

fajardoleo avatar mte90 avatar vovafeldman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

freemius-php-sdk's Issues

Notice: Undefined property: Freemius_Api::$_sandbox

๐Ÿž bug report

Behavior:
I tried some scheduled tasks via wp-cli, and the following notice appeared
Notice: Undefined property: Freemius_Api::$_sandbox in /path/to/freemius/php-sdk/freemius/Freemius.php on line 69

Affected line
https://github.com/Freemius/freemius-php-sdk/blob/master/freemius/Freemius.php#L69

Cause
The affected line contains the following code:
return ($this->_sandbox ? FS_API__SANDBOX_ADDRESS : FS_API__ADDRESS) . $pCanonizedPath;

Property $this->_sandbox is not declared as part of the Freemius_Api class, it's a dynamic property. Due to that, it doesn't exist until something sets its value:

// This throws a notice
echo $this->_sandbox; 
// This creates and initialises the property
$this->_sandbox = 'value';
// This works as expected
echo $this->_sandbox;

Solution
Declaring the Freemius_Api::$_sandbox property will fix the issue. This will become necessary anyway, because dynamic properties will be deprecated in PHP 8.2 and completely removed in PHP 9.0
lob/84a9be4717effd7697a217e0d931f48ae0d2ecc6/config.php#L160

Versions: (*)

  • Freemius PHP SDK Version: dev-master, from Packagist.
  • WordPress Version: 5.8
  • PHP Version: 7.4.x or newer.

Conflict if used in a WordPress site where another plugin has activated freemius wordpress sdk

If used in a wordpress site that has active plugins that use freemius wordpress-sdk there is a conflict

[17-Jan-2020 14:11:11 UTC] PHP Fatal error: Cannot make non static method Freemius_Api_Base::Test() static in class Freemius_Api_WordPress in /home/badlywi
red/public_html/wp-content/plugins/fullworks-anti-spam-pro/includes/vendor/freemius/wordpress-sdk/includes/sdk/FreemiusWordPress.php on line 704
[17-Jan-2020 14:11:11 UTC] PHP Stack trace:
[17-Jan-2020 14:11:11 UTC] PHP 1. {main}() /home/mydomain/public_html/wp-admin/plugins.php:0
[17-Jan-2020 14:11:11 UTC] PHP 2. require_once() /home/mydomain/public_html/wp-admin/plugins.php:10
[17-Jan-2020 14:11:11 UTC] PHP 3. do_action() /home/mydomain/public_html/wp-admin/admin.php:367
[17-Jan-2020 14:11:11 UTC] PHP 4. WP_Hook->do_action() /home/mydomain/public_html/wp-includes/plugin.php:478
[17-Jan-2020 14:11:11 UTC] PHP 5. WP_Hook->apply_filters() /home/mydomain/public_html/wp-includes/class-wp-hook.php:312
[17-Jan-2020 14:11:11 UTC] PHP 6. wp_update_plugins() /home/mydomain/public_html/wp-includes/class-wp-hook.php:288
[17-Jan-2020 14:11:11 UTC] PHP 7. set_site_transient() /home/mydomain/public_html/wp-includes/update.php:334
[17-Jan-2020 14:11:11 UTC] PHP 8. apply_filters() /home/mydomain/public_html/wp-includes/option.php:1832
[17-Jan-2020 14:11:11 UTC] PHP 9. WP_Hook->apply_filters() /home/mydomain/public_html/wp-includes/plugin.php:206
[17-Jan-2020 14:11:11 UTC] PHP 10. FS_Plugin_Updater->pre_set_site_transient_update_plugins_filter() /home/mydomain/public_html/wp-includes/class-wp-hook
.php:290
[17-Jan-2020 14:11:11 UTC] PHP 11. Freemius->get_update() /home/mydomain/public_html/wp-content/plugins/fullworks-anti-spam-pro/includes/vendor/freemius/
wordpress-sdk/includes/class-fs-plugin-updater.php:517
[17-Jan-2020 14:11:11 UTC] PHP 12. Freemius->check_updates() /home/mydomain/public_html/wp-content/plugins/fullworks-anti-spam-pro/includes/vendor/freemi
us/wordpress-sdk/includes/class-freemius.php:18962
[17-Jan-2020 14:11:11 UTC] PHP 13. Freemius->_fetch_newer_version() /home/mydomain/public_html/wp-content/plugins/fullworks-anti-spam-pro/includes/vendor
/freemius/wordpress-sdk/includes/class-freemius.php:20514
[17-Jan-2020 14:11:11 UTC] PHP 14. Freemius->_fetch_latest_version() /home/mydomain/public_html/wp-content/plugins/fullworks-anti-spam-pro/includes/vendo
r/freemius/wordpress-sdk/includes/class-freemius.php:18917
[17-Jan-2020 14:11:11 UTC] PHP 15. Freemius->get_api_site_or_plugin_scope() /home/mydomain/public_html/wp-content/plugins/fullworks-anti-spam-pro/include
s/vendor/freemius/wordpress-sdk/includes/class-freemius.php:20358
[17-Jan-2020 14:11:11 UTC] PHP 16. Freemius->get_api_site_scope() /home/mydomain/public_html/wp-content/plugins/fullworks-anti-spam-pro/includes/vendor/f
reemius/wordpress-sdk/includes/class-freemius.php:21644

Fatal error - Cannot declare class Freemius_Api_Base, because the name is already in use

๐Ÿž bug report

Behavior:
I tried some scheduled tasks via wp-cli, and the following notice appeared
An error of type E_ERROR was caused in line 50 of the file /path-to/src/vendor/freemius/php-sdk/freemius/FreemiusBase.php](http://example.org/path-to/src/vendor/freemius/php-sdk/freemius/FreemiusBase.php). Error message: Cannot declare class Freemius_Api_Base, because the name is already in use.

Affected line
https://github.com/Freemius/freemius-php-sdk/blob/master/freemius/FreemiusBase.php#L46 to https://github.com/Freemius/freemius-php-sdk/blob/master/freemius/FreemiusBase.php#L50

Cause
The affected lines contain the following code:

if ( class_exists( 'Freemius_Api_Base' ) ) {
  return;
}	

abstract class Freemius_Api_Base {
  // Class details
}

Although there is a class_exists() check before the declaration of the class, this doesn't always seem to cause the return line to actually stop the execution and prevent the class from being declared. This is something I noticed in the past with other classes, unrelated to Freemius. The if class exists -> return logic doesn't always seem to work.

Solution
The solution I applied was to replace the if class exists -> return with a condition that declares the class only when it doesn't exist. That is:

if ( !class_exists( 'Freemius_Api_Base' ) ) {
  abstract class Freemius_Api_Base {
    // Class details
  }
}	

This produces more consistent results, and prevents fatal errors.

Versions: (*)

  • Freemius PHP SDK Version: dev-master, from Packagist.
  • WordPress Version: 6.0
  • PHP Version: 7.4.x, 8.0

count description doesn't respect the limit defined in the documentation

Using something like

$inactive_sites = $api->Api("/plugins/{$first_plugin_id}/installs.json?filter=active&count=30", 'GET');

I'm unable to get more than 25 results returned. I can set the value to less than 25 and it returns the expected number of results.

The API documentation states:

Ranges from 1 to 50. Example: 30. Default: 25.

and

Pagination: All collection queries optionally accept count (limit) and offset params while limit can range from 1 to 50 and defaults to 25.

Suggested fix: align API with documentation.

scope : store not working correctly

for API_SCOPE : store , path for purchases /purchases shows nothing means empty array. Also from scope i cannot get the plugins lists means actually developer scope data should be accessed from store scope too.

Calls to Pricing API with a PUT request fail the the optional "licenses" argument is not specified

The documentation (https://freemius.docs.apiary.io/#reference/pricing/plans-pricing/update-pricing) indicates the following:

Request Body JSON Data

Key Required Description
monthly_price No ย 
annual_price No ย 
lifetime_price No ย 
licenses No The number of license activation supported by the license. E.g. when the value is 1, the premium license can only be activated on single site.

Based on the above, I made a call as follows:

  • Method: PUT
  • Path: /plugins/123/plans/456/pricing/789.json
  • Body: {"annual_price":"10"}'

Expected result: the annual price for pricing 789 would be changed to 10.
Actual result:

 'error' =>
    object(stdClass)[4452]
      public 'type' => string 'ObjectExist' (length=11)
      public 'message' => string 'There's already another pricing configured for  installs license.' (length=65)
      public 'code' => string 'pricing_exist' (length=13)
      public 'http' => int 401

Notice that the message says "There's already another pricing configured for installs license". There are two spaces between "for" and "installs", which leads me to think that the response was generated by a sprintf() call which tried to embed the "licenses" argument (not passed with the call) into the message.

Hypothesis about the cause, and possible solution

The "PUT" call should update the attributes of the pricing, based on the ID. It should not try to create another pricing. My speculation is that the "licenses" argument is being used to identify the pricing together with the ID. That could make sense with a POST call, to avoid creating a duplicate pricing, but the PUT call should only use the pricing ID, as it's unique.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.