| 1 |
<?php |
| 2 |
/** |
| 3 |
* The file that defines the core plugin class |
| 4 |
* |
| 5 |
* A class definition that includes attributes and functions used across both the |
| 6 |
* public-facing side of the site and the admin area. |
| 7 |
* |
| 8 |
* @link https://posimyth.com/ |
| 9 |
* @since 1.0.0 |
| 10 |
* |
| 11 |
* @package Wdesignkit |
| 12 |
* @subpackage Wdesignkit/includes |
| 13 |
*/ |
| 14 |
|
| 15 |
namespace wdkit\wdkit_datahooks; |
| 16 |
|
| 17 |
/**Exit if accessed directly.*/ |
| 18 |
if ( ! defined( 'ABSPATH' ) ) { |
| 19 |
exit; |
| 20 |
} |
| 21 |
|
| 22 |
if ( ! class_exists( 'Wdkit_Data_Hooks' ) ) { |
| 23 |
|
| 24 |
/** |
| 25 |
* Wdkit_Data_Hooks |
| 26 |
* |
| 27 |
* @since 1.0.0 |
| 28 |
*/ |
| 29 |
class Wdkit_Data_Hooks { |
| 30 |
|
| 31 |
/** |
| 32 |
* Member Variable |
| 33 |
* |
| 34 |
* @var instance |
| 35 |
*/ |
| 36 |
private static $instance; |
| 37 |
|
| 38 |
/** |
| 39 |
* Initiator |
| 40 |
*/ |
| 41 |
public static function get_instance() { |
| 42 |
if ( ! isset( self::$instance ) ) { |
| 43 |
self::$instance = new self(); |
| 44 |
} |
| 45 |
|
| 46 |
return self::$instance; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Define the core functionality of the plugin. |
| 51 |
*/ |
| 52 |
public function __construct() { |
| 53 |
add_action( 'wdkit_admin_create_default', array( $this, 'wdkit_create_default' ), 10 ); |
| 54 |
add_action( 'wdkit_active_settings', array( $this, 'wdkit_active_settings_function' ), 10, 2 ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Create Default setting data in db |
| 59 |
* |
| 60 |
* @since 1.0.0 |
| 61 |
*/ |
| 62 |
public function wdkit_create_default() { |
| 63 |
|
| 64 |
$wkit_settings_panel = get_option( 'wkit_settings_panel', false ); |
| 65 |
if ( empty( $wkit_settings_panel ) ) { |
| 66 |
$settings_options = array( |
| 67 |
'builder' => true, |
| 68 |
'template' => true, |
| 69 |
'gutenberg_builder' => true, |
| 70 |
'gutenberg_core_builder' => false, |
| 71 |
'elementor_builder' => true, |
| 72 |
'bricks_builder' => false, |
| 73 |
'debugger_mode' => false, |
| 74 |
'gutenberg_template' => true, |
| 75 |
'elementor_template' => true, |
| 76 |
'code_snippet' => true, |
| 77 |
); |
| 78 |
|
| 79 |
add_option( 'wkit_settings_panel', $settings_options ); |
| 80 |
} |
| 81 |
|
| 82 |
$wkit_builder = get_option( 'wkit_builder', false ); |
| 83 |
if ( empty( $wkit_builder ) ) { |
| 84 |
add_option( 'wkit_builder', array( 'WDesignKit' ), '', 'yes' ); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Active Settings Function |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
*/ |
| 93 |
public function wdkit_active_settings_function( $settings = array(), $builder = '' ) { |
| 94 |
|
| 95 |
$wkit_settings_panel = get_option( 'wkit_settings_panel', false ); |
| 96 |
|
| 97 |
if ( $wkit_settings_panel == false || empty( $wkit_settings_panel ) ) { |
| 98 |
do_action( 'wdkit_admin_create_default' ); |
| 99 |
$wkit_settings_panel = get_option( 'wkit_settings_panel', array() ); |
| 100 |
} |
| 101 |
|
| 102 |
// Merge DB values with new settings. |
| 103 |
$updated_settings = array_merge( $wkit_settings_panel, $settings ); |
| 104 |
|
| 105 |
if ( in_array( 'nexter-blocks', $builder ) ) { |
| 106 |
|
| 107 |
if ( is_plugin_active( 'the-plus-addons-for-block-editor/the-plus-addons-for-block-editor.php' ) ) { |
| 108 |
$updated_settings['gutenberg_builder'] = true; |
| 109 |
$updated_settings['gutenberg_template'] = true; |
| 110 |
}else{ |
| 111 |
$updated_settings['gutenberg_builder'] = false; |
| 112 |
$updated_settings['gutenberg_template'] = false; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
if ( in_array( 'elementor', $builder ) ) { |
| 117 |
|
| 118 |
if ( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 119 |
$updated_settings['elementor_builder'] = true; |
| 120 |
$updated_settings['elementor_template'] = true; |
| 121 |
}else{ |
| 122 |
$updated_settings['elementor_builder'] = false; |
| 123 |
$updated_settings['elementor_template'] = false; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
// Save updated settings back to the database. |
| 128 |
update_option( 'wkit_settings_panel', $updated_settings ); |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Check Error and Get Response Body Data |
| 133 |
* |
| 134 |
* @param string $super_global it is main party of array & file. |
| 135 |
* @param string $key it is static value for file and array key. |
| 136 |
* */ |
| 137 |
public static function get_super_global_value( $super_global, $key ) { |
| 138 |
if ( ! isset( $super_global[ $key ] ) ) { |
| 139 |
return null; |
| 140 |
} |
| 141 |
|
| 142 |
if ( $_FILES === $super_global ) { |
| 143 |
$super_global[ $key ]['name'] = sanitize_file_name( $super_global[ $key ]['name'] ); |
| 144 |
|
| 145 |
return $super_global[ $key ]; |
| 146 |
} |
| 147 |
|
| 148 |
return wp_kses_post_deep( wp_unslash( $super_global[ $key ] ) ); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Check Error and Get Response Body Data |
| 153 |
* |
| 154 |
* @param string $data it is main party of array. |
| 155 |
* @param string $key it is static value for file and array key. |
| 156 |
* */ |
| 157 |
public static function sanitize_array_recursive( $data, $key ) { |
| 158 |
|
| 159 |
if ( is_array( $data[ $key ] ) ) { |
| 160 |
foreach ( $data[ $key ] as $index => $value ) { |
| 161 |
$data[ $index ] = self::sanitize_array_recursive( $value ); |
| 162 |
} |
| 163 |
|
| 164 |
return $data; |
| 165 |
} |
| 166 |
|
| 167 |
return sanitize_text_field( $data[ $key ] ); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
Wdkit_Data_Hooks::get_instance(); |
| 172 |
} |
| 173 |
|