← All changes
|
jetpack_vendor/automattic/jetpack-licensing/src/class-licensing.php
+34
-3
13.7.2
→
16.3-beta
View file →
| @@ -66,8 +66,39 @@ | ||
| 66 | 66 | add_action( 'rest_api_init', array( $this, 'initialize_endpoints' ) ); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | + * Register the hooks the package needs on every request. | |
| 71 | + * | |
| 72 | + * Separate from `initialize()`, which consumers call only when they offer the | |
| 73 | + * licensing UI: the activation screen also renders from the Jetpack plugin's | |
| 74 | + * own route, so the illustrations need a URL there too. | |
| 75 | + * | |
| 76 | + * @since 4.1.0 | |
| 77 | + * | |
| 78 | + * @return void | |
| 79 | + */ | |
| 80 | + public static function configure() { | |
| 81 | + add_filter( 'jetpack_admin_js_script_data', array( self::class, 'add_script_data' ) ); | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Add the package's image base URL to the admin script data. | |
| 86 | + * | |
| 87 | + * Other plugins' bundles request the activation screen's images from this copy, so never rename one. | |
| 88 | + * | |
| 89 | + * @since 4.1.0 | |
| 90 | + * | |
| 91 | + * @param array $data Script data. | |
| 92 | + * @return array | |
| 93 | + */ | |
| 94 | + public static function add_script_data( $data ) { | |
| 95 | + $data['licensing']['assetsUrl'] = trailingslashit( plugins_url( 'assets/images/', __DIR__ ) ); | |
| 96 | + | |
| 97 | + return $data; | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 70 | 101 | * Initialize endpoints required for Licensing package. |
| 71 | 102 | * |
| 72 | 103 | * @since 1.7.0 |
| 73 | 104 | * |
| @@ -286,9 +317,9 @@ | ||
| 286 | 317 | |
| 287 | 318 | /** |
| 288 | 319 | * Load current user's licenses. |
| 289 | 320 | * |
| 290 | - * @param bool $unattached_only Only return unattached licenses. | |
| 321 | + * @param bool $unattached_only Only return unattached and not revoked licenses. | |
| 291 | 322 | * |
| 292 | 323 | * @return array |
| 293 | 324 | */ |
| 294 | 325 | public function get_user_licenses( $unattached_only = false ) { |
| @@ -303,9 +334,9 @@ | ||
| 303 | 334 | if ( $unattached_only ) { |
| 304 | 335 | $items = array_filter( |
| 305 | 336 | $items, |
| 306 | 337 | static function ( $item ) { |
| 307 | - return $item->attached_at === null; | |
| 338 | + return $item->attached_at === null && $item->revoked_at === null; | |
| 308 | 339 | } |
| 309 | 340 | ); |
| 310 | 341 | } |
| 311 | 342 | |
| @@ -352,8 +383,8 @@ | ||
| 352 | 383 | if ( $plugin_slug && count( $licenses ) |
| 353 | 384 | && apply_filters( 'jetpack_connection_user_has_license', false, $licenses, $plugin_slug ) |
| 354 | 385 | ) { |
| 355 | 386 | wp_safe_redirect( '/wp-admin/admin.php?page=my-jetpack#/add-license' ); |
| 356 | - exit; | |
| 387 | + exit( 0 ); | |
| 357 | 388 | } |
| 358 | 389 | } |
| 359 | 390 | } |