<?php
/**
* The Metadata Class
*
* @since 0.9.0
* @package RankMath
* @subpackage RankMath\Core
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath;
defined( 'ABSPATH' ) || exit;
/**
* Metadata class.
*/
abstract class Metadata {
/**
* Type of object the metadata is for.
*
* @var string
*/
protected $meta_type = 'post';
/**
* Holds the object.
*
* @var WP_Post|WP_Term|WP_User
*/
protected $object = null;
/**
* Holds the object ID.
*
* @var int
*/
protected $object_id = null;
/**
* Holds multiple objects.
*
* @var array
*/
protected static $objects = [];
/**
* Holds the properties.
*
* @var array
*/
protected $properties = [];
/**
* Getter.
*
* @param string $property Key to get.
* @return mixed
*/
public function __get( $property ) {
if ( \property_exists( $this, $property ) ) {
return $this->$property;
}
if ( isset( $this->properties[ $property ] ) ) {
return $this->properties[ $property ];
}
if ( isset( $this->object->$property ) ) {
return $this->object->$property;
}
return get_metadata( $this->meta_type, $this->object_id, $property, true );
}
/**
* Setter.
* This prevents the Dynamic Properties deprecation notice in PHP 8.2.
*
* @param string $property Key to set.
* @param mixed $value Value to set.
* @return void
*/
public function __set( $property, $value ) {
$this->properties[ $property ] = $value;
}
/**
* Constructor.
*
* @param WP_Post|WP_Term|WP_User $object_data Current object.
*/
public function __construct( $object_data ) {
$this->object = $object_data;
}
/**
* If object found.
*
* @return bool
*/
public function is_found() {
return ! is_null( $this->object );
}
/**
* Get attached object.
*
* @return object
*/
public function get_object() {
return $this->object;
}
/**
* Get metadata for the object.
*
* @param string $key Value to get, without prefix.
* @param string $default_value Default value to use when metadata does not exists.
* @return mixed
*/
public function get_metadata( $key, $default_value = '' ) {
$meta_key = 'rank_math_' . $key;
if ( isset( $this->$meta_key ) ) {
return $this->$meta_key;
}
$value = $this->$meta_key;
$replaced = $this->maybe_replace_vars( $key, $value, $this->object );
if ( false !== $replaced ) {
$this->$meta_key = $replaced;
return $this->$meta_key;
}
if ( ! $value || ( $key === 'focus_keyword' && ! is_string( $value ) ) ) {
return $default_value;
}
$this->$meta_key = Helper::normalize_data( $value );
return $this->$meta_key;
}
/**
* Maybe replace variables in meta data.
*
* @param string $key Key to check whether it contains variables.
* @param mixed $value Value used to replace variables in.
* @param object $object_data Object used for replacements.
* @return string|bool False if replacement not needed. Replaced variable string.
*/
public function maybe_replace_vars( $key, $value, $object_data ) {
$need_replacements = [ 'title', 'description', 'facebook_title', 'twitter_title', 'facebook_description', 'twitter_description', 'snippet_name', 'snippet_desc' ];
// Early bail.
if ( ! in_array( $key, $need_replacements, true ) || ! is_string( $value ) || '' === $value ) {
return false;
}
$value = \str_replace(
[ '%seo_title%', '%seo_description%' ],
[ '%title%', '%excerpt%' ],
$value
);
return Helper::replace_vars( $value, $object_data );
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| 3rdparty/ | 2026-07-21 14:14 | 568.06 KB | 76129f60960:kunden | dxwrx-r--r | |
| abilities/ | 2026-07-21 14:14 | 135.66 KB | 76129f60960:kunden | dxwrx-r--r | |
| admin/ | 2026-07-21 14:14 | 567.8 KB | 76129f60960:kunden | dxwrx-r--r | |
| cli/ | 2026-07-21 14:14 | 836 B | 76129f60960:kunden | dxwrx-r--r | |
| frontend/ | 2026-07-21 14:14 | 105.79 KB | 76129f60960:kunden | dxwrx-r--r | |
| helpers/ | 2026-07-21 14:14 | 138.04 KB | 76129f60960:kunden | dxwrx-r--r | |
| metaboxes/ | 2026-07-21 14:14 | 28 B | 76129f60960:kunden | dxwrx-r--r | |
| module/ | 2026-07-21 14:14 | 29.13 KB | 76129f60960:kunden | dxwrx-r--r | |
| modules/ | 2026-07-21 14:14 | 4.47 MB | 76129f60960:kunden | dxwrx-r--r | |
| opengraph/ | 2026-07-21 14:14 | 56.01 KB | 76129f60960:kunden | dxwrx-r--r | |
| replace-variables/ | 2026-07-21 14:14 | 69.13 KB | 76129f60960:kunden | dxwrx-r--r | |
| rest/ | 2026-07-21 14:14 | 56.29 KB | 76129f60960:kunden | dxwrx-r--r | |
| settings/ | 2026-07-21 14:14 | 69.92 KB | 76129f60960:kunden | dxwrx-r--r | |
| traits/ | 2026-07-21 14:14 | 12.61 KB | 76129f60960:kunden | dxwrx-r--r | |
| updates/ | 2026-07-21 14:14 | 19.48 KB | 76129f60960:kunden | dxwrx-r--r | |
| class-auto-updater.php | 2026-07-21 14:14 | 2.23 KB | 76129f60960:kunden | -xw-x----- | |
| class-cmb2.php | 2026-07-21 14:14 | 11.38 KB | 76129f60960:kunden | -xw-x----- | |
| class-common.php | 2026-07-21 14:14 | 7.02 KB | 76129f60960:kunden | -xw-x----- | |
| class-compatibility.php | 2026-07-21 14:14 | 2.52 KB | 76129f60960:kunden | -xw-x----- | |
| class-data-encryption.php | 2026-07-21 14:14 | 4.07 KB | 76129f60960:kunden | -xw-x----- | |
| class-defaults.php | 2026-07-21 14:14 | 1.13 KB | 76129f60960:kunden | -xw-x----- | |
| class-frontend-seo-score.php | 2026-07-21 14:14 | 9.78 KB | 76129f60960:kunden | -xw-x----- | |
| class-helper.php | 2026-07-21 14:14 | 11.3 KB | 76129f60960:kunden | -xw-x----- | |
| class-installer.php | 2026-07-21 14:14 | 23.4 KB | 76129f60960:kunden | -xw-x----- | |
| class-json-manager.php | 2026-07-21 14:14 | 2.78 KB | 76129f60960:kunden | -xw-x----- | |
| class-kb.php | 2026-07-21 14:14 | 12.72 KB | 76129f60960:kunden | -xw-x----- | |
| class-metadata.php | 2026-07-21 14:14 | 3.49 KB | 76129f60960:kunden | -xw-x----- | |
| class-post.php | 2026-07-21 14:14 | 4.68 KB | 76129f60960:kunden | -xw-x----- | |
| class-rewrite.php | 2026-07-21 14:14 | 9.57 KB | 76129f60960:kunden | -xw-x----- | |
| class-settings.php | 2026-07-21 14:14 | 3.41 KB | 76129f60960:kunden | -xw-x----- | |
| class-term.php | 2026-07-21 14:14 | 3.04 KB | 76129f60960:kunden | -xw-x----- | |
| class-thumbnail-overlay.php | 2026-07-21 14:14 | 7.89 KB | 76129f60960:kunden | -xw-x----- | |
| class-tracking.php | 2026-07-21 14:14 | 12.61 KB | 76129f60960:kunden | -xw-x----- | |
| class-update-email.php | 2026-07-21 14:14 | 5.27 KB | 76129f60960:kunden | -xw-x----- | |
| class-updates.php | 2026-07-21 14:14 | 2.62 KB | 76129f60960:kunden | -xw-x----- | |
| class-user.php | 2026-07-21 14:14 | 1.55 KB | 76129f60960:kunden | -xw-x----- | |
| index.php | 2026-07-21 14:14 | 28 B | 76129f60960:kunden | -xw-x----- | |
| interface-runner.php | 2026-07-21 14:14 | 380 B | 76129f60960:kunden | -xw-x----- | |
| template-tags.php | 2026-07-21 14:14 | 2.03 KB | 76129f60960:kunden | -xw-x----- | |