Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
iandunn committed Aug 27, 2021
1 parent b2cbf26 commit d737467
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 51 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"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",
"paths" : {
"mu-plugins/" : "https://dotorg.svn.wordpress.org/wordpress/website/wp-content/mu-plugins/git-sync/ -- todo: name this better, but probably want a subfolder in mu-plugins/ so can cleanly sync"
"require": {},
"extra": {
"sync-svn": {
"main-branch": "trunk",
"paths": {
"mu-plugins/": "https://dotorg.svn.wordpress.org/wordpress/website/wp-content/mu-plugins/git-sync/ -- todo: name this better, but probably want a subfolder in mu-plugins/ so can cleanly sync"
}
}
}
Expand Down
29 changes: 8 additions & 21 deletions mu-plugins/blocks/global-header-footer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,18 @@

## 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';
```

1. Add entries to the `repositories` and `require-dev` sections of `composer.json`
1. Run `composer update` to install it
1. `require_once .../global-header-footer/blocks.php` file. See `wporg-news-2021` as an example.

## Include directly in PHP (for classic themes)

Add as a composer dependency, install, then
The same as above, but include `universal-header.php` directly. See `{ todo }` as an example.

```php
require_once WPORG_GIT_MUPLUGINS_DIR . '/mu-plugins/blocks/global-header-footer/universal-header.php';
```
## Embed as an iframe (for non-WP software like Trac, Codex, etc)

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
```
todo add example, maybe w/ something like `src=http...?embed_context=codex`
```
39 changes: 14 additions & 25 deletions mu-plugins/blocks/global-header-footer/blocks.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<?php

/*
* This file should only contain logic related to blocks.
* Anything that applies to loading the header as raw PHP, iframe'ing, etc, should go in `universal-header.php`.
*/

namespace WordPressdotorg\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
add_action( 'init', __NAMESPACE__ . '\register_block_types', 10 );


function register_assets() {
// don't want this visible in Inserter. need to create ticket for that?
/**
* Register block types
*
* These are intentionally missing arguments like `title`, `category`, `icon`, etc, because we don't want them showing up in the Block Inserter, regardless of which theme is running.
*/
function register_block_types() {
register_block_type(
'wporg/global-header',
array( 'render_callback' => __NAMESPACE__ . '\render_global_header' )
Expand All @@ -25,39 +32,21 @@ function register_assets() {
/**
* 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
*/

function render_global_header() {
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 ) {
function render_global_footer() {
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

0 comments on commit d737467

Please sign in to comment.