@@ -13,328 +13,328 @@ |
||
| 13 | 13 | * @version 1.6 |
| 14 | 14 | */ |
| 15 | 15 | class EDD_SL_Plugin_Updater { |
| 16 | - private $api_url = ''; |
|
| 17 | - private $api_data = array(); |
|
| 18 | - private $name = ''; |
|
| 19 | - private $slug = ''; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Class constructor. |
|
| 23 | - * |
|
| 24 | - * @uses plugin_basename() |
|
| 25 | - * @uses hook() |
|
| 26 | - * |
|
| 27 | - * @param string $_api_url The URL pointing to the custom API endpoint. |
|
| 28 | - * @param string $_plugin_file Path to the plugin file. |
|
| 29 | - * @param array $_api_data Optional data to send with API calls. |
|
| 30 | - * @return void |
|
| 31 | - */ |
|
| 32 | - function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
| 33 | - $this->api_url = trailingslashit( $_api_url ); |
|
| 34 | - $this->api_data = $_api_data; |
|
| 35 | - $this->name = plugin_basename( $_plugin_file ); |
|
| 36 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
| 37 | - $this->version = $_api_data['version']; |
|
| 38 | - |
|
| 39 | - // Set up hooks. |
|
| 40 | - $this->init(); |
|
| 41 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Set up WordPress filters to hook into WP's update process. |
|
| 46 | - * |
|
| 47 | - * @uses add_filter() |
|
| 48 | - * |
|
| 49 | - * @return void |
|
| 50 | - */ |
|
| 51 | - public function init() { |
|
| 16 | + private $api_url = ''; |
|
| 17 | + private $api_data = array(); |
|
| 18 | + private $name = ''; |
|
| 19 | + private $slug = ''; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Class constructor. |
|
| 23 | + * |
|
| 24 | + * @uses plugin_basename() |
|
| 25 | + * @uses hook() |
|
| 26 | + * |
|
| 27 | + * @param string $_api_url The URL pointing to the custom API endpoint. |
|
| 28 | + * @param string $_plugin_file Path to the plugin file. |
|
| 29 | + * @param array $_api_data Optional data to send with API calls. |
|
| 30 | + * @return void |
|
| 31 | + */ |
|
| 32 | + function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
| 33 | + $this->api_url = trailingslashit( $_api_url ); |
|
| 34 | + $this->api_data = $_api_data; |
|
| 35 | + $this->name = plugin_basename( $_plugin_file ); |
|
| 36 | + $this->slug = basename( $_plugin_file, '.php' ); |
|
| 37 | + $this->version = $_api_data['version']; |
|
| 38 | + |
|
| 39 | + // Set up hooks. |
|
| 40 | + $this->init(); |
|
| 41 | + add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Set up WordPress filters to hook into WP's update process. |
|
| 46 | + * |
|
| 47 | + * @uses add_filter() |
|
| 48 | + * |
|
| 49 | + * @return void |
|
| 50 | + */ |
|
| 51 | + public function init() { |
|
| 52 | 52 | |
| 53 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 54 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
| 53 | + add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 54 | + add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
| 55 | 55 | |
| 56 | - add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
| 57 | - } |
|
| 56 | + add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Check for Updates at the defined API endpoint and modify the update array. |
|
| 61 | - * |
|
| 62 | - * This function dives into the update API just when WordPress creates its update array, |
|
| 63 | - * then adds a custom API call and injects the custom plugin data retrieved from the API. |
|
| 64 | - * It is reassembled from parts of the native WordPress plugin update code. |
|
| 65 | - * See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
|
| 66 | - * |
|
| 67 | - * @uses api_request() |
|
| 68 | - * |
|
| 69 | - * @param array $_transient_data Update array build by WordPress. |
|
| 70 | - * @return array Modified update array with custom plugin data. |
|
| 71 | - */ |
|
| 72 | - function check_update( $_transient_data ) { |
|
| 59 | + /** |
|
| 60 | + * Check for Updates at the defined API endpoint and modify the update array. |
|
| 61 | + * |
|
| 62 | + * This function dives into the update API just when WordPress creates its update array, |
|
| 63 | + * then adds a custom API call and injects the custom plugin data retrieved from the API. |
|
| 64 | + * It is reassembled from parts of the native WordPress plugin update code. |
|
| 65 | + * See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
|
| 66 | + * |
|
| 67 | + * @uses api_request() |
|
| 68 | + * |
|
| 69 | + * @param array $_transient_data Update array build by WordPress. |
|
| 70 | + * @return array Modified update array with custom plugin data. |
|
| 71 | + */ |
|
| 72 | + function check_update( $_transient_data ) { |
|
| 73 | 73 | |
| 74 | - global $pagenow; |
|
| 74 | + global $pagenow; |
|
| 75 | 75 | |
| 76 | - if( ! is_object( $_transient_data ) ) { |
|
| 77 | - $_transient_data = new stdClass; |
|
| 78 | - } |
|
| 76 | + if( ! is_object( $_transient_data ) ) { |
|
| 77 | + $_transient_data = new stdClass; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - if( 'plugins.php' == $pagenow && is_multisite() ) { |
|
| 81 | - return $_transient_data; |
|
| 82 | - } |
|
| 80 | + if( 'plugins.php' == $pagenow && is_multisite() ) { |
|
| 81 | + return $_transient_data; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
| 84 | + if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
| 85 | 85 | |
| 86 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 86 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 87 | 87 | |
| 88 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
| 88 | + if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
| 89 | 89 | |
| 90 | - $this->did_check = true; |
|
| 90 | + $this->did_check = true; |
|
| 91 | 91 | |
| 92 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 92 | + if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 93 | 93 | |
| 94 | - $_transient_data->response[ $this->name ] = $version_info; |
|
| 94 | + $_transient_data->response[ $this->name ] = $version_info; |
|
| 95 | 95 | |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $_transient_data->last_checked = time(); |
|
| 99 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
| 98 | + $_transient_data->last_checked = time(); |
|
| 99 | + $_transient_data->checked[ $this->name ] = $this->version; |
|
| 100 | 100 | |
| 101 | - } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $_transient_data; |
|
| 106 | - } |
|
| 105 | + return $_transient_data; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
|
| 110 | - * |
|
| 111 | - * @param string $file |
|
| 112 | - * @param array $plugin |
|
| 113 | - */ |
|
| 114 | - public function show_update_notification( $file, $plugin ) { |
|
| 108 | + /** |
|
| 109 | + * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
|
| 110 | + * |
|
| 111 | + * @param string $file |
|
| 112 | + * @param array $plugin |
|
| 113 | + */ |
|
| 114 | + public function show_update_notification( $file, $plugin ) { |
|
| 115 | 115 | |
| 116 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
| 117 | - return; |
|
| 118 | - } |
|
| 116 | + if( ! current_user_can( 'update_plugins' ) ) { |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - if( ! is_multisite() ) { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 120 | + if( ! is_multisite() ) { |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - if ( $this->name != $file ) { |
|
| 125 | - return; |
|
| 126 | - } |
|
| 124 | + if ( $this->name != $file ) { |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - // Remove our filter on the site transient |
|
| 129 | - remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
| 128 | + // Remove our filter on the site transient |
|
| 129 | + remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); |
|
| 130 | 130 | |
| 131 | - $update_cache = get_site_transient( 'update_plugins' ); |
|
| 131 | + $update_cache = get_site_transient( 'update_plugins' ); |
|
| 132 | 132 | |
| 133 | - if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
| 133 | + if ( ! is_object( $update_cache ) || empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
|
| 134 | 134 | |
| 135 | - $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
| 136 | - $version_info = get_transient( $cache_key ); |
|
| 135 | + $cache_key = md5( 'edd_plugin_' .sanitize_key( $this->name ) . '_version_info' ); |
|
| 136 | + $version_info = get_transient( $cache_key ); |
|
| 137 | 137 | |
| 138 | - if( false === $version_info ) { |
|
| 138 | + if( false === $version_info ) { |
|
| 139 | 139 | |
| 140 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 140 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
| 141 | 141 | |
| 142 | - set_transient( $cache_key, $version_info, 3600 ); |
|
| 143 | - } |
|
| 142 | + set_transient( $cache_key, $version_info, 3600 ); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | |
| 146 | - if( ! is_object( $version_info ) ) { |
|
| 147 | - return; |
|
| 148 | - } |
|
| 146 | + if( ! is_object( $version_info ) ) { |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 150 | + if( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 151 | 151 | |
| 152 | - $update_cache->response[ $this->name ] = $version_info; |
|
| 152 | + $update_cache->response[ $this->name ] = $version_info; |
|
| 153 | 153 | |
| 154 | - } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - $update_cache->last_checked = time(); |
|
| 157 | - $update_cache->checked[ $this->name ] = $this->version; |
|
| 156 | + $update_cache->last_checked = time(); |
|
| 157 | + $update_cache->checked[ $this->name ] = $this->version; |
|
| 158 | 158 | |
| 159 | - set_site_transient( 'update_plugins', $update_cache ); |
|
| 159 | + set_site_transient( 'update_plugins', $update_cache ); |
|
| 160 | 160 | |
| 161 | - } else { |
|
| 161 | + } else { |
|
| 162 | 162 | |
| 163 | - $version_info = $update_cache->response[ $this->name ]; |
|
| 163 | + $version_info = $update_cache->response[ $this->name ]; |
|
| 164 | 164 | |
| 165 | - } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - // Restore our filter |
|
| 168 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 167 | + // Restore our filter |
|
| 168 | + add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
| 169 | 169 | |
| 170 | - if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 170 | + if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
| 171 | 171 | |
| 172 | - // build a plugin list row, with update notification |
|
| 173 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
| 174 | - echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
| 172 | + // build a plugin list row, with update notification |
|
| 173 | + $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
| 174 | + echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
| 175 | 175 | |
| 176 | - $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
| 176 | + $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); |
|
| 177 | 177 | |
| 178 | - if ( empty( $version_info->download_link ) ) { |
|
| 179 | - printf( |
|
| 180 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'edd' ), |
|
| 181 | - esc_html( $version_info->name ), |
|
| 182 | - esc_url( $changelog_link ), |
|
| 183 | - esc_html( $version_info->new_version ) |
|
| 184 | - ); |
|
| 185 | - } else { |
|
| 186 | - printf( |
|
| 187 | - __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'edd' ), |
|
| 188 | - esc_html( $version_info->name ), |
|
| 189 | - esc_url( $changelog_link ), |
|
| 190 | - esc_html( $version_info->new_version ), |
|
| 191 | - esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
| 192 | - ); |
|
| 193 | - } |
|
| 178 | + if ( empty( $version_info->download_link ) ) { |
|
| 179 | + printf( |
|
| 180 | + __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a>.', 'edd' ), |
|
| 181 | + esc_html( $version_info->name ), |
|
| 182 | + esc_url( $changelog_link ), |
|
| 183 | + esc_html( $version_info->new_version ) |
|
| 184 | + ); |
|
| 185 | + } else { |
|
| 186 | + printf( |
|
| 187 | + __( 'There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.', 'edd' ), |
|
| 188 | + esc_html( $version_info->name ), |
|
| 189 | + esc_url( $changelog_link ), |
|
| 190 | + esc_html( $version_info->new_version ), |
|
| 191 | + esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - echo '</div></td></tr>'; |
|
| 196 | - } |
|
| 197 | - } |
|
| 195 | + echo '</div></td></tr>'; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * Updates information on the "View version x.x details" page with custom data. |
|
| 202 | - * |
|
| 203 | - * @uses api_request() |
|
| 204 | - * |
|
| 205 | - * @param mixed $_data |
|
| 206 | - * @param string $_action |
|
| 207 | - * @param object $_args |
|
| 208 | - * @return object $_data |
|
| 209 | - */ |
|
| 210 | - function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
| 200 | + /** |
|
| 201 | + * Updates information on the "View version x.x details" page with custom data. |
|
| 202 | + * |
|
| 203 | + * @uses api_request() |
|
| 204 | + * |
|
| 205 | + * @param mixed $_data |
|
| 206 | + * @param string $_action |
|
| 207 | + * @param object $_args |
|
| 208 | + * @return object $_data |
|
| 209 | + */ |
|
| 210 | + function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
| 211 | 211 | |
| 212 | 212 | |
| 213 | - if ( $_action != 'plugin_information' ) { |
|
| 213 | + if ( $_action != 'plugin_information' ) { |
|
| 214 | 214 | |
| 215 | - return $_data; |
|
| 215 | + return $_data; |
|
| 216 | 216 | |
| 217 | - } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
| 219 | + if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
| 220 | 220 | |
| 221 | - return $_data; |
|
| 221 | + return $_data; |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - $to_send = array( |
|
| 226 | - 'slug' => $this->slug, |
|
| 227 | - 'is_ssl' => is_ssl(), |
|
| 228 | - 'fields' => array( |
|
| 229 | - 'banners' => false, // These will be supported soon hopefully |
|
| 230 | - 'reviews' => false |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 225 | + $to_send = array( |
|
| 226 | + 'slug' => $this->slug, |
|
| 227 | + 'is_ssl' => is_ssl(), |
|
| 228 | + 'fields' => array( |
|
| 229 | + 'banners' => false, // These will be supported soon hopefully |
|
| 230 | + 'reviews' => false |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | 233 | |
| 234 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
| 234 | + $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
| 235 | 235 | |
| 236 | - if ( false !== $api_response ) { |
|
| 237 | - $_data = $api_response; |
|
| 238 | - } |
|
| 236 | + if ( false !== $api_response ) { |
|
| 237 | + $_data = $api_response; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - return $_data; |
|
| 241 | - } |
|
| 240 | + return $_data; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * Disable SSL verification in order to prevent download update failures |
|
| 246 | - * |
|
| 247 | - * @param array $args |
|
| 248 | - * @param string $url |
|
| 249 | - * @return object $array |
|
| 250 | - */ |
|
| 251 | - function http_request_args( $args, $url ) { |
|
| 252 | - // If it is an https request and we are performing a package download, disable ssl verification |
|
| 253 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
| 254 | - $args['sslverify'] = false; |
|
| 255 | - } |
|
| 256 | - return $args; |
|
| 257 | - } |
|
| 244 | + /** |
|
| 245 | + * Disable SSL verification in order to prevent download update failures |
|
| 246 | + * |
|
| 247 | + * @param array $args |
|
| 248 | + * @param string $url |
|
| 249 | + * @return object $array |
|
| 250 | + */ |
|
| 251 | + function http_request_args( $args, $url ) { |
|
| 252 | + // If it is an https request and we are performing a package download, disable ssl verification |
|
| 253 | + if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
| 254 | + $args['sslverify'] = false; |
|
| 255 | + } |
|
| 256 | + return $args; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Calls the API and, if successfull, returns the object delivered by the API. |
|
| 261 | - * |
|
| 262 | - * @uses get_bloginfo() |
|
| 263 | - * @uses wp_remote_post() |
|
| 264 | - * @uses is_wp_error() |
|
| 265 | - * |
|
| 266 | - * @param string $_action The requested action. |
|
| 267 | - * @param array $_data Parameters for the API action. |
|
| 268 | - * @return false||object |
|
| 269 | - */ |
|
| 270 | - private function api_request( $_action, $_data ) { |
|
| 271 | - |
|
| 272 | - global $wp_version; |
|
| 273 | - |
|
| 274 | - $data = array_merge( $this->api_data, $_data ); |
|
| 275 | - |
|
| 276 | - if ( $data['slug'] != $this->slug ) |
|
| 277 | - return; |
|
| 278 | - |
|
| 279 | - if ( empty( $data['license'] ) ) |
|
| 280 | - return; |
|
| 281 | - |
|
| 282 | - if( $this->api_url == home_url() ) { |
|
| 283 | - return false; // Don't allow a plugin to ping itself |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $api_params = array( |
|
| 287 | - 'edd_action' => 'get_version', |
|
| 288 | - 'license' => $data['license'], |
|
| 289 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
| 290 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
| 291 | - 'slug' => $data['slug'], |
|
| 292 | - 'author' => $data['author'], |
|
| 293 | - 'url' => home_url() |
|
| 294 | - ); |
|
| 259 | + /** |
|
| 260 | + * Calls the API and, if successfull, returns the object delivered by the API. |
|
| 261 | + * |
|
| 262 | + * @uses get_bloginfo() |
|
| 263 | + * @uses wp_remote_post() |
|
| 264 | + * @uses is_wp_error() |
|
| 265 | + * |
|
| 266 | + * @param string $_action The requested action. |
|
| 267 | + * @param array $_data Parameters for the API action. |
|
| 268 | + * @return false||object |
|
| 269 | + */ |
|
| 270 | + private function api_request( $_action, $_data ) { |
|
| 271 | + |
|
| 272 | + global $wp_version; |
|
| 273 | + |
|
| 274 | + $data = array_merge( $this->api_data, $_data ); |
|
| 275 | + |
|
| 276 | + if ( $data['slug'] != $this->slug ) |
|
| 277 | + return; |
|
| 278 | + |
|
| 279 | + if ( empty( $data['license'] ) ) |
|
| 280 | + return; |
|
| 281 | + |
|
| 282 | + if( $this->api_url == home_url() ) { |
|
| 283 | + return false; // Don't allow a plugin to ping itself |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $api_params = array( |
|
| 287 | + 'edd_action' => 'get_version', |
|
| 288 | + 'license' => $data['license'], |
|
| 289 | + 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
| 290 | + 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
| 291 | + 'slug' => $data['slug'], |
|
| 292 | + 'author' => $data['author'], |
|
| 293 | + 'url' => home_url() |
|
| 294 | + ); |
|
| 295 | 295 | |
| 296 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
| 296 | + $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
| 297 | 297 | |
| 298 | - if ( ! is_wp_error( $request ) ) { |
|
| 299 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
| 300 | - } |
|
| 298 | + if ( ! is_wp_error( $request ) ) { |
|
| 299 | + $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - if ( $request && isset( $request->sections ) ) { |
|
| 303 | - $request->sections = maybe_unserialize( $request->sections ); |
|
| 304 | - } else { |
|
| 305 | - $request = false; |
|
| 306 | - } |
|
| 302 | + if ( $request && isset( $request->sections ) ) { |
|
| 303 | + $request->sections = maybe_unserialize( $request->sections ); |
|
| 304 | + } else { |
|
| 305 | + $request = false; |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - return $request; |
|
| 309 | - } |
|
| 308 | + return $request; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - public function show_changelog() { |
|
| 311 | + public function show_changelog() { |
|
| 312 | 312 | |
| 313 | 313 | |
| 314 | - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
| 315 | - return; |
|
| 316 | - } |
|
| 314 | + if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
| 315 | + return; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - if( empty( $_REQUEST['plugin'] ) ) { |
|
| 319 | - return; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if( empty( $_REQUEST['slug'] ) ) { |
|
| 323 | - return; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - if( ! current_user_can( 'update_plugins' ) ) { |
|
| 327 | - wp_die( __( 'You do not have permission to install plugin updates', 'edd' ), __( 'Error', 'edd' ), array( 'response' => 403 ) ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
| 331 | - |
|
| 332 | - if( $response && isset( $response->sections['changelog'] ) ) { |
|
| 333 | - echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - exit; |
|
| 338 | - } |
|
| 318 | + if( empty( $_REQUEST['plugin'] ) ) { |
|
| 319 | + return; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if( empty( $_REQUEST['slug'] ) ) { |
|
| 323 | + return; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + if( ! current_user_can( 'update_plugins' ) ) { |
|
| 327 | + wp_die( __( 'You do not have permission to install plugin updates', 'edd' ), __( 'Error', 'edd' ), array( 'response' => 403 ) ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
| 331 | + |
|
| 332 | + if( $response && isset( $response->sections['changelog'] ) ) { |
|
| 333 | + echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + exit; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | 340 | } |
@@ -71,8 +71,8 @@ |
||
| 71 | 71 | |
| 72 | 72 | case 'user_id' : |
| 73 | 73 | return '<a href="' . |
| 74 | - admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . ( ! empty( $item['user_id'] ) ? urlencode( $item['user_id'] ) : give_get_payment_user_email( $item['payment_id'] ) ) ) . |
|
| 75 | - '">' . $item['user_name'] . '</a>'; |
|
| 74 | + admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&user=' . ( ! empty( $item['user_id'] ) ? urlencode( $item['user_id'] ) : give_get_payment_user_email( $item['payment_id'] ) ) ) . |
|
| 75 | + '">' . $item['user_name'] . '</a>'; |
|
| 76 | 76 | |
| 77 | 77 | case 'amount' : |
| 78 | 78 | return give_currency_filter( give_format_amount( $item['amount'] ) ); |
@@ -1170,9 +1170,9 @@ |
||
| 1170 | 1170 | |
| 1171 | 1171 | //Sanity check - ensure form has goal set to output |
| 1172 | 1172 | if ( empty( $form->ID ) |
| 1173 | - || ( is_singular( 'give_forms' ) && $goal_option !== 'yes' ) |
|
| 1174 | - || $goal_option !== 'yes' |
|
| 1175 | - || $goal == 0 |
|
| 1173 | + || ( is_singular( 'give_forms' ) && $goal_option !== 'yes' ) |
|
| 1174 | + || $goal_option !== 'yes' |
|
| 1175 | + || $goal == 0 |
|
| 1176 | 1176 | ) { |
| 1177 | 1177 | //not this form, bail |
| 1178 | 1178 | return false; |
@@ -97,10 +97,10 @@ |
||
| 97 | 97 | |
| 98 | 98 | //Single Form settings varies compared to the Global default settings |
| 99 | 99 | if ( ! empty( $form_default ) && |
| 100 | - $form_id !== null && |
|
| 101 | - $default !== $form_default && |
|
| 102 | - $form_default !== 'global' && |
|
| 103 | - give_is_gateway_active( $form_default ) |
|
| 100 | + $form_id !== null && |
|
| 101 | + $default !== $form_default && |
|
| 102 | + $form_default !== 'global' && |
|
| 103 | + give_is_gateway_active( $form_default ) |
|
| 104 | 104 | ) { |
| 105 | 105 | $default = $form_default; |
| 106 | 106 | } |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 | |
| 80 | 80 | //validate display_style and float_labels value |
| 81 | 81 | if ( ( $key == 'display_style' && ! in_array( $value, array( 'onpage', 'reveal', 'modal' ) ) ) |
| 82 | - || ( $key == 'float_labels' && ! in_array( $value, array( 'enabled', 'disabled' ) ) ) |
|
| 82 | + || ( $key == 'float_labels' && ! in_array( $value, array( 'enabled', 'disabled' ) ) ) |
|
| 83 | 83 | ) { |
| 84 | 84 | |
| 85 | 85 | $atts[ $key ] = ''; |
@@ -246,8 +246,8 @@ |
||
| 246 | 246 | |
| 247 | 247 | // do not reindex array! |
| 248 | 248 | $field['options'] = array( |
| 249 | - '' => ( $field['placeholder'] ? $field['placeholder'] : sprintf( '– %s –', __( 'Select', 'give' ) ) ), |
|
| 250 | - ) + $field['options']; |
|
| 249 | + '' => ( $field['placeholder'] ? $field['placeholder'] : sprintf( '– %s –', __( 'Select', 'give' ) ) ), |
|
| 250 | + ) + $field['options']; |
|
| 251 | 251 | |
| 252 | 252 | foreach ( $field['options'] as $value => $text ) { |
| 253 | 253 | $new_listbox['values'][] = array( |
@@ -117,8 +117,8 @@ |
||
| 117 | 117 | $shortcode_button_pages = array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ); |
| 118 | 118 | // Only run in admin post/page creation and edit screens |
| 119 | 119 | if ( in_array( $pagenow, $shortcode_button_pages ) |
| 120 | - && apply_filters( 'give_shortcode_button_condition', true ) |
|
| 121 | - && ! empty( self::$shortcodes ) |
|
| 120 | + && apply_filters( 'give_shortcode_button_condition', true ) |
|
| 121 | + && ! empty( self::$shortcodes ) |
|
| 122 | 122 | ) { |
| 123 | 123 | |
| 124 | 124 | $shortcodes = array(); |
@@ -115,8 +115,8 @@ |
||
| 115 | 115 | |
| 116 | 116 | case 'num_purchases' : |
| 117 | 117 | $value = '<a href="' . |
| 118 | - admin_url( '/edit.php?post_type=give_forms&page=give-payment-history&user=' . urlencode( $item['email'] ) |
|
| 119 | - ) . '">' . esc_html( $item['num_purchases'] ) . '</a>'; |
|
| 118 | + admin_url( '/edit.php?post_type=give_forms&page=give-payment-history&user=' . urlencode( $item['email'] ) |
|
| 119 | + ) . '">' . esc_html( $item['num_purchases'] ) . '</a>'; |
|
| 120 | 120 | break; |
| 121 | 121 | |
| 122 | 122 | case 'amount_spent' : |
@@ -71,9 +71,9 @@ |
||
| 71 | 71 | ) ); |
| 72 | 72 | |
| 73 | 73 | add_role( 'give_accountant', __( 'Give Accountant', 'give' ), array( |
| 74 | - 'read' => true, |
|
| 75 | - 'edit_posts' => false, |
|
| 76 | - 'delete_posts' => false |
|
| 74 | + 'read' => true, |
|
| 75 | + 'edit_posts' => false, |
|
| 76 | + 'delete_posts' => false |
|
| 77 | 77 | ) ); |
| 78 | 78 | |
| 79 | 79 | add_role( 'give_worker', __( 'Give Worker', 'give' ), array( |