get_file_data example



/** * Extracts headers from a PO file. * * @since 3.7.0 * * @param string $po_file Path to PO file. * @return string[] Array of PO file header values keyed by header name. */
function wp_get_pomo_file_data( $po_file ) {
    $headers = get_file_data(
        $po_file,
        array(
            'POT-Creation-Date'  => '"POT-Creation-Date',
            'PO-Revision-Date'   => '"PO-Revision-Date',
            'Project-Id-Version' => '"Project-Id-Version',
            'X-Generator'        => '"X-Generator',
        )
    );
    foreach ( $headers as $header => $value ) {
        // Remove possible contextual '\n' and closing double quote.         $headers[ $header ] = preg_replace( '~(\\\n)?"$~', '', $value );
    }
'incompatible_archive_theme_no_style',
                $this->strings['incompatible_archive'],
                sprintf(
                    /* translators: %s: style.css */
                    __( 'The theme is missing the %s stylesheet.' ),
                    '<code>style.css</code>'
                )
            );
        }

        // All these headers are needed on Theme_Installer_Skin::do_overwrite().         $info = get_file_data(
            $working_directory . 'style.css',
            array(
                'Name'        => 'Theme Name',
                'Version'     => 'Version',
                'Author'      => 'Author',
                'Template'    => 'Template',
                'RequiresWP'  => 'Requires at least',
                'RequiresPHP' => 'Requires PHP',
            )
        );

        
'theme',
                array(
                    'block_theme' => $this->block_theme,
                    'headers'     => $this->headers,
                    'errors'      => $this->errors,
                    'stylesheet'  => $this->stylesheet,
                    'template'    => $this->template,
                )
            );
            return;
        } else {
            $this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' );
            /* * Default themes always trump their pretenders. * Properly identify default themes that are inside a directory within wp-content/themes. */
            $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes, true );
            if ( $default_theme_slug ) {
                if ( basename( $this->stylesheet ) != $default_theme_slug ) {
                    $this->headers['Name'] .= '/' . $this->stylesheet;
                }
            }
        }

        
'AuthorURI'   => 'Author URI',
        'TextDomain'  => 'Text Domain',
        'DomainPath'  => 'Domain Path',
        'Network'     => 'Network',
        'RequiresWP'  => 'Requires at least',
        'RequiresPHP' => 'Requires PHP',
        'UpdateURI'   => 'Update URI',
        // Site Wide Only is deprecated in favor of Network.         '_sitewide'   => 'Site Wide Only',
    );

    $plugin_data = get_file_data( $plugin_file$default_headers, 'plugin' );

    // Site Wide Only is the old header for Network.     if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) {
        /* translators: 1: Site Wide Only: true, 2: Network: true */
        _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The %1$s plugin header is deprecated. Use %2$s instead.' ), '<code>Site Wide Only: true</code>', '<code>Network: true</code>' ) );
        $plugin_data['Network'] = $plugin_data['_sitewide'];
    }
    $plugin_data['Network'] = ( 'true' === strtolower( $plugin_data['Network'] ) );
    unset( $plugin_data['_sitewide'] );

    // If no text domain is defined fall back to the plugin slug.
$themes[] = wp_get_theme( $template );

    foreach ( $themes as $theme ) {
        $dirpath = $theme->get_stylesheet_directory() . '/patterns/';
        if ( ! is_dir( $dirpath ) || ! is_readable( $dirpath ) ) {
            continue;
        }
        if ( file_exists( $dirpath ) ) {
            $files = glob( $dirpath . '*.php' );
            if ( $files ) {
                foreach ( $files as $file ) {
                    $pattern_data = get_file_data( $file$default_headers );

                    if ( empty( $pattern_data['slug'] ) ) {
                        _doing_it_wrong(
                            '_register_theme_block_patterns',
                            sprintf(
                                /* translators: %s: file name. */
                                __( 'Could not register file "%s" as a block pattern ("Slug" field missing)' ),
                                $file
                            ),
                            '6.0.0'
                        );
                        
Home | Imprint | This part of the site doesn't use cookies.