Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ziodave committed Jan 3, 2024
1 parent d29aab8 commit d46eb93
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
17 changes: 8 additions & 9 deletions src/classes/jsonld/class-jsonld-article-wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ public function after_get_jsonld( $jsonld, $post_id, $context ) {

$author_jsonld = $this->get_author_linked_entity( $article_jsonld );


// Get primary author in case co-authors exist.
$primary_author = $this->get_primary_author($article_jsonld['author']);
$primary_author = $this->get_primary_author( $article_jsonld['author'] );

/**
* The author entities can be present in graph for some entity types
* for Person and Organization, so check before we add it to graph.
Expand All @@ -135,17 +134,17 @@ private function is_article( $schema_types ) {

/**
* Get primary author from author array.
*
*
* A helper function that checks the structure of the author array and returns the primary author.
*
* @param array|string $author The author array.
*
*
* @param array|string $author The author array.
*
* @return array|string The primary author.
*
*
* @since 3.51.4
*/
private function get_primary_author( $author ) {

// Nested array of co-authors. Return the primary author.
if ( is_array( $author ) && ! empty( $author ) && ! isset( $author['@id'] ) ) {
return $author[0];
Expand Down
16 changes: 8 additions & 8 deletions src/includes/class-wordlift-post-to-jsonld-converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,27 @@ public function convert( $post_id, &$references = array(), &$references_infos =

/**
* Call the `wl_post_jsonld_author` filter.
*
*
* This filter checks if there are co-authors or a single author and
* returns a JSON-LD fragment for the author(s).
*
*
* @param array $value {
*
*
* @type array $jsonld The JSON-LD structure.
* @type int[] $references An array of post IDs.
* }
*
*
* @param int $post_id The {@link WP_Post} `id`.
*
*
* @since 3.51.4
*
*
* @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/
*/
$ret_val = apply_filters(
'wl_jsonld_author',
array(
'author' => $this->get_author( $post->post_author, $references ),
'references' => $references
'author' => $this->get_author( $post->post_author, $references ),
'references' => $references,
),
$post_id
);
Expand Down
54 changes: 27 additions & 27 deletions src/modules/jsonld-author-filter/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@

/**
* Filter the author object to add the co-authors.
*
*
* This filter checks if there are co-authors or a single author and
* returns a JSON-LD fragment for the author(s).
*
*
* @param array $value {
* @type array $author The author JSON-LD structure.
* @type int[] $references An array of post IDs.
* }
* @param int $post_id The post ID.
* @param int $post_id The post ID.
*
* @return array An array with the updated JSON-LD and references.
*
*
* @since 3.51.4
*
*
* @see https://www.geeklab.info/2010/04/wordpress-pass-variables-by-reference-with-apply_filter/
*/
function _wl_jsonld_author__author_filter( $args_arr, $post_id ) {

$author = $args_arr['author'];
$references = $args_arr['references'];
$author = $args_arr['author'];
$references = $args_arr['references'];

$coauthor_plugin_path = 'co-authors-plus/co-authors-plus.php';

$coauthor_plugin_path = 'co-authors-plus/co-authors-plus.php';
// If the co-authors plugin is active.
if ( is_plugin_active( $coauthor_plugin_path ) && function_exists( 'get_coauthors' ) ) {

// If the co-authors plugin is active.
if ( is_plugin_active( $coauthor_plugin_path ) && function_exists( 'get_coauthors' ) ) {
$coauthors = get_coauthors( $post_id );

$coauthors = get_coauthors( $post_id );
// And we have multiple authors on a post.
if ( count( $coauthors ) > 1 ) {

// And we have multiple authors on a post.
if ( count( $coauthors ) > 1 ) {
// Clear the existing author.
$author = array();

// Clear the existing author.
$author = array();

// Build array of authors.
foreach ( $coauthors as $coauthor ) {
$author[] = Wordlift_Post_To_Jsonld_Converter::get_instance()->get_author( $coauthor->ID, $references );
}
}
}
// Build array of authors.
foreach ( $coauthors as $coauthor ) {
$author[] = Wordlift_Post_To_Jsonld_Converter::get_instance()->get_author( $coauthor->ID, $references );
}
}
}

return array(
'author' => $author,
'references' => $references,
);
return array(
'author' => $author,
'references' => $references,
);
}

// Add the filter
add_filter('wl_jsonld_author', '_wl_jsonld_author__author_filter', 10, 2);
add_filter( 'wl_jsonld_author', '_wl_jsonld_author__author_filter', 10, 2 );

0 comments on commit d46eb93

Please sign in to comment.