File manager - Edit - /home/palg2351/public_html/sinergihub.id/wp-content/themes/landingpress-wp/inc/metabox.php
Back
<?php namespace LandingPress\Core; if (! defined('ABSPATH')) { exit; // Exit if accessed directly } class Metabox { public function __construct() { add_action('load-post.php', array($this, 'init')); add_action('load-post-new.php', array($this, 'init')); } public function init() { add_action('add_meta_boxes', array($this, 'add_meta_boxes')); add_action('save_post', array($this, 'save_post'), 10, 2); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); } public function enqueue_scripts() { wp_enqueue_media(); wp_enqueue_style('choices', get_template_directory_uri() . '/assets/lib/choices/choices.min.css', array(), '11.0.2'); wp_enqueue_script('choices', get_template_directory_uri() . '/assets/lib/choices/choices.min.js', array(), '11.0.2', false); wp_enqueue_style('pickr', get_template_directory_uri() . '/assets/lib/pickr/nano.min.css', array(), '1.9.1'); wp_enqueue_script('pickr', get_template_directory_uri() . '/assets/lib/pickr/pickr.es5.min.js', array(), '1.9.1', false); wp_enqueue_script('landingpress-metabox', get_template_directory_uri() . '/assets/js/metabox.min.js', array('jquery', 'pickr'), filemtime(get_template_directory() . '/assets/js/metabox.min.js'), true); wp_enqueue_style('landingpress-metabox', get_template_directory_uri() . '/assets/css/metabox.min.css', array('pickr'), filemtime(get_template_directory() . '/assets/css/metabox.min.css')); do_action('landingpress_metabox_enqueue_scripts'); } public function add_meta_boxes() { $post_types = apply_filters('landingpress_metabox_post_types', array('post', 'page')); if (!empty($post_types)) { add_meta_box('landingpress_metabox', 'LandingPress', array($this, 'render'), $post_types, 'normal', 'high'); } } private function render_field($field_id, $field, $post_id) { $value = get_post_meta($post_id, $field['setting'], true); $name = $field['setting']; $id = 'landingpress_metabox_' . $field_id; $label = isset($field['label']) ? $field['label'] : ''; $type = isset($field['type']) ? $field['type'] : 'text'; $placeholder = isset($field['placeholder']) ? $field['placeholder'] : ''; $classes = array( 'landingpress-field-wrap', 'landingpress-field-wrap-type-' . esc_attr($type), 'landingpress-field-' . esc_attr($field_id) ); if (!empty($field['conditions'])) { $classes[] = 'landingpress-field-conditional'; $conditions_attr = ' data-conditions=\'' . json_encode($field['conditions']) . '\''; $style_attr = ' style="display: none;"'; } else { $conditions_attr = ''; $style_attr = ''; } if (isset($field['row_start']) && $field['row_start']) { echo '<div class="landingpress-field-row">'; } echo '<div class="' . implode(' ', $classes) . '"' . $conditions_attr . $style_attr . '>'; switch ($type) { case 'checkbox': echo '<input type="checkbox" id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" value="1"' . checked($value, '1', false) . '>'; echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; break; case 'select': echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; if (isset($field['choices']) && is_array($field['choices'])) { echo '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" class="regular-text">'; foreach ($field['choices'] as $choice_value => $choice_label) { echo '<option value="' . esc_attr($choice_value) . '"' . selected($value, $choice_value, false) . '>' . esc_html($choice_label) . '</option>'; } echo '</select>'; } break; case 'select2': echo '<div class="landingpress-choices-container">'; echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; if (isset($field['choices']) && is_array($field['choices'])) { echo '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" class="regular-text">'; foreach ($field['choices'] as $choice_value => $choice_label) { echo '<option value="' . esc_attr($choice_value) . '"' . selected($value, $choice_value, false) . '>' . esc_html($choice_label) . '</option>'; } echo '</select>'; } echo '</div>'; break; case 'select-multiple': echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; if (isset($field['choices']) && is_array($field['choices'])) { if (!is_array($value)) { $value = array($value); } echo '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '[]" multiple="multiple" class="regular-text">'; foreach ($field['choices'] as $choice_value => $choice_label) { echo '<option value="' . esc_attr($choice_value) . '"' . selected(in_array($choice_value, $value), true, false) . '>' . esc_html($choice_label) . '</option>'; } echo '</select>'; } break; case 'radio': echo '<label>' . wp_kses_post($label) . '</label>'; if (isset($field['choices']) && is_array($field['choices'])) { echo '<div class="landingpress-radio-options">'; foreach ($field['choices'] as $choice_value => $choice_label) { $radio_id = $id . '_' . $choice_value; echo '<div class="landingpress-radio-option">'; echo '<input type="radio" id="' . esc_attr($radio_id) . '" name="' . esc_attr($name) . '" value="' . esc_attr($choice_value) . '"' . checked($value, $choice_value, false) . '>'; echo '<label for="' . esc_attr($radio_id) . '">' . esc_html($choice_label) . '</label>'; echo '</div>'; } echo '</div>'; } break; case 'color': echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; echo '<div class="landingpress-color-container">'; echo '<button class="landingpress-color-button"></button>'; echo '<input class="landingpress-color-control" type="text" id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" value="' . esc_attr($value) . '"/>'; echo '</div>'; break; case 'image': case 'image_id': echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; echo '<div class="landingpress-image-container">'; if ($value) : echo wp_get_attachment_image($value, 'medium'); endif; echo '</div>'; echo '<p>'; echo '<input type="hidden" name="' . esc_attr($name) . '" class="landingpress-image-id" value="' . esc_attr($value) . '" data-extensions="' . esc_attr($field['extensions'] ?? '') . '" />'; echo '<button type="button" class="landingpress-image-upload button">' . esc_html__('Upload image', 'landingpress-wp') . '</button>'; echo '<button type="button" class="landingpress-image-remove button" ' . (empty($value) ? ' style="display:none;"' : '') . '>' . esc_html__('Remove image', 'landingpress-wp') . '</button>'; echo '</p>'; break; case 'image_url': echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; echo '<div class="landingpress-image-container">'; if ($value) : echo '<img src="' . esc_attr($value) . '" alt="' . esc_attr($label) . '" />'; endif; echo '</div>'; echo '<p>'; echo '<input type="hidden" name="' . esc_attr($name) . '" class="landingpress-image-url" value="' . esc_attr($value) . '" data-extensions="' . esc_attr($field['extensions'] ?? '') . '" />'; echo '<button type="button" class="landingpress-image-upload button">' . esc_html__('Upload image', 'landingpress-wp') . '</button>'; echo '<button type="button" class="landingpress-image-remove button" ' . (empty($value) ? ' style="display:none;"' : '') . '>' . esc_html__('Remove image', 'landingpress-wp') . '</button>'; echo '</p>'; break; case 'file_id': echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; echo '<div class="landingpress-file-container">'; if ($value) : $file = get_attached_file($value); if ($file) { echo '<span class="landingpress-file-name">' . esc_html(basename($file)) . '</span>'; } endif; echo '</div>'; echo '<p>'; echo '<input type="hidden" name="' . esc_attr($name) . '" class="landingpress-file-id" value="' . esc_attr($value) . '" data-extensions="' . esc_attr($field['extensions'] ?? '') . '" />'; echo '<button type="button" class="landingpress-file-upload button">' . esc_html__('Upload file', 'landingpress-wp') . '</button>'; echo '<button type="button" class="landingpress-file-remove button" ' . (empty($value) ? ' style="display:none;"' : '') . '>' . esc_html__('Remove file', 'landingpress-wp') . '</button>'; echo '</p>'; break; case 'file_url': echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; echo '<div class="landingpress-file-container">'; if ($value) : echo '<span class="landingpress-file-name">' . esc_html(basename($value)) . '</span>'; endif; echo '</div>'; echo '<p>'; echo '<input type="hidden" name="' . esc_attr($name) . '" class="landingpress-file-url" value="' . esc_attr($value) . '" data-extensions="' . esc_attr($field['extensions'] ?? '') . '" />'; echo '<button type="button" class="landingpress-file-upload button">' . esc_html__('Upload file', 'landingpress-wp') . '</button>'; echo '<button type="button" class="landingpress-file-remove button" ' . (empty($value) ? ' style="display:none;"' : '') . '>' . esc_html__('Remove file', 'landingpress-wp') . '</button>'; echo '</p>'; break; case 'number': $class_size = isset($field['size']) ? $field['size'] . '-text' : 'small-text'; echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; echo '<input type="number" id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" value="' . esc_attr($value) . '" placeholder="' . esc_attr($placeholder) . '"'; if (isset($field['choices'])) { if (isset($field['choices']['min'])) { echo ' min="' . esc_attr($field['choices']['min']) . '"'; } if (isset($field['choices']['max'])) { echo ' max="' . esc_attr($field['choices']['max']) . '"'; } if (isset($field['choices']['step'])) { echo ' step="' . esc_attr($field['choices']['step']) . '"'; } } echo ' class="' . esc_attr($class_size) . '">'; if (isset($field['choices']['unit'])) { echo '<span class="landingpress-unit">' . esc_html($field['choices']['unit']) . '</span>'; } break; case 'repeater': if (!empty($field['label'])) { echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; } if (!empty($field['description']) && $type == 'repeater') { echo '<p class="description">' . wp_kses_post($field['description']) . '</p>'; } if (!empty($field['children']) && !empty($field['setting'])) { $this->render_repeater($field, $post_id); } break; case 'message': case 'custom': if (!empty($field['label'])) { echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; } break; case 'textarea': $class_size = isset($field['size']) ? $field['size'] . '-text' : 'regular-text'; $rows = isset($field['rows']) ? $field['rows'] : 2; echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; echo '<textarea id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" class="' . esc_attr($class_size) . '" rows="' . esc_attr($rows) . '" placeholder="' . esc_attr($placeholder) . '">' . esc_textarea($value) . '</textarea>'; break; case 'text': default: $class_size = isset($field['size']) ? $field['size'] . '-text' : 'regular-text'; echo '<label for="' . esc_attr($id) . '">' . wp_kses_post($label) . '</label>'; echo '<input type="text" id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" value="' . esc_attr($value) . '" class="' . esc_attr($class_size) . '" placeholder="' . esc_attr($placeholder) . '">'; break; } if (!empty($field['description']) && $type !== 'repeater') { echo '<p class="description">' . wp_kses_post($field['description']) . '</p>'; } do_action('landingpress_metabox_field', $field_id, $field, $post_id); echo '</div>'; if (isset($field['row_end']) && $field['row_end']) { echo '</div>'; } } private function render_repeater($field, $post_id) { $model = $field['model'] ?? 'acf'; $setting = $field['setting'] ?? ''; $children = $field['children'] ?? []; $button_add = $field['button_add'] ?? esc_html__('Add New', 'landingpress-wp'); if (empty($children) || empty($setting)) { return; } $data = []; if ($model === 'acf') { $count = get_post_meta($post_id, $setting, true); if ($count) { for ($i = 0; $i < $count; $i++) { $child_data = []; foreach ($children as $child) { $child_setting = $child['setting'] ?? ''; if (empty($child_setting)) { continue; } $child_data[$child_setting] = get_post_meta($post_id, "{$setting}_{$i}_{$child_setting}", true); } $data[] = $child_data; } } } else { $data = get_post_meta($post_id, $setting); } ?> <div class="landingpress-repeater-container" data-prefix="<?php echo esc_attr($setting); ?>" data-saved='<?php echo wp_json_encode($data); ?>'> <div class="landingpress-repeater-items"></div> <button type="button" class="button landingpress-repeater-add"><?php echo esc_html($button_add); ?></button> <template class="landingpress-repeater-template"> <div class="landingpress-repeater-item" data-index="{index}"> <div class="landingpress-repeater-content"> <?php foreach ($children as $child) : ?> <?php $type = $child['type'] ?? 'text'; ?> <?php if (isset($child['row_start']) && $child['row_start']) : ?> <div class="landingpress-repeater-field-grid"> <?php endif; ?> <div class="landingpress-repeater-field"> <label><?php echo esc_html($child['label']); ?></label> <?php if ($type === 'number') : ?> <input type="number" name="{prefix}_{index}_<?php echo esc_attr($child['setting']); ?>" class="landingpress-repeater-field-input" placeholder="<?php echo (isset($child['placeholder']) ? esc_attr($child['placeholder']) : ''); ?>" <?php if (isset($child['min']) && $child['min'] !== '') : ?> min="<?php echo esc_attr($child['min']); ?>" <?php endif; ?><?php if (isset($child['max']) && $child['max'] !== '') : ?> max="<?php echo esc_attr($child['max']); ?>" <?php endif; ?><?php if (isset($child['step']) && $child['step'] !== '') : ?> step="<?php echo esc_attr($child['step']); ?>" <?php endif; ?>> <?php elseif ($type === 'select') : ?> <select name="{prefix}_{index}_<?php echo esc_attr($child['setting']); ?>" class="landingpress-repeater-field-input"> <?php foreach ($child['choices'] as $choice) : ?> <option value="<?php echo esc_attr($choice); ?>"><?php echo esc_html($choice); ?></option> <?php endforeach; ?> </select> <?php else : ?> <input type="text" name="{prefix}_{index}_<?php echo esc_attr($child['setting']); ?>" class="landingpress-repeater-field-input" placeholder="<?php echo (isset($child['placeholder']) ? esc_attr($child['placeholder']) : ''); ?>"> <?php endif; ?> </div> <?php if (isset($child['row_end']) && $child['row_end']) : ?> </div> <?php endif; ?> <?php endforeach; ?> </div> <div class="landingpress-repeater-sidebar"> <div class="landingpress-repeater-actions"> <span class="landingpress-repeater-move-up dashicons dashicons-arrow-up-alt2"></span> <span class="landingpress-repeater-move-down dashicons dashicons-arrow-down-alt2"></span> <span class="landingpress-repeater-remove dashicons dashicons-remove"></span> </div> </div> </div> </template> </div> <?php } public function render() { $post_type = get_post_type(); $post_id = get_the_ID(); $fields = apply_filters('landingpress_metabox_fields', array(), $post_type, $post_id); if (empty($fields)) { return; } $sections = array(); $section_fields = array(); // First pass - collect sections foreach ($fields as $key => $field) { if (isset($field['type']) && $field['type'] === 'section') { $sections[$key] = $field; // Set default priority of 10 if not specified if (!isset($sections[$key]['priority'])) { $sections[$key]['priority'] = 10; } $section_fields[$key] = array(); } } // Second pass - collect fields for each section foreach ($fields as $key => $field) { if (isset($field['section'])) { $section_fields[$field['section']][$key] = $field; // Set default priority of 10 if not specified if (!isset($section_fields[$field['section']][$key]['priority'])) { $section_fields[$field['section']][$key]['priority'] = 10; } } } // Sort sections by priority uasort($sections, function ($a, $b) { return $a['priority'] - $b['priority']; }); // Sort fields within each section by priority foreach ($section_fields as $section_key => &$fields_array) { uasort($fields_array, function ($a, $b) { return $a['priority'] - $b['priority']; }); } if (empty($sections)) { return; } wp_nonce_field('landingpress_metabox_nonce', 'landingpress_metabox_nonce'); ?> <div class="landingpress-tab-container"> <div class="landingpress-tab-nav"> <?php foreach ($sections as $section_id => $section) : ?> <button type="button" class="landingpress-tab-button <?php echo ($section_id === array_key_first($sections)) ? 'active' : ''; ?>" data-tab="<?php echo esc_attr($section_id); ?>"> <?php echo esc_html($section['title']); ?> </button> <?php endforeach; ?> </div> <div class="landingpress-tab-contents"> <?php foreach ($sections as $section_id => $section) : ?> <div id="<?php echo esc_attr($section_id); ?>" class="landingpress-tab-content <?php echo ($section_id === array_key_first($sections)) ? 'active' : ''; ?>"> <button type="button" class="landingpress-accordion-header <?php echo ($section_id === array_key_first($sections)) ? 'active' : ''; ?>" data-tab="<?php echo esc_attr($section_id); ?>"> <?php echo esc_html($section['title']); ?> </button> <div class="landingpress-accordion-content <?php echo ($section_id === array_key_first($sections)) ? 'active' : ''; ?>"> <h3><?php echo esc_html($section['title']); ?></h3> <?php if (!empty($section['description'])) : ?> <p><?php echo wp_kses_post($section['description']); ?></p> <?php endif; ?> <?php if (!empty($section_fields[$section_id])) : ?> <?php foreach ($section_fields[$section_id] as $field_id => $field) : ?> <?php $this->render_field($field_id, $field, $post_id); ?> <?php endforeach; ?> <?php endif; ?> </div> </div> <?php endforeach; ?> </div> </div> <?php } private function sanitize_value($value, $field = []) { if (!empty($field['sanitization_callback']) && method_exists($this, $field['sanitization_callback'])) { $value = call_user_func(array($this, $field['sanitization_callback']), $value, $field); } elseif (!empty($field['sanitization_callback']) && function_exists($field['sanitization_callback'])) { $value = call_user_func($field['sanitization_callback'], $value, $field); } else { if (isset($field['type'])) { switch ($field['type']) { case 'text': $value = sanitize_text_field($value); break; case 'textarea': $value = sanitize_textarea_field($value); break; case 'email': $value = sanitize_email($value); break; case 'url': $value = sanitize_url($value); break; case 'number': $value = ($value !== '' && $value !== null) ? floatval($value) : ''; break; case 'checkbox': $value = $this->sanitize_checkbox($value, $field); break; case 'radio': $value = $this->sanitize_radio($value, $field); break; case 'select': $value = $this->sanitize_select($value, $field); break; case 'select-multiple': $value = $this->sanitize_select_multiple($value, $field); break; case 'color': $value = $this->sanitize_color($value, $field); break; case 'image_id': $value = $this->sanitize_image_id($value, $field); break; case 'image_url': $value = $this->sanitize_image_url($value, $field); break; case 'file_id': $value = $this->sanitize_file_id($value, $field); break; case 'file_url': $value = $this->sanitize_file_url($value, $field); break; default: $value = sanitize_text_field($value); break; } } else { // Default sanitization if no type specified $value = sanitize_text_field($value); } } return $value; } public function save_post($post_id, $post) { if (!isset($_POST['landingpress_metabox_nonce']) || !wp_verify_nonce($_POST['landingpress_metabox_nonce'], 'landingpress_metabox_nonce')) { return $post_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } if (!current_user_can('edit_post', $post_id)) { return $post_id; } $post_type = get_post_type($post_id); $fields = apply_filters('landingpress_metabox_fields', array(), $post_type, $post_id); if (empty($fields)) { return; } foreach ($fields as $field_id => $field) { // Skip non-data fields if (isset($field['type']) && in_array($field['type'], array('section', 'heading', 'notes', 'message', 'custom'))) { continue; } if (isset($field['type']) && $field['type'] === 'repeater') { $this->save_repeater($field, $post_id); continue; } $setting = isset($field['setting']) ? $field['setting'] : ''; if (!empty($setting)) { $value = isset($_POST[$setting]) ? $_POST[$setting] : ''; if ($value !== '' && $value !== null) { $value = $this->sanitize_value($value, $field); update_post_meta($post_id, $setting, $value); } else { delete_post_meta($post_id, $setting); } } } do_action('landingpress_metabox_save', $post_id, $post); } private function save_repeater($field, $post_id) { $model = $field['model'] ?? 'acf'; $setting = $field['setting'] ?? ''; $children = $field['children'] ?? []; if (empty($children) || empty($setting)) { return; } $first_child_setting = ''; if (!empty($children)) { foreach ($children as $child) { if (!empty($child['setting'])) { $first_child_setting = $child['setting']; break; } } } $count = 0; while (isset($_POST["{$setting}_{$count}_{$first_child_setting}"])) { $count++; } if ($model === 'acf') { // Clean up old data $old_count = get_post_meta($post_id, $setting, true); if ($old_count) { for ($i = 0; $i < $old_count; $i++) { foreach ($children as $child) { $child_setting = $child['setting'] ?? ''; if (empty($child_setting)) { continue; } delete_post_meta($post_id, "{$setting}_{$i}_{$child_setting}"); } } } if ($count > 0) { update_post_meta($post_id, $setting, $count); for ($i = 0; $i < $count; $i++) { foreach ($children as $child) { $child_setting = $child['setting'] ?? ''; if (empty($child_setting)) { continue; } $value = $_POST["{$setting}_{$i}_{$child_setting}"] ?? ''; if ($value !== '' && $value !== null) { $value = $this->sanitize_value($value, $child); } update_post_meta($post_id, "{$setting}_{$i}_{$child_setting}", $value); } } } else { delete_post_meta($post_id, $setting); } } else { delete_post_meta($post_id, $setting); if ($count > 0) { for ($i = 0; $i < $count; $i++) { $data = []; foreach ($children as $child) { $child_setting = $child['setting'] ?? ''; if (empty($child_setting)) { continue; } $value = $_POST["{$setting}_{$i}_{$child_setting}"] ?? ''; if ($value !== '' && $value !== null) { $value = $this->sanitize_value($value, $child); } $data[$child_setting] = $value; } add_post_meta($post_id, $setting, $data); } } } } private function sanitize_wp_filter_post_kses($data, $field = []) { $data = stripslashes($data); if (function_exists('force_balance_tags')) { $data = force_balance_tags($data); } return wp_kses($data, 'post'); } private function sanitize_html($html, $field = []) { if (is_array($html)) { return array_map(array($this, 'sanitize_wp_filter_post_kses'), $html); } else { return $this->sanitize_wp_filter_post_kses($html); } } private function sanitize_wp_filter_nohtml_kses($data, $field = []) { return wp_kses(stripslashes($data), 'strip'); } private function sanitize_nohtml($nohtml, $field = []) { if (is_array($nohtml)) { return array_map(array($this, 'sanitize_wp_filter_nohtml_kses'), $nohtml); } else { return $this->sanitize_wp_filter_nohtml_kses($nohtml); } } private function sanitize_unfiltered($html, $field = []) { if (current_user_can('unfiltered_html')) { return stripslashes($html); } else { if (is_array($html)) { return array_map(array($this, 'sanitize_wp_filter_post_kses'), $html); } else { return $this->sanitize_wp_filter_post_kses($html); } } } private function sanitize_checkbox($checked, $field = []) { return ((isset($checked) && true == $checked) ? true : false); } private function sanitize_radio($input, $field = []) { $choices = $field['choices'] ?? []; $default = $field['default'] ?? ''; if (isset($choices[''])) { $default = ''; } return (array_key_exists($input, $choices) ? $input : $default); } private function sanitize_select($input, $field = []) { $choices = $field['choices'] ?? []; $default = $field['default'] ?? ''; if (isset($choices[''])) { $default = ''; } return (array_key_exists($input, $choices) ? $input : $default); } private function sanitize_select_multiple($input, $field = []) { $input_keys = $input; $choices = $field['choices'] ?? []; foreach ($input_keys as $key => $value) { if (! array_key_exists($value, $choices)) { unset($input[$key]); } } return (is_array($input) ? $input : array()); } private function sanitize_color($color, $field = []) { if (empty($color)) { return ''; } // Check for hex color format if (preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $color)) { return $color; } // Check for rgb format if (preg_match('/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/', $color, $matches)) { $r = min(255, max(0, intval($matches[1]))); $g = min(255, max(0, intval($matches[2]))); $b = min(255, max(0, intval($matches[3]))); return "rgb($r,$g,$b)"; } // Check for rgba format if (preg_match('/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([0-1](?:\.\d+)?)\s*\)$/', $color, $matches)) { $r = min(255, max(0, intval($matches[1]))); $g = min(255, max(0, intval($matches[2]))); $b = min(255, max(0, intval($matches[3]))); $a = min(1, max(0, floatval($matches[4]))); return "rgba($r,$g,$b,$a)"; } return ''; } private function sanitize_image_id($image_id, $field = []) { $extensions = !empty($field['extensions']) ? $field['extensions'] : 'jpg,jpeg,png,svg,webp,avif'; if (empty($image_id)) { return ''; } $image_url = wp_get_attachment_url($image_id); if (!$image_url) { return ''; } $file_ext = strtolower(pathinfo($image_url, PATHINFO_EXTENSION)); $allowed_extensions = array_map('trim', explode(',', strtolower($extensions))); if (!in_array($file_ext, $allowed_extensions)) { return ''; } return $image_id; } private function sanitize_image_url($image_url, $field = []) { $extensions = !empty($field['extensions']) ? $field['extensions'] : 'jpg,jpeg,png,svg,webp,avif'; if (empty($image_url)) { return ''; } $file_ext = strtolower(pathinfo($image_url, PATHINFO_EXTENSION)); $allowed_extensions = array_map('trim', explode(',', strtolower($extensions))); if (!in_array($file_ext, $allowed_extensions)) { return ''; } return $image_url; } private function sanitize_file_id($file_id, $field = []) { $extensions = !empty($field['extensions']) ? $field['extensions'] : 'pdf,zip'; if (empty($file_id)) { return ''; } $file_url = wp_get_attachment_url($file_id); if (!$file_url) { return ''; } $file_ext = strtolower(pathinfo($file_url, PATHINFO_EXTENSION)); $allowed_extensions = array_map('trim', explode(',', strtolower($extensions))); if (!in_array($file_ext, $allowed_extensions)) { return ''; } return $file_id; } private function sanitize_file_url($file_url, $field = []) { $extensions = !empty($field['extensions']) ? $field['extensions'] : 'pdf,zip'; if (empty($file_url)) { return ''; } $file_ext = strtolower(pathinfo($file_url, PATHINFO_EXTENSION)); $allowed_extensions = array_map('trim', explode(',', strtolower($extensions))); if (!in_array($file_ext, $allowed_extensions)) { return ''; } return $file_url; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0.07 |
proxy
|
phpinfo
|
Settings