Skip to content

Commit

Permalink
Merge pull request #16714 from Yoast/P3-370-options-for-global-social…
Browse files Browse the repository at this point in the history
…-templates

P3-370 Add new options for global social templates
  • Loading branch information
enricobattocchi authored Mar 17, 2021
2 parents c4563c0 + 7b9b48e commit 327cf52
Showing 1 changed file with 113 additions and 52 deletions.
165 changes: 113 additions & 52 deletions inc/options/class-wpseo-option-titles.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,63 @@ class WPSEO_Option_Titles extends WPSEO_Option {
*/
protected $defaults = [
// Form fields.
'forcerewritetitle' => false,
'separator' => 'sc-dash',
'title-home-wpseo' => '%%sitename%% %%page%% %%sep%% %%sitedesc%%', // Text field.
'title-author-wpseo' => '', // Text field.
'title-archive-wpseo' => '%%date%% %%page%% %%sep%% %%sitename%%', // Text field.
'title-search-wpseo' => '', // Text field.
'title-404-wpseo' => '', // Text field.

'metadesc-home-wpseo' => '', // Text area.
'metadesc-author-wpseo' => '', // Text area.
'metadesc-archive-wpseo' => '', // Text area.
'rssbefore' => '', // Text area.
'rssafter' => '', // Text area.

'noindex-author-wpseo' => false,
'noindex-author-noposts-wpseo' => true,
'noindex-archive-wpseo' => true,

'disable-author' => false,
'disable-date' => false,
'disable-post_format' => false,
'disable-attachment' => true,
'is-media-purge-relevant' => false,

'breadcrumbs-404crumb' => '', // Text field.
'breadcrumbs-display-blog-page' => true,
'breadcrumbs-boldlast' => false,
'breadcrumbs-archiveprefix' => '', // Text field.
'breadcrumbs-enable' => true,
'breadcrumbs-home' => '', // Text field.
'breadcrumbs-prefix' => '', // Text field.
'breadcrumbs-searchprefix' => '', // Text field.
'breadcrumbs-sep' => '»', // Text field.

'website_name' => '',
'person_name' => '',
'person_logo' => '',
'person_logo_id' => 0,
'alternate_website_name' => '',
'company_logo' => '',
'company_logo_id' => 0,
'company_logo_meta' => false,
'person_logo_meta' => false,
'company_name' => '',
'company_or_person' => 'company',
'company_or_person_user_id' => false,

'stripcategorybase' => false,
'forcerewritetitle' => false,
'separator' => 'sc-dash',
'title-home-wpseo' => '%%sitename%% %%page%% %%sep%% %%sitedesc%%', // Text field.
'title-author-wpseo' => '', // Text field.
'title-archive-wpseo' => '%%date%% %%page%% %%sep%% %%sitename%%', // Text field.
'title-search-wpseo' => '', // Text field.
'title-404-wpseo' => '', // Text field.

'social-title-author-wpseo' => '%%title%%', // Text field.
'social-title-archive-wpseo' => '%%title%%', // Text field.
'social-description-author-wpseo' => '%%excerpt%%', // Text area.
'social-description-archive-wpseo' => '%%excerpt%%', // Text area.
'social-image-url-author-wpseo' => '', // Hidden input field.
'social-image-url-archive-wpseo' => '', // Hidden input field.
'social-image-id-author-wpseo' => '', // Hidden input field.
'social-image-id-archive-wpseo' => '', // Hidden input field.

'metadesc-home-wpseo' => '', // Text area.
'metadesc-author-wpseo' => '', // Text area.
'metadesc-archive-wpseo' => '', // Text area.
'rssbefore' => '', // Text area.
'rssafter' => '', // Text area.

'noindex-author-wpseo' => false,
'noindex-author-noposts-wpseo' => true,
'noindex-archive-wpseo' => true,

'disable-author' => false,
'disable-date' => false,
'disable-post_format' => false,
'disable-attachment' => true,
'is-media-purge-relevant' => false,

'breadcrumbs-404crumb' => '', // Text field.
'breadcrumbs-display-blog-page' => true,
'breadcrumbs-boldlast' => false,
'breadcrumbs-archiveprefix' => '', // Text field.
'breadcrumbs-enable' => true,
'breadcrumbs-home' => '', // Text field.
'breadcrumbs-prefix' => '', // Text field.
'breadcrumbs-searchprefix' => '', // Text field.
'breadcrumbs-sep' => '»', // Text field.

'website_name' => '',
'person_name' => '',
'person_logo' => '',
'person_logo_id' => 0,
'alternate_website_name' => '',
'company_logo' => '',
'company_logo_id' => 0,
'company_logo_meta' => false,
'person_logo_meta' => false,
'company_name' => '',
'company_or_person' => 'company',
'company_or_person_user_id' => false,

'stripcategorybase' => false,

/**
* Uses enrich_defaults to add more along the lines of:
Expand Down Expand Up @@ -123,6 +132,10 @@ class WPSEO_Option_Titles extends WPSEO_Option {
'taxonomy-',
'schema-page-type-',
'schema-article-type-',
'social-title-',
'social-description-',
'social-image-url-',
'social-image-id-',
];

/**
Expand Down Expand Up @@ -273,12 +286,20 @@ public function enrich_defaults() {
$enriched_defaults[ 'post_types-' . $pt->name . '-maintax' ] = 0; // Select box.
$enriched_defaults[ 'schema-page-type-' . $pt->name ] = 'WebPage';
$enriched_defaults[ 'schema-article-type-' . $pt->name ] = ( YoastSEO()->helpers->schema->article->is_article_post_type( $pt->name ) ) ? 'Article' : 'None';
$enriched_defaults[ 'social-title-' . $pt->name ] = '%%title%%'; // Text field.
$enriched_defaults[ 'social-description-' . $pt->name ] = '%%excerpt%%'; // Text area.
$enriched_defaults[ 'social-image-url-' . $pt->name ] = ''; // Hidden input field.
$enriched_defaults[ 'social-image-id-' . $pt->name ] = ''; // Hidden input field.

if ( ! $pt->_builtin && WPSEO_Post_Type::has_archive( $pt ) ) {
$enriched_defaults[ 'title-ptarchive-' . $pt->name ] = $archive . ' %%page%% %%sep%% %%sitename%%'; // Text field.
$enriched_defaults[ 'metadesc-ptarchive-' . $pt->name ] = ''; // Text area.
$enriched_defaults[ 'bctitle-ptarchive-' . $pt->name ] = ''; // Text field.
$enriched_defaults[ 'noindex-ptarchive-' . $pt->name ] = false;
$enriched_defaults[ 'title-ptarchive-' . $pt->name ] = $archive . ' %%page%% %%sep%% %%sitename%%'; // Text field.
$enriched_defaults[ 'metadesc-ptarchive-' . $pt->name ] = ''; // Text area.
$enriched_defaults[ 'bctitle-ptarchive-' . $pt->name ] = ''; // Text field.
$enriched_defaults[ 'noindex-ptarchive-' . $pt->name ] = false;
$enriched_defaults[ 'social-title-ptarchive-' . $pt->name ] = '%%title%%'; // Text field.
$enriched_defaults[ 'social-description-ptarchive-' . $pt->name ] = '%%excerpt%%'; // Text area.
$enriched_defaults[ 'social-image-url-ptarchive-' . $pt->name ] = ''; // Hidden input field.
$enriched_defaults[ 'social-image-id-ptarchive-' . $pt->name ] = ''; // Hidden input field.
}
}
}
Expand All @@ -296,6 +317,11 @@ public function enrich_defaults() {

$enriched_defaults[ 'noindex-tax-' . $tax->name ] = ( $tax->name === 'post_format' );

$enriched_defaults[ 'social-title-tax-' . $tax->name ] = '%%title%%'; // Text field.
$enriched_defaults[ 'social-description-tax-' . $tax->name ] = '%%excerpt%%'; // Text area.
$enriched_defaults[ 'social-image-url-tax-' . $tax->name ] = ''; // Hidden input field.
$enriched_defaults[ 'social-image-id-tax-' . $tax->name ] = ''; // Hidden input field.

if ( ! $tax->_builtin ) {
$enriched_defaults[ 'taxonomy-' . $tax->name . '-ptparent' ] = 0; // Select box;.
}
Expand Down Expand Up @@ -366,10 +392,15 @@ protected function validate_option( $dirty, $clean, $old ) {
* 'title-' . $pt->name
* 'title-ptarchive-' . $pt->name
* 'title-tax-' . $tax->name
* 'social-title-' . $pt->name
* 'social-title-ptarchive-' . $pt->name
* 'social-title-tax-' . $tax->name
* 'social-title-author-wpseo', 'social-title-archive-wpseo'
*/
case 'website_name':
case 'alternate_website_name':
case 'title-':
case 'social-title-':
if ( isset( $dirty[ $key ] ) ) {
$clean[ $key ] = WPSEO_Utils::sanitize_text_field( $dirty[ $key ] );
}
Expand All @@ -387,6 +418,10 @@ protected function validate_option( $dirty, $clean, $old ) {
}
break;

/*
* Covers:
* 'company_logo', 'person_logo' // phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- This isn't commented out code.
*/
case 'company_logo':
case 'person_logo':
// When a logo changes, we need to ditch the caches we have for it.
Expand All @@ -395,6 +430,17 @@ protected function validate_option( $dirty, $clean, $old ) {
$this->validate_url( $key, $dirty, $old, $clean );
break;

/*
* Covers:
* 'social-image-url-' . $pt->name
* 'social-image-url-ptarchive-' . $pt->name
* 'social-image-url-tax-' . $tax->name
* 'social-image-url-author-wpseo', 'social-image-url-archive-wpseo'
*/
case 'social-image-url-':
$this->validate_url( $key, $dirty, $old, $clean );
break;

/*
* Covers:
* 'metadesc-home-wpseo', 'metadesc-author-wpseo', 'metadesc-archive-wpseo'
Expand All @@ -403,11 +449,16 @@ protected function validate_option( $dirty, $clean, $old ) {
* 'metadesc-tax-' . $tax->name
* and also:
* 'bctitle-ptarchive-' . $pt->name
* 'social-description-' . $pt->name
* 'social-description-ptarchive-' . $pt->name
* 'social-description-tax-' . $tax->name
* 'social-description-author-wpseo', 'social-description-archive-wpseo'
*/
case 'metadesc-':
case 'bctitle-ptarchive-':
case 'company_name':
case 'person_name':
case 'social-description-':
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
$clean[ $key ] = WPSEO_Utils::sanitize_text_field( $dirty[ $key ] );
}
Expand Down Expand Up @@ -501,9 +552,19 @@ protected function validate_option( $dirty, $clean, $old ) {
}
break;

/*
* Covers:
* 'company_or_person_user_id'
* 'company_logo_id', 'person_logo_id'
* 'social-image-id-' . $pt->name
* 'social-image-id-ptarchive-' . $pt->name
* 'social-image-id-tax-' . $tax->name
* 'social-image-id-author-wpseo', 'social-image-id-archive-wpseo'
*/
case 'company_or_person_user_id':
case 'company_logo_id':
case 'person_logo_id':
case 'social-image-id-':
if ( isset( $dirty[ $key ] ) ) {
$int = WPSEO_Utils::validate_int( $dirty[ $key ] );
if ( $int !== false && $int >= 0 ) {
Expand Down

0 comments on commit 327cf52

Please sign in to comment.