HEX
Server: LiteSpeed
System: Linux cde4.duelhost.dk 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: dmhkjfau (1027)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/dmhkjfau/public_html/wp-content/plugins/wp-seopress/src/Services/Metas/RobotMeta.php
<?php // phpcs:ignore

namespace SEOPress\Services\Metas;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use SEOPress\Helpers\Metas\RobotSettings;

/**
 * RobotMeta
 */
class RobotMeta {

	/**
	 * The getKeyValue function.
	 *
	 * @param string $meta The meta.
	 *
	 * @return string
	 */
	protected function getKeyValue( $meta ) { // phpcs:ignore -- TODO: check if method is outside this class before renaming.
		switch ( $meta ) {
			case '_seopress_robots_index':
				return 'noindex';
			case '_seopress_robots_follow':
				return 'nofollow';
			case '_seopress_robots_snippet':
				return 'nosnippet';
			case '_seopress_robots_imageindex':
				return 'noimageindex';
			case '_seopress_robots_canonical':
				return 'canonical';
			case '_seopress_robots_primary_cat':
				return 'primarycat';
			case '_seopress_robots_breadcrumbs':
				return 'breadcrumbs';
		}

		return null;
	}

	/**
	 * The getValue function.
	 *
	 * @param array $context The context.
	 * @param bool  $use_default Use default value only if you get the value from the database after this function.
	 *
	 * @return string|null
	 */
	public function getValue( $context, $use_default = true ) { // phpcs:ignore -- TODO: check if method is outside this class before renaming.
		$data = array();

		$id = null;

		$callback = 'get_post_meta';
		if ( isset( $context['post'] ) ) {
			$id = $context['post']->ID;
		} elseif ( isset( $context['term_id'] ) ) {
			$id       = $context['term_id'];
			$callback = 'get_term_meta';
		}

		if ( ! $id ) {
			return $data;
		}

		$metas = RobotSettings::getMetaKeys( $id );

		$data = array();
		foreach ( $metas as $key => $value ) {
			$name = $this->getKeyValue( $value['key'] );
			if ( null === $name ) {
				continue;
			}

			if ( $value['use_default'] && $use_default ) {
				$data[ $name ] = true === $value['default'] || 'yes' === $value['default'] ? true : $value['default']; //phpcs:ignore
			} else {
				$result = $callback( $id, $value['key'], true );

				$data[ $name ] = 'checkbox' === $value['type'] ? ( true === $result || 'yes' === $result ? true : false ) : $result; //phpcs:ignore
			}
		}

		return $data;
	}
}