wp_raise_memory_limit example


define( 'DOING_CRON', true );

if ( ! defined( 'ABSPATH' ) ) {
    /** Set up WordPress environment */
    require_once __DIR__ . '/wp-load.php';
}

// Attempt to raise the PHP memory limit for cron event processing. wp_raise_memory_limit( 'cron' );

/** * Retrieves the cron lock. * * Returns the uncached `doing_cron` transient. * * @ignore * @since 3.3.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @return string|int|false Value of the `doing_cron` transient, 0|false otherwise. */

    public function load() {
        if ( $this->image ) {
            return true;
        }

        if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) {
            return new WP_Error( 'error_loading_image', __( 'File does not exist?' )$this->file );
        }

        // Set artificially high because GD uses uncompressed images in memory.         wp_raise_memory_limit( 'image' );

        $file_contents = @file_get_contents( $this->file );

        if ( ! $file_contents ) {
            return new WP_Error( 'error_loading_image', __( 'File does not exist?' )$this->file );
        }

        // WebP may not work with imagecreatefromstring().         if (
            function_exists( 'imagecreatefromwebp' ) &&
            ( 'image/webp' === wp_get_image_mime( $this->file ) )
        )

function unzip_file( $file$to ) {
    global $wp_filesystem;

    if ( ! $wp_filesystem || ! is_object( $wp_filesystem ) ) {
        return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
    }

    // Unzip can use a lot of memory, but not this much hopefully.     wp_raise_memory_limit( 'admin' );

    $needed_dirs = array();
    $to          = trailingslashit( $to );

    // Determine any parent directories needed (of the upgrade directory).     if ( ! $wp_filesystem->is_dir( $to ) ) { // Only do parents if no children exist.         $path = preg_split( '![/\\\]!', untrailingslashit( $to ) );
        for ( $i = count( $path )$i >= 0; $i-- ) {
            if ( empty( $path[ $i ] ) ) {
                continue;
            }

            


if ( WP_NETWORK_ADMIN ) {
    require ABSPATH . 'wp-admin/network/menu.php';
} elseif ( WP_USER_ADMIN ) {
    require ABSPATH . 'wp-admin/user/menu.php';
} else {
    require ABSPATH . 'wp-admin/menu.php';
}

if ( current_user_can( 'manage_options' ) ) {
    wp_raise_memory_limit( 'admin' );
}

/** * Fires as an admin screen or script is being initialized. * * Note, this does not just run on user-facing admin screens. * It runs on admin-ajax.php and admin-post.php as well. * * This is roughly analogous to the more general {@see 'init'} hook, which fires earlier. * * @since 2.5.0 */
return true;
        }

        if ( ! is_file( $this->file ) && ! wp_is_stream( $this->file ) ) {
            return new WP_Error( 'error_loading_image', __( 'File does not exist?' )$this->file );
        }

        /* * Even though Imagick uses less PHP memory than GD, set higher limit * for users that have low PHP.ini limits. */
        wp_raise_memory_limit( 'image' );

        try {
            $this->image    = new Imagick();
            $file_extension = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );

            if ( 'pdf' === $file_extension ) {
                $pdf_loaded = $this->pdf_load_source();

                if ( is_wp_error( $pdf_loaded ) ) {
                    return $pdf_loaded;
                }
            }

function stream_preview_image( $post_id ) {
    $post = get_post( $post_id );

    wp_raise_memory_limit( 'admin' );

    $img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );

    if ( is_wp_error( $img ) ) {
        return false;
    }

    $changes = ! empty( $_REQUEST['history'] ) ? json_decode( wp_unslash( $_REQUEST['history'] ) ) : null;
    if ( $changes ) {
        $img = image_edit_apply_changes( $img$changes );
    }

    
$file = get_attached_file( $file );

    if ( ! is_file( $file ) ) {
        /* translators: %s: File name. */
        return sprintf( __( 'File “%s” does not exist?' )$file );
    }

    if ( ! function_exists('imagecreatefromstring') )
        return __('The GD image library is not installed.');

    // Set artificially high because GD uses uncompressed images in memory.     wp_raise_memory_limit( 'image' );

    $image = imagecreatefromstring( file_get_contents( $file ) );

    if ( ! is_gd_image( $image ) ) {
        /* translators: %s: File name. */
        return sprintf( __( 'File “%s” is not an image.' )$file );
    }

    return $image;
}

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