| @@ -57,10 +57,8 @@ | ||
| 57 | 57 | register_activation_hook( WDKIT_FILE, array( __CLASS__, 'wdkit_activation' ) ); |
| 58 | 58 | register_deactivation_hook( WDKIT_FILE, array( __CLASS__, 'wdkit_deactivation' ) ); |
| 59 | 59 | |
| 60 | 60 | add_action( 'plugins_loaded', array( $this, 'wdkit_plugin_loaded' ) ); |
| 61 | - | |
| 62 | - //add_action( 'activated_plugin', array( $this,'wdkit_activate_redirect') ); | |
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | /** |
| 66 | 64 | * Check Setting Panal switch On off |
| @@ -67,10 +65,11 @@ | ||
| 67 | 65 | * |
| 68 | 66 | * @since 1.0.0 |
| 69 | 67 | * |
| 70 | 68 | * @param string $type check builder type. |
| 69 | + * @param mixed $features_manager Optional. The features manager instance or additional settings. Default is an empty string. | |
| 71 | 70 | */ |
| 72 | - public static function wdkit_is_compatible( $type ) { | |
| 71 | + public static function wdkit_is_compatible( $type, $features_manager = '' ) { | |
| 73 | 72 | $wkit_settings_panel = get_option( 'wkit_settings_panel', false ); |
| 74 | 73 | |
| 75 | 74 | if ( empty( $wkit_settings_panel ) ) { |
| 76 | 75 | do_action( 'wdkit_admin_create_default' ); |
| @@ -78,8 +77,10 @@ | ||
| 78 | 77 | return false; |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | $builder = ! empty( $wkit_settings_panel['builder'] ) ? $wkit_settings_panel['builder'] : false; |
| 81 | + $template = ! empty( $wkit_settings_panel['template'] ) ? $wkit_settings_panel['template'] : false; | |
| 82 | + $code_snippet = ! empty( $wkit_settings_panel['code_snippet'] ) ? $wkit_settings_panel['code_snippet'] : false; | |
| 82 | 83 | $b_d_type = false; |
| 83 | 84 | if ( 'elementor' === $type ) { |
| 84 | 85 | $b_d_type = ! empty( $wkit_settings_panel['elementor_builder'] ) ? $wkit_settings_panel['elementor_builder'] : false; |
| 85 | 86 | } elseif ( 'gutenberg' === $type ) { |
| @@ -85,16 +86,30 @@ | ||
| 85 | 86 | } elseif ( 'gutenberg' === $type ) { |
| 86 | 87 | $b_d_type = ! empty( $wkit_settings_panel['gutenberg_builder'] ) ? $wkit_settings_panel['gutenberg_builder'] : false; |
| 87 | 88 | } elseif ( 'bricks' === $type ) { |
| 88 | 89 | $b_d_type = ! empty( $wkit_settings_panel['bricks_builder'] ) ? $wkit_settings_panel['bricks_builder'] : false; |
| 90 | + } elseif ( 'gutenberg_core' === $type ) { | |
| 91 | + $b_d_type = ! empty( $wkit_settings_panel['gutenberg_core_builder'] ) ? $wkit_settings_panel['gutenberg_core_builder'] : false; | |
| 89 | 92 | } elseif ( 'builder' === $type ) { |
| 90 | 93 | $b_d_type = $builder; |
| 94 | + } elseif ( 'template' === $type ) { | |
| 95 | + $b_d_type = ! empty( $wkit_settings_panel['template'] ) ? $wkit_settings_panel['template'] : false; | |
| 96 | + } elseif ( 'gutenberg_template' === $type ) { | |
| 97 | + $b_d_type = ! empty( $wkit_settings_panel['gutenberg_template'] ) ? $wkit_settings_panel['gutenberg_template'] : false; | |
| 98 | + } elseif ( 'elementor_template' === $type ) { | |
| 99 | + $b_d_type = ! empty( $wkit_settings_panel['elementor_template'] ) ? $wkit_settings_panel['elementor_template'] : false; | |
| 100 | + } elseif ( 'code_snippet' === $type ) { | |
| 101 | + $b_d_type = ! empty( $wkit_settings_panel['code_snippet'] ) ? $wkit_settings_panel['code_snippet'] : false; | |
| 91 | 102 | } else { |
| 92 | 103 | $b_d_type = false; |
| 93 | 104 | } |
| 94 | 105 | |
| 95 | - if ( empty( $builder ) || empty( $b_d_type ) ) { | |
| 106 | + if ( 'widget' === $features_manager && empty( $builder ) || empty( $b_d_type ) ) { | |
| 96 | 107 | return false; |
| 108 | + } elseif ( 'template' === $features_manager && empty( $template ) || empty( $b_d_type ) ) { | |
| 109 | + return false; | |
| 110 | + } elseif ( 'code_snippet' === $features_manager && empty( $code_snippet ) || empty( $b_d_type ) ) { | |
| 111 | + return false; | |
| 97 | 112 | } |
| 98 | 113 | |
| 99 | 114 | return true; |
| 100 | 115 | } |
| @@ -105,8 +120,71 @@ | ||
| 105 | 120 | * @return void |
| 106 | 121 | */ |
| 107 | 122 | public static function wdkit_activation() { |
| 108 | 123 | do_action( 'wdkit_admin_create_default' ); |
| 124 | + | |
| 125 | + if ( function_exists( 'wdesignkit_harden_builder_dir' ) && defined( 'WDKIT_BUILDER_PATH' ) ) { | |
| 126 | + wdesignkit_harden_builder_dir( WDKIT_BUILDER_PATH ); | |
| 127 | + } | |
| 128 | + | |
| 129 | + // Rebuild the widget registry from disk on every activation. The cache never expires, so | |
| 130 | + // anything that changed the builder directory while this plugin was inactive — a version | |
| 131 | + // rollback that writes widget files without knowing about the cache, a migration, an | |
| 132 | + // uploads restore, a direct FTP edit — otherwise left a stale cache authoritative with | |
| 133 | + // no self-healing path (ClickUp 86d41cd1z). The cache key also carries WDKIT_VERSION, so | |
| 134 | + // a version change orphans the previous entry; this covers same-version reactivation. | |
| 135 | + if ( function_exists( 'wdesignkit_invalidate_widget_registry' ) ) { | |
| 136 | + foreach ( array( 'elementor', 'gutenberg', 'gutenberg_core', 'bricks' ) as $builder_slug ) { | |
| 137 | + wdesignkit_invalidate_widget_registry( $builder_slug ); | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | + // Collect the registry caches belonging to OTHER versions while we are here. The line | |
| 142 | + // above only clears the current version's keys — by design, since those are the ones that | |
| 143 | + // might be stale. The old versions' keys were never deleted by anything, so each release | |
| 144 | + // left one permanent row per builder in wp_options (verified: twelve rows across three | |
| 145 | + // versions on a twice-upgraded site). Activation is the natural place for the sweep: it is | |
| 146 | + // the one moment the plugin knows the version may just have changed. | |
| 147 | + if ( function_exists( 'wdesignkit_purge_stale_widget_registries' ) ) { | |
| 148 | + wdesignkit_purge_stale_widget_registries(); | |
| 149 | + } | |
| 150 | + | |
| 151 | + // Scheduling belongs here rather than in the request path (ClickUp 86d41cp05). | |
| 152 | + if ( function_exists( 'wdesignkit_schedule_widget_trash_purge' ) ) { | |
| 153 | + wdesignkit_schedule_widget_trash_purge(); | |
| 154 | + } | |
| 155 | + | |
| 156 | + /* | |
| 157 | + * Report this activation to the analytics hub, and stamp the install time. | |
| 158 | + * | |
| 159 | + * The SDK's `activated_plugin` listener cannot see a plugin's OWN activation: WordPress has | |
| 160 | + * already fired `plugins_loaded` before it includes the plugin file, so the plugins_loaded | |
| 161 | + * callback in wdesignkit.php never runs this request, Posimyth_Tracker_WDK::init() never | |
| 162 | + * registers, and nothing is listening when `activated_plugin` fires. Deactivation worked | |
| 163 | + * (the plugin IS loaded there) while activation silently reported nothing — and because | |
| 164 | + * on_deactivate() clears the activate-reported flag, every deactivate/reactivate cycle lost | |
| 165 | + * one activation from the hub's count for good. on_self_activate() is the SDK's documented | |
| 166 | + * entry point for exactly this, and it is consent-gated like every other event. | |
| 167 | + * | |
| 168 | + * The subclass has to be required by hand here for the same reason: the plugins_loaded | |
| 169 | + * callback that normally requires it does not run during this request. The shared base is | |
| 170 | + * already loaded — posimyth_sdk_register() in wdesignkit.php loads immediately when | |
| 171 | + * plugins_loaded has already fired. | |
| 172 | + * | |
| 173 | + * The leading backslash is required and is not decoration: this file declares | |
| 174 | + * `namespace wdkit` and the SDK class is global, so without it PHP resolves the call as | |
| 175 | + * `wdkit\Posimyth_Tracker_WDK` and fatals — exactly as documented in wdkit_deactivation() | |
| 176 | + * below. The class_exists() guard does not protect against that, because its argument is a | |
| 177 | + * string and strings are always read as fully qualified. | |
| 178 | + */ | |
| 179 | + $wdkit_tracker = WDKIT_PATH . 'includes/posimyth-sdk/class-posimyth-tracker-wdk.php'; | |
| 180 | + if ( is_readable( $wdkit_tracker ) ) { | |
| 181 | + require_once $wdkit_tracker; | |
| 182 | + } | |
| 183 | + | |
| 184 | + if ( class_exists( 'Posimyth_Tracker_WDK' ) ) { | |
| 185 | + \Posimyth_Tracker_WDK::on_self_activate(); | |
| 186 | + } | |
| 109 | 187 | } |
| 110 | 188 | |
| 111 | 189 | /** |
| 112 | 190 | * Plugin deactivation. |
| @@ -113,8 +191,39 @@ | ||
| 113 | 191 | * |
| 114 | 192 | * @return void |
| 115 | 193 | */ |
| 116 | 194 | public static function wdkit_deactivation() { |
| 195 | + $get_white_label = get_option( 'wkit_white_label' ); | |
| 196 | + | |
| 197 | + if ( ! empty( $get_white_label ) ) { | |
| 198 | + delete_option( 'wkit_white_label' ); | |
| 199 | + } | |
| 200 | + | |
| 201 | + /* | |
| 202 | + * Stop the analytics heartbeat. | |
| 203 | + * | |
| 204 | + * Posimyth_Tracker_WDK::init() schedules a weekly `posimyth_heartbeat_wdk` event. Without | |
| 205 | + * this, deactivating the plugin leaves that event in WordPress forever — firing against a | |
| 206 | + * hook with no listener and showing up in every cron listing. Deactivation only, never | |
| 207 | + * uninstall: purge_state() in uninstall.php handles the stored options, and calling that | |
| 208 | + * here would wipe consent every time someone toggled the plugin off. | |
| 209 | + * | |
| 210 | + * The leading backslash is required and is not decoration. This file declares | |
| 211 | + * `namespace wdkit`, and the SDK class is global — without it PHP resolves the call as | |
| 212 | + * `wdkit\Posimyth_Tracker_WDK` and fatals on deactivation. The class_exists() guard above | |
| 213 | + * does NOT catch that: its argument is a string, which is always read as fully qualified, | |
| 214 | + * so the guard passed and the very next line died. | |
| 215 | + */ | |
| 216 | + if ( class_exists( 'Posimyth_Tracker_WDK' ) ) { | |
| 217 | + \Posimyth_Tracker_WDK::unschedule(); | |
| 218 | + } | |
| 219 | + | |
| 220 | + // Widget-trash purge cron, added on release. Unrelated to the heartbeat above — both are | |
| 221 | + // scheduled by this plugin, so deactivation has to clear both or the survivor is orphaned. | |
| 222 | + $timestamp = wp_next_scheduled( 'wdesignkit_purge_widget_trash_cron' ); | |
| 223 | + if ( $timestamp ) { | |
| 224 | + wp_unschedule_event( $timestamp, 'wdesignkit_purge_widget_trash_cron' ); | |
| 225 | + } | |
| 117 | 226 | } |
| 118 | 227 | |
| 119 | 228 | /** |
| 120 | 229 | * Files load plugin loaded. |
| @@ -127,12 +236,15 @@ | ||
| 127 | 236 | } |
| 128 | 237 | |
| 129 | 238 | /** |
| 130 | 239 | * Load Text Domain. |
| 131 | - * Text Domain : wdkit | |
| 240 | + * On WP 6.7+ core auto-loads translations via the plugin header; the | |
| 241 | + * manual call is only needed for WP 6.0–6.6. | |
| 132 | 242 | */ |
| 133 | 243 | public function load_textdomain() { |
| 134 | - load_plugin_textdomain( 'wdesignkit', false, WDKIT_BDNAME . '/languages/' ); | |
| 244 | + if ( version_compare( get_bloginfo( 'version' ), '6.7', '<' ) ) { | |
| 245 | + load_plugin_textdomain( 'wdesignkit', false, WDKIT_BDNAME . '/languages/' ); | |
| 246 | + } | |
| 135 | 247 | } |
| 136 | 248 | |
| 137 | 249 | /** |
| 138 | 250 | * Load the required dependencies for this plugin. |
| @@ -146,30 +258,37 @@ | ||
| 146 | 258 | |
| 147 | 259 | /** |
| 148 | 260 | * The class responsible for defining all actions that occur in the admin area. |
| 149 | 261 | */ |
| 262 | + require_once WDKIT_INCLUDES . 'admin/white_label/class-wdkit-white-label.php'; | |
| 263 | + | |
| 150 | 264 | require_once WDKIT_INCLUDES . 'admin/notices/class-wdkit-notice-main.php'; |
| 151 | 265 | |
| 266 | + require_once WDKIT_INCLUDES . 'admin/hooks/class-wdkit-dashboard-main.php'; | |
| 267 | + | |
| 152 | 268 | require_once WDKIT_INCLUDES . 'admin/class-wdkit-enqueue.php'; |
| 153 | 269 | require_once WDKIT_INCLUDES . 'admin/class-wdesignkit-data-query.php'; |
| 154 | 270 | require_once WDKIT_INCLUDES . 'admin/class-wdkit-depends-installer.php'; |
| 155 | - require_once WDKIT_INCLUDES . 'admin/class-api.php'; | |
| 156 | 271 | |
| 272 | + // PHP importer service layer. Class definitions only - registers no hooks and | |
| 273 | + // instantiates nothing, so this is inert until something calls it. The browser | |
| 274 | + // importer does not, and its AJAX path is unchanged. | |
| 275 | + require_once WDKIT_INCLUDES . 'admin/import/import-load.php'; | |
| 276 | + | |
| 277 | + // Must load before widget-load-files.php: the Gutenberg/Gutenberg Core loaders | |
| 278 | + // register their widgets synchronously in their own constructor (not on a later | |
| 279 | + // hook), so wdesignkit_get_widget_registry() has to already be defined by the | |
| 280 | + // time widget-load-files.php requires and instantiates them below. | |
| 281 | + require_once WDKIT_INCLUDES . 'abilities/class-wdk-ability-main.php'; | |
| 282 | + | |
| 283 | + // WordPress 7.1 ability execution lifecycle hooks. Inert on older versions | |
| 284 | + // (the hook names simply do not exist), so it is loaded unconditionally. | |
| 285 | + require_once WDKIT_INCLUDES . 'abilities/class-wdk-ability-lifecycle.php'; | |
| 286 | + | |
| 157 | 287 | require_once WDKIT_INCLUDES . 'widget-load/widget-load-files.php'; |
| 288 | + require_once WDKIT_INCLUDES . 'widget-load/dynamic-listing/dynamic-listing.php'; | |
| 158 | 289 | } |
| 159 | 290 | |
| 160 | - /** | |
| 161 | - * Activation Reset | |
| 162 | - * | |
| 163 | - * @since 1.0.9 | |
| 164 | - */ | |
| 165 | - public function wdkit_activate_redirect( $plugin ){ | |
| 166 | - | |
| 167 | - if( 'wdesignkit/wdesignkit.php' === $plugin ) { | |
| 168 | - exit( wp_redirect( admin_url( 'admin.php?page=wdesign-kit' ) ) ); | |
| 169 | - } | |
| 170 | - | |
| 171 | - } | |
| 172 | 291 | } |
| 173 | 292 | |
| 174 | 293 | Wdkit_Wdesignkit::get_instance(); |
| 175 | 294 | } |