wp_json_file_decode example


    protected static function read_json_file( $file_path ) {
        if ( $file_path ) {
            if ( array_key_exists( $file_pathstatic::$theme_json_file_cache ) ) {
                return static::$theme_json_file_cache[ $file_path ];
            }

            $decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) );
            if ( is_array( $decoded_file ) ) {
                static::$theme_json_file_cache[ $file_path ] = $decoded_file;
                return static::$theme_json_file_cache[ $file_path ];
            }
        }

        return array();
    }

    /** * Returns a data structure used in theme.json translation. * * @since 5.8.0 * @deprecated 5.9.0 * * @return array An array of theme.json fields that are translatable and the keys that are translatable. */
/** * Gets i18n schema for block's metadata read from `block.json` file. * * @since 5.9.0 * * @return object The schema for block's metadata. */
function get_block_metadata_i18n_schema() {
    static $i18n_block_schema;

    if ( ! isset( $i18n_block_schema ) ) {
        $i18n_block_schema = wp_json_file_decode( __DIR__ . '/block-i18n.json' );
    }

    return $i18n_block_schema;
}

/** * Registers a block type from the metadata stored in the `block.json` file. * * @since 5.5.0 * @since 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields. * @since 5.9.0 Added support for `variations` and `viewScript` fields. * @since 6.1.0 Added support for `render` field. * @since 6.3.0 Added `selectors` field. * * @param string $file_or_folder Path to the JSON file with metadata definition for * the block or path to the folder where the `block.json` file is located. * If providing the path to a JSON file, the filename must end with `block.json`. * @param array $args Optional. Array of block type arguments. Accepts any public property * of `WP_Block_Type`. See WP_Block_Type::__construct() for information * on accepted arguments. Default empty array. * @return WP_Block_Type|false The registered block type on success, or false on failure. */
Home | Imprint | This part of the site doesn't use cookies.