Skip to content

Commit

Permalink
Merge trunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenDufresne committed Mar 7, 2022
2 parents 7edb018 + 7674f5d commit fcf6262
Show file tree
Hide file tree
Showing 20 changed files with 571 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
README-svn.txt
build
**/node_modules
**/vendor
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@
},
"require-dev": {
"wporg/wporg-repo-tools": "dev-trunk"
},
"config": {
"allow-plugins": {
"composer/installers": true
}
}
}
203 changes: 203 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions mu-plugins/blocks/global-header-footer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
1. Add `<!-- wp:wporg/global-header /-->` to the theme's `block-templates/*.html` files.


## Classic themes
## Classic themes in the w.org network

The same as above, but instead of adding the block to `block-templates/*.html` files, you'd add it to `themes/{name}/header.php`:

Expand All @@ -23,8 +23,23 @@ echo do_blocks( '<!-- wp:wporg/global-header /-->' );
⚠️ You can't just `require header.php` directly, because the dynamic blocks need to be processed by `do_blocks()`, and `blocks.php` does additional work that's necessary.


## Classic themes in other networks

If a WP site isn't in the main w.org network (e.g., buddypress.org, *.wordpress.net, etc), then the setup is still the same:

```php
echo do_blocks( '<!-- wp:wporg/global-footer /-->' );
```

The only difference is that `get_global_styles()` fetches them via the endpoint rather than using `switch_to_blog()`.

See `r18316-dotorg` for an example.


## Non-WP software (like Trac, Codex, etc)

@todo - probably pull contents from a REST API
Use the API endpoints to get the markup and styles. See `register_routes()` for the endpoints. Examples:

see https://github.com/WordPress/wporg-mu-plugins/issues/45
* Trac: [`templates/update-headers.php`](https://github.com/dd32/wordpress.org/blob/c019f1ceb345310c472136d951f82d97fd517cda/trac.wordpress.org/templates/update-headers.php) in Meta SVN.
* Codex: `grab-wporg-header-footer.sh` runs on a cron and updates `header.inc`, then `skins/codex/Codex.php` includes them. See `r14081-deploy`. Codex has heavy page caching, only systems can clear the page cache.
* Planet: `planet/bin/generate-index-template.sh` in `dotorg`.
38 changes: 16 additions & 22 deletions mu-plugins/blocks/global-header-footer/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
add_action( 'enqueue_block_assets', __NAMESPACE__ . '\register_block_types_js' );
add_filter( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_block_assets', 200 ); // Always last.
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_compat_wp4_styles', 5 ); // Before any theme CSS.
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_fonts' );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\unregister_classic_global_styles', 20 );
add_action( 'wp_head', __NAMESPACE__ . '\preload_google_fonts' );
add_filter( 'style_loader_src', __NAMESPACE__ . '\update_google_fonts_url', 10, 2 );
add_filter( 'render_block_core/navigation-link', __NAMESPACE__ . '\swap_submenu_arrow_svg' );
Expand Down Expand Up @@ -53,10 +53,15 @@ function register_block_types() {
function register_block_assets() {
$suffix = is_rtl() ? '-rtl' : '';

// Load `block-library` styles first, so that our styles override them.
$style_dependencies = array( 'wp-block-library' );
if ( wp_style_is( 'wporg-global-fonts', 'registered' ) ) {
$style_dependencies[] = 'wporg-global-fonts';
}
wp_register_style(
'wporg-global-header-footer',
plugins_url( "/build/style$suffix.css", __FILE__ ),
array( 'wp-block-library' ), // Load `block-library` styles first, so that our styles override them.
$style_dependencies,
filemtime( __DIR__ . "/build/style$suffix.css" )
);

Expand Down Expand Up @@ -240,29 +245,23 @@ function enqueue_compat_wp4_styles() {
'wp4-styles',
'https://s.w.org/style/wp4' . $suffix . '.css',
array( 'open-sans' ),
97
filemtime( WPORGPATH . '/style/wp4' . $suffix . '.css' )
);

wp_enqueue_style( 'wp4-styles' );
}
}

/**
* Load EB Garamond & Inter (fonts) for use in header & footer on classic themes.
*
* In the block theme, this is loaded by `theme.json` & `WordPressdotorg\Theme\News_2021\enqueue_assets`.
* Unregister the `global-styles` from classic themes, to avoid overwriting our custom properties.
*/
function enqueue_fonts() {
function unregister_classic_global_styles() {
if ( wp_is_block_theme() ) {
return;
}

wp_enqueue_style(
'wporg-news-fonts-css',
'https://fonts.googleapis.com/css2?family=Inter:[email protected]&family=EB+Garamond:wght@400&display=swap',
array(),
null
);
wp_dequeue_style( 'global-styles' );
wp_deregister_style( 'global-styles' );
}

/**
Expand Down Expand Up @@ -903,13 +902,13 @@ function get_global_styles() {
return fetch_global_styles();
}

// Switch to `w.org/news-test` to generate correct theme properties.
switch_to_blog( 706 ); // TODO change this to `w.org/news` when the redesign launches.
// Switch to `w.org/news` to generate correct theme properties.
switch_to_blog( WPORG_NEWS_BLOGID );

// Clear the static `$theme` property, which is set by the current (classic theme) site.
WP_Theme_JSON_Resolver::clean_cached_data();

$styles = wp_get_global_stylesheet( [ 'variables' ] );
$styles = wp_get_global_stylesheet( [ 'variables', 'presets' ] );
// Also set the block-gap style, which isn't technically a theme variable.
$styles .= 'body { --wp--style--block-gap: 24px; }';

Expand All @@ -934,7 +933,7 @@ function fetch_global_styles() {
$request_args = array();

// Route request to sandbox when testing.
if ( defined( 'WPORG_SANDBOXED' ) && WPORG_SANDBOXED ) {
if ( 'staging' === wp_get_environment_type() ) {
$hostname = '127.0.0.1';
$request_args['headers']['host'] = 'wordpress.org';

Expand Down Expand Up @@ -1015,11 +1014,6 @@ function get_menu_url_for_current_page( $menu_items ) {
return '';
}

// Temporary
if ( 'https://wordpress.org/news-test/' === home_url( '/' ) ) {
return 'https://wordpress.org/news/';
}

// Is it the Global Search?
if ( str_starts_with( $compare, 'https://wordpress.org/search/' ) ) {
if ( isset( $_GET['in'] ) ) {
Expand Down
26 changes: 12 additions & 14 deletions mu-plugins/blocks/global-header-footer/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,20 @@
<div class="wp-block-group global-footer__logos-container">
<!-- wp:group {"layout":{"type":"flex","allowOrientation":false,"justifyContent":"left"}} -->
<div class="wp-block-group">
<!-- wp:html -->
<!-- The design calls for two logos, a small "mark" on mobile/tablet, and the full logo for desktops. -->
<!-- wp:image {"width":27,"height":27,"className":"global-footer__wporg-logo-mark"} -->
<figure class="wp-block-image is-resized global-footer__wporg-logo-mark">
<a href="<?php echo esc_url( get_home_url() ); ?>">
<img src="https://wordpress.org/style/images/w-mark.svg" alt="<?php echo esc_html_x( 'WordPress.org', 'Image alt text', 'wporg' ); ?>" width="27" height="27" />
</a>
</figure>
<!-- /wp:image -->
<figure class="wp-block-image global-footer__wporg-logo-mark">
<a href="<?php echo esc_url( get_home_url() ); ?>">
<?php require __DIR__ . '/images/w-mark.svg'; ?>
</a>
</figure>

<!-- wp:image {"width":160,"height":24,"className":"global-footer__wporg-logo-full"} -->
<figure class="wp-block-image is-resized global-footer__wporg-logo-full">
<a href="<?php echo esc_url( get_home_url() ); ?>">
<img src="<?php echo plugin_dir_url( __FILE__ ) . 'images/wporg-logo.svg'; ?>" alt="<?php echo esc_html_x( 'WordPress.org', 'Image alt text', 'wporg' ); ?>" width="160" height="24" />
</a>
</figure>
<!-- /wp:image -->
<figure class="wp-block-image global-footer__wporg-logo-full">
<a href="<?php echo esc_url( get_home_url() ); ?>">
<?php require __DIR__ . '/images/wporg-logo.svg'; ?>
</a>
</figure>
<!-- /wp:html -->

<?php if ( ! empty( $locale_title ) ) : ?>
<!-- wp:paragraph {"className":"global-footer__wporg-locale-title"} -->
Expand Down
Loading

0 comments on commit fcf6262

Please sign in to comment.