Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@ba00570 from refs/tags/v1.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
prcdevgitbot committed Sep 11, 2024
1 parent 1151461 commit 5fcf55b
Show file tree
Hide file tree
Showing 36 changed files with 21,230 additions and 27 deletions.
1 change: 1 addition & 0 deletions includes/features/blocks/embed-block/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
Empty file.
34 changes: 34 additions & 0 deletions includes/features/blocks/embed-block/build/block.json
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"
}
1 change: 1 addition & 0 deletions includes/features/blocks/embed-block/build/index.asset.php
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');
1 change: 1 addition & 0 deletions includes/features/blocks/embed-block/build/index.css

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

6 changes: 6 additions & 0 deletions includes/features/blocks/embed-block/build/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions includes/features/blocks/embed-block/build/index.js.map

Large diffs are not rendered by default.

Empty file.
76 changes: 76 additions & 0 deletions includes/features/blocks/embed-block/embed-block.php
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' ),
)
);
}
}
Loading

0 comments on commit 5fcf55b

Please sign in to comment.