Example #1
0
function wfu_delete_file($file_code, $type)
{
    if ($type == 'dir') {
        return;
    }
    $user = wp_get_current_user();
    $is_admin = current_user_can('manage_options');
    //check if user is allowed to view file details
    if (!$is_admin) {
        return;
    }
    $file_code = wfu_sanitize_code($file_code);
    $dec_file = wfu_get_filepath_from_safe($file_code);
    if ($dec_file === false) {
        return;
    }
    $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
    if ($type == 'dir' && substr($dec_file, -1) == '/') {
        $dec_file = substr($dec_file, 0, -1);
    }
    //check if user is allowed to perform this action
    if (!wfu_current_user_owes_file($dec_file)) {
        return;
    }
    if (isset($_POST['submit'])) {
        if ($_POST['submit'] == "Delete") {
            //pre-log delete action
            if ($type == 'file') {
                $retid = wfu_log_action('delete', $dec_file, $user->ID, '', 0, 0, '', null);
            }
            if ($type == 'dir' && $dec_file != "") {
                wfu_delTree($dec_file);
            } else {
                unlink($dec_file);
            }
            //revert log action if file has not been deleted
            if ($type == 'file' && file_exists($dec_file)) {
                wfu_revert_log_action($retid);
            }
        }
    }
    return true;
}
function wfu_delete_file($file, $type)
{
    $dec_file = wfu_plugin_decode_string($file);
    $dec_file = wfu_flatten_path($dec_file);
    if ($type == 'dir' && substr($dec_file, -1) == '/') {
        $dec_file = substr($dec_file, 0, -1);
    }
    //check if user is allowed to perform this action
    $user = wfu_current_user_allowed_action('delete', $dec_file);
    if ($user == null) {
        return;
    }
    if (isset($_POST['submit'])) {
        if ($_POST['submit'] == "Delete") {
            //pre-log delete action
            if ($type == 'file') {
                $retid = wfu_log_action('delete', $dec_file, $user->ID, '', 0, '', null);
            }
            if ($type == 'dir' && $dec_file != "") {
                wfu_delTree($dec_file);
            } else {
                unlink($dec_file);
            }
            //revert log action if file has not been deleted
            if ($type == 'file' && file_exists($dec_file)) {
                wfu_revert_log_action($retid);
            }
        }
    }
    return true;
}