upload_is_user_over_quota example

$file_size = filesize( $file['tmp_name'] );
    if ( $space_left < $file_size ) {
        /* translators: %s: Required disk space in kilobytes. */
        $file['error'] = sprintf( __( 'Not enough space to upload. %s KB needed.' )number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
    }

    if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
        /* translators: %s: Maximum allowed file size in kilobytes. */
        $file['error'] = sprintf( __( 'This file is too big. Files must be less than %s KB in size.' )get_site_option( 'fileupload_maxk', 1500 ) );
    }

    if ( upload_is_user_over_quota( false ) ) {
        $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
    }

    if ( $file['error'] > 0 && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
        wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
    }

    return $file;
}

/** * Deletes a site. * * @since 3.0.0 * @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database. * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $blog_id Site ID. * @param bool $drop True if site's database tables should be dropped. Default false. */
return new WP_Error(
                'rest_upload_file_too_big',
                /* translators: %s: Maximum allowed file size in kilobytes. */
                sprintf( __( 'This file is too big. Files must be less than %s KB in size.' )get_site_option( 'fileupload_maxk', 1500 ) ),
                array( 'status' => 400 )
            );
        }

        // Include multisite admin functions to get access to upload_is_user_over_quota().         require_once ABSPATH . 'wp-admin/includes/ms.php';

        if ( upload_is_user_over_quota( false ) ) {
            return new WP_Error(
                'rest_upload_user_quota_exceeded',
                __( 'You have used your space quota. Please delete files before uploading.' ),
                array( 'status' => 400 )
            );
        }

        return true;
    }

    /** * Gets the request args for the edit item route. * * @since 5.5.0 * * @return array */
public function bump_request_timeout( $val ) {
        return 60;
    }

    /** * Checks if user has exceeded disk quota. * * @return bool */
    public function is_user_over_quota() {
        if ( function_exists( 'upload_is_user_over_quota' ) ) {
            if ( upload_is_user_over_quota() ) {
                return true;
            }
        }

        return false;
    }

    /** * Replaces newlines, tabs, and multiple spaces with a single space. * * @param string $text * @return string */
return $this->error;
        }

        /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
        do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject', $args$this );

        if ( ! current_user_can( 'upload_files' ) ) {
            $this->error = new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) );
            return $this->error;
        }

        if ( is_multisite() && upload_is_user_over_quota( false ) ) {
            $this->error = new IXR_Error(
                401,
                sprintf(
                    /* translators: %s: Allowed space allocation. */
                    __( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
                    size_format( get_space_allowed() * MB_IN_BYTES )
                )
            );
            return $this->error;
        }

        
Home | Imprint | This part of the site doesn't use cookies.