-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See pewresearch/pewresearch-org@ba00570 from refs/tags/v1.0.15
- Loading branch information
1 parent
1151461
commit 5fcf55b
Showing
36 changed files
with
21,230 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode |
Empty file.
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,34 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"name": "prc-platform/interactive", | ||
"version": "0.1.0", | ||
"title": "Interactive Feature", | ||
"description": "Create an embed of a feature post. Update the feature, and the changes will apply everywhere it is embedded.", | ||
"category": "media", | ||
"keywords": [ | ||
"features", | ||
"interactive", | ||
"embed", | ||
"feature" | ||
], | ||
"attributes": { | ||
"ref": { | ||
"type": "number" | ||
} | ||
}, | ||
"supports": { | ||
"anchor": true, | ||
"html": false | ||
}, | ||
"usesContext": [ | ||
"queryId", | ||
"query", | ||
"queryContext", | ||
"templateSlug", | ||
"previewPostType" | ||
], | ||
"textdomain": "prc-platform-interactive", | ||
"editorScript": "file:./index.js", | ||
"render": "file:./render.php" | ||
} |
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 @@ | ||
<?php return array('dependencies' => array('prc-components', 'react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives'), 'version' => 'a41fbdea79e755ad3b33'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
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,76 @@ | ||
<?php | ||
namespace PRC\Platform; | ||
|
||
/** | ||
* Block Name: Feature Embed Block | ||
* Description: A block that embeds a feature elsewhere on the site. | ||
* Requires at least: 6.4 | ||
* Requires PHP: 8.1 | ||
* Author: Ben Wormald | ||
* | ||
* @package prc-platform | ||
*/ | ||
|
||
class Embed_Block extends Features { | ||
public function __construct($loader) { | ||
$this->init($loader); | ||
} | ||
|
||
public function init($loader = null) { | ||
if ( null !== $loader ) { | ||
$loader->add_action( 'init', $this, 'block_init' ); | ||
} | ||
} | ||
|
||
// TODO: This exact function is being used at least in 3 places (feature, chart, data table). Maybe let's centralize?. | ||
public function render_synced_feature( $attributes, $content ) { | ||
if ( is_admin() ) { | ||
return; | ||
} | ||
static $seen_refs = array(); | ||
if ( empty( $attributes['ref'] ) ) { | ||
return ''; | ||
} | ||
$synced_feature = get_post( $attributes['ref'] ); | ||
// if there is no post, or the post is not a feature, return an empty string | ||
if ( ! $synced_feature || self::$post_type !== $synced_feature->post_type ) { | ||
return ''; | ||
} | ||
|
||
if ( isset( $seen_refs[ $attributes['ref'] ] ) ) { | ||
// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent | ||
// is set in `wp_debug_mode()`. | ||
$is_debug = WP_DEBUG && WP_DEBUG_DISPLAY; | ||
|
||
return $is_debug ? | ||
// translators: Visible only in the front end, this warning takes the place of a faulty block. | ||
__( '[block rendering halted]' ) : | ||
''; | ||
} | ||
// if the post is not published or is password protected, return an empty string | ||
if ( 'publish' !== $synced_feature->post_status || ! empty( $synced_feature->post_password ) ) { | ||
return ''; | ||
} | ||
|
||
$seen_refs[ $attributes['ref'] ] = true; | ||
|
||
// Handle embeds | ||
global $wp_embed; | ||
$content = $wp_embed->run_shortcode( $synced_feature->post_content ); | ||
$content = $wp_embed->autoembed( $content ); | ||
|
||
$content = do_blocks( $content ); | ||
// remove the reference from the seen_refs array | ||
unset( $seen_refs[ $attributes['ref'] ] ); | ||
return $content; | ||
} | ||
|
||
public function block_init() { | ||
register_block_type( | ||
__DIR__ . '/build', | ||
array( | ||
'render_callback' => array( $this, 'render_synced_feature' ), | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.