les( array( 'dimensions' => $dimensions_block_styles ) ); if ( ! empty( $styles['css'] ) ) { // Inject dimensions styles to the first element, presuming it's the wrapper, if it exists. $tags = new WP_HTML_Tag_Processor( $block_content ); if ( $tags->next_tag() ) { $existing_style = $tags->get_attribute( 'style' ); $updated_style = ''; if ( ! empty( $existing_style ) ) { $updated_style = $existing_style; if ( ! str_ends_with( $existing_style, ';' ) ) { $updated_style .= ';'; } } $updated_style .= $styles['css']; $tags->set_attribute( 'style', $updated_style ); if ( ! empty( $styles['classnames'] ) ) { foreach ( explode( ' ', $styles['classnames'] ) as $class_name ) { if ( str_contains( $class_name, 'aspect-ratio' ) && ! isset( $block_attributes['style']['dimensions']['aspectRatio'] ) ) { continue; } $tags->add_class( $class_name ); } } } return $tags->get_updated_html(); } return $block_content; } add_filter( 'render_block', 'wp_render_dimensions_support', 10, 2 ); // Register the block support. WP_Block_Supports::get_instance()->register( 'dimensions', array( 'register_attribute' => 'wp_register_dimensions_support', 'apply' => 'wp_apply_dimensions_support', ) ); ult; } /** * Identical to gzgets, except that * gzgetss attempts to strip any HTML and PHP * tags from the text it reads. * * @param resource $zp The gz-file pointer. It must be valid, and must point to a file * successfully opened by gzopen. * @param int $length The length of data to get. * @param string $allowable_tags You can use this optional parameter to specify tags which should not * be stripped. * @return string The uncompressed and stripped string. * @throws ZlibException * */ function gzgetss($zp, int $length, string $allowable_tags = null): string { error_clear_last(); if ($allowable_tags !== null) { $result = \gzgetss($zp, $length, $allowable_tags); } else { $result = \gzgetss($zp, $length); } if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * This function inflates a deflated string. * * @param string $data The data compressed by gzdeflate. * @param int $length The maximum length of data to decode. * @return string The original uncompressed data. * * The function will return an error if the uncompressed data is more than * 32768 times the length of the compressed input data * or more than the optional parameter length. * @throws ZlibException * */ function gzinflate(string $data, int $length = 0): string { error_clear_last(); $result = \gzinflate($data, $length); if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * Reads to EOF on the given gz-file pointer from the current position and * writes the (uncompressed) results to standard output. * * @param resource $zp The gz-file pointer. It must be valid, and must point to a file * successfully opened by gzopen. * @return int The number of uncompressed characters read from gz * and passed through to the input. * @throws ZlibException * */ function gzpassthru($zp): int { error_clear_last(); $result = \gzpassthru($zp); if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * Sets the file position indicator of the given gz-file pointer to the * beginning of the file stream. * * @param resource $zp The gz-file pointer. It must be valid, and must point to a file * successfully opened by gzopen. * @throws ZlibException * */ function gzrewind($zp): void { error_clear_last(); $result = \gzrewind($zp); if ($result === false) { throw ZlibException::createFromPhpError(); } } /** * This function uncompress a compressed string. * * @param string $data The data compressed by gzcompress. * @param int $length The maximum length of data to decode. * @return string The original uncompressed data. * * The function will return an error if the uncompressed data is more than * 32768 times the length of the compressed input data * or more than the optional parameter length. * @throws ZlibException * */ function gzuncompress(string $data, int $length = 0): string { error_clear_last(); $result = \gzuncompress($data, $length); if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * * * @param resource $resource * @return int Returns number of bytes read so far. * @throws ZlibException * */ function inflate_get_read_len($resource): int { error_clear_last(); $result = \inflate_get_read_len($resource); if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * Usually returns either ZLIB_OK or ZLIB_STREAM_END. * * @param resource $resource * @return int Returns decompression status. * @throws ZlibException * */ function inflate_get_status($resource): int { error_clear_last(); $result = \inflate_get_status($resource); if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * Incrementally inflates encoded data in the specified context. * * Limitation: header information from GZIP compressed data are not made * available. * * @param resource $context A context created with inflate_init. * @param string $encoded_data A chunk of compressed data. * @param int $flush_mode One of ZLIB_BLOCK, * ZLIB_NO_FLUSH, * ZLIB_PARTIAL_FLUSH, * ZLIB_SYNC_FLUSH (default), * ZLIB_FULL_FLUSH, ZLIB_FINISH. * Normally you will want to set ZLIB_NO_FLUSH to * maximize compression, and ZLIB_FINISH to terminate * with the last chunk of data. See the zlib manual for a * detailed description of these constants. * @return string Returns a chunk of uncompressed data. * @throws ZlibException * */ function inflate_add($context, string $encoded_data, int $flush_mode = ZLIB_SYNC_FLUSH): string { error_clear_last(); $result = \inflate_add($context, $encoded_data, $flush_mode); if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * Initialize an incremental inflate context with the specified * encoding. * * @param int $encoding One of the ZLIB_ENCODING_* constants. * @param array $options An associative array which may contain the following elements: * * * level * * * The compression level in range -1..9; defaults to -1. * * * * * memory * * * The compression memory level in range 1..9; defaults to 8. * * * * * window * * * The zlib window size (logarithmic) in range 8..15; defaults to 15. * * * * * strategy * * * One of ZLIB_FILTERED, * ZLIB_HUFFMAN_ONLY, ZLIB_RLE, * ZLIB_FIXED or * ZLIB_DEFAULT_STRATEGY (the default). * * * * * dictionary * * * A string or an array of strings * of the preset dictionary (default: no preset dictionary). * * * * * * The compression level in range -1..9; defaults to -1. * * The compression memory level in range 1..9; defaults to 8. * * The zlib window size (logarithmic) in range 8..15; defaults to 15. * * One of ZLIB_FILTERED, * ZLIB_HUFFMAN_ONLY, ZLIB_RLE, * ZLIB_FIXED or * ZLIB_DEFAULT_STRATEGY (the default). * * A string or an array of strings * of the preset dictionary (default: no preset dictionary). * @return resource Returns an inflate context resource (zlib.inflate) on * success. * @throws ZlibException * */ function inflate_init(int $encoding, array $options = null) { error_clear_last(); $result = \inflate_init($encoding, $options); if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * Reads a file, decompresses it and writes it to standard output. * * readgzfile can be used to read a file which is not in * gzip format; in this case readgzfile will directly * read from the file without decompression. * * @param string $filename The file name. This file will be opened from the filesystem and its * contents written to standard output. * @param int $use_include_path You can set this optional parameter to 1, if you * want to search for the file in the include_path too. * @return int Returns the number of (uncompressed) bytes read from the file on success * @throws ZlibException * */ function readgzfile(string $filename, int $use_include_path = 0): int { error_clear_last(); $result = \readgzfile($filename, $use_include_path); if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; } /** * Uncompress any raw/gzip/zlib encoded data. * * @param string $data * @param int $max_decoded_len * @return string Returns the uncompressed data. * @throws ZlibException * */ function zlib_decode(string $data, int $max_decoded_len = null): string { error_clear_last(); if ($max_decoded_len !== null) { $result = \zlib_decode($data, $max_decoded_len); } else { $result = \zlib_decode($data); } if ($result === false) { throw ZlibException::createFromPhpError(); } return $result; }