| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use PXLBSAdminify\Libs\Featured; |
| 6 | 6 | use PXLBSAdminify\Inc\Admin\Admin; |
| 7 | 7 | use PXLBSAdminify\Inc\Classes\Assets; |
| 8 | +use PXLBSAdminify\Inc\Classes\IconPicker_Assets; | |
| 8 | 9 | use PXLBSAdminify\Inc\Classes\Upgrade; |
| 9 | 10 | use PXLBSAdminify\Inc\Classes\Feedback; |
| 10 | 11 | use PXLBSAdminify\Inc\Admin\AdminSettings; |
| 11 | 12 | use PXLBSAdminify\Inc\Classes\Pro_Upgrade; |
| @@ -21,8 +22,10 @@ | ||
| 21 | 22 | const VERSION = PXLBSADMINIFY_VER; |
| 22 | 23 | |
| 23 | 24 | private static $instance = null; |
| 24 | 25 | |
| 26 | + private $was_active_before_update = false; | |
| 27 | + | |
| 25 | 28 | public function __construct() { |
| 26 | 29 | add_action( 'plugins_loaded', array($this, 'maybe_run_upgrades'), -100 ); |
| 27 | 30 | // This should run earlier |
| 28 | 31 | add_action( 'plugins_loaded', array($this, 'maybe_loaded_addons'), -200 ); |
| @@ -28,8 +31,21 @@ | ||
| 28 | 31 | add_action( 'plugins_loaded', array($this, 'maybe_loaded_addons'), -200 ); |
| 29 | 32 | // add_action('plugins_loaded', array($this, 'pxlbsadminify_plugins_loaded'), 999); |
| 30 | 33 | add_filter( 'plugin_action_links_' . PXLBSADMINIFY_BASE, array($this, 'plugin_action_links') ); |
| 31 | 34 | add_filter( 'network_admin_plugin_action_links_' . PXLBSADMINIFY_BASE, array($this, 'plugin_action_links') ); |
| 35 | + // Freemius drops this plugin from `active_plugins` when it updates itself. | |
| 36 | + add_filter( | |
| 37 | + 'upgrader_pre_install', | |
| 38 | + array($this, 'pxlbsadminify_remember_active_state'), | |
| 39 | + 1, | |
| 40 | + 2 | |
| 41 | + ); | |
| 42 | + add_filter( | |
| 43 | + 'upgrader_post_install', | |
| 44 | + array($this, 'pxlbsadminify_restore_active_state'), | |
| 45 | + 20, | |
| 46 | + 3 | |
| 47 | + ); | |
| 32 | 48 | add_filter( 'admin_body_class', array($this, 'pxlbsadminify_body_class'), 99 ); |
| 33 | 49 | // Load textdomain and include files on init for WP 6.7+ compatibility |
| 34 | 50 | // Textdomain must be loaded before files that use translations |
| 35 | 51 | // Priority order: 0=textdomain, 1=include files (registers options), 5=framework setup |
| @@ -45,8 +61,55 @@ | ||
| 45 | 61 | } |
| 46 | 62 | jltwp_adminify()->add_filter( 'pricing_url', [$this, 'pxlbsadminify_pricing_url'] ); |
| 47 | 63 | } |
| 48 | 64 | |
| 65 | + /** | |
| 66 | + * Record whether this plugin was active when its own update starts. | |
| 67 | + * | |
| 68 | + * @param bool|\WP_Error $response Install response. | |
| 69 | + * @param array $hook_extra Extra arguments passed to hooked filters. | |
| 70 | + * | |
| 71 | + * @return bool|\WP_Error | |
| 72 | + */ | |
| 73 | + public function pxlbsadminify_remember_active_state( $response, $hook_extra ) { | |
| 74 | + if ( !empty( $hook_extra['plugin'] ) && PXLBSADMINIFY_BASE === $hook_extra['plugin'] ) { | |
| 75 | + $this->was_active_before_update = in_array( PXLBSADMINIFY_BASE, (array) get_option( 'active_plugins', array() ), true ); | |
| 76 | + } | |
| 77 | + return $response; | |
| 78 | + } | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * Put this plugin back into `active_plugins` after its own update. | |
| 82 | + * | |
| 83 | + * The Freemius SDK assumes the free and the premium build never run side by side, | |
| 84 | + * so FS_Plugin_Updater::_maybe_update_folder_name() rewrites our `active_plugins` | |
| 85 | + * entry to the premium basename once the free package is updated while Adminify Pro | |
| 86 | + * is installed - which silently deactivates this plugin. Both packages have to stay | |
| 87 | + * active here, so restore the entry the SDK removed. | |
| 88 | + * | |
| 89 | + * Network activations are unaffected: those live in `active_sitewide_plugins`, which | |
| 90 | + * the SDK handler never touches. | |
| 91 | + * | |
| 92 | + * @param bool|\WP_Error $response Install response. | |
| 93 | + * @param array $hook_extra Extra arguments passed to hooked filters. | |
| 94 | + * @param array $result Installation result data. | |
| 95 | + * | |
| 96 | + * @return bool|\WP_Error | |
| 97 | + */ | |
| 98 | + public function pxlbsadminify_restore_active_state( $response, $hook_extra, $result ) { | |
| 99 | + if ( empty( $hook_extra['plugin'] ) || PXLBSADMINIFY_BASE !== $hook_extra['plugin'] || !$this->was_active_before_update ) { | |
| 100 | + return $response; | |
| 101 | + } | |
| 102 | + $active_plugins = (array) get_option( 'active_plugins', array() ); | |
| 103 | + if ( !in_array( PXLBSADMINIFY_BASE, $active_plugins, true ) ) { | |
| 104 | + $active_plugins[] = PXLBSADMINIFY_BASE; | |
| 105 | + $active_plugins = array_values( array_unique( $active_plugins ) ); | |
| 106 | + sort( $active_plugins ); | |
| 107 | + update_option( 'active_plugins', $active_plugins ); | |
| 108 | + } | |
| 109 | + return $response; | |
| 110 | + } | |
| 111 | + | |
| 49 | 112 | function pxlbsadminify_pricing_url( $pricing_url ) { |
| 50 | 113 | $pricing_url = 'https://wpadminify.com/pricing'; |
| 51 | 114 | return $pricing_url; |
| 52 | 115 | } |
| @@ -130,8 +193,9 @@ | ||
| 130 | 193 | } |
| 131 | 194 | |
| 132 | 195 | public function pxlbsadminify_include_files() { |
| 133 | 196 | new Assets(); |
| 197 | + new IconPicker_Assets(); | |
| 134 | 198 | new Admin(); |
| 135 | 199 | new Featured(); |
| 136 | 200 | new Feedback(); |
| 137 | 201 | new Notifications(); |