| @@ -1,11 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * PHP snippets plugin base |
| 4 | 4 | * |
| 5 | - * @author Webcraftic <WordPress.webraftic@gmail.com> | |
| 6 | - * @copyright (c) 19.02.2018, Webcraftic | |
| 7 | - * @version 1.0 | |
| 5 | + * @package Woody_Code_Snippets | |
| 8 | 6 | */ |
| 9 | 7 | |
| 10 | 8 | // Exit if accessed directly |
| 11 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -13,79 +11,116 @@ | ||
| 13 | 11 | } |
| 14 | 12 | |
| 15 | 13 | if ( ! class_exists( 'WINP_Plugin' ) ) { |
| 16 | 14 | |
| 17 | - class WINP_Plugin extends Wbcr_Factory475_Plugin { | |
| 15 | + class WINP_Plugin { | |
| 18 | 16 | |
| 19 | 17 | /** |
| 20 | - * @var Wbcr_Factory475_Plugin | |
| 18 | + * Custom license provider (overrides parent's premium property) | |
| 19 | + * | |
| 20 | + * @var WINP_License | |
| 21 | 21 | */ |
| 22 | + public $premium; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * @var WINP_Plugin | |
| 26 | + */ | |
| 22 | 27 | private static $app; |
| 23 | 28 | |
| 24 | 29 | /** |
| 25 | - * @param string $plugin_path | |
| 26 | - * @param array $data | |
| 30 | + * Snippets custom post type instance. | |
| 27 | 31 | * |
| 32 | + * @var WINP_SnippetsType|null | |
| 33 | + */ | |
| 34 | + private $snippets_type; | |
| 35 | + | |
| 36 | + /** | |
| 28 | 37 | * @throws Exception |
| 29 | 38 | */ |
| 30 | - public function __construct( $plugin_path, $data ) { | |
| 31 | - parent::__construct( $plugin_path, $data ); | |
| 39 | + public function __construct() { | |
| 40 | + self::$app = $this; | |
| 32 | 41 | |
| 33 | - self::$app = $this; | |
| 42 | + // Initialize custom license provider. | |
| 43 | + require_once WINP_PLUGIN_DIR . '/includes/class.license.php'; | |
| 44 | + $this->premium = new WINP_License(); | |
| 34 | 45 | |
| 46 | + require_once WINP_PLUGIN_DIR . '/includes/class.rest.php'; | |
| 47 | + new WINP_Rest(); | |
| 48 | + | |
| 49 | + require_once WINP_PLUGIN_DIR . '/admin/pages/class.settings.php'; | |
| 50 | + require_once WINP_PLUGIN_DIR . '/admin/pages/class.new-item.php'; | |
| 51 | + require_once WINP_PLUGIN_DIR . '/admin/pages/class.snippet-library.php'; | |
| 52 | + | |
| 53 | + WINP_Settings::get_instance(); | |
| 54 | + WINP_NewItem::get_instance(); | |
| 55 | + WINP_SnippetLibrary::get_instance(); | |
| 56 | + | |
| 35 | 57 | $this->load_global(); |
| 36 | 58 | |
| 37 | - if ( is_admin() ) { | |
| 38 | - $this->initActivation(); | |
| 59 | + if ( is_admin() || WINP_Helper::doing_rest_api() ) { | |
| 39 | 60 | |
| 40 | 61 | if ( WINP_Helper::doing_ajax() ) { |
| 41 | 62 | require WINP_PLUGIN_DIR . '/admin/ajax/ajax.php'; |
| 42 | - require WINP_PLUGIN_DIR . '/admin/ajax/check-license.php'; | |
| 43 | 63 | require WINP_PLUGIN_DIR . '/admin/ajax/snippet-library.php'; |
| 44 | 64 | } |
| 45 | 65 | |
| 46 | 66 | $this->load_backend(); |
| 47 | 67 | } |
| 48 | - add_action( 'init', function () { | |
| 49 | - if(WINP_Plugin::app()->premium->is_active()){ | |
| 50 | - update_option( 'insert_php_logger_flag', 'yes' ); | |
| 68 | + add_action( | |
| 69 | + 'init', | |
| 70 | + function () { | |
| 71 | + if ( WINP_Plugin::app()->premium->is_active() ) { | |
| 72 | + update_option( WINP_PLUGIN_NAMESPACE . '_logger_flag', 'yes' ); | |
| 73 | + } | |
| 51 | 74 | } |
| 52 | - } ); | |
| 53 | - add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] ); | |
| 54 | - add_filter( 'themeisle_sdk_ran_promos', [ __CLASS__, 'sdk_hide_promo_notice' ] ); | |
| 75 | + ); | |
| 76 | + | |
| 77 | + add_filter( WINP_PLUGIN_NAMESPACE . '_logger_data', [ $this, 'get_logger_data' ] ); | |
| 78 | + add_filter( 'themeisle_sdk_blackfriday_data', [ $this, 'add_black_friday_data' ] ); | |
| 55 | 79 | } |
| 56 | 80 | |
| 57 | 81 | /** |
| 58 | - * Hide SDK promo notice for pro uses. | |
| 82 | + * Get plugin instance | |
| 59 | 83 | * |
| 60 | - * @access public | |
| 84 | + * @return WINP_Plugin | |
| 61 | 85 | */ |
| 62 | - public static function sdk_hide_promo_notice( $should_show ) { | |
| 63 | - return WINP_Plugin::app()->premium->is_active(); | |
| 86 | + public static function app() { | |
| 87 | + return self::$app; | |
| 64 | 88 | } |
| 89 | + | |
| 65 | 90 | /** |
| 66 | - * Register product into SDK. | |
| 91 | + * Survey data. | |
| 67 | 92 | * |
| 68 | - * @param array $products All products. | |
| 69 | - * | |
| 70 | - * @return array Registered product. | |
| 93 | + * @return array<string, mixed> | |
| 71 | 94 | */ |
| 72 | - public static function register_sdk( $products ) { | |
| 73 | - $products[] = WINP_PLUGIN_FILE; | |
| 95 | + public function get_survey_data() { | |
| 96 | + $install_time = get_option( WINP_PLUGIN_NAMESPACE . '_install', time() ); | |
| 97 | + $days_since_install = round( ( time() - $install_time ) / DAY_IN_SECONDS ); | |
| 98 | + $total_snippets = wp_count_posts( WINP_SNIPPETS_POST_TYPE ); | |
| 99 | + $total_snippets = isset( $total_snippets->publish ) ? $total_snippets->publish : 0; | |
| 74 | 100 | |
| 75 | - return $products; | |
| 101 | + $data = [ | |
| 102 | + 'environmentId' => 'cmiooosih4vm0ad01eihjub64', | |
| 103 | + 'attributes' => [ | |
| 104 | + 'free_version' => WINP_PLUGIN_VERSION, | |
| 105 | + 'pro_version' => defined( 'WASP_PLUGIN_VERSION' ) ? WASP_PLUGIN_VERSION : '', | |
| 106 | + 'install_days_number' => $days_since_install, | |
| 107 | + 'license_status' => self::app()->premium->is_active(), | |
| 108 | + 'total_snippets' => $total_snippets, | |
| 109 | + ], | |
| 110 | + ]; | |
| 111 | + | |
| 112 | + if ( self::app()->premium->is_active() ) { | |
| 113 | + $data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', self::app()->premium->get_key() ); | |
| 114 | + } | |
| 115 | + | |
| 116 | + return $data; | |
| 76 | 117 | } |
| 77 | - /** | |
| 78 | - * @return WINP_Plugin | |
| 79 | - */ | |
| 80 | - public static function app() { | |
| 81 | - return self::$app; | |
| 82 | - } | |
| 83 | 118 | |
| 84 | 119 | /** |
| 85 | 120 | * @return bool |
| 86 | 121 | */ |
| 87 | - public function currentUserCan() { | |
| 122 | + public function current_user_car() { | |
| 88 | 123 | return current_user_can( 'manage_options' ); |
| 89 | 124 | } |
| 90 | 125 | |
| 91 | 126 | /** |
| @@ -92,12 +127,12 @@ | ||
| 92 | 127 | * Get Execute_Snippet object |
| 93 | 128 | * |
| 94 | 129 | * @return WINP_Execute_Snippet |
| 95 | 130 | */ |
| 96 | - public function getExecuteObject() { | |
| 131 | + public function get_execute_object() { | |
| 97 | 132 | require_once WINP_PLUGIN_DIR . '/includes/class.execute.snippet.php'; |
| 98 | 133 | |
| 99 | - return new WINP_Execute_Snippet(); | |
| 134 | + return WINP_Execute_Snippet::app(); | |
| 100 | 135 | } |
| 101 | 136 | |
| 102 | 137 | /** |
| 103 | 138 | * Get WINP_Api object |
| @@ -104,8 +139,9 @@ | ||
| 104 | 139 | * |
| 105 | 140 | * @return WINP_Api |
| 106 | 141 | */ |
| 107 | 142 | public function get_api_object() { |
| 143 | + require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php'; | |
| 108 | 144 | require_once WINP_PLUGIN_DIR . '/admin/includes/class.api.php'; |
| 109 | 145 | |
| 110 | 146 | return new WINP_Api(); |
| 111 | 147 | } |
| @@ -121,69 +157,76 @@ | ||
| 121 | 157 | return new WINP_Common_Snippet(); |
| 122 | 158 | } |
| 123 | 159 | |
| 124 | 160 | /** |
| 125 | - * @throws \Exception | |
| 126 | - * @since 2.2.0 | |
| 127 | - * @author Alexander Kovalev <alex.kovalevv@gmail.com> | |
| 161 | + * Plugin activation hook. | |
| 162 | + * Creates demo snippets on first activation and sets up capabilities. | |
| 163 | + * | |
| 164 | + * @return void | |
| 128 | 165 | */ |
| 129 | - /* | |
| 130 | - public function plugins_loaded() { | |
| 131 | - $this->register_pages(); | |
| 132 | - }*/ | |
| 166 | + public function activation_hook() { | |
| 167 | + // Add custom capabilities to administrator role. | |
| 168 | + $this->get_snippets_type()->add_capabilities(); | |
| 133 | 169 | |
| 134 | - protected function initActivation() { | |
| 135 | - include_once WINP_PLUGIN_DIR . '/admin/activation.php'; | |
| 136 | - $this->registerActivation( 'WINP_Activation' ); | |
| 170 | + // Create demo snippets with examples of use. | |
| 171 | + if ( ! get_option( 'wbcr_inp_demo_snippets_created' ) ) { | |
| 172 | + WINP_Helper::create_demo_snippets(); | |
| 173 | + } | |
| 174 | + | |
| 175 | + WINP_Helper::flush_page_cache(); | |
| 137 | 176 | } |
| 138 | 177 | |
| 139 | 178 | /** |
| 140 | - * @throws \Exception | |
| 141 | - * @since 2.2.0 | |
| 142 | - * @author Alexander Kovalev <alex.kovalevv@gmail.com> | |
| 179 | + * Plugin deactivation hook. | |
| 180 | + * Removes custom capabilities. | |
| 181 | + * | |
| 182 | + * @return void | |
| 143 | 183 | */ |
| 144 | - public function register_pages() { | |
| 145 | - require_once WINP_PLUGIN_DIR . '/admin/pages/page.php'; | |
| 146 | - | |
| 147 | - $this->registerPage( 'WINP_NewItemPage', WINP_PLUGIN_DIR . '/admin/pages/new-item.php' ); | |
| 148 | - $this->registerPage( 'WINP_SettingsPage', WINP_PLUGIN_DIR . '/admin/pages/settings.php' ); | |
| 149 | - $this->registerPage( 'WINP_SnippetLibraryPage', WINP_PLUGIN_DIR . '/admin/pages/snippet-library.php' ); | |
| 150 | - $this->registerPage( 'WINP_License_Page', WINP_PLUGIN_DIR . '/admin/pages/license.php' ); | |
| 151 | - $this->registerPage( 'WINP_AboutPage', WINP_PLUGIN_DIR . '/admin/pages/about.php' ); | |
| 184 | + public function deactivation_hook() { | |
| 185 | + // Remove custom capabilities from administrator role. | |
| 186 | + $this->get_snippets_type()->remove_capabilities(); | |
| 152 | 187 | } |
| 153 | 188 | |
| 154 | 189 | /** |
| 155 | - * @throws \Exception | |
| 156 | - * @since 2.2.0 | |
| 157 | - * @author Alexander Kovalev <alex.kovalevv@gmail.com> | |
| 190 | + * Get the snippets post type handler, loading it on demand. | |
| 191 | + * | |
| 192 | + * The (de)activation hooks can run outside of admin/REST requests | |
| 193 | + * (e.g. `wp plugin activate` via WP-CLI), where load_backend() and | |
| 194 | + * therefore register_types() never ran. | |
| 195 | + * | |
| 196 | + * @return WINP_SnippetsType | |
| 158 | 197 | */ |
| 159 | - public function register_depence_pages() { | |
| 160 | - require_once WINP_PLUGIN_DIR . '/admin/pages/page.php'; | |
| 198 | + private function get_snippets_type() { | |
| 199 | + if ( is_null( $this->snippets_type ) ) { | |
| 200 | + require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php'; | |
| 201 | + require_once WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php'; | |
| 202 | + $this->snippets_type = new WINP_SnippetsType(); | |
| 203 | + } | |
| 161 | 204 | |
| 162 | - if ( ! ( defined( 'WASP_PLUGIN_ACTIVE' ) && WASP_PLUGIN_ACTIVE ) ) { | |
| 163 | - $this->registerPage( 'WINP_ImportPage', WINP_PLUGIN_DIR . '/admin/pages/import.php' ); | |
| 164 | - } | |
| 205 | + return $this->snippets_type; | |
| 165 | 206 | } |
| 166 | 207 | |
| 167 | 208 | /** |
| 168 | - * @throws \Exception | |
| 209 | + * Register custom post types and taxonomies. | |
| 210 | + * | |
| 211 | + * @throws \Exception Exception. | |
| 169 | 212 | * @since 2.2.0 |
| 170 | - * @author Alexander Kovalev <alex.kovalevv@gmail.com> | |
| 171 | 213 | */ |
| 172 | 214 | private function register_types() { |
| 173 | 215 | require_once WINP_PLUGIN_DIR . '/admin/types/snippets-post-types.php'; |
| 174 | - Wbcr_FactoryTypes415::register( 'WINP_SnippetsType', $this ); | |
| 216 | + $this->snippets_type = new WINP_SnippetsType(); | |
| 175 | 217 | |
| 176 | 218 | require_once WINP_PLUGIN_DIR . '/admin/types/snippets-taxonomy.php'; |
| 177 | - Wbcr_FactoryTaxonomies335::register( 'WINP_SnippetsTaxonomy', $this ); | |
| 219 | + new WINP_SnippetsTaxonomy(); | |
| 178 | 220 | } |
| 179 | 221 | |
| 180 | 222 | /** |
| 181 | - * @author Alexander Kovalev <alex.kovalevv@gmail.com> | |
| 223 | + * Register shortcodes. | |
| 224 | + * | |
| 182 | 225 | * @since 2.2.0 |
| 183 | 226 | */ |
| 184 | 227 | private function register_shortcodes() { |
| 185 | - $action = self::app()->request->get( 'action', '' ); | |
| 228 | + $action = WINP_HTTP::get( 'action', '' ); | |
| 186 | 229 | if ( ! ( 'edit' == $action && is_admin() ) ) { |
| 187 | 230 | require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcodes.php'; |
| 188 | 231 | require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-php.php'; |
| 189 | 232 | require_once WINP_PLUGIN_DIR . '/includes/shortcodes/shortcode-text.php'; |
| @@ -205,35 +248,19 @@ | ||
| 205 | 248 | |
| 206 | 249 | /** |
| 207 | 250 | * Initialization and require files for backend and frontend. |
| 208 | 251 | * |
| 209 | - * @author Alexander Kovalev <alex.kovalevv@gmail.com> | |
| 210 | 252 | * @since 2.2.0 |
| 211 | 253 | */ |
| 212 | 254 | private function load_global() { |
| 213 | 255 | require_once WINP_PLUGIN_DIR . '/admin/includes/class.gutenberg.snippet.php'; |
| 256 | + require_once WINP_PLUGIN_DIR . '/includes/class.admin-bar.php'; | |
| 214 | 257 | |
| 215 | 258 | new WINP_Gutenberg_Snippet(); |
| 259 | + WINP_Admin_Bar::instance(); | |
| 216 | 260 | |
| 217 | - $this->getExecuteObject()->registerHooks(); | |
| 261 | + $this->get_execute_object()->register_hooks(); | |
| 218 | 262 | $this->register_shortcodes(); |
| 219 | - | |
| 220 | - /** | |
| 221 | - * Enables/Disable safe mode, in which the php code will not be executed. | |
| 222 | - */ | |
| 223 | - add_action( 'plugins_loaded', function () { | |
| 224 | - if ( isset( $_GET['wbcr-php-snippets-safe-mode'] ) ) { | |
| 225 | - WINP_Helper::enable_safe_mode(); | |
| 226 | - wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-safe-mode' ] ) ) ); | |
| 227 | - die(); | |
| 228 | - } | |
| 229 | - | |
| 230 | - if ( isset( $_GET['wbcr-php-snippets-disable-safe-mode'] ) ) { | |
| 231 | - WINP_Helper::disable_safe_mode(); | |
| 232 | - wp_safe_redirect( esc_url( remove_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' ] ) ) ); | |
| 233 | - die(); | |
| 234 | - } | |
| 235 | - }, - 1 ); | |
| 236 | 263 | } |
| 237 | 264 | |
| 238 | 265 | /** |
| 239 | 266 | * Initialization and require files for backend. |
| @@ -239,46 +266,40 @@ | ||
| 239 | 266 | * Initialization and require files for backend. |
| 240 | 267 | * |
| 241 | 268 | * @throws \Exception |
| 242 | 269 | * @since 2.2.0 |
| 243 | - * @author Alexander Kovalev <alex.kovalevv@gmail.com> | |
| 244 | 270 | */ |
| 245 | 271 | private function load_backend() { |
| 246 | 272 | require_once WINP_PLUGIN_DIR . '/admin/includes/class.snippets.viewtable.php'; |
| 247 | 273 | require_once WINP_PLUGIN_DIR . '/admin/includes/class.filter.snippet.php'; |
| 248 | 274 | require_once WINP_PLUGIN_DIR . '/admin/includes/class.actions.snippet.php'; |
| 249 | - require_once WINP_PLUGIN_DIR . '/admin/includes/class.import.snippet.php'; | |
| 250 | 275 | require_once WINP_PLUGIN_DIR . '/admin/includes/class.notices.php'; |
| 276 | + require_once WINP_PLUGIN_DIR . '/admin/includes/class.admin.notices.php'; | |
| 251 | 277 | require_once WINP_PLUGIN_DIR . '/admin/includes/class.request.php'; |
| 252 | - require_once WINP_PLUGIN_DIR . '/admin/metaboxes/metabox.php'; | |
| 253 | 278 | require_once WINP_PLUGIN_DIR . '/admin/boot.php'; |
| 254 | 279 | |
| 255 | - $this->get_common_object()->registerHooks(); | |
| 256 | - | |
| 280 | + $this->get_common_object()->register_hooks(); | |
| 257 | 281 | $this->register_types(); |
| 258 | 282 | |
| 259 | 283 | new WINP_Filter_List(); |
| 260 | - new WINP_Export_Snippet(); | |
| 261 | - new WINP_Import_Snippet(); | |
| 262 | - new WINP_WarningNotices(); | |
| 284 | + new WINP_Actions_Snippet(); | |
| 285 | + WINP_Notices::instance(); | |
| 286 | + new WINP_Admin_Notices(); | |
| 263 | 287 | |
| 264 | - # Required for i18n to be loaded properly | |
| 265 | - add_action( 'plugins_loaded', [ $this, 'register_pages' ] ); | |
| 288 | + if ( ! defined( 'E2E_TESTING' ) ) { | |
| 289 | + add_filter( | |
| 290 | + 'themeisle-sdk/survey/' . WINP_PLUGIN_SLUG, | |
| 291 | + function ( $data, $page_slug ) { | |
| 292 | + if ( empty( $page_slug ) ) { | |
| 293 | + return $data; | |
| 294 | + } | |
| 266 | 295 | |
| 267 | - # Required for compatibility with the premium plugin. | |
| 268 | - # We set the priority to 30 to wait for the premium plugin to load. | |
| 269 | - add_action( 'plugins_loaded', [ $this, 'register_depence_pages' ], 30 ); | |
| 270 | - | |
| 271 | - add_action( 'wbcr_factory_forms_475_register_controls', function () { | |
| 272 | - $colorControls = [ | |
| 273 | - [ | |
| 274 | - 'type' => 'winp-dropdown', | |
| 275 | - 'class' => 'WINP_FactoryForms_Dropdown', | |
| 276 | - 'include' => WINP_PLUGIN_DIR . '/includes/controls/class.dropdown.php', | |
| 277 | - ], | |
| 278 | - ]; | |
| 279 | - $this->forms->registerControls( $colorControls ); | |
| 280 | - } ); | |
| 296 | + return $this->get_survey_data(); | |
| 297 | + }, | |
| 298 | + 10, | |
| 299 | + 2 | |
| 300 | + ); | |
| 301 | + } | |
| 281 | 302 | } |
| 282 | 303 | |
| 283 | 304 | /** |
| 284 | 305 | * Метод проверяет активацию премиум плагина и наличие действующего лицензионного ключа |
| @@ -285,14 +306,122 @@ | ||
| 285 | 306 | * |
| 286 | 307 | * @return bool |
| 287 | 308 | */ |
| 288 | 309 | public function is_premium() { |
| 289 | - if ( $this->premium->is_active() && $this->premium->is_activate() //&& $this->premium->is_install_package() | |
| 290 | - ) { | |
| 291 | - return true; | |
| 310 | + return $this->premium->is_active(); | |
| 311 | + } | |
| 312 | + | |
| 313 | + /** | |
| 314 | + * Logger data. | |
| 315 | + * | |
| 316 | + * @return array<string, mixed> | |
| 317 | + */ | |
| 318 | + public function get_logger_data() { | |
| 319 | + $settings = WINP_Settings::get_instance()->get_settings(); | |
| 320 | + | |
| 321 | + // Each settings has a lot of keys, we only want name and value items. So map them. | |
| 322 | + $settings = array_map( | |
| 323 | + function ( $setting ) { | |
| 324 | + return [ | |
| 325 | + 'name' => isset( $setting['name'] ) ? $setting['name'] : '', | |
| 326 | + 'value' => isset( $setting['value'] ) ? $setting['value'] : '', | |
| 327 | + ]; | |
| 328 | + }, | |
| 329 | + $settings | |
| 330 | + ); | |
| 331 | + | |
| 332 | + $total_snippets = wp_count_posts( WINP_SNIPPETS_POST_TYPE ); | |
| 333 | + $total_snippets = isset( $total_snippets->publish ) ? $total_snippets->publish : 0; | |
| 334 | + | |
| 335 | + // Count snippets by type. | |
| 336 | + $snippet_types = [ 'php', 'css', 'js', 'text', 'html', 'advert', 'universal' ]; | |
| 337 | + $types_count = []; | |
| 338 | + | |
| 339 | + foreach ( $snippet_types as $type ) { | |
| 340 | + $count = get_posts( | |
| 341 | + [ | |
| 342 | + 'post_type' => WINP_SNIPPETS_POST_TYPE, | |
| 343 | + 'post_status' => 'publish', | |
| 344 | + 'meta_key' => 'wbcr_inp_snippet_type', | |
| 345 | + 'meta_value' => $type, | |
| 346 | + 'posts_per_page' => -1, | |
| 347 | + 'fields' => 'ids', | |
| 348 | + ] | |
| 349 | + ); | |
| 350 | + | |
| 351 | + if ( ! empty( $count ) ) { | |
| 352 | + $types_count[ $type ] = count( $count ); | |
| 353 | + } | |
| 354 | + } | |
| 355 | + | |
| 356 | + return [ | |
| 357 | + 'settings' => $settings, | |
| 358 | + 'stats' => [ | |
| 359 | + 'total_snippets' => $total_snippets, | |
| 360 | + 'types' => $types_count, | |
| 361 | + ], | |
| 362 | + ]; | |
| 363 | + } | |
| 364 | + | |
| 365 | + /** | |
| 366 | + * Set the black friday data. | |
| 367 | + * | |
| 368 | + * @param array<string, mixed> $configs The configuration array for the loaded products. | |
| 369 | + * | |
| 370 | + * @return array<string, mixed> The configurations. | |
| 371 | + */ | |
| 372 | + public function add_black_friday_data( $configs ) { | |
| 373 | + $config = $configs['default']; | |
| 374 | + | |
| 375 | + $message = __( 'Conditional logic, revision history, import/export. Manage your custom code properly. Exclusively for existing Woody users.', 'insert-php' ); | |
| 376 | + $cta_label = __( 'Get Woody Pro', 'insert-php' ); | |
| 377 | + | |
| 378 | + $plan = apply_filters( 'product_woody_license_plan', 0 ); | |
| 379 | + $status = apply_filters( 'product_woody_license_status', 'invalid' ); | |
| 380 | + $license = apply_filters( 'product_woody_license_key', false ); | |
| 381 | + $pro_product_slug = defined( 'WASP_PLUGIN_FILE' ) ? basename( dirname( WASP_PLUGIN_FILE ) ) : ''; | |
| 382 | + | |
| 383 | + $is_pro = 'valid' === $status; | |
| 384 | + $is_expired = 'expired' === $status || 'active-expired' === $status; | |
| 385 | + | |
| 386 | + if ( $is_pro ) { | |
| 387 | + // translators: %s is the discount percentage. | |
| 388 | + $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - up to %s off', 'insert-php' ), '30%' ); | |
| 389 | + // translators: %1$s - discount, %2$s - discount. | |
| 390 | + $message = sprintf( __( 'Upgrade your Woody Pro plan: %1$s off this week. Already on the plan you need? Renew early and save up to %2$s.', 'insert-php' ), '30%', '20%' ); | |
| 391 | + $cta_label = __( 'See your options', 'insert-php' ); | |
| 392 | + } elseif ( $is_expired ) { | |
| 393 | + // translators: %s is the discount percentage. | |
| 394 | + $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'insert-php' ), '50%' ); | |
| 395 | + $message = __( 'Your Woody Pro features are still here, just locked. Renew at a reduced rate this week.', 'insert-php' ); | |
| 396 | + $cta_label = __( 'Reactivate now', 'insert-php' ); | |
| 292 | 397 | } else { |
| 293 | - return false; | |
| 398 | + // translators: %s - discount. | |
| 399 | + $config['title'] = sprintf( __( 'Woody Pro: %s off this week', 'insert-php' ), '60%' ); | |
| 400 | + // translators: %s is the discount percentage. | |
| 401 | + $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'insert-php' ), '60%' ); | |
| 294 | 402 | } |
| 403 | + | |
| 404 | + $url_params = [ | |
| 405 | + 'utm_term' => $is_pro ? 'plan-' . $plan : 'free', | |
| 406 | + 'lkey' => ! empty( $license ) ? $license : false, | |
| 407 | + 'expired' => $is_expired ? '1' : false, | |
| 408 | + ]; | |
| 409 | + | |
| 410 | + if ( ( $is_pro || $is_expired ) && ! empty( $pro_product_slug ) ) { | |
| 411 | + $config['plugin_meta_targets'] = [ $pro_product_slug ]; | |
| 412 | + } | |
| 413 | + | |
| 414 | + $config['cta_label'] = $cta_label; | |
| 415 | + $config['message'] = $message; | |
| 416 | + | |
| 417 | + $config['sale_url'] = add_query_arg( | |
| 418 | + $url_params, | |
| 419 | + tsdk_translate_link( tsdk_utmify( 'https://themeisle.link/woody-bf', 'bfcm', 'woody' ) ) | |
| 420 | + ); | |
| 421 | + | |
| 422 | + $configs[ WINP_PLUGIN_SLUG ] = $config; | |
| 423 | + | |
| 424 | + return $configs; | |
| 295 | 425 | } |
| 296 | - | |
| 297 | 426 | } |
| 298 | 427 | } |