PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / trunk
WDesignKit – AI Templates, Widget Builder & MCP Workflow vtrunk
2.6.6 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5.0 2.4.0 2.3.3 2.3.2 2.3.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 All 128 releases
wdesignkit / includes / admin / class-wdkit-data-hooks.php

class-wdkit-data-hooks.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow trunk, at includes/admin/class-wdkit-data-hooks.php

183 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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' => true,
73 'debugger_mode' => false,
74 'gutenberg_template' => true,
75 'elementor_template' => true,
76 'code_snippet' => true,
77 'cross_copy_paste' => false,
78 'cross_copy_paste_elementor' => true,
79 'cross_copy_paste_gutenberg' => true,
80 'cross_copy_paste_bricks' => false,
81 );
82
83 add_option( 'wkit_settings_panel', $settings_options );
84 }
85
86 $wkit_builder = get_option( 'wkit_builder', false );
87 if ( empty( $wkit_builder ) ) {
88 add_option( 'wkit_builder', array( 'WDesignKit' ), '', 'yes' );
89 }
90 }
91
92 /**
93 * Active Settings Function
94 *
95 * @since 1.0.0
96 */
97 public function wdkit_active_settings_function( $settings = array(), $builder = array() ) {
98
99 $wkit_settings_panel = get_option( 'wkit_settings_panel', false );
100
101 if ( $wkit_settings_panel == false || empty( $wkit_settings_panel ) ) {
102 do_action( 'wdkit_admin_create_default' );
103 $wkit_settings_panel = get_option( 'wkit_settings_panel', array() );
104 }
105
106 // Merge DB values with new settings.
107 $updated_settings = array_merge( $wkit_settings_panel, $settings );
108
109 $builder = is_array( $builder ) ? $builder : array();
110
111 if ( ! function_exists( 'is_plugin_active' ) ) {
112 require_once ABSPATH . 'wp-admin/includes/plugin.php';
113 }
114
115 if ( in_array( 'nexter-blocks', $builder, true ) ) {
116
117 if ( is_plugin_active( 'the-plus-addons-for-block-editor/the-plus-addons-for-block-editor.php' ) ) {
118 $updated_settings['gutenberg_builder'] = true;
119 $updated_settings['gutenberg_template'] = true;
120 }else{
121 $updated_settings['gutenberg_builder'] = false;
122 $updated_settings['gutenberg_template'] = false;
123 }
124 }
125
126 if ( in_array( 'elementor', $builder, true ) ) {
127
128 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
129 $updated_settings['elementor_builder'] = true;
130 $updated_settings['elementor_template'] = true;
131 }else{
132 $updated_settings['elementor_builder'] = false;
133 $updated_settings['elementor_template'] = false;
134 }
135 }
136
137 // Save updated settings back to the database.
138 update_option( 'wkit_settings_panel', $updated_settings );
139 }
140
141 /**
142 * Check Error and Get Response Body Data
143 *
144 * @param string $super_global it is main party of array & file.
145 * @param string $key it is static value for file and array key.
146 * */
147 public static function get_super_global_value( $super_global, $key ) {
148 if ( ! isset( $super_global[ $key ] ) ) {
149 return null;
150 }
151
152 if ( $_FILES === $super_global ) {
153 $super_global[ $key ]['name'] = sanitize_file_name( $super_global[ $key ]['name'] );
154
155 return $super_global[ $key ];
156 }
157
158 return wp_kses_post_deep( wp_unslash( $super_global[ $key ] ) );
159 }
160
161 /**
162 * Check Error and Get Response Body Data
163 *
164 * @param string $data it is main party of array.
165 * @param string $key it is static value for file and array key.
166 * */
167 public static function sanitize_array_recursive( $data, $key ) {
168
169 if ( is_array( $data[ $key ] ) ) {
170 foreach ( $data[ $key ] as $index => $value ) {
171 $data[ $index ] = self::sanitize_array_recursive( $data[ $key ], $index );
172 }
173
174 return $data;
175 }
176
177 return sanitize_text_field( $data[ $key ] );
178 }
179 }
180
181 Wdkit_Data_Hooks::get_instance();
182 }
183