← Back
Editing: class-function-handler.php
<?php namespace GD_cORe\handlers; if ( ! defined( 'ABSPATH' ) ) { exit; } /** * The admin-specific functionality of the plugin. * * * @package GD_cORe * @subpackage GD_cORe/admin */ class Base_Function extends Main { public function __construct(){ parent::__construct(); } /** * function to empty a directory * * @param string $src Directory path to remove * @return bool Success status * @since 1.0.0 **/ public function rrmdir($src){ // Validate input parameter if (empty($src) || !is_string($src)) { error_log("rrmdir: Invalid source parameter"); return false; } // Resolve real path to prevent path traversal $realSrc = realpath($src); if (!$realSrc) { error_log("rrmdir: Path does not exist: $src"); return false; } // Define allowed base directories for security $allowedBases = [ realpath(WP_CONTENT_DIR . '/plugins'), realpath(WP_CONTENT_DIR . '/themes'), realpath(WP_CONTENT_DIR . '/uploads/temp'), // if needed for temp files ]; // Ensure path is within allowed directories $isAllowed = false; foreach ($allowedBases as $allowedBase) { if ($allowedBase && strpos($realSrc, $allowedBase) === 0) { $isAllowed = true; break; } } if (!$isAllowed) { error_log("rrmdir: Path traversal attempt blocked: $src -> $realSrc"); return false; } // Additional safety: don't delete WordPress core directories $wpContentDir = realpath(WP_CONTENT_DIR); if ($realSrc === $wpContentDir || $realSrc === realpath(ABSPATH)) { error_log("rrmdir: Attempted to delete critical WordPress directory: $realSrc"); return false; } // Proceed with safe recursive removal if (!is_dir($realSrc)) { error_log("rrmdir: Not a directory: $realSrc"); return false; } $dir = opendir($realSrc); if (!$dir) { error_log("rrmdir: Cannot open directory: $realSrc"); return false; } while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { $full = $realSrc . '/' . $file; if (is_dir($full)) { self::rrmdir($full); } else { // Safe file deletion with existence check if (file_exists($full) && is_file($full)) { unlink($full); } } } } closedir($dir); // Final safety check before removing directory if (is_dir($realSrc) && $realSrc !== $wpContentDir) { rmdir($realSrc); } return true; } /** * handles admin redirects even when headers are already sent * * @return empty * @since 3.0.0 **/ public function redirect($url){ if (!headers_sent()){ exit(wp_redirect($url)); }else{ echo '<script type="text/javascript">'; echo 'window.location.href="'.$url.'";'; echo '</script>'; echo '<noscript>'; echo '<meta http-equiv="refresh" content="0;url='.$url.'" />'; echo '</noscript>'; exit; } } }
Save File
Cancel