Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@4f8ef9e from refs/heads/release/5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
prcdevgitbot committed Mar 14, 2024
1 parent 6db7ad3 commit 2019422
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 277 deletions.
24 changes: 16 additions & 8 deletions blocks/attachment-info/attachment-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,24 @@ public function init($loader = null) {
}
}

public function get_attachments($parent_post_id) {
public function get_attachments($parent_post_id, $post_id = null) {
$cached_data = false;
// $cached_data = wp_cache_get( $parent_post_id, 'attachment-info' );
if (false !== $cached_data) {
return $cached_data;
}

// check if this is an attachment page and if so get it's id...
$post__not_in = [];
if ( is_attachment($post_id) ) {
$post__not_in = [$post_id];
}

$attachments = new WP_Query( array(
'post_type' => 'attachment',
'post_parent' => $parent_post_id,
'post_status' => 'inherit',
'post__not_in' => $post__not_in,
'posts_per_page' => 50,
'orderby' => 'date',
'order' => 'asc',
Expand Down Expand Up @@ -81,14 +88,15 @@ public function get_attachments($parent_post_id) {

public function render_block_callback( $attributes, $content, $block ) {
$post_id = $block->context['postId'];

$parent_post_id = wp_get_post_parent_id($post_id);

$heading_text = array_key_exists('heading', $attributes) ? $attributes['heading'] : false;

$attachments = $this->get_attachments($parent_post_id);
$attachments = $this->get_attachments($parent_post_id, $post_id);

$post_title = get_the_title($post_id);
$post_url = get_the_permalink($post_id);
$parent_post_title = get_the_title($parent_post_id);
$parent_post_url = get_the_permalink($parent_post_id);

if (! $attachments ) {
return '';
Expand All @@ -110,15 +118,15 @@ public function render_block_callback( $attributes, $content, $block ) {
);

$content .= wp_sprintf(
'<li class="%1$s"><a href="%2$s" target="_blank">%3$s</a></li>',
'<li class="%1$s"><a href="%2$s">%3$s</a></li>',
$list_item_classnames,
$post_url,
$post_title,
$parent_post_url,
$parent_post_title,
);

foreach ($attachments as $attachment) {
$content .= wp_sprintf(
'<li class="%1$s"><a href="%2$s" target="_blank">%3$s</a></li>',
'<li class="%1$s"><a href="%2$s">%3$s</a></li>',
$list_item_classnames,
$attachment['link'],
$attachment['title'],
Expand Down
2 changes: 1 addition & 1 deletion blocks/progress-bar/build/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"backgroundColor": {
"type": "string",
"default": "ui-beige-very-light"
"default": "beige"
},
"categoryLabelColor": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion blocks/progress-bar/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('prc-charting-library', 'prc-icons', 'react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '741129c48c9b6b5dfbce');
<?php return array('dependencies' => array('prc-charting-library', 'prc-icons', 'react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => 'e54a5d567837b8e867ad');
2 changes: 1 addition & 1 deletion blocks/progress-bar/build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion blocks/progress-bar/build/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 2019422

Please sign in to comment.