PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.2
ShopBuilder – WooCommerce Builder For Elementor v2.0.2
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 +45 -132 3.4.22.0.2 View file →
@@ -1,157 +1,70 @@
1 1 <?php
2 -/**
3 - * Activation Helpers class
4 - *
5 - * @package RadiusTheme\SB
6 - */
7 2
8 3 namespace RadiusTheme\SB\Helpers;
9 4
10 -use WC_Product_Simple;
5 +// Do not allow directly accessing this file.
6 +use RadiusTheme\SB\Models\DataModel;
11 7 use RadiusTheme\SB\Models\Settings;
12 -use RadiusTheme\SB\Models\ExtraSettings;
13 8
14 -// Do not allow directly accessing this file.
15 9 if ( ! defined( 'ABSPATH' ) ) {
16 10 exit( 'This script cannot be accessed directly.' );
17 11 }
18 12
19 -/**
20 - * Activation Helpers class
21 - */
22 13 class Installation {
23 - /**
24 - * Init.
25 - *
26 - * @return void
27 - */
28 - public static function init() {
29 - add_action( 'init', [ __CLASS__, 'check_version' ], 5 );
30 - }
31 14
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 - }
15 + public static function init(){
16 + add_action( 'init', [ __CLASS__, 'check_version' ], 5 );
17 + }
49 18
50 - /**
51 - * Activation.
52 - *
53 - * @return void
54 - */
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 + }
27 +
55 28 public static function activate() {
56 - if ( ! is_blog_installed() ) {
57 - return;
58 - }
29 + if ( ! is_blog_installed() ) {
30 + return;
31 + }
59 32
60 - if ( ExtraSettings::instance()->get_option( 'first_instilled_version', false ) ) {
61 - ExtraSettings::instance()->set_option( 'first_instilled_version', RTSB_VERSION );
62 - }
33 + // Check if we are not already running this routine.
34 + if ( 'yes' === get_transient( 'rtsb_installing' ) ) {
35 + return;
36 + }
63 37
64 - if ( ! ExtraSettings::instance()->get_option( 'rtsb_plugin_activation_time', false ) ) {
65 - ExtraSettings::instance()->set_option( 'rtsb_plugin_activation_time', strtotime( 'now' ) );
66 - }
67 -
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 );
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 );
75 40 delete_transient( 'rtsb_installing' );
76 41 }
77 42
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 - }
43 + private static function update_rtsb_version() {
44 + update_option( 'rtsb_version', RTSB_VERSION );
45 + }
86 46
87 - /**
88 - * Deactivation.
89 - *
90 - * @return void
91 - */
92 - public static function deactivation() {
93 - delete_option( 'shopbuilder_permalinks_flushed' );
94 - self::clear_scheduled_events();
95 - }
96 - /**
97 - * Clear Scheduled Events
98 - *
99 - * @return void
100 - */
101 - public static function clear_scheduled_events() {
102 - $schedule = get_option( 'rtsb_cron_schedule_free', [] );
103 - if ( empty( $schedule ) ) {
104 - return;
105 - }
106 - foreach ( $schedule as $v ) {
107 - wp_clear_scheduled_hook( $v );
108 - }
109 - }
110 - /**
111 - * Set default options.
112 - *
113 - * @return void
114 - */
115 - public static function set_default_options() {
116 - $sections = Settings::instance()->get_sections();
117 - foreach ( $sections as $sections_id => $section ) {
118 - if ( ! empty( $section['list'] ) ) {
119 - foreach ( $section['list'] as $blocks_id => $blocks ) {
120 - $rawOptions = [];
121 - if ( ! rtsb()->has_pro() && 'free' !== ( $blocks['package'] ?? '' ) ) {
47 + public static function deactivation() { }
48 +
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'] ?? '' ) ){
122 56 continue;
123 57 }
124 58 $rawOptions['active'] = $blocks['active'] ?? null;
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 + }
125 68
126 - if ( ! empty( $blocks['fields'] ) ) {
127 - foreach ( $blocks['fields'] as $field_id => $field ) {
128 - $type = 'array' === gettype( $field['value'] ) ? [] : '';
129 - $rawOptions[ $field_id ] = ! empty( $field['value'] ) ? $field['value'] : $type;
130 - }
131 - }
132 - Fns::set_options( $sections_id, $blocks_id, $rawOptions );
133 - }
134 - }
135 - }
136 - }
137 69
138 - /**
139 - * Create product.
140 - *
141 - * @return int
142 - */
143 - public static function create_wc_product() {
144 - $product = new WC_Product_Simple();
145 - $product->set_name( 'Confirm at least one product is created before deleting' );
146 - $product->set_description( 'This is a ShopBuilder demo preview product' );
147 - $product->set_short_description( 'This is a ShopBuilder product' );
148 - $product->set_status( 'draft' );
149 -
150 - $product->set_regular_price( 50 );
151 - $product->set_sale_price( 49 );
152 - $product->set_price( 49 );
153 -
154 - $product->set_sku( '' );
155 - return $product->save();
156 - }
157 -}
70 +}