Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global header/footer block architecture #4

Merged
merged 4 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

Over time, this is intended to become the canonical source repository all `mu-plugins` on the WordPress.org network. At the moment, it only includes a few.

## Usage

1. Add to a project's `composer.json`, example
1. run `composer update` to download it
1. do in env/0-sandbox.php . on production, it's already defined
```php
define( 'WPORG_GIT_MUPLUGINS_DIR', dirname( ABSPATH ) . '/vendor/wporg/wporg-mu-plugins' );
```
1. `require_once` the files that you want. e.g., have a themes's `functions.php`
```php
require_once WPORG_GIT_MUPLUGINS_DIR . '/mu-plugins/blocks/global-header-footer/blocks.php';
```

## Sync/Deploy

Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "wordpress/wporg-mu-plugins",
"description": "`mu-plugins` for the WordPress.org network",
"license": "GPL-2.0-or-later",
"require": {},
"name": "wporg/wporg-mu-plugins",
"description": "`mu-plugins` for the WordPress.org network",
"license": "GPL-2.0-or-later",
"extra" : {
"sync-svn" : {
"main-branch" : "trunk",
Expand Down
32 changes: 32 additions & 0 deletions mu-plugins/blocks/global-header-footer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Global Header

## Setup




## Register as a block (for Full Site Editing themes)

Add as a composer dependency, install, then add this to a theme's `functions.php`:

```php
require_once WPORG_GIT_MUPLUGINS_DIR . '/mu-plugins/blocks/global-header-footer/blocks.php';
```


## Include directly in PHP (for classic themes)

Add as a composer dependency, install, then

```php
require_once WPORG_GIT_MUPLUGINS_DIR . '/mu-plugins/blocks/global-header-footer/universal-header.php';
```

todo path should be "blocks", or more generic like "components", "template-parts", ?


## Embed as an iframe (for Trac, Codex, etc)

<iframe ...>

src=http...?embed_context=codex
63 changes: 63 additions & 0 deletions mu-plugins/blocks/global-header-footer/blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace WordPress_org\MU_Plugins\Global_Header_Footer;
iandunn marked this conversation as resolved.
Show resolved Hide resolved

defined( 'WPINC' ) || die();

add_action( 'init', __NAMESPACE__ . '\register_assets', 9 );
// why 9? if can be 10, then callers could be 9


function register_assets() {
// don't want this visible in Inserter. need to create ticket for that?

register_block_type(
'wordpress-org/global-header',
iandunn marked this conversation as resolved.
Show resolved Hide resolved
array( 'render_callback' => __NAMESPACE__ . '\render_global_header' )
);

register_block_type(
'wordpress-org/global-footer',
array( 'render_callback' => __NAMESPACE__ . '\render_global_footer' )
);
coreymckrill marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Render the global header in a block context.
*
* @param array $attributes Block attributes.
*
* @return string
*/
function render_global_header( $attributes ) {
/*
todo
meta tags included called automaticaly in FSE themes
so the header needs to avoid adding them for FSE, or we need to disable FSE automatically adding them
*/

ob_start();
require_once __DIR__ . '/universal-header.php';
// cant include inside namespace b/c that messes things up?
// if so, is there a way to de-scope it?

return ob_get_clean();
}

/**
* Render the global footer in a block context.
*
* @param array $attributes Block attributes.
*
* @return string
*/
function render_global_footer( $attributes ) {
ob_start();
require_once __DIR__ . '/universal-footer.php';
return ob_get_clean();
}


// maybe make an api endpoint to serve this to codex/trac?

// all universal logic should go inside header.php, so that Trac, the Codex, etc can load it
5 changes: 5 additions & 0 deletions mu-plugins/blocks/global-header-footer/universal-footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
echo 'this is the global footer :)';
return;


4 changes: 4 additions & 0 deletions mu-plugins/blocks/global-header-footer/universal-header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
echo 'this is the global header :)';
return;