function acfe_get_human_readable_location()

in web/wp-content/plugins/acf-extended/includes/acfe-file-functions.php [189:260]


function acfe_get_human_readable_location($path, $prefix = true, $new_line = true){
    
    // vars
    $located = '';
    $path = wp_normalize_path($path);
    $file_exists = file_exists($path);
    
    // paths to check
    $stylesheet_path = wp_normalize_path(get_stylesheet_directory());
    $template_path = wp_normalize_path(get_template_directory());
    $wp_plugin_dir = wp_normalize_path(WP_PLUGIN_DIR);
    $abspath = wp_normalize_path(ABSPATH);
    
    // prefix labels
    $prefix_label = array(
        __('Located', 'acfe'),
        __('Not found', 'acfe'),
    );
    
    if(is_array($prefix)){
        $prefix_label = $prefix;
    }
    
    if(strpos($path, $stylesheet_path) !== false){
    
        $rel_path = str_replace($stylesheet_path, '', $path);
    
        if($prefix){
            $located .= ($file_exists ? $prefix_label[0] : $prefix_label[1]) . ' ';
        }
        
        $located .= __('in theme:', 'acfe') . ($new_line ? "<br/>" : ' ');
        $located .= $rel_path;
        
    }elseif(strpos($path, $template_path) !== false){
    
        $rel_path = str_replace($template_path, '', $path);
    
        if($prefix){
            $located .= ($file_exists ? $prefix_label[0] : $prefix_label[1]) . ' ';
        }
        
        $located .= __('in theme:', 'acfe') . ($new_line ? "<br/>" : ' ');
        $located .= $rel_path;
        
    }elseif(strpos($path, $wp_plugin_dir) !== false){
    
        $rel_path = str_replace($wp_plugin_dir, '', $path);
    
        if($prefix){
            $located .= ($file_exists ? $prefix_label[0] : $prefix_label[1]) . ' ';
        }
        
        $located .= __('in plugin:', 'acfe') . ($new_line ? "<br/>" : ' ');
        $located .= $rel_path;
        
    }else{
        
        $rel_file = str_replace($abspath, '', $path);
    
        if($prefix){
            $located .= ($file_exists ? $prefix_label[0] : $prefix_label[1]) . ' ';
        }
        
        $located .= __('in:', 'acfe') . ($new_line ? "<br/>" : ' ');
        $located .= $rel_file;
        
    }
    
    return $located;
    
}