← Back
Editing: GD-cORe-admin-themes-forms.php
<?php if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Validates and sanitizes theme slug from POST data * * @param string $post_key The POST key to validate * @return string Sanitized theme slug * @since 4.1.0 */ function validate_theme_slug($post_key) { if (!isset($_POST[$post_key])) { wp_die('Missing theme slug parameter', 'Security Error', ['response' => 400]); return; } $theme_slug = sanitize_text_field($_POST[$post_key]); // Whitelist validation - only allow safe characters if (!preg_match('/^[a-zA-Z0-9_-]+$/', $theme_slug)) { wp_die('Invalid theme slug format', 'Security Error', ['response' => 400]); return; } return $theme_slug; } if(is_admin() && is_user_logged_in() && current_user_can('manage_options')){ $theme_actions = new GD_cORe\handlers\Themes(); $theme_action_submitted = isset($_POST['theme-Install']) || isset($_POST['theme-Update']) || isset($_POST['theme-Activate']); if ($theme_action_submitted) { check_admin_referer('gd_core_themes_action'); } // if a theme install request is made if(isset($_POST['theme-Install'])){ $theme_slug = validate_theme_slug('theme-slug'); $theme_actions->install_the_theme($theme_slug); } // if a theme update request is made if(isset($_POST['theme-Update'])){ $theme_slug = validate_theme_slug('theme-slug'); $theme_actions->update_required_theme($theme_slug); } // if a theme activation request is made if(isset($_POST['theme-Activate'])){ $theme_slug = validate_theme_slug('theme-slug'); $theme_actions->switch_the_theme($theme_slug); } }
Save File
Cancel