← All changes
|
libraries/freemius/includes/class-fs-plugin-updater.php
+51
-6
2.4
→
3.0
View file →
| @@ -105,8 +105,10 @@ | ||
| 105 | 105 | ), 11, 2 ); |
| 106 | 106 | |
| 107 | 107 | if ( ! $this->_fs->has_any_active_valid_license() ) { |
| 108 | 108 | add_action( 'admin_head', array( &$this, 'catch_plugin_information_dialog_contents' ) ); |
| 109 | + } else { | |
| 110 | + add_action( 'admin_footer', array( &$this, '_add_fs_allow_updater_and_dialog_request_param' ) ); | |
| 109 | 111 | } |
| 110 | 112 | |
| 111 | 113 | if ( ! WP_FS__IS_PRODUCTION_MODE ) { |
| 112 | 114 | add_filter( 'http_request_host_is_external', array( |
| @@ -130,15 +132,48 @@ | ||
| 130 | 132 | } |
| 131 | 133 | |
| 132 | 134 | /** |
| 133 | 135 | * @author Leo Fajardo (@leorw) |
| 136 | + * @since 2.7.4 | |
| 137 | + */ | |
| 138 | + function _add_fs_allow_updater_and_dialog_request_param() { | |
| 139 | + if ( ! $this->is_plugin_information_dialog_for_plugin() ) { | |
| 140 | + return; | |
| 141 | + } | |
| 142 | + ?> | |
| 143 | + <script type="text/javascript"> | |
| 144 | + if ( typeof jQuery !== 'undefined' ) { | |
| 145 | + jQuery( document ).on( 'wp-plugin-updating', function( event, args ) { | |
| 146 | + if ( typeof args === 'object' && args.slug && typeof args.slug === 'string' ) { | |
| 147 | + if ( <?php echo json_encode( $this->_fs->get_slug() ) ?> === args.slug ) { | |
| 148 | + args.fs_allow_updater_and_dialog = true; | |
| 149 | + } | |
| 150 | + } | |
| 151 | + } ); | |
| 152 | + } | |
| 153 | + </script> | |
| 154 | + <?php | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * @author Leo Fajardo (@leorw) | |
| 159 | + * @since 2.7.4 | |
| 160 | + * | |
| 161 | + * @return bool | |
| 162 | + */ | |
| 163 | + private function is_plugin_information_dialog_for_plugin() { | |
| 164 | + return ( | |
| 165 | + 'plugin-information' === fs_request_get( 'tab', false ) && | |
| 166 | + $this->_fs->get_slug() === fs_request_get_raw( 'plugin', false ) | |
| 167 | + ); | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * @author Leo Fajardo (@leorw) | |
| 134 | 172 | * @since 2.1.4 |
| 135 | 173 | */ |
| 136 | 174 | function catch_plugin_information_dialog_contents() { |
| 137 | - if ( | |
| 138 | - 'plugin-information' !== fs_request_get( 'tab', false ) || | |
| 139 | - $this->_fs->get_slug() !== fs_request_get_raw( 'plugin', false ) | |
| 140 | - ) { | |
| 175 | + if ( ! $this->is_plugin_information_dialog_for_plugin() ) { | |
| 141 | 176 | return; |
| 142 | 177 | } |
| 143 | 178 | |
| 144 | 179 | add_action( 'admin_footer', array( &$this, 'edit_and_echo_plugin_information_dialog_contents' ), 0, 1 ); |
| @@ -615,9 +650,9 @@ | ||
| 615 | 650 | } |
| 616 | 651 | |
| 617 | 652 | $slug = $this->_fs->get_slug(); |
| 618 | 653 | |
| 619 | - if ( $this->_fs->is_org_repo_compliant() && $this->_fs->is_freemium() ) { | |
| 654 | + if ( $this->can_fetch_data_from_wp_org() ) { | |
| 620 | 655 | if ( ! isset( $this->_translation_updates ) ) { |
| 621 | 656 | $this->_translation_updates = array(); |
| 622 | 657 | |
| 623 | 658 | $translation_updates = $this->fetch_wp_org_module_translation_updates( $module_type, $slug ); |
| @@ -873,8 +908,18 @@ | ||
| 873 | 908 | return $res; |
| 874 | 909 | } |
| 875 | 910 | |
| 876 | 911 | /** |
| 912 | + * Returns true if the product can fetch data from WordPress.org. | |
| 913 | + * | |
| 914 | + * @author Leo Fajardo (@leorw) | |
| 915 | + * @since 2.7.4 | |
| 916 | + */ | |
| 917 | + private function can_fetch_data_from_wp_org() { | |
| 918 | + return ( $this->_fs->is_org_repo_compliant() && $this->_fs->is_freemium() ); | |
| 919 | + } | |
| 920 | + | |
| 921 | + /** | |
| 877 | 922 | * Fetches module translation updates from wordpress.org. |
| 878 | 923 | * |
| 879 | 924 | * @author Leo Fajardo (@leorw) |
| 880 | 925 | * @since 2.1.2 |
| @@ -1056,9 +1101,9 @@ | ||
| 1056 | 1101 | $is_addon = true; |
| 1057 | 1102 | } |
| 1058 | 1103 | |
| 1059 | 1104 | $plugin_in_repo = false; |
| 1060 | - if ( ! $is_addon ) { | |
| 1105 | + if ( ! $is_addon && $this->can_fetch_data_from_wp_org() ) { | |
| 1061 | 1106 | // Try to fetch info from .org repository. |
| 1062 | 1107 | $data = self::_fetch_plugin_info_from_repository( $action, $args ); |
| 1063 | 1108 | |
| 1064 | 1109 | $plugin_in_repo = ( false !== $data ); |