-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global header/footer block architecture
- Loading branch information
Showing
6 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace WordPress_org\MU_Plugins\Global_Header_Footer; | ||
|
||
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', | ||
array( 'render_callback' => __NAMESPACE__ . '\render_global_header' ) | ||
); | ||
|
||
register_block_type( | ||
'wordpress-org/global-footer', | ||
array( 'render_callback' => __NAMESPACE__ . '\render_global_footer' ) | ||
); | ||
} | ||
|
||
/** | ||
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
echo 'this is the global footer :)'; | ||
return; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
echo 'this is the global header :)'; | ||
return; | ||
|