| 1 |
<?php |
| 2 |
/** |
| 3 |
* Compatibility layer for the old GVT_API_Manager license system. |
| 4 |
* |
| 5 |
* Old gVectors addons include gvt-api-manager.php, which registers hooks |
| 6 |
* to communicate with the old gVectors license server (gvectors.com/gvt-api.php). |
| 7 |
* This is now superseded by the Paddle module's license system. |
| 8 |
* |
| 9 |
* This file MUST be loaded in the global namespace (before the core plugin namespace). |
| 10 |
* |
| 11 |
* Strategy: |
| 12 |
* 1) Define a dummy GVT_API_Manager class so that old addon copies which |
| 13 |
* include gvt-api-manager.php with `class_exists('GVT_API_Manager')` guard |
| 14 |
* will NOT define or instantiate the real class — prevents all old hooks. |
| 15 |
* |
| 16 |
* 2) If the real class was already loaded (addon loaded before gVectors Core Plugin), |
| 17 |
* remove all hooks registered by GVT_API_Manager instances to stop |
| 18 |
* unnecessary API calls to the old server and conflicting update checks. |
| 19 |
*/ |
| 20 |
|
| 21 |
if( ! class_exists( 'GVT_API_Manager' ) ) { |
| 22 |
/** |
| 23 |
* Dummy GVT_API_Manager class. |
| 24 |
* Accepts the same constructor arguments as the real class but does nothing. |
| 25 |
* Prevents old addon installs from registering legacy license hooks. |
| 26 |
*/ |
| 27 |
class GVT_API_Manager { |
| 28 |
public function __construct( $plugin_filename, $plugin_option_slug, $admin_hook ) { |
| 29 |
// Intentionally empty — old license manager superseded by the Paddle module. |
| 30 |
} |
| 31 |
} |
| 32 |
} else { |
| 33 |
/** |
| 34 |
* Real GVT_API_Manager was already loaded (addon loaded before gVectors Core Plugin). |
| 35 |
* Remove all hooks it registered to prevent: |
| 36 |
* - Update checks against the old gvectors.com server |
| 37 |
* - Old license activation forms and admin notices |
| 38 |
* - Old auto-update UI customizations |
| 39 |
* - Old plugin action links (Disconnect License) |
| 40 |
*/ |
| 41 |
function gvectors_remove_old_gvt_api_manager_hooks() { |
| 42 |
global $wp_filter; |
| 43 |
|
| 44 |
// Collect removals first, then apply — safe against foreach mutation issues |
| 45 |
$removals = []; |
| 46 |
foreach( $wp_filter as $tag => $filter_obj ) { |
| 47 |
if( ! is_object( $filter_obj ) || empty( $filter_obj->callbacks ) ) continue; |
| 48 |
|
| 49 |
foreach( $filter_obj->callbacks as $priority => $callbacks ) { |
| 50 |
foreach( $callbacks as $key => $callback ) { |
| 51 |
if( ! is_array( $callback['function'] ) ) continue; |
| 52 |
if( ! is_object( $callback['function'][0] ) ) continue; |
| 53 |
if( ! ( $callback['function'][0] instanceof GVT_API_Manager ) ) continue; |
| 54 |
|
| 55 |
$removals[] = [ $tag, $priority, $key ]; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
foreach( $removals as $r ) { |
| 61 |
unset( $wp_filter[ $r[0] ]->callbacks[ $r[1] ][ $r[2] ] ); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
add_action( 'plugins_loaded', 'gvectors_remove_old_gvt_api_manager_hooks', 0 ); // priority 0 = as early as possible within plugins_loaded |
| 66 |
add_action( 'wp_loaded', 'gvectors_remove_old_gvt_api_manager_hooks', 999 ); // priority 0 = as early as possible within plugins_loaded |
| 67 |
} |
| 68 |
|