PluginProbe
Email Log / 2.1.0
Email Log v2.1.0
2.63 2.4.8 2.4.9 2.6 2.61 2.62 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.9 0.9.1 0.9.2 1.1 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 61 releases
email-log / include / Core / Request / OverridePluginAPI.php

OverridePluginAPI.php in Email Log 2.1.0, at include/Core/Request/OverridePluginAPI.php

95 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace EmailLog\Core\Request;
2
3 use EmailLog\Addon\API\EDDUpdater;
4 use EmailLog\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 * @since 2.0.0
14 */
15 class OverridePluginAPI implements Loadie {
16
17 /**
18 * Setup actions.
19 *
20 * @inheritdoc
21 */
22 public function load() {
23 add_action( 'admin_init', array( $this, 'setup_updaters_for_inactive_addons' ) );
24
25 add_filter( 'plugins_api_result', array( $this, 'add_version_to_plugin_api_response' ), 100, 3 );
26 }
27
28 /**
29 * Setup updaters for all in-active addons.
30 */
31 public function setup_updaters_for_inactive_addons() {
32 $email_log = email_log();
33 $licenser = $email_log->get_licenser();
34
35 if ( is_null( $licenser ) ) {
36 return;
37 }
38
39 $inactive_addons = $licenser->get_addon_list()->get_inactive_addons();
40
41 foreach ( $inactive_addons as $inactive_addon ) {
42 $license_key = $licenser->get_addon_license_key( $inactive_addon->name );
43
44 $updater = new EDDUpdater(
45 $email_log->get_store_url(),
46 $inactive_addon->file,
47 array(
48 'version' => $inactive_addon->get_version(),
49 'license' => $license_key,
50 'item_name' => $inactive_addon->name,
51 'author' => $inactive_addon->author,
52 )
53 );
54
55 $licenser->add_updater( $updater );
56 }
57 }
58
59 /**
60 * Add version attribute to plugin API response.
61 *
62 * The API response generated by EDD doesn't have the version attribute and it results in some warnings.
63 * This method fixes it by manually adding the version attribute to the API response.
64 *
65 * @since 2.1.0
66 *
67 * @param object $response API Response.
68 * @param string $action Action name.
69 * @param array $args Arguments for the function.
70 *
71 * @return object Modified API response.
72 */
73 public function add_version_to_plugin_api_response( $response, $action, $args ) {
74 if ( 'plugin_information' !== $action ) {
75 return $response;
76 }
77
78 if ( ! isset( $args->slug ) || ( substr( $args->slug, 0, 10 ) != 'email-log-' ) ) {
79 return $response;
80 }
81
82 if ( isset( $response->version ) ) {
83 return $response;
84 }
85
86 if ( ! isset( $response->new_version ) ) {
87 return $response;
88 }
89
90 $response->version = $response->new_version;
91
92 return $response;
93 }
94 }
95