| @@ -1,70 +1,73 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace RadiusTheme\SB\Helpers; | |
| 4 | - | |
| 5 | -// Do not allow directly accessing this file. | |
| 6 | -use RadiusTheme\SB\Models\DataModel; | |
| 7 | -use RadiusTheme\SB\Models\Settings; | |
| 8 | - | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - exit( 'This script cannot be accessed directly.' ); | |
| 11 | -} | |
| 12 | - | |
| 13 | -class Installation { | |
| 14 | - | |
| 15 | - public static function init(){ | |
| 16 | - add_action( 'init', [ __CLASS__, 'check_version' ], 5 ); | |
| 17 | - } | |
| 18 | - | |
| 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 | - | |
| 28 | - public static function activate() { | |
| 29 | - if ( ! is_blog_installed() ) { | |
| 30 | - return; | |
| 31 | - } | |
| 32 | - | |
| 33 | - // Check if we are not already running this routine. | |
| 34 | - if ( 'yes' === get_transient( 'rtsb_installing' ) ) { | |
| 35 | - return; | |
| 36 | - } | |
| 37 | - | |
| 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 ); | |
| 40 | - delete_transient( 'rtsb_installing' ); | |
| 41 | - } | |
| 42 | - | |
| 43 | - private static function update_rtsb_version() { | |
| 44 | - update_option( 'rtsb_version', RTSB_VERSION ); | |
| 45 | - } | |
| 46 | - | |
| 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'] ?? '' ) ){ | |
| 56 | - continue; | |
| 57 | - } | |
| 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 | - } | |
| 68 | - | |
| 69 | - | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace RadiusTheme\SB\Helpers; | |
| 4 | + | |
| 5 | +// Do not allow directly accessing this file. | |
| 6 | +use RadiusTheme\SB\Models\DataModel; | |
| 7 | +use RadiusTheme\SB\Models\Settings; | |
| 8 | + | |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | + exit( 'This script cannot be accessed directly.' ); | |
| 11 | +} | |
| 12 | + | |
| 13 | +class Installation { | |
| 14 | + | |
| 15 | + public static function init(){ | |
| 16 | + add_action( 'init', [ __CLASS__, 'check_version' ], 5 ); | |
| 17 | + } | |
| 18 | + | |
| 19 | + public static function check_version() { | |
| 20 | + if ( version_compare( get_option( 'rtsb_version' ), RTSB_VERSION, '<' ) ) { | |
| 21 | + self::activate(); | |
| 22 | + } | |
| 23 | + } | |
| 24 | + | |
| 25 | + public static function activate() { | |
| 26 | + if ( ! is_blog_installed() ) { | |
| 27 | + return; | |
| 28 | + } | |
| 29 | + | |
| 30 | + // Check if we are not already running this routine. | |
| 31 | + if ( 'yes' === get_transient( 'rtsb_installing' ) ) { | |
| 32 | + return; | |
| 33 | + } | |
| 34 | + | |
| 35 | + // If we made it till here nothing is running yet, lets set the transient now. | |
| 36 | + set_transient( 'rtsb_installing', 'yes', MINUTE_IN_SECONDS * 10 ); | |
| 37 | + | |
| 38 | + if ( ! get_option( 'rtsb_version' ) ) { | |
| 39 | + self::set_default_options(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + self::update_rtsb_version(); | |
| 43 | + | |
| 44 | + delete_transient( 'rtsb_installing' ); | |
| 45 | + } | |
| 46 | + | |
| 47 | + private static function update_rtsb_version() { | |
| 48 | + update_option( 'rtsb_version', RTSB_VERSION ); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public static function deactivation() { } | |
| 52 | + | |
| 53 | + public static function set_default_options(){ | |
| 54 | + $sections = Settings::instance()->get_sections(); | |
| 55 | + foreach ( $sections as $sections_id => $section ) { | |
| 56 | + $rawOptions = []; | |
| 57 | + if ( ! empty( $section['list'] ) ) { | |
| 58 | + foreach ( $section['list'] as $blocks_id => $blocks) { | |
| 59 | + if( ! empty( $blocks['active'] ) ){ | |
| 60 | + $rawOptions['active'] = $blocks['active']; | |
| 61 | + } | |
| 62 | + foreach ( $blocks['fields'] as $field_id => $field) { | |
| 63 | + $type = 'array' === gettype( $field['value'] ) ? [] : '' ; | |
| 64 | + $rawOptions[$field_id] = ! empty( $field['value'] ) ? $field['value'] : $type; | |
| 65 | + } | |
| 66 | + Fns::set_options( $sections_id, $blocks_id, $rawOptions ); | |
| 67 | + } | |
| 68 | + } | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + | |
| 70 | 73 | } |