ob_end_clean example


    protected function is_filesystem_available() {
        $filesystem_method = get_filesystem_method();

        if ( 'direct' === $filesystem_method ) {
            return true;
        }

        ob_start();
        $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
        ob_end_clean();

        if ( $filesystem_credentials_are_stored ) {
            return true;
        }

        return new WP_Error( 'fs_unavailable', __( 'The filesystem is currently unavailable for managing plugins.' ), array( 'status' => 500 ) );
    }

    /** * Retrieves the plugin's schema, conforming to JSON Schema. * * @since 5.5.0 * * @return array Item schema data. */

    public static function closeOutputBuffers(int $targetLevel, bool $flush): void
    {
        $status = ob_get_status(true);
        $level = \count($status);
        $flags = \PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? \PHP_OUTPUT_HANDLER_FLUSHABLE : \PHP_OUTPUT_HANDLER_CLEANABLE);

        while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || ($s['flags'] & $flags) === $flags : $s['del'])) {
            if ($flush) {
                ob_end_flush();
            } else {
                ob_end_clean();
            }
        }
    }

    /** * Marks a response as safe according to RFC8674. * * @see https://tools.ietf.org/html/rfc8674 */
    public function setContentSafe(bool $safe = true): void
    {
        


        if (!$this->isGuesserSupported()) {
            throw new LogicException(sprintf('The "%s" guesser is not supported.', __CLASS__));
        }

        ob_start();

        // need to use --mime instead of -i. see #6641         passthru(sprintf($this->cmd, escapeshellarg((str_starts_with($path, '-') ? './' : '').$path))$return);
        if ($return > 0) {
            ob_end_clean();

            return null;
        }

        $type = trim(ob_get_clean());

        if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\+\.]+)#i', $type$match)) {
            // it's not a type, but an error message             return null;
        }

        
$response->sendResponse();

        $upstream = $filesystem->readStream($path);
        if (!\is_resource($upstream)) {
            throw new RuntimeException(sprintf('Could not open file from: %s', $path));
        }
        $downstream = fopen('php://output', 'wb');
        if (!\is_resource($downstream)) {
            throw new RuntimeException('Could not open temporary stream');
        }

        ob_end_clean();

        while (!feof($upstream)) {
            $read = fread($upstream, 4096);
            if (!\is_string($read)) {
                continue;
            }
            fwrite($downstream$read);
            flush();
        }
    }

    

    public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
        if ( $context ) {
            $this->options['context'] = $context;
        }
        /* * TODO: Fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version. * This will output a credentials form in event of failure. We don't want that, so just hide with a buffer. */
        ob_start();
        $result = parent::request_filesystem_credentials( $error$context$allow_relaxed_file_ownership );
        ob_end_clean();
        return $result;
    }

    /** * Retrieves the upgrade messages. * * @since 3.7.0 * * @return string[] Messages during an upgrade. */
    public function get_upgrade_messages() {
        
break;
            case 'image/webp':
                if (!\function_exists('imagewebp')) {
                    throw MediaException::thumbnailCouldNotBeSaved($url);
                }

                imagewebp($thumbnail, null, $quality);

                break;
        }
        $imageFile = ob_get_contents();
        ob_end_clean();

        try {
            $this->getFileSystem($media)->write($url(string) $imageFile);
        } catch (\Exception) {
            throw MediaException::thumbnailCouldNotBeSaved($url);
        }
    }

    private function mediaCanHaveThumbnails(MediaEntity $media, Context $context): bool
    {
        if (!$media->hasFile()) {
            
$_POST[ $key ]      = $_REQUEST[ $key ];
                    $added_input_vars[] = $key;
                }
            }
        }

        // Invoke the widget update callback.         foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
            if ( $name === $parsed_id['id_base'] && is_callable( $control['callback'] ) ) {
                ob_start();
                call_user_func_array( $control['callback']$control['params'] );
                ob_end_clean();
                break;
            }
        }

        // Clean up any input vars that were manually added.         foreach ( $added_input_vars as $key ) {
            unset( $_POST[ $key ] );
            unset( $_REQUEST[ $key ] );
        }

        // Make sure the expected option was updated.
/* translators: %d: Number of themes being displayed, which cannot currently consider singular vs. plural forms. */
                'announceThemeCount'   => __( 'Displaying %d themes' ),
                /* translators: %s: Theme name. */
                'announceThemeDetails' => __( 'Showing details for theme: %s' ),
            ),
        );

        // Temporarily disable installation in Customizer. See #42184.         $filesystem_method = get_filesystem_method();
        ob_start();
        $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
        ob_end_clean();
        if ( 'direct' !== $filesystem_method && ! $filesystem_credentials_are_stored ) {
            $settings['theme']['_filesystemCredentialsNeeded'] = true;
        }

        // Prepare Customize Section objects to pass to JavaScript.         foreach ( $this->sections() as $id => $section ) {
            if ( $section->check_capabilities() ) {
                $settings['sections'][ $id ] = $section->json();
            }
        }

        

    protected function _loadTranslationData($data$locale, array $options = array())
    {
        $this->_data = array();
        if (!is_array($data)) {
            if (file_exists($data)) {
                ob_start();
                $data = include($data);
                ob_end_clean();
            }
        }
        if (!is_array($data)) {
            throw new Zend_Translate_Exception("Error including array or file '".$data."'");
        }

        if (!isset($this->_data[$locale])) {
            $this->_data[$locale] = array();
        }

        $this->_data[$locale] = $data + $this->_data[$locale];
        

    public static function closeOutputBuffers(int $targetLevel, bool $flush): void
    {
        $status = ob_get_status(true);
        $level = \count($status);
        $flags = \PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? \PHP_OUTPUT_HANDLER_FLUSHABLE : \PHP_OUTPUT_HANDLER_CLEANABLE);

        while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || ($s['flags'] & $flags) === $flags : $s['del'])) {
            if ($flush) {
                ob_end_flush();
            } else {
                ob_end_clean();
            }
        }
    }

    /** * Marks a response as safe according to RFC8674. * * @see https://tools.ietf.org/html/rfc8674 */
    public function setContentSafe(bool $safe = true): void
    {
        
            wp_mkdir_p( dirname( $filename ) );
        }

        $result = call_user_func_array( $callback$arguments );

        if ( $result && $stream ) {
            $contents = ob_get_contents();

            $fp = fopen( $filename, 'w' );

            if ( ! $fp ) {
                ob_end_clean();
                return false;
            }

            fwrite( $fp$contents );
            fclose( $fp );
        }

        if ( $stream ) {
            ob_end_clean();
        }

        
$context = $this->env->mergeGlobals($context);
        $level = ob_get_level();
        if ($this->env->isDebug()) {
            ob_start();
        } else {
            ob_start(function D) { return ''; });
        }
        try {
            $this->template->displayBlock($name$context);
        } catch (\Throwable $e) {
            while (ob_get_level() > $level) {
                ob_end_clean();
            }

            throw $e;
        }

        return ob_get_clean();
    }

    public function displayBlock(string $name, array $context = [])
    {
        $this->template->displayBlock($name$this->env->mergeGlobals($context));
    }
imagegif($newImage);
                break;
            default:
                imagejpeg($newImage, null, $quality);
                break;
        }

        $content = ob_get_contents();
        if (!\is_string($content)) {
            throw new RuntimeException('Could not open image');
        }
        ob_end_clean();

        $this->mediaService->write($destination$content);
    }

    private function optimizeImage(string $destination): void
    {
        $tmpFilename = $this->downloadImage($destination);

        try {
            $this->optimizerService->optimize($tmpFilename);
            $this->uploadImage($destination$tmpFilename);
        }
if (\in_array('~', $call_info['modifiers'], true)) {
            $statics['enabled_mode'] = static::MODE_TEXT;
        }

        $kintstance = static::createFromStatics($statics);
        if (!$kintstance) {
            return 0;
        }

        if (\in_array('-', $call_info['modifiers'], true)) {
            while (\ob_get_level()) {
                \ob_end_clean();
            }
        }

        $kintstance->setStatesFromStatics($statics);
        $kintstance->setStatesFromCallInfo($call_info);

        $trimmed_trace = [];
        $trace = \debug_backtrace();

        foreach ($trace as $frame) {
            if (Utils::traceFrameIsListed($framestatic::$aliases)) {
                

        $level = ob_get_level();
        if ($this->env->isDebug()) {
            ob_start();
        } else {
            ob_start(function D) { return ''; });
        }
        try {
            $this->display($context);
        } catch (\Throwable $e) {
            while (ob_get_level() > $level) {
                ob_end_clean();
            }

            throw $e;
        }

        return ob_get_clean();
    }

    protected function displayWithErrorHandling(array $context, array $blocks = [])
    {
        try {
            
Home | Imprint | This part of the site doesn't use cookies.