Current File : /dom405686/wp-content/plugins/wordpress-seo/src/abilities/infrastructure/abstract-seo-field-map.php
<?php
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
namespace Yoast\WP\SEO\Abilities\Infrastructure;
use WPSEO_Rank;
use Yoast\WP\SEO\Models\Indexable;
use Yoast\WP\SEO\Surfaces\Values\Meta;
/**
* Shared translation between the ability input, an indexable, and the SEO data of a single entity.
*
* Subclasses declare which input fields they can write and how the read output is shaped;
* the patch semantics and the rendered-value lookup are the same for every entity type.
*/
abstract class Abstract_SEO_Field_Map {
/**
* Maps each rendered output field to the Meta property holding the value as
* it is actually output on the front end (template applied, replacement
* variables expanded).
*
* @var array<string, string>
*/
private const RENDERED_FIELDS = [
'seo_title' => 'title',
'meta_description' => 'meta_description',
'canonical' => 'canonical',
'open_graph_title' => 'open_graph_title',
'open_graph_description' => 'open_graph_description',
'twitter_title' => 'twitter_title',
'twitter_description' => 'twitter_description',
];
/**
* Returns the string input fields mapped to the indexable column they write to.
*
* @return array<string, string> The string fields.
*/
abstract protected function get_string_fields(): array;
/**
* Returns the boolean input fields mapped to the indexable column they write to.
*
* Excludes `noindex`, which is tri-state (null resets to the default) and is
* handled separately.
*
* @return array<string, string> The boolean fields.
*/
abstract protected function get_boolean_fields(): array;
/**
* Applies a validated input patch onto an indexable.
*
* Only fields present in the input are touched (patch semantics); a present but
* empty/null value clears the field by setting its column to null. The mutated
* indexable is the desired state, which the caller cascades to the source of truth.
* Flags left out of the patch keep their current value, so advanced-robots flags
* merge for free.
*
* @param array<string, int|string|bool|null> $input The validated input patch.
* @param Indexable $indexable The indexable to mutate.
*
* @return array<string> The indexable columns the patch touched, so the caller can cascade
* only those.
*/
public function apply_to_indexable( array $input, Indexable $indexable ): array {
$changed_columns = [];
foreach ( $this->get_string_fields() as $input_key => $column ) {
if ( \array_key_exists( $input_key, $input ) ) {
$value = $input[ $input_key ];
$indexable->{$column} = ( $value === null || $value === '' ) ? null : (string) $value;
$changed_columns[] = $column;
}
}
foreach ( $this->get_boolean_fields() as $input_key => $column ) {
if ( \array_key_exists( $input_key, $input ) ) {
$indexable->{$column} = \rest_sanitize_boolean( $input[ $input_key ] );
$changed_columns[] = $column;
}
}
if ( \array_key_exists( 'noindex', $input ) ) {
// Tri-state: null resets to the default, true = noindex, false = index.
$indexable->is_robots_noindex = ( $input['noindex'] === null ) ? null : \rest_sanitize_boolean( $input['noindex'] );
$changed_columns[] = 'is_robots_noindex';
}
return $changed_columns;
}
/**
* Returns the SEO data fields every entity type shares, keyed by output-schema property name.
*
* Alongside the raw stored fields, each rendered companion (`*_rendered`)
* carries the value as it is actually output on the front end: the global
* default template is applied where no custom value is set, and replacement
* variables are expanded. For noindex, the post-type or taxonomy default is
* applied where no custom value is set.
*
* @param Indexable $indexable The indexable to read from.
* @param Meta|false $meta The meta values for the entity, or false when unavailable.
*
* @return array<string, string|bool|null> The shared SEO data fields.
*/
protected function get_shared_seo_fields( $indexable, $meta ): array {
return [
'seo_title' => $indexable->title,
'seo_title_rendered' => $this->rendered( $meta, 'seo_title' ),
'meta_description' => $indexable->description,
'meta_description_rendered' => $this->rendered( $meta, 'meta_description' ),
'focus_keyphrase' => $indexable->primary_focus_keyword,
'canonical' => $indexable->canonical,
'canonical_rendered' => $this->rendered( $meta, 'canonical' ),
'is_cornerstone' => (bool) $indexable->is_cornerstone,
'noindex' => $indexable->is_robots_noindex,
'noindex_rendered' => $this->rendered_noindex( $meta ),
'open_graph_title' => $indexable->open_graph_title,
'open_graph_title_rendered' => $this->rendered( $meta, 'open_graph_title' ),
'open_graph_description' => $indexable->open_graph_description,
'open_graph_description_rendered' => $this->rendered( $meta, 'open_graph_description' ),
'twitter_title' => $indexable->twitter_title,
'twitter_title_rendered' => $this->rendered( $meta, 'twitter_title' ),
'twitter_description' => $indexable->twitter_description,
'twitter_description_rendered' => $this->rendered( $meta, 'twitter_description' ),
'seo_score' => WPSEO_Rank::from_numeric_score( (int) $indexable->primary_focus_keyword_score )->get_rank(),
'readability_score' => WPSEO_Rank::from_numeric_score( (int) $indexable->readability_score )->get_rank(),
// A zero score maps to NO_FOCUS ("not available") via the rank ranges, same as the scores above.
'inclusive_language_score' => WPSEO_Rank::from_numeric_score( (int) $indexable->inclusive_language_score )->get_rank(),
];
}
/**
* Returns the front-end output for a rendered field, or null when nothing is output.
*
* @param Meta|false $meta The meta values for the entity, or false when unavailable.
* @param string $output_field The rendered output field name.
*
* @return string|null The rendered value, or null when empty or unavailable.
*/
protected function rendered( $meta, string $output_field ): ?string {
if ( ! $meta instanceof Meta ) {
return null;
}
$value = $meta->{ self::RENDERED_FIELDS[ $output_field ] };
// Treat an empty presented value as "nothing is output" rather than an empty string.
if ( $value === null || $value === '' ) {
return null;
}
return (string) $value;
}
/**
* Returns whether the front-end robots meta tag tells search engines not to index the entity.
*
* Reading the presented robots value rather than the stored one resolves a missing setting to
* the post-type or taxonomy default, and includes the other rules that force a noindex, such as
* private posts, the site-wide author archive settings and the `wpseo_robots` filter.
*
* @param Meta|false $meta The meta values for the entity, or false when unavailable.
*
* @return bool|null Whether the entity is noindexed, or null when unavailable.
*/
protected function rendered_noindex( $meta ): ?bool {
if ( ! $meta instanceof Meta ) {
return null;
}
// Mirrors the noindex check of the canonical and rel prev/next presenters, to stay consistent with the front end.
return \in_array( 'noindex', $meta->robots, true );
}
}
Distinguish Your Business From The Rest With The People That Make Up Your Team
We go Beyond a Resume to find high value, committed people
ready, willing, and able to add true value toward your organization's mission.
The right people make or break your business
We focus on resolving two types of challenges surrounding staffing and recruiting at Beyond a Resume: The first challenge comes when a business continues to grow, but does not have the full-time, internal, talent acquisition resources to hire the right people or talent necessary to keep up with their rate of progression as a company.
The second is a business that has a dedicated internal Human Resources Team, but requires outsourced assistance when the volume of people and talent needed exceeds short term internal capacity, OR the position(s) they seek to fill demand a specific skill set that is difficult to find, requiring added bandwidth.
In nearly any line of business, growth is a challenge in and of itself. Yet, the real problems arise in managing growth to ensure your progress remains profitable, sustainable, and repeatable. The biggest factor in this equation is usually found in your people. When you have the right people, success is unlimited. On the other hand, when you don’t have the right people in place or are having trouble finding enough of the right people, failure or stagnation is imminent.
The frustration that comes with the process of “hiring” can bring you to new levels of stress as the time cost involved eats away at your production elsewhere. If you have experienced this in the past, or are currently struggling with this issue, you’re certainly not alone. You may simply need the right partner to take the worst parts of this process off your plate so you can concentrate on your responsibilities, while we work diligently to reduce the noise and deliver only the ideal candidates worth your time and attention.
People can make or break your business and we go Beyond a Resume to find high value, committed people ready, willing, and able to add true value.