Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes invalid <meta itemprop="author">, <meta itemprop="tagline">, and 2x twitter:-og tags #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions includes/iworks/class-iworks-opengraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ class iWorks_OpenGraph {
/**
* Schema.org mapping
*
* @version 2.9.4
* @since 2.9.3
* @since 2.9.4 Removes invalid `<meta itemprop="author">` (fixes iworks/og#9)
*/
private $schema_org_mapping = array(
'name' => array( 'og', 'title' ),
'headline' => array( 'og', 'blogdescription' ),
'description' => array( 'og', 'description' ),
'datePublished' => array( 'article', 'published_time' ),
'dateModified' => array( 'article', 'modified_time' ),
'author' => array( 'profile', 'username' ),
'dateModified' => array( 'article', 'modified_time' )
);

/**
Expand Down Expand Up @@ -291,7 +292,6 @@ public function wp_head() {
'tag' => array(),
),
'twitter' => array(
'partner' => 'ogwp',
'site' => apply_filters( 'og_twitter_site', '' ),
'creator' => apply_filters( 'og_twitter_creator', '' ),
'widgets' => apply_filters( 'og_twitter_widgets', array() ),
Expand Down Expand Up @@ -587,7 +587,7 @@ public function wp_head() {
/**
* og:profile
*/
$og['article']['author'] = $this->get_the_author_meta_array( $post->post_author );
$og['article']['author'] = $this->get_the_author_meta_array( $post->post_author )['username'];
$og['profile'] = $this->get_the_author_meta_array( $post->post_author );
}
/**
Expand Down Expand Up @@ -884,7 +884,7 @@ public function wp_head() {
/**
* Twitter
*/
foreach ( array( 'title', 'description', 'url' ) as $key ) {
foreach ( array( 'title', 'description' ) as $key ) {
if ( isset( $og['og'][ $key ] ) ) {
$og['twitter'][ $key ] = $og['og'][ $key ];
}
Expand All @@ -903,15 +903,6 @@ public function wp_head() {
}
}
}
/**
* site slogan
*
* @since 3.2.3
*/
$og['schema']['tagline'] = apply_filters(
'og_schema_tagline',
get_option( 'blogdescription' )
);
}
/**
* Produce image extra tags
Expand Down Expand Up @@ -1546,25 +1537,39 @@ private function get_type() {
}

/**
* get user array
* get user profile array
*
* @since 3.0.1
*/
private function get_the_author_meta_array( $author_id ) {
/**
* Filter `og:profile` values.
*
* @version 2.8.0
* @since 2.7.6
* @since 2.8.0 Prevents leaking protected personal data (related to iworks/og#9)
*
* @link https://ogp.me/#type_profile
* @link https://developer.wordpress.org/reference/functions/get_the_author_meta/
*
* @param array Array of `og:profile` values.
* @param integer User ID.
* @return array For `og:profile` and `og:article:author:` values.
*/
$author_display_name = get_the_author_meta( 'display_name', $author_id );
$author_first_name = get_the_author_meta( 'first_name', $author_id );
$author_last_name = get_the_author_meta( 'last_name', $author_id );
$author_nicename_is_fullname = ($author_display_name === $author_first_name.' '.$author_last_name ? true : false);

return apply_filters(
'og_profile',
array(
'first_name' => get_the_author_meta( 'first_name', $author_id ),
'last_name' => get_the_author_meta( 'last_name', $author_id ),
'username' => get_the_author_meta( 'display_name', $author_id ),
( $author_nicename_is_fullname ?
array(
'first_name' => $author_first_name
,'last_name' => $author_last_name
,'username' => $author_display_name
) : array(
'username' => $author_display_name
)
),
$author_id
);
Expand Down