Skip to content

Commit af58ac5

Browse files
committed
Merge branch 'trunk' of https://github.com/Yoast/wordpress-seo into PC-965-yoast-markers-break-html-of-content
2 parents 33b6b48 + df0429e commit af58ac5

31 files changed

Lines changed: 455 additions & 96 deletions

admin/class-admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function add_action_link( $links, $file ) {
252252
}
253253

254254
// Add link to premium landing page.
255-
$premium_link = '<a style="font-weight: bold;" href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yb' ) ) . '" target="_blank">' . __( 'Get Premium', 'wordpress-seo' ) . '</a>';
255+
$premium_link = '<a style="font-weight: bold;" href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yb' ) ) . '" target="_blank" data-action="load-nfd-ctb" data-ctb-id="57d6a568-783c-45e2-a388-847cff155897">' . __( 'Get Premium', 'wordpress-seo' ) . '</a>';
256256
array_unshift( $links, $premium_link );
257257

258258
return $links;

inc/class-wpseo-admin-bar-menu.php

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* @package WPSEO
66
*/
77

8-
use WPSEO_Shortlinker;
98
use Yoast\WP\SEO\Helpers\Product_Helper;
109
use Yoast\WP\SEO\Helpers\Score_Icon_Helper;
1110
use Yoast\WP\SEO\Models\Indexable;
@@ -80,6 +79,13 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
8079
*/
8180
protected $product_helper;
8281

82+
/**
83+
* Holds the shortlinker instance.
84+
*
85+
* @var WPSEO_Shortlinker
86+
*/
87+
protected $shortlinker;
88+
8389
/**
8490
* Whether SEO Score is enabled.
8591
*
@@ -108,12 +114,14 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
108114
* @param Indexable_Repository|null $indexable_repository Optional. The Indexable_Repository.
109115
* @param Score_Icon_Helper|null $score_icon_helper Optional. The Score_Icon_Helper.
110116
* @param Product_Helper|null $product_helper Optional. The product helper.
117+
* @param WPSEO_Shortlinker|null $shortlinker The shortlinker.
111118
*/
112119
public function __construct(
113120
WPSEO_Admin_Asset_Manager $asset_manager = null,
114121
Indexable_Repository $indexable_repository = null,
115122
Score_Icon_Helper $score_icon_helper = null,
116-
Product_Helper $product_helper = null
123+
Product_Helper $product_helper = null,
124+
WPSEO_Shortlinker $shortlinker = null
117125
) {
118126
if ( ! $asset_manager ) {
119127
$asset_manager = new WPSEO_Admin_Asset_Manager();
@@ -127,11 +135,15 @@ public function __construct(
127135
if ( ! $product_helper ) {
128136
$product_helper = YoastSEO()->helpers->product;
129137
}
138+
if ( ! $shortlinker ) {
139+
$shortlinker = new WPSEO_Shortlinker();
140+
}
130141

131142
$this->product_helper = $product_helper;
132143
$this->asset_manager = $asset_manager;
133144
$this->indexable_repository = $indexable_repository;
134145
$this->score_icon_helper = $score_icon_helper;
146+
$this->shortlinker = $shortlinker;
135147
}
136148

137149
/**
@@ -246,7 +258,7 @@ public function add_menu( WP_Admin_Bar $wp_admin_bar ) {
246258
[
247259
'parent' => self::MENU_IDENTIFIER,
248260
'id' => 'wpseo-frontend-inspector',
249-
'href' => 'https://yoa.st/admin-bar-frontend-inspector',
261+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-frontend-inspector' ),
250262
'title' => __( 'Front-end SEO inspector', 'wordpress-seo' ) . new Premium_Badge_Presenter( 'wpseo-frontend-inspector-badge' ),
251263
'meta' => [
252264
'tabindex' => '0',
@@ -461,17 +473,17 @@ protected function add_seo_tools_submenu( WP_Admin_Bar $wp_admin_bar ) {
461473
[
462474
'id' => 'wpseo-semrush',
463475
'title' => 'Semrush',
464-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-semrush' ),
476+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-semrush' ),
465477
],
466478
[
467479
'id' => 'wpseo-wincher',
468480
'title' => 'Wincher',
469-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-wincher' ),
481+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-wincher' ),
470482
],
471483
[
472484
'id' => 'wpseo-google-trends',
473485
'title' => 'Google trends',
474-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-gtrends' ),
486+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-gtrends' ),
475487
],
476488
];
477489

@@ -498,17 +510,17 @@ protected function add_how_to_submenu( WP_Admin_Bar $wp_admin_bar ) {
498510
[
499511
'id' => 'wpseo-learn-seo',
500512
'title' => __( 'Learn more SEO', 'wordpress-seo' ),
501-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-learn-more-seo' ),
513+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-learn-more-seo' ),
502514
],
503515
[
504516
'id' => 'wpseo-improve-blogpost',
505517
'title' => __( 'Improve your blog post', 'wordpress-seo' ),
506-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-improve-blog-post' ),
518+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-improve-blog-post' ),
507519
],
508520
[
509521
'id' => 'wpseo-write-better-content',
510522
'title' => __( 'Write better content', 'wordpress-seo' ),
511-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-write-better' ),
523+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-write-better' ),
512524
],
513525
];
514526

@@ -535,22 +547,22 @@ protected function add_get_help_submenu( WP_Admin_Bar $wp_admin_bar ) {
535547
[
536548
'id' => 'wpseo-yoast-help',
537549
'title' => __( 'Yoast.com help section', 'wordpress-seo' ),
538-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-yoast-help' ),
550+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-yoast-help' ),
539551
],
540552
[
541553
'id' => 'wpseo-premium-support',
542554
'title' => __( 'Yoast Premium support', 'wordpress-seo' ),
543-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-premium-support' ),
555+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-premium-support' ),
544556
],
545557
[
546558
'id' => 'wpseo-wp-support-forums',
547559
'title' => __( 'WordPress.org support forums', 'wordpress-seo' ),
548-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-wp-support-forums' ),
560+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-wp-support-forums' ),
549561
],
550562
[
551563
'id' => 'wpseo-learn-seo-2',
552564
'title' => __( 'Learn more SEO', 'wordpress-seo' ),
553-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-learn-more-seo-help' ),
565+
'href' => $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-learn-more-seo-help' ),
554566
],
555567
];
556568

@@ -569,11 +581,14 @@ protected function add_premium_link( WP_Admin_Bar $wp_admin_bar ) {
569581
[
570582
'parent' => self::MENU_IDENTIFIER,
571583
'id' => 'wpseo-get-premium',
572-
'title' => __( 'Get Yoast SEO Premium', 'wordpress-seo' ) . ' &raquo;',
573-
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/admin-bar-get-premium' ),
584+
// Circumvent an issue in the WP admin bar API in order to pass `data` attributes. See https://core.trac.wordpress.org/ticket/38636.
585+
'title' => sprintf(
586+
'<a href="%1$s" target="_blank" data-action="load-nfd-ctb" data-ctb-id="57d6a568-783c-45e2-a388-847cff155897" style="padding:0;">%2$s &raquo;</a>',
587+
$this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-get-premium' ),
588+
__( 'Get Yoast SEO Premium', 'wordpress-seo' )
589+
),
574590
'meta' => [
575591
'tabindex' => '0',
576-
'target' => '_blank',
577592
],
578593
]
579594
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"typescript": "^4.2.4"
8585
},
8686
"yoast": {
87-
"pluginVersion": "19.12-RC6"
87+
"pluginVersion": "19.12-RC7"
8888
},
8989
"version": "0.0.0"
9090
}

packages/js/src/settings/components/search.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { debounce, first, groupBy, includes, isEmpty, map, max, reduce, split, t
99
import PropTypes from "prop-types";
1010
import { useHotkeys } from "react-hotkeys-hook";
1111
import { useNavigate } from "react-router-dom";
12+
import { safeToLocaleLower } from "../helpers";
1213
import { useParsedUserAgent, useSelectSettings } from "../hooks";
1314

1415
const QUERY_MIN_CHARS = 3;
@@ -37,6 +38,7 @@ const Search = () => {
3738
// eslint-disable-next-line no-unused-vars
3839
const [ isOpen, , , setOpen, setClose ] = useToggleState( false );
3940
const [ query, setQuery ] = useState( "" );
41+
const userLocale = useSelectSettings( "selectPreference", [], "userLocale" );
4042
const queryableSearchIndex = useSelectSettings( "selectQueryableSearchIndex" );
4143
const [ results, setResults ] = useState( [] );
4244
const ariaSvgProps = useSvgAria();
@@ -77,8 +79,8 @@ const Search = () => {
7779
return false;
7880
}
7981

80-
// Split query into words.
81-
const splitQuery = split( trimmedQuery, " " );
82+
// Lowercase and split query into words.
83+
const splitQuery = split( safeToLocaleLower( trimmedQuery, userLocale ), " " );
8284

8385
// Filter search index by split query and store number of hits.
8486
// A hit is registered if a single word from split query in found in a fields keywords.
@@ -115,7 +117,7 @@ const Search = () => {
115117
} );
116118

117119
setResults( sortedGroupedQueryResults );
118-
}, 100 ), [ queryableSearchIndex ] );
120+
}, 100 ), [ queryableSearchIndex, userLocale ] );
119121

120122
const handleQueryChange = useCallback( event => {
121123
setQuery( event.target.value );
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Lowercase a string in a locale, but with invalid locale safety.
3+
* @param {string} string The string to lowercase.
4+
* @param {string} locale The locale string.
5+
* @returns {string} The lower case string if locale is valid, the string if locale is invalid.
6+
*/
7+
export const safeToLocaleLower = ( string, locale ) => {
8+
try {
9+
return string.toLocaleLowerCase( locale );
10+
} catch ( error ) {
11+
console.error( error.message );
12+
return string;
13+
}
14+
};

packages/js/src/settings/helpers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./i18n";
12
export * from "./user-social-profiles";
23
export * from "./search";
34
export * from "./submit";

packages/js/src/settings/helpers/search.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import { __, sprintf } from "@wordpress/i18n";
33
import { Code } from "@yoast/ui-library";
44
import { createInterpolateElement } from "@wordpress/element";
5-
import { omit, reduce, times, toLower, filter, includes, isEmpty } from "lodash";
5+
import { omit, reduce, times, filter, includes, isEmpty } from "lodash";
6+
import { safeToLocaleLower } from "./i18n";
67

78
/**
89
* @param {Object} postType The post type.
10+
* @param {Object} options The options.
11+
* @param {string} options.userLocale The user locale string.
912
* @returns {Object} The search index for the post type.
1013
*/
11-
export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } ) => ( {
14+
export const createPostTypeSearchIndex = ( { name, label, route, hasArchive }, { userLocale } ) => ( {
1215
[ `title-${ name }` ]: {
1316
route: `/post-type/${ route }`,
1417
routeLabel: label,
@@ -30,7 +33,7 @@ export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } )
3033
fieldLabel: sprintf(
3134
// translators: %1$s expands to the post type plural, e.g. Posts.
3235
__( "Show %1$s in search results", "wordpress-seo" ),
33-
toLower( label )
36+
safeToLocaleLower( label, userLocale )
3437
),
3538
keywords: [],
3639
},
@@ -120,7 +123,7 @@ export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } )
120123
fieldLabel: sprintf(
121124
// translators: %1$s expands to the post type plural, e.g. Posts.
122125
__( "Show the archive for %1$s in search results", "wordpress-seo" ),
123-
toLower( label )
126+
safeToLocaleLower( label, userLocale )
124127
),
125128
keywords: [],
126129
},
@@ -150,9 +153,11 @@ export const createPostTypeSearchIndex = ( { name, label, route, hasArchive } )
150153

151154
/**
152155
* @param {Object} taxonomy The taxonomy.
156+
* @param {Object} options The options.
157+
* @param {string} options.userLocale The user locale string.
153158
* @returns {Object} The search index for the taxonomy.
154159
*/
155-
export const createTaxonomySearchIndex = ( { name, label, route } ) => ( {
160+
export const createTaxonomySearchIndex = ( { name, label, route }, { userLocale } ) => ( {
156161
[ `title-tax-${ name }` ]: {
157162
route: `/taxonomy/${ route }`,
158163
routeLabel: label,
@@ -175,7 +180,7 @@ export const createTaxonomySearchIndex = ( { name, label, route } ) => ( {
175180
/* translators: %1$s expands to "Yoast SEO". %2$s expands to the taxonomy plural, e.g. Categories. */
176181
__( "Enable %1$s for %2$s", "wordpress-seo" ),
177182
"Yoast SEO",
178-
toLower( label )
183+
safeToLocaleLower( label, userLocale )
179184
),
180185
keywords: [],
181186
},
@@ -193,7 +198,7 @@ export const createTaxonomySearchIndex = ( { name, label, route } ) => ( {
193198
fieldLabel: sprintf(
194199
// translators: %1$s expands to the taxonomy plural, e.g. Categories.
195200
__( "Show %1$s in search results", "wordpress-seo" ),
196-
toLower( label )
201+
safeToLocaleLower( label, userLocale )
197202
),
198203
keywords: [],
199204
},
@@ -232,9 +237,11 @@ export const createTaxonomySearchIndex = ( { name, label, route } ) => ( {
232237
/**
233238
* @param {Object} postTypes The post types.
234239
* @param {Object} taxonomies The taxonomies.
240+
* @param {Object} options The options.
241+
* @param {string} options.userLocale The user locale string.
235242
* @returns {Object} The search index.
236243
*/
237-
export const createSearchIndex = ( postTypes, taxonomies ) => ( {
244+
export const createSearchIndex = ( postTypes, taxonomies, { userLocale } = {} ) => ( {
238245
blogdescription: {
239246
route: "/site-basics",
240247
routeLabel: __( "Site basics", "wordpress-seo" ),
@@ -751,7 +758,7 @@ export const createSearchIndex = ( postTypes, taxonomies ) => ( {
751758
fieldId: `input-wpseo_titles-post_types-${ postType.name }-maintax`,
752759
fieldLabel: createInterpolateElement(
753760
// translators: %1$s expands to the post type plural, e.g. posts.
754-
sprintf( __( "Breadcrumbs for %1$s<code />", "wordpress-seo" ), toLower( postType.label ) ),
761+
sprintf( __( "Breadcrumbs for %1$s<code />", "wordpress-seo" ), safeToLocaleLower( postType.label, userLocale ) ),
755762
{
756763
code: <Code className="yst-ml-2 group-hover:yst-bg-primary-200 group-hover:yst-text-primary-800">{ postType.name }</Code>,
757764
}
@@ -768,7 +775,7 @@ export const createSearchIndex = ( postTypes, taxonomies ) => ( {
768775
fieldId: `input-wpseo_titles-taxonomy-${ taxonomy.name }-ptparent`,
769776
fieldLabel: createInterpolateElement(
770777
// translators: %1$s expands to the taxonomy plural, e.g. categories.
771-
sprintf( __( "Breadcrumbs for %1$s<code />", "wordpress-seo" ), toLower( taxonomy.label ) ),
778+
sprintf( __( "Breadcrumbs for %1$s<code />", "wordpress-seo" ), safeToLocaleLower( taxonomy.label, userLocale ) ),
772779
{
773780
code: <Code className="yst-ml-2 group-hover:yst-bg-primary-200 group-hover:yst-text-primary-800">{ taxonomy.name }</Code>,
774781
}
@@ -1056,12 +1063,12 @@ export const createSearchIndex = ( postTypes, taxonomies ) => ( {
10561063
// Post types - Attachments are handled separately above.
10571064
...reduce( omit( postTypes, [ "attachment" ] ), ( acc, postType ) => ( {
10581065
...acc,
1059-
...createPostTypeSearchIndex( postType ),
1066+
...createPostTypeSearchIndex( postType, { userLocale } ),
10601067
} ), {} ),
10611068
// Taxonomies
10621069
...reduce( omit( taxonomies, [ "post_format" ] ), ( acc, taxonomy ) => ( {
10631070
...acc,
1064-
...createTaxonomySearchIndex( taxonomy ),
1071+
...createTaxonomySearchIndex( taxonomy, { userLocale } ),
10651072
} ), {} ),
10661073
},
10671074
wpseo_social: {

packages/js/src/settings/routes/author-archives.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { __, sprintf } from "@wordpress/i18n";
44
import { Badge, Code, Link } from "@yoast/ui-library";
55
import FeatureUpsell from "@yoast/ui-library/src/components/feature-upsell";
66
import { useFormikContext } from "formik";
7-
import { toLower } from "lodash";
87
import {
98
FieldsetLayout,
109
FormikFlippedToggleField,
@@ -14,6 +13,7 @@ import {
1413
OpenGraphDisabledAlert,
1514
RouteLayout,
1615
} from "../components";
16+
import { safeToLocaleLower } from "../helpers";
1717
import { withFormikDummyField } from "../hocs";
1818
import { useSelectSettings } from "../hooks";
1919

@@ -25,8 +25,9 @@ const FormikReplacementVariableEditorFieldWithDummy = withFormikDummyField( Form
2525
const AuthorArchives = () => {
2626
const label = __( "Author archives", "wordpress-seo" );
2727
const singularLabel = __( "Author archive", "wordpress-seo" );
28-
const labelLower = useMemo( () => toLower( label ), [ label ] );
29-
const singularLabelLower = useMemo( () => toLower( singularLabel ), [ singularLabel ] );
28+
const userLocale = useSelectSettings( "selectPreference", [], "userLocale" );
29+
const labelLower = useMemo( () => safeToLocaleLower( label, userLocale ), [ label, userLocale ] );
30+
const singularLabelLower = useMemo( () => safeToLocaleLower( singularLabel, userLocale ), [ singularLabel, userLocale ] );
3031

3132
const premiumUpsellConfig = useSelectSettings( "selectUpsellSettingsAsProps" );
3233
const replacementVariables = useSelectSettings( "selectReplacementVariablesFor", [], "author_archives", "custom-post-type_archive" );

packages/js/src/settings/routes/date-archives.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { createInterpolateElement, useMemo } from "@wordpress/element";
33
import { __, sprintf } from "@wordpress/i18n";
44
import { Badge, Code, FeatureUpsell, Link } from "@yoast/ui-library";
55
import { useFormikContext } from "formik";
6-
import { toLower } from "lodash";
76
import {
87
FieldsetLayout,
98
FormikFlippedToggleField,
@@ -13,6 +12,7 @@ import {
1312
OpenGraphDisabledAlert,
1413
RouteLayout,
1514
} from "../components";
15+
import { safeToLocaleLower } from "../helpers";
1616
import { withFormikDummyField } from "../hocs";
1717
import { useSelectSettings } from "../hooks";
1818

@@ -23,7 +23,8 @@ const FormikReplacementVariableEditorFieldWithDummy = withFormikDummyField( Form
2323
*/
2424
const DateArchives = () => {
2525
const label = __( "Date archives", "wordpress-seo" );
26-
const labelLower = useMemo( () => toLower( label ), [ label ] );
26+
const userLocale = useSelectSettings( "selectPreference", [], "userLocale" );
27+
const labelLower = useMemo( () => safeToLocaleLower( label, userLocale ), [ label, userLocale ] );
2728

2829
const premiumUpsellConfig = useSelectSettings( "selectUpsellSettingsAsProps" );
2930
const replacementVariables = useSelectSettings( "selectReplacementVariablesFor", [], "date_archive", "custom-post-type_archive" );

0 commit comments

Comments
 (0)