PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.5
ShopBuilder – WooCommerce Builder For Elementor v2.6.5
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
← All changes | app/Helpers/Installation.php +99 -54 2.1.0 → 2.6.5 View file →
@@ -1,88 +1,135 @@
1 1 <?php
2 +/**
3 + * Activation Helpers class
4 + *
5 + * @package RadiusTheme\SB
6 + */
2 7
3 8 namespace RadiusTheme\SB\Helpers;
4 9
5 -// Do not allow directly accessing this file.
10 +use WC_Product_Simple;
11 +use RadiusTheme\SB\Models\Settings;
6 12 use RadiusTheme\SB\Models\ExtraSettings;
7 -use RadiusTheme\SB\Models\Settings;
8 13
14 +// Do not allow directly accessing this file.
9 15 if ( ! defined( 'ABSPATH' ) ) {
10 16 exit( 'This script cannot be accessed directly.' );
11 17 }
12 18
19 +/**
20 + * Activation Helpers class
21 + */
13 22 class Installation {
23 + /**
24 + * Init.
25 + *
26 + * @return void
27 + */
28 + public static function init() {
29 + add_action( 'init', [ __CLASS__, 'check_version' ], 5 );
30 + }
14 31
15 - public static function init(){
16 - add_action( 'init', [ __CLASS__, 'check_version' ], 5 );
17 - }
32 + /**
33 + * Check version.
34 + *
35 + * @return int|void
36 + */
37 + public static function check_version() {
38 + $version = ExtraSettings::instance()->get_option( 'rtsb_version', '' ) ?? get_option( 'rtsb_version' );
39 + if ( version_compare( $version, RTSB_VERSION, '<' ) ) {
40 + if ( ! $version ) {
41 + self::set_default_options();
42 + if ( ! Fns::get_product() ) {
43 + return self::create_wc_product();
44 + }
45 + }
46 + self::update_rtsb_version();
47 + }
48 + }
18 49
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 - }
31 -
50 + /**
51 + * Activation.
52 + *
53 + * @return void
54 + */
32 55 public static function activate() {
33 - if ( ! is_blog_installed() ) {
34 - return;
35 - }
56 + if ( ! is_blog_installed() ) {
57 + return;
58 + }
36 59
37 - if( ExtraSettings::instance()->get_option( 'first_instilled_version', false ) ){
60 + if ( ExtraSettings::instance()->get_option( 'first_instilled_version', false ) ) {
38 61 ExtraSettings::instance()->set_option( 'first_instilled_version', RTSB_VERSION );
39 62 }
40 63
41 - // Check if we are not already running this routine.
42 - if ( 'yes' === get_transient( 'rtsb_installing' ) ) {
43 - return;
44 - }
64 + if ( ! ExtraSettings::instance()->get_option( 'rtsb_plugin_activation_time', false ) ) {
65 + ExtraSettings::instance()->set_option( 'rtsb_plugin_activation_time', strtotime( 'now' ) );
66 + }
45 67
46 - // If we made it till here nothing is running yet, lets set the transient now.
47 - set_transient( 'rtsb_installing', 'yes', MINUTE_IN_SECONDS * 10 );
68 + // Check if we are not already running this routine.
69 + if ( 'yes' === get_transient( 'rtsb_installing' ) ) {
70 + return;
71 + }
72 +
73 + // If we made it till here nothing is running yet, lets set the transient now.
74 + set_transient( 'rtsb_installing', 'yes', MINUTE_IN_SECONDS * 10 );
48 75 delete_transient( 'rtsb_installing' );
49 76 }
50 77
51 - private static function update_rtsb_version() {
52 - // update_option( 'rtsb_version', RTSB_VERSION );
53 - ExtraSettings::instance()->set_option( 'rtsb_version', RTSB_VERSION );
54 - }
78 + /**
79 + * Update version.
80 + *
81 + * @return void
82 + */
83 + private static function update_rtsb_version() {
84 + ExtraSettings::instance()->set_option( 'rtsb_version', RTSB_VERSION );
85 + }
55 86
56 - public static function deactivation() { }
87 + /**
88 + * Deactivation.
89 + *
90 + * @return void
91 + */
92 + public static function deactivation() {
93 + delete_option( 'shopbuilder_permalinks_flushed' );
94 + }
57 95
58 - public static function set_default_options(){
59 - $sections = Settings::instance()->get_sections();
60 - foreach ( $sections as $sections_id => $section ) {
61 - $rawOptions = [];
62 - if ( ! empty( $section['list'] ) ) {
63 - foreach ( $section['list'] as $blocks_id => $blocks) {
64 - if( ! rtsb()->has_pro() && 'free' !== ( $blocks['package'] ?? '' ) ){
96 + /**
97 + * Set default options.
98 + *
99 + * @return void
100 + */
101 + public static function set_default_options() {
102 + $sections = Settings::instance()->get_sections();
103 + foreach ( $sections as $sections_id => $section ) {
104 + if ( ! empty( $section['list'] ) ) {
105 + foreach ( $section['list'] as $blocks_id => $blocks ) {
106 + $rawOptions = [];
107 + if ( ! rtsb()->has_pro() && 'free' !== ( $blocks['package'] ?? '' ) ) {
65 108 continue;
66 109 }
67 110 $rawOptions['active'] = $blocks['active'] ?? null;
68 - foreach ( $blocks['fields'] as $field_id => $field ) {
69 - $type = 'array' === gettype( $field['value'] ) ? [] : '' ;
70 - $rawOptions[$field_id] = ! empty( $field['value'] ) ? $field['value'] : $type;
71 - }
72 - Fns::set_options( $sections_id, $blocks_id, $rawOptions );
73 - }
74 - }
75 - }
76 - }
77 111
112 + if ( ! empty( $blocks['fields'] ) ) {
113 + foreach ( $blocks['fields'] as $field_id => $field ) {
114 + $type = 'array' === gettype( $field['value'] ) ? [] : '';
115 + $rawOptions[ $field_id ] = ! empty( $field['value'] ) ? $field['value'] : $type;
116 + }
117 + }
118 + Fns::set_options( $sections_id, $blocks_id, $rawOptions );
119 + }
120 + }
121 + }
122 + }
123 +
78 124 /**
125 + * Create product.
126 + *
79 127 * @return int
80 - * @throws \WC_Data_Exception
81 128 */
82 129 public static function create_wc_product() {
83 130
84 - $product = new \WC_Product_Simple();
131 + $product = new WC_Product_Simple();
85 132 $product->set_name( 'Confirm at least one product is created before deleting' );
86 133 $product->set_description( 'This is a ShopBuilder demo preview product' );
87 134 $product->set_short_description( 'This is a ShopBuilder product' );
88 135 $product->set_status( 'draft' );
@@ -97,7 +144,5 @@
97 144 $product->set_stock_status( 'instock' );
98 145
99 146 return $product->save();
100 147 }
101 -
102 -
103 -}
148 +}