PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.4.8
Easy Elements for Elementor – Addons & Website Templates v1.4.8
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / includes / Admin / settings-framework / fields / FieldManager.php

FieldManager.php in Easy Elements for Elementor – Addons & Website Templates 1.4.8, at includes/Admin/settings-framework/fields/FieldManager.php

98 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3 class Easyel_FieldManager {
4 protected $fields_path;
5 protected $registered_types = [];
6
7 public function __construct($fields_path) {
8 $this->fields_path = rtrim($fields_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
9 $this->load_core_types();
10 add_action('wp_ajax_easyel_save_settings', array( $this, 'easyel_save_settings_callback') );
11 }
12
13
14 protected function load_core_types(){
15 $types = ['text','number','checkbox','radio','select','group'];
16 foreach($types as $t){
17 $file = $this->fields_path . $t . '.php';
18 if(file_exists($file)){
19 include_once $file;
20 $this->registered_types[$t] = true;
21 }
22 }
23 }
24
25 public function register_type($type, $callable_file){
26
27 $resolved = realpath( $callable_file );
28 if ( false === $resolved ) {
29 return false;
30 }
31
32 $allowed_root = realpath( defined( 'EASYELEMENTS_DIR_PATH' ) ? EASYELEMENTS_DIR_PATH : dirname( __FILE__, 4 ) );
33 if ( false === $allowed_root || 0 !== strpos( $resolved, $allowed_root . DIRECTORY_SEPARATOR ) ) {
34 return false;
35 }
36
37 if ( substr( $resolved, -4 ) !== '.php' ) {
38 return false;
39 }
40
41 include_once $resolved;
42 $this->registered_types[$type] = true;
43 return true;
44 }
45
46 public function render_field($sub_field, $value, $field_context = []){
47 $type = $sub_field['type'] ?? 'text';
48 // allow group to receive parent field context
49 if($type === 'group'){
50 if(function_exists('easyel_field_group')){
51 easyel_field_group($field_context, $field_context['settings'] ?? []);
52 }
53 return;
54 }
55
56 $sub_field['full_name'] = $sub_field['full_name'] ?? ($field_context['name'] . '[' . $sub_field['name'] . ']');
57
58 $fn = 'easyel_field_' . $type;
59 if(function_exists($fn)){
60 call_user_func($fn, $sub_field, $value);
61 return true;
62 }
63
64 // fallback simple input
65 $class = $sub_field['class'] ?? '';
66 $placeholder = $sub_field['placeholder'] ?? $sub_field['name'];
67 printf('<input type="text" class="easyel-settings-field-input %s" name="%s" value="%s" placeholder="%s" />', esc_attr($class), esc_attr($sub_field['full_name']), esc_attr($value), esc_attr($placeholder));
68 return false;
69 }
70
71 public function render_fields_group($field, $settings){
72 echo '<div class="easyel-settings-field-group">';
73 foreach($field['options'] as $sub){
74 $name = $field['name'].'['.$sub['name'].']';
75 $sub['full_name'] = $name;
76 $value = $settings[$field['name']][$sub['name']] ?? ($sub['default'] ?? '');
77 $this->render_field($sub, $value, ['name'=>$field['name'],'settings'=>$settings,'field'=>$field]);
78 }
79 echo '</div>';
80 }
81
82 public function easyel_save_settings_callback() {
83
84 if ( ! current_user_can( 'manage_options' ) ) {
85 wp_send_json_error( ['msg' => 'Unauthorized'], 403 );
86 }
87
88 check_ajax_referer( 'easy_elements_settings_nonce', 'nonce' );
89
90 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
91 $posted = $_POST['settings'] ?? [];
92 $settings = map_deep( wp_unslash( $posted ), 'sanitize_text_field' );
93
94 update_option( 'easy_element_settings', $settings );
95
96 wp_send_json_success(['message' => 'Settings saved successfully!']);
97 }
98 }