Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@50cdde9 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 2ef40bc commit b0021fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 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/navigation-mega-menu/build/style-index.css

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

4 changes: 3 additions & 1 deletion blocks/navigation-mega-menu/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@
border-bottom-width: 1px;
border-bottom-color: var(--active-border-color);
border-bottom-style: solid;
border-top-width: 0px;
border-top-width: 1px;
border-top-color: var(--active-border-color);
border-top-style: solid;
max-width: 100vw;
width: 100vw;

Expand Down

0 comments on commit b0021fc

Please sign in to comment.