| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/pods/src/Pods/WP/ |
Upload File : |
<?php
namespace Pods\WP;
// Don't load directly.
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
use Pods\Whatsit\Pod;
use PodsMeta;
use PodsForm;
/**
* Meta specific functionality.
*
* @since 3.2.0
*/
class Meta {
/**
* The list of registered meta.
*
* @since 3.2.0
*/
private $registered_meta = [];
/**
* Add the class hooks.
*
* @since 3.2.0
*/
public function hook() {
$this->register_meta();
}
/**
* Remove the class hooks.
*
* @since 3.2.0
*/
public function unhook() {
$this->unregister_meta();
}
/**
* Determine whether to register meta fields.
*
* @since 3.2.0
*
* @return bool Whether to register meta fields.
*/
public function should_register_meta(): bool {
$should_register_meta = filter_var( pods_get_setting( 'register_meta_integration', false ), FILTER_VALIDATE_BOOLEAN );
/**
* Allow filtering whether to register meta fields.
*
* @since 3.2.0
*
* @param bool $should_register_meta Whether to register meta fields.
*/
return (bool) apply_filters( 'pods_wp_meta_should_register_meta', $should_register_meta );
}
/**
* Register the meta fields only if needed.
*
* @since 3.2.0
*/
public function register_meta() {
if ( ! $this->should_register_meta() ) {
return;
}
$can_use_dynamic_feature_display = pods_can_use_dynamic_feature( 'display' );
$pods_to_register = [
'post' => [],
];
foreach ( PodsMeta::$post_types as $pod ) {
if ( ! $pod instanceof Pod || ! pods_can_use_dynamic_features( $pod ) ) {
continue;
}
$pods_to_register['post'][] = $pod;
}
foreach ( $pods_to_register as $type => $pods ) {
/** @var array<int,Pod> $pods */
foreach ( $pods as $pod ) {
$pod_name = $pod->get_name();
$pod_type = $pod->get_type();
$pod_storage = $pod->get_storage();
$fields = $pod->get_fields();
// REST API pod config.
$pod_rest_enabled = filter_var( $pod->get_arg( 'rest_enable', false ), FILTER_VALIDATE_BOOLEAN );
$pod_rest_field_location = $pod->get_arg( 'rest_api_field_location', 'object', true );
$post_type_has_custom_fields = (
$pod_rest_enabled
&& 'post_type' === $pod_type
&& post_type_supports( $pod_name, 'custom-fields' )
);
$all_fields_have_rest = (
$can_use_dynamic_feature_display
&& $pod_rest_enabled
&& $post_type_has_custom_fields
&& filter_var( $pod->get_arg( 'read_all', false ), FILTER_VALIDATE_BOOLEAN )
);
// Revision pod config.
$all_fields_have_revisions = (
'post_type' === $pod_type
&& 'meta' === $pod_storage
&& filter_var( $pod->get_arg( 'read_all', false ), FILTER_VALIDATE_BOOLEAN )
);
$pod_has_revisions = (
'post_type' === $pod_type
&& post_type_supports( $pod_name, 'revisions' )
);
foreach ( $fields as $field ) {
$field_is_repeatable = $field->is_repeatable();
// REST API field config.
$field_has_rest = (
'meta' === $pod_rest_field_location
&& $post_type_has_custom_fields
&& $can_use_dynamic_feature_display
&& (
$all_fields_have_rest
|| (
$pod_rest_enabled
&& filter_var( $field->get_arg( 'rest_read', false ), FILTER_VALIDATE_BOOLEAN )
)
)
);
// Revision field config.
$field_has_revisions = (
$pod_has_revisions
&& (
$all_fields_have_revisions
|| (
'post_type' === $pod_type
&& 'meta' === $pod_storage
&& filter_var( $pod->get_arg( 'revisions_revision_field', false ), FILTER_VALIDATE_BOOLEAN )
)
)
);
$meta_args = [
'object_subtype' => $pod_name,
'type' => 'string',
'description' => $field['label'],
'default' => $field->get_arg( 'default', '' ),
'single' => ! $field_is_repeatable,
'show_in_rest' => $field_has_rest,
];
if ( $field_has_revisions ) {
$meta_args['revisions_enabled'] = true;
}
register_meta(
$type,
$field['name'],
$meta_args
);
if ( ! isset( $this->registered_meta[ $type ] ) ) {
$this->registered_meta[ $type ] = [];
}
$this->registered_meta[] = [
'object_type' => $type,
'meta_key' => $field['name'], // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'object_subtype' => $pod_name,
];
}
}
}
}
/**
* Unregister the meta fields.
*
* @since 3.2.0
*/
public function unregister_meta() {
foreach ( $this->registered_meta as $field ) {
unregister_meta_key( $field['object_type'], $field['meta_key'], $field['object_subtype'] );
}
$this->registered_meta = [];
}
}