| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace RadiusTheme\SB\Helpers; |
| 4 | 4 | |
| 5 | 5 | // Do not allow directly accessing this file. |
| 6 | -use RadiusTheme\SB\Models\ExtraSettings; | |
| 6 | +use RadiusTheme\SB\Models\DataModel; | |
| 7 | 7 | use RadiusTheme\SB\Models\Settings; |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | 10 | exit( 'This script cannot be accessed directly.' ); |
| @@ -11,97 +11,60 @@ | ||
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | class Installation { |
| 14 | 14 | |
| 15 | - public static function init() { | |
| 16 | - add_action( 'init', [ __CLASS__, 'check_version' ], 5 ); | |
| 17 | - } | |
| 15 | + public static function init(){ | |
| 16 | + add_action( 'init', [ __CLASS__, 'check_version' ], 5 ); | |
| 17 | + } | |
| 18 | 18 | |
| 19 | - public static function check_version() { | |
| 20 | - $version = ExtraSettings::instance()->get_option( 'rtsb_version' ) ?? get_option( 'rtsb_version' ); | |
| 21 | - if ( version_compare( $version, RTSB_VERSION, '<' ) ) { | |
| 22 | - if ( ! $version ) { | |
| 23 | - self::set_default_options(); | |
| 24 | - if ( ! Fns::get_product() ) { | |
| 25 | - return self::create_wc_product(); | |
| 26 | - } | |
| 27 | - } | |
| 28 | - self::update_rtsb_version(); | |
| 29 | - } | |
| 30 | - } | |
| 19 | + public static function check_version() { | |
| 20 | + if ( version_compare( get_option( 'rtsb_version' ), RTSB_VERSION, '<' ) ) { | |
| 21 | + if ( ! get_option( 'rtsb_version' ) ) { | |
| 22 | + self::set_default_options(); | |
| 23 | + } | |
| 24 | + self::update_rtsb_version(); | |
| 25 | + } | |
| 26 | + } | |
| 31 | 27 | |
| 32 | 28 | public static function activate() { |
| 33 | - if ( ! is_blog_installed() ) { | |
| 34 | - return; | |
| 35 | - } | |
| 36 | - // flush_rewrite_rules(); | |
| 37 | - if ( ExtraSettings::instance()->get_option( 'first_instilled_version', false ) ) { | |
| 38 | - ExtraSettings::instance()->set_option( 'first_instilled_version', RTSB_VERSION ); | |
| 39 | - } | |
| 29 | + if ( ! is_blog_installed() ) { | |
| 30 | + return; | |
| 31 | + } | |
| 40 | 32 | |
| 41 | - if ( ! ExtraSettings::instance()->get_option( 'rtsb_plugin_activation_time', false ) ) { | |
| 42 | - ExtraSettings::instance()->set_option( 'rtsb_plugin_activation_time', strtotime( 'now' ) ); | |
| 43 | - } | |
| 33 | + // Check if we are not already running this routine. | |
| 34 | + if ( 'yes' === get_transient( 'rtsb_installing' ) ) { | |
| 35 | + return; | |
| 36 | + } | |
| 44 | 37 | |
| 45 | - // Check if we are not already running this routine. | |
| 46 | - if ( 'yes' === get_transient( 'rtsb_installing' ) ) { | |
| 47 | - return; | |
| 48 | - } | |
| 49 | - | |
| 50 | - // If we made it till here nothing is running yet, lets set the transient now. | |
| 51 | - set_transient( 'rtsb_installing', 'yes', MINUTE_IN_SECONDS * 10 ); | |
| 38 | + // If we made it till here nothing is running yet, lets set the transient now. | |
| 39 | + set_transient( 'rtsb_installing', 'yes', MINUTE_IN_SECONDS * 10 ); | |
| 52 | 40 | delete_transient( 'rtsb_installing' ); |
| 53 | 41 | } |
| 54 | 42 | |
| 55 | - private static function update_rtsb_version() { | |
| 56 | - // update_option( 'rtsb_version', RTSB_VERSION ); | |
| 57 | - ExtraSettings::instance()->set_option( 'rtsb_version', RTSB_VERSION ); | |
| 58 | - } | |
| 43 | + private static function update_rtsb_version() { | |
| 44 | + update_option( 'rtsb_version', RTSB_VERSION ); | |
| 45 | + } | |
| 59 | 46 | |
| 60 | - public static function deactivation() { | |
| 61 | - delete_option( 'shopbuilder_permalinks_flushed' ); | |
| 62 | - } | |
| 47 | + public static function deactivation() { } | |
| 63 | 48 | |
| 64 | - public static function set_default_options() { | |
| 65 | - $sections = Settings::instance()->get_sections(); | |
| 66 | - foreach ( $sections as $sections_id => $section ) { | |
| 67 | - $rawOptions = []; | |
| 68 | - if ( ! empty( $section['list'] ) ) { | |
| 69 | - foreach ( $section['list'] as $blocks_id => $blocks ) { | |
| 70 | - if ( ! rtsb()->has_pro() && 'free' !== ( $blocks['package'] ?? '' ) ) { | |
| 49 | + public static function set_default_options(){ | |
| 50 | + $sections = Settings::instance()->get_sections(); | |
| 51 | + foreach ( $sections as $sections_id => $section ) { | |
| 52 | + $rawOptions = []; | |
| 53 | + if ( ! empty( $section['list'] ) ) { | |
| 54 | + foreach ( $section['list'] as $blocks_id => $blocks) { | |
| 55 | + if( ! rtsb()->has_pro() && 'free' !== ( $blocks['package'] ?? '' ) ){ | |
| 71 | 56 | continue; |
| 72 | 57 | } |
| 73 | 58 | $rawOptions['active'] = $blocks['active'] ?? null; |
| 74 | - foreach ( $blocks['fields'] as $field_id => $field ) { | |
| 75 | - $type = 'array' === gettype( $field['value'] ) ? [] : ''; | |
| 76 | - $rawOptions[ $field_id ] = ! empty( $field['value'] ) ? $field['value'] : $type; | |
| 77 | - } | |
| 78 | - Fns::set_options( $sections_id, $blocks_id, $rawOptions ); | |
| 79 | - } | |
| 80 | - } | |
| 81 | - } | |
| 82 | - } | |
| 59 | + foreach ( $blocks['fields'] as $field_id => $field ) { | |
| 60 | + $type = 'array' === gettype( $field['value'] ) ? [] : '' ; | |
| 61 | + $rawOptions[$field_id] = ! empty( $field['value'] ) ? $field['value'] : $type; | |
| 62 | + } | |
| 63 | + Fns::set_options( $sections_id, $blocks_id, $rawOptions ); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + } | |
| 67 | + } | |
| 83 | 68 | |
| 84 | - /** | |
| 85 | - * @return int | |
| 86 | - * @throws \WC_Data_Exception | |
| 87 | - */ | |
| 88 | - public static function create_wc_product() { | |
| 89 | 69 | |
| 90 | - $product = new \WC_Product_Simple(); | |
| 91 | - $product->set_name( 'Confirm at least one product is created before deleting' ); | |
| 92 | - $product->set_description( 'This is a ShopBuilder demo preview product' ); | |
| 93 | - $product->set_short_description( 'This is a ShopBuilder product' ); | |
| 94 | - $product->set_status( 'draft' ); | |
| 95 | - | |
| 96 | - $product->set_regular_price( 50 ); | |
| 97 | - $product->set_sale_price( 49 ); | |
| 98 | - $product->set_price( 49 ); | |
| 99 | - | |
| 100 | - $product->set_sku( 'SAMPLE-001' ); | |
| 101 | - | |
| 102 | - $product->set_manage_stock( false ); | |
| 103 | - $product->set_stock_status( 'instock' ); | |
| 104 | - | |
| 105 | - return $product->save(); | |
| 106 | - } | |
| 107 | -} | |
| 70 | +} | |