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/Actions/Ajax/PreviewMetaTitle.php
<?php // phpcs:ignore

namespace SEOPress\Actions\Ajax;

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

use SEOPress\Core\Hooks\ExecuteHooksBackend;

/**
 * Preview Meta Title
 */
class PreviewMetaTitle implements ExecuteHooksBackend {
	/**
	 * The Preview Meta Title hooks.
	 *
	 * @since 4.4.0
	 *
	 * @return void
	 */
	public function hooks() {
		add_action( 'wp_ajax_get_preview_meta_title', array( $this, 'get' ) );
	}

	/**
	 * The Preview Meta Title get.
	 *
	 * @since 4.4.0
	 *
	 * @return array
	 */
	public function get() {
        if ( ! isset($_GET['template'])) { //phpcs:ignore
			wp_send_json_error();
			return;
		}

		check_ajax_referer( 'get_preview_meta_title', 'nonce' );

		$template = stripcslashes( $_GET['template'] ); // phpcs:ignore
		$post_id  = isset( $_GET['post_id'] ) ? (int) $_GET['post_id'] : null;
		$home_id  = isset( $_GET['home_id'] ) ? (int) $_GET['home_id'] : null;
		$term_id  = isset( $_GET['term_id'] ) ? (int) $_GET['term_id'] : null;

		if ( ! current_user_can( 'edit_post', $post_id ) ) {
			return;
		}

		$context_page = seopress_get_service( 'ContextPage' )->buildContextWithCurrentId( (int) $_GET['post_id'] );
		if ( $post_id ) {
			$context_page->setPostById( (int) $_GET['post_id'] );
			$context_page->setIsSingle( true );

			$terms = get_the_terms( $post_id, 'post_tag' );

			if ( ! empty( $terms ) ) {
				$context_page->setHasTag( true );
			}

			$categories = get_the_terms( $post_id, 'category' );
			if ( ! empty( $categories ) ) {
				$context_page->setHasCategory( true );
			}
		}

		if ( $post_id === $home_id && null !== $home_id ) {
			$context_page->setIsHome( true );
		}

		if ( $post_id === $term_id && null !== $term_id ) {
			$context_page->setIsCategory( true );
			$context_page->setTermId( $term_id );
		}

		$value = seopress_get_service( 'TagsToString' )->replace( $template, $context_page->getContext() );

		wp_send_json_success( $value );
	}
}