Check_Email_Log_List_Action.php
2 years ago
Check_Email_Nonce_Checker.php
2 years ago
Check_Email_Override_PluginAPI.php
2 years ago
Check_Email_Override_PluginAPI.php
71 lines
| 1 | <?php namespace CheckEmail\Core\Request; |
| 2 | |
| 3 | use CheckEmail\Addon\API\EDDUpdater; |
| 4 | use CheckEmail\Core\Loadie; |
| 5 | |
| 6 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 7 | |
| 8 | /** |
| 9 | * Override WordPress Plugin API. |
| 10 | * This is already done by EDD_SL_Plugin_Updater for Active add-on |
| 11 | * and this class does it for all in active or yet to be installed add-ons. |
| 12 | */ |
| 13 | class Check_Email_Override_PluginAPI implements Loadie { |
| 14 | |
| 15 | public function load() { |
| 16 | add_action( 'admin_init', array( $this, 'setup_updaters_for_inactive_addons' ) ); |
| 17 | |
| 18 | add_filter( 'plugins_api_result', array( $this, 'add_version_to_plugin_api_response' ), 100, 3 ); |
| 19 | } |
| 20 | |
| 21 | public function setup_updaters_for_inactive_addons() { |
| 22 | $check_email = wpchill_check_email(); |
| 23 | $licenser = $check_email->get_licenser(); |
| 24 | |
| 25 | if ( is_null( $licenser ) ) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | $inactive_addons = $licenser->get_addon_list()->get_inactive_addons(); |
| 30 | |
| 31 | foreach ( $inactive_addons as $inactive_addon ) { |
| 32 | $license_key = $licenser->get_addon_license_key( $inactive_addon->name ); |
| 33 | |
| 34 | $updater = new EDDUpdater( |
| 35 | $check_email->get_store_url(), |
| 36 | $inactive_addon->file, |
| 37 | array( |
| 38 | 'version' => $inactive_addon->get_version(), |
| 39 | 'license' => $license_key, |
| 40 | 'item_name' => $inactive_addon->name, |
| 41 | 'author' => $inactive_addon->author, |
| 42 | ) |
| 43 | ); |
| 44 | |
| 45 | $licenser->add_updater( $updater ); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public function add_version_to_plugin_api_response( $response, $action, $args ) { |
| 50 | if ( 'plugin_information' !== $action ) { |
| 51 | return $response; |
| 52 | } |
| 53 | |
| 54 | if ( ! isset( $args->slug ) || ( substr( $args->slug, 0, 10 ) != 'check-email-log-' ) ) { |
| 55 | return $response; |
| 56 | } |
| 57 | |
| 58 | if ( isset( $response->version ) ) { |
| 59 | return $response; |
| 60 | } |
| 61 | |
| 62 | if ( ! isset( $response->new_version ) ) { |
| 63 | return $response; |
| 64 | } |
| 65 | |
| 66 | $response->version = $response->new_version; |
| 67 | |
| 68 | return $response; |
| 69 | } |
| 70 | } |
| 71 |