Skip to content

Commit

Permalink
Merge pull request #2849 from Parsely/update/remove-repeated-metas-php
Browse files Browse the repository at this point in the history
  • Loading branch information
acicovic authored Oct 16, 2024
2 parents b490e5b + 82f57cd commit b83be77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use Parsely\Parsely;
use WP_Post;

use const Parsely\PARSELY_FILE;

/**
* Renders metadata in the WordPress front-end header.
*
Expand Down Expand Up @@ -115,30 +113,47 @@ public function render_metadata( string $meta_type ): void {
} else {
// Assume `meta_type` is `repeated_metas`.
$parsely_post_type = $this->parsely->convert_jsonld_to_parsely_type( $metadata['@type'] ?? '' );
$tags = '';

// @phpstan-ignore-next-line
if ( isset( $metadata['keywords'] ) && is_array( $metadata['keywords'] ) ) {
$metadata['keywords'] = implode( ',', $metadata['keywords'] );
$tags = implode( ',', $metadata['keywords'] );
}

$parsely_metas = array(
'title' => $metadata['headline'],
'link' => $metadata['url'] ?? null,
'link' => $metadata['url'] ?? '',
'type' => $parsely_post_type,
'image-url' => $metadata['thumbnailUrl'] ?? null,
'pub-date' => $metadata['datePublished'] ?? null,
'section' => $metadata['articleSection'] ?? null,
'tags' => $metadata['keywords'] ?? null,
'author' => isset( $metadata['author'] ),
'image-url' => $metadata['thumbnailUrl'] ?? '',
'pub-date' => $metadata['datePublished'] ?? '',
'section' => $metadata['articleSection'] ?? '',
'tags' => $tags,
);
$parsely_metas = array_filter( $parsely_metas, array( $this, 'filter_empty_and_not_string_from_array' ) );

// Output metas.
foreach ( $parsely_metas as $parsely_meta_key => $parsely_meta_val ) {
printf(
'<meta name="%s" content="%s" />%s',
esc_attr( 'parsely-' . $parsely_meta_key ),
esc_attr( $parsely_meta_val ),
"\n"
);
}

// Output author metas (they can be multiple).
if ( isset( $metadata['author'] ) ) {
$parsely_page_authors = wp_list_pluck( $metadata['author'], 'name' );
$parsely_page_authors = array_filter( $parsely_page_authors, array( $this, 'filter_empty_and_not_string_from_array' ) );
}

include plugin_dir_path( PARSELY_FILE ) . 'views/repeated-metas.php';
foreach ( $parsely_page_authors as $parsely_author_name ) {
printf(
'<meta name="parsely-author" content="%s" />%s',
esc_attr( $parsely_author_name ),
"\n"
);
}
}
}

// Add any custom metadata.
Expand Down
31 changes: 0 additions & 31 deletions views/repeated-metas.php

This file was deleted.

0 comments on commit b83be77

Please sign in to comment.