| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugins Update checker |
| 4 |
*/ |
| 5 |
add_filter( 'http_request_args', 'welcart_http_request_args', 10, 2 ); |
| 6 |
function welcart_http_request_args( $a, $b ) { |
| 7 |
if ( false === strpos( $b, ( USCES_UPDATE_INFO_URL . '/update_info/plugins/info.php' ) ) && false === strpos( $b, ( USCES_UPDATE_INFO_URL . '/update_info/themes/info.php' ) ) ) { |
| 8 |
return $a; |
| 9 |
} |
| 10 |
$a['body'] = array( |
| 11 |
'wpver' => get_bloginfo( 'version' ), |
| 12 |
'wcver' => USCES_VERSION, |
| 13 |
'prhost' => ( isset( $_SERVER['SERVER_NAME'] ) ? wp_unslash( $_SERVER['SERVER_NAME'] ) : '' ), |
| 14 |
); |
| 15 |
|
| 16 |
return $a; |
| 17 |
} |
| 18 |
|
| 19 |
add_action( 'init', 'welcart_update_check' ); |
| 20 |
function welcart_update_check() { |
| 21 |
|
| 22 |
if ( ! is_admin() ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
$current = get_site_transient( 'update_wcex_plugins' ); |
| 27 |
if ( ! is_object( $current ) ) { |
| 28 |
$current = new stdClass; |
| 29 |
} |
| 30 |
require USCES_PLUGIN_DIR . '/update_check/plugin-update-checker.php'; |
| 31 |
|
| 32 |
$timeout = 2 * HOUR_IN_SECONDS; |
| 33 |
|
| 34 |
$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); |
| 35 |
if ( $time_not_changed ) { |
| 36 |
|
| 37 |
$wcproducts = $current->products; |
| 38 |
|
| 39 |
} else { |
| 40 |
|
| 41 |
$options = array( |
| 42 |
'body' => array( |
| 43 |
'wpver' => get_bloginfo( 'version' ), |
| 44 |
'wcver' => USCES_VERSION, |
| 45 |
'prhost' => ( isset( $_SERVER['SERVER_NAME'] ) ? wp_unslash( $_SERVER['SERVER_NAME'] ) : '' ), |
| 46 |
'checktime' => time(), |
| 47 |
), |
| 48 |
); |
| 49 |
$response = wp_remote_post( USCES_UPDATE_INFO_URL . '/update_info/info_api.php', $options ); |
| 50 |
if ( is_wp_error( $response ) ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
$wcproducts = (array) json_decode( $response['body'], true ); |
| 54 |
|
| 55 |
if ( empty( $wcproducts ) ) { |
| 56 |
return; |
| 57 |
} |
| 58 |
$current->last_checked = time(); |
| 59 |
$current->products = $wcproducts; |
| 60 |
set_site_transient( 'update_wcex_plugins', $current ); |
| 61 |
} |
| 62 |
|
| 63 |
$wcproducts = (array) $wcproducts; |
| 64 |
|
| 65 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 66 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 67 |
} |
| 68 |
$plugins = get_plugins(); |
| 69 |
$installed = array(); |
| 70 |
$update_required = array(); |
| 71 |
foreach ( $plugins as $path => $pv ) { |
| 72 |
|
| 73 |
if ( array_key_exists( $pv['Name'], $wcproducts ) ) { |
| 74 |
$slug = $wcproducts[ $pv['Name'] ]; |
| 75 |
$fullpath = USCES_WP_PLUGIN_DIR . '/' . $path; |
| 76 |
$installed[ $slug ] = $fullpath; |
| 77 |
} |
| 78 |
|
| 79 |
if ( 'wcex_auto_delivery/wcex_auto_delivery.php' === $path ) { |
| 80 |
if ( version_compare( $pv['Version'], '1.7.3', '<' ) ) { |
| 81 |
$update_required[] = $pv['Name']; |
| 82 |
} |
| 83 |
} |
| 84 |
if ( 'wcex_dlseller/wcex_dlseller.php' === $path ) { |
| 85 |
if ( version_compare( $pv['Version'], '3.5.3', '<' ) ) { |
| 86 |
$update_required[] = $pv['Name']; |
| 87 |
} |
| 88 |
} |
| 89 |
if ( 'wcex_widget_cart/wcex_widget_cart.php' === $path ) { |
| 90 |
if ( version_compare( $pv['Version'], '1.2.5', '<' ) ) { |
| 91 |
$update_required[] = $pv['Name']; |
| 92 |
} |
| 93 |
} |
| 94 |
if ( 'wcex_multiple_shipping/wcex_multiple_shipping.php' === $path ) { |
| 95 |
if ( version_compare( $pv['Version'], '1.2.10', '<' ) ) { |
| 96 |
$update_required[] = $pv['Name']; |
| 97 |
} |
| 98 |
} |
| 99 |
if ( 'wcex_favorites/wcex_favorites.php' === $path ) { |
| 100 |
if ( version_compare( $pv['Version'], '1.0.4', '<' ) ) { |
| 101 |
$update_required[] = $pv['Name']; |
| 102 |
} |
| 103 |
} |
| 104 |
if ( 'wcex_coupon/wcex_coupon.php' === $path ) { |
| 105 |
if ( version_compare( $pv['Version'], '1.3.1', '<' ) ) { |
| 106 |
$update_required[] = $pv['Name']; |
| 107 |
} |
| 108 |
} |
| 109 |
if ( 'wcex_a8net/wcex_a8net.php' === $path ) { |
| 110 |
if ( version_compare( $pv['Version'], '1.0.2', '<' ) ) { |
| 111 |
$update_required[] = $pv['Name']; |
| 112 |
} |
| 113 |
} |
| 114 |
if ( 'wcex_google_analytics_4/wcex_google_analytics_4.php' === $path ) { |
| 115 |
if ( version_compare( $pv['Version'], '1.0.6', '<' ) ) { |
| 116 |
$update_required[] = $pv['Name']; |
| 117 |
} |
| 118 |
} |
| 119 |
if ( 'wcex_google_shopping/wcex_google_shopping.php' === $path ) { |
| 120 |
if ( version_compare( $pv['Version'], '2.0.3', '<' ) ) { |
| 121 |
$update_required[] = $pv['Name']; |
| 122 |
} |
| 123 |
} |
| 124 |
if ( 'wcex_instagram_shopping/wcex_instagram_shopping.php' === $path ) { |
| 125 |
if ( version_compare( $pv['Version'], '1.1.1', '<' ) ) { |
| 126 |
$update_required[] = $pv['Name']; |
| 127 |
} |
| 128 |
} |
| 129 |
if ( 'wcex_item_list_layout/wcex_item_list_layout.php' === $path ) { |
| 130 |
if ( version_compare( $pv['Version'], '1.4.1', '<' ) ) { |
| 131 |
$update_required[] = $pv['Name']; |
| 132 |
} |
| 133 |
} |
| 134 |
// if ( 'wcex_mailmaga/wcex_mailmaga.php' === $path ) { |
| 135 |
// if ( version_compare( $pv['Version'], '1.0.8', '<' ) ) { |
| 136 |
// $update_required[] = $pv['Name']; |
| 137 |
// } |
| 138 |
// } |
| 139 |
if ( 'wcex_mobile/wcex_mobile.php' === $path ) { |
| 140 |
if ( version_compare( $pv['Version'], '1.2.18', '<' ) ) { |
| 141 |
$update_required[] = $pv['Name']; |
| 142 |
} |
| 143 |
} |
| 144 |
if ( 'wcex_multiprice/wcex_multiprice.php' === $path ) { |
| 145 |
if ( version_compare( $pv['Version'], '1.3.3', '<' ) ) { |
| 146 |
$update_required[] = $pv['Name']; |
| 147 |
} |
| 148 |
} |
| 149 |
if ( 'wcex_nextengine/wcex_nextengine.php' === $path ) { |
| 150 |
if ( version_compare( $pv['Version'], '1.1.6', '<' ) ) { |
| 151 |
$update_required[] = $pv['Name']; |
| 152 |
} |
| 153 |
} |
| 154 |
if ( 'wcex_rakurakuzaiko/wcex_rakurakuzaiko.php' === $path ) { |
| 155 |
if ( version_compare( $pv['Version'], '1.3.4', '<' ) ) { |
| 156 |
$update_required[] = $pv['Name']; |
| 157 |
} |
| 158 |
} |
| 159 |
if ( 'wcex_reports/wcex_reports.php' === $path ) { |
| 160 |
if ( version_compare( $pv['Version'], '3.0.2', '<' ) ) { |
| 161 |
$update_required[] = $pv['Name']; |
| 162 |
} |
| 163 |
} |
| 164 |
if ( 'wcex_slide_showcase/wcex_slide_showcase.php' === $path ) { |
| 165 |
if ( version_compare( $pv['Version'], '1.0.7', '<' ) ) { |
| 166 |
$update_required[] = $pv['Name']; |
| 167 |
} |
| 168 |
} |
| 169 |
if ( 'wcex_zaikorobot/wcex_zaikorobot.php' === $path ) { |
| 170 |
if ( version_compare( $pv['Version'], '1.1.6', '<' ) ) { |
| 171 |
$update_required[] = $pv['Name']; |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
if ( ! empty( $update_required ) ) { |
| 177 |
if ( current_user_can( 'wel_manage_setting' ) ) { |
| 178 |
usces_update_notice( $update_required ); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
$themes = wp_get_themes(); |
| 183 |
foreach ( $themes as $path => $theme ) { |
| 184 |
$Name = $theme->get( 'Name' ); |
| 185 |
if ( array_key_exists( $Name, $wcproducts ) ) { |
| 186 |
$slug = $wcproducts[ $Name ]; |
| 187 |
$fullpath = get_theme_root() . '/' . $path . '/functions.php'; |
| 188 |
$installed[ $slug ] = $fullpath; |
| 189 |
} |
| 190 |
} |
| 191 |
foreach ( $installed as $slug => $fullpath ) { |
| 192 |
|
| 193 |
$json_path = USCES_UPDATE_INFO_URL . '/update_info/plugins/' . $slug . '.json'; |
| 194 |
$$slug = Puc_v4_Factory::buildUpdateChecker( $json_path, $fullpath, $slug ); |
| 195 |
|
| 196 |
add_filter( 'puc_manual_check_link-' . $slug, 'usces_manual_check_label' ); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
function usces_update_notice( $update_required ) { |
| 201 |
|
| 202 |
add_action( 'admin_notices', function() use ( $update_required ) { |
| 203 |
$notice = '<div class="notice notice-warning is-dismissible">'; |
| 204 |
$notice .= '<p>'; |
| 205 |
$notice .= __( 'The following plugins are outdated and will not function properly. Please update them immediately.', 'usces' ); |
| 206 |
$notice .= '<br><a href="' . admin_url( 'plugins.php' ) . '">'; |
| 207 |
$notice .= implode( '<br>', $update_required ); |
| 208 |
$notice .= '</a></p>'; |
| 209 |
$notice .= '</div>'; |
| 210 |
echo $notice; |
| 211 |
} ); |
| 212 |
} |
| 213 |
|
| 214 |
function usces_manual_check_label( $label ) { |
| 215 |
return __( 'Check for updates', 'usces' ); |
| 216 |
} |
| 217 |
|
| 218 |
add_action( 'init', 'usces_check_for_updates' ); |
| 219 |
function usces_check_for_updates() { |
| 220 |
|
| 221 |
if ( isset( $_GET['puc_update_check_result'], $_GET['puc_slug'] ) && ! empty( $_GET['puc_slug'] ) ) { |
| 222 |
$filter_handle = 'puc_manual_check_message-' . wp_unslash( $_GET['puc_slug'] ); |
| 223 |
|
| 224 |
add_filter( $filter_handle, 'usces_manual_check_message', 10, 2 ); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
function usces_manual_check_message( $message, $status ) { |
| 229 |
|
| 230 |
if ( ! is_admin() ) { |
| 231 |
return; |
| 232 |
} |
| 233 |
|
| 234 |
$query = array( |
| 235 |
'wpver' => get_bloginfo( 'version' ), |
| 236 |
'wcver' => USCES_VERSION, |
| 237 |
'prhost' => ( isset( $_SERVER['SERVER_NAME'] ) ? wp_unslash( $_SERVER['SERVER_NAME'] ) : '' ), |
| 238 |
'manual_check' => 1, |
| 239 |
'checktime' => time(), |
| 240 |
); |
| 241 |
|
| 242 |
$json_path = USCES_UPDATE_INFO_URL . '/update_info/plugins/' . $_GET['puc_slug'] . '.json'; |
| 243 |
$update_json = @file_get_contents( $json_path ); |
| 244 |
$update_info = (array) json_decode( $update_json, true ); |
| 245 |
$check_url = add_query_arg( $query, $update_info['download_url'] ); |
| 246 |
$check_info = @file_get_contents( $check_url ); |
| 247 |
|
| 248 |
if ( empty( $check_info ) ) { |
| 249 |
|
| 250 |
$message = __( 'An unexpected error has occurred.', 'usces' ) . '(ERROR0)'; |
| 251 |
|
| 252 |
} else { |
| 253 |
|
| 254 |
switch ( $check_info ) { |
| 255 |
case '422 Unprocessable Entity': |
| 256 |
$message = __( 'Update Right is invalid. The corresponding plug-in does not exist.', 'usces' ) . '(ERROR422)'; |
| 257 |
break; |
| 258 |
case '401 Unauthorized': |
| 259 |
$message = __( 'Update Right is invalid. The domain of your site does not match.', 'usces' ) . '(DomainMismatch)'; |
| 260 |
break; |
| 261 |
case '402 Payment Required': |
| 262 |
$message = __( 'Update Right is invalid. There is no valid license purchase information.', 'usces' ) . '(OrderCanceled)'; |
| 263 |
break; |
| 264 |
case '400 Bad Request': |
| 265 |
$message = __( 'Update Right is invalid. The domain of your site does not match.', 'usces' ) . '(ClientDomainMissing)'; |
| 266 |
break; |
| 267 |
case '403 Forbidden': |
| 268 |
$message = __( 'An unexpected error has occurred.', 'usces' ) . '(ERROR403)'; |
| 269 |
break; |
| 270 |
default: |
| 271 |
$message = __( 'Update Right is valid. You can update it.', 'usces' ); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
return $message; |
| 276 |
} |
| 277 |
|
| 278 |
|