Skip to content

Commit

Permalink
Revert PHP types in qtranxf_checkCanonical (#1314)
Browse files Browse the repository at this point in the history
The main purpose is to filter `redirect_canonical` (WP hook).
The WP documentation is not precise regarding the types so we have
to relax the types check. Check first if the redirect URL is false.

The second parameter is the requested URL but it is ignored.
See #1320, wrong usage with Yoast. The second parameter has a
different meaning with Yoast. Removing the types will work but the
Yoast hook should be rewritten with a different function.

Rewrite the function to handle the default language in convertURL.
  • Loading branch information
herrvigg committed Apr 15, 2023
1 parent 2e8e453 commit 773c778
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,12 +815,19 @@ function qtranxf_updated_usermeta( int $meta_id, int $object_id, string $meta_ke
qtranxf_cache_delete_metadata( 'user', $object_id );
}

// TODO check API with Yoast, seems it's only 1 parameter?
function qtranxf_checkCanonical( string $redirect_url, string $requested_url ): string {
global $q_config;
$lang = $q_config['language'];
/**
* Hook for redirect_canonical.
*
* @param string|false $redirect_url Attention! WordPress documents it as string, but it can be false.
* @param mixed $requested_url Attention! WordPress documents it as string, but it can be array or null.
*
*/
function qtranxf_checkCanonical( $redirect_url, $requested_url ): string {
if ( $redirect_url === false ) {
return false;
}
// fix canonical conflicts with language urls
return qtranxf_convertURL( $redirect_url, $lang );
return qtranxf_convertURL( $redirect_url );
}

/**
Expand Down

0 comments on commit 773c778

Please sign in to comment.