Skip to content

Commit

Permalink
Fix warnings Yoast breadcrumbs front (#1086)
Browse files Browse the repository at this point in the history
Add additional checks and make it consistent.
  • Loading branch information
herrvigg committed Dec 4, 2021
1 parent 2a9d363 commit a7168a0
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions modules/wp-seo/wp-seo-front.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,43 @@ function qtranxf_wpseo_add_filters_front() {
add_filter( $name, 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage', $priority );
}

add_filter( 'wpseo_schema_webpage', 'qtranxf_wpseo_webpage_schema', 10, 2 );
function qtranxf_wpseo_webpage_schema( $piece, $context ) {
if ( array_key_exists( 'description', $piece ) ) {
if ( isset( $piece['description'] ) ) {
$piece['description'] = qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage( $piece['description'] );
}
if ( array_key_exists( 'name', $piece ) ) {
if ( isset( $piece['name'] ) ) {
$piece['name'] = qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage( $piece['name'] );
}

return $piece;
}

add_filter( 'wpseo_breadcrumb_single_link_info', 'qtranxf_wpseo_breadcrumbs_link', 10, 3 );
add_filter( 'wpseo_schema_webpage', 'qtranxf_wpseo_webpage_schema', 10, 2 );

function qtranxf_wpseo_breadcrumbs_link( $link_info, $index, $crumbs ) {
global $q_config;

$link_info['text'] = qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage( $link_info['text'] );
$link_info['url'] = qtranxf_convertURL( $link_info['url'], $q_config['language'] );
if ( isset( $data['text'] ) ) {
$link_info['text'] = qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage( $link_info['text'] );
}
if ( isset( $data['url'] ) ) {
$link_info['url'] = qtranxf_convertURL( $link_info['url'], $q_config['language'] );
}

return $link_info;
}

add_filter( 'wpseo_breadcrumb_single_link_info', 'qtranxf_wpseo_breadcrumbs_link', 10, 3 );

function qtranxf_wpseo_schema_website( $data ) {
global $q_config;

$data['@id'] = qtranxf_convertURL( $data['@id'], $q_config['language'] );
$data['url'] = qtranxf_convertURL( $data['url'], $q_config['language'] );
if ( isset( $data['@id'] ) ) {
$data['@id'] = qtranxf_convertURL( $data['@id'], $q_config['language'] );
}
if ( isset( $data['url'] ) ) {
$data['url'] = qtranxf_convertURL( $data['url'], $q_config['language'] );
}

return $data;
}
Expand All @@ -66,17 +76,17 @@ function qtranxf_wpseo_schema_website( $data ) {
function qtranxf_wpseo_json_ld_search_url( $search_url ) {
global $q_config;

$search_url = qtranxf_convertURL( $search_url, $q_config['language'] );

return $search_url;
return qtranxf_convertURL( $search_url, $q_config['language'] );
}

add_filter( 'wpseo_json_ld_search_url', 'qtranxf_wpseo_json_ld_search_url', 10, 3 );

function qtranxf_wpseo_schema_imageobject( $data ) {
global $q_config;

$data['@id'] = qtranxf_convertURL( $data['@id'], $q_config['language'] );
if ( isset( $data['@id'] ) ) {
$data['@id'] = qtranxf_convertURL( $data['@id'], $q_config['language'] );
}

return $data;
}
Expand All @@ -88,22 +98,24 @@ function qtranxf_wpseo_schema_webpage( $data ) {

$lang = $q_config['language'];

$data['@id'] = qtranxf_convertURL( $data['@id'], $lang );
$data['url'] = qtranxf_convertURL( $data['url'], $lang );

if ( isset( $data['@id'] ) ) {
$data['@id'] = qtranxf_convertURL( $data['@id'], $lang );
}
if ( isset( $data['url'] ) ) {
$data['url'] = qtranxf_convertURL( $data['url'], $lang );
}
if ( isset( $data['isPartOf']['@id'] ) ) {
$data['isPartOf']['@id'] = qtranxf_convertURL( $data['isPartOf']['@id'], $lang );
}
if ( isset( $data['primaryImageOfPage']['@id'] ) ) {
$data['primaryImageOfPage']['@id'] = qtranxf_convertURL( $data['primaryImageOfPage']['@id'], $lang );
}
// It seems to work fine for $data['author']['@id'] without filter.

if ( isset( $data['breadcrumb']['@id'] ) ) {
$data['breadcrumb']['@id'] = qtranxf_convertURL( $data['breadcrumb']['@id'], $lang );
}
if ( $data['potentialAction'][0]['target'] ) {
$data['potentialAction'][0]['target'] = [ qtranxf_convertURL( $data['potentialAction'][0]->target, $lang ) ];
if ( isset( $data['potentialAction'][0]['target'] ) ) {
$data['potentialAction'][0]['target'] = [ qtranxf_convertURL( $data['potentialAction'][0]['target'], $lang ) ];
}

return $data;
Expand All @@ -114,7 +126,9 @@ function qtranxf_wpseo_schema_webpage( $data ) {
function qtranxf_wpseo_schema_breadcrumb( $data ) {
global $q_config;

$data['@id'] = qtranxf_convertURL( $data['@id'], $q_config['language'] );
if ( isset( $data['@id'] ) ) {
$data['@id'] = qtranxf_convertURL( $data['@id'], $q_config['language'] );
}

return $data;
}
Expand Down

0 comments on commit a7168a0

Please sign in to comment.