This commit is contained in:
Tony Volpe
2024-06-17 14:41:24 -04:00
parent f885e93ca8
commit a00f379f7f
11158 changed files with 0 additions and 1781316 deletions

View File

@@ -1,7 +0,0 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit0c422f20871bcbf1c73c1006dcf06201::getLoader();

View File

@@ -1,572 +0,0 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see https://www.php-fig.org/psr/psr-0/
* @see https://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
/** @var ?string */
private $vendorDir;
// PSR-4
/**
* @var array[]
* @psalm-var array<string, array<string, int>>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, array<int, string>>
*/
private $prefixDirsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* @var array[]
* @psalm-var array<string, array<string, string[]>>
*/
private $prefixesPsr0 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var string[]
* @psalm-var array<string, string>
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var bool[]
* @psalm-var array<string, bool>
*/
private $missingClasses = array();
/** @var ?string */
private $apcuPrefix;
/**
* @var self[]
*/
private static $registeredLoaders = array();
/**
* @param ?string $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
}
/**
* @return string[]
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
}
return array();
}
/**
* @return array[]
* @psalm-return array<string, array<int, string>>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return string[] Array of classname => path
* @psalm-return array<string, string>
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param string[] $classMap Class to filename map
* @psalm-param array<string, string> $classMap
*
* @return void
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*
* @return void
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 base directories
*
* @return void
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*
* @return void
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*
* @return void
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return true|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
return null;
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
/**
* Returns the currently registered loaders indexed by their corresponding vendor directories.
*
* @return self[]
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
/**
* @param string $class
* @param string $ext
* @return string|false
*/
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
* @private
*/
function includeFile($file)
{
include $file;
}

View File

@@ -1,357 +0,0 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer;
use Composer\Autoload\ClassLoader;
use Composer\Semver\VersionParser;
/**
* This class is copied in every Composer installed project and available to all
*
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
*
* To require its presence, you can require `composer-runtime-api ^2.0`
*/
class InstalledVersions
{
/**
* @var mixed[]|null
* @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
*/
private static $installed;
/**
* @var bool|null
*/
private static $canGetVendors;
/**
* @var array[]
* @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
*/
private static $installedByVendor = array();
/**
* Returns a list of all package names which are present, either by being installed, replaced or provided
*
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackages()
{
$packages = array();
foreach (self::getInstalled() as $installed) {
$packages[] = array_keys($installed['versions']);
}
if (1 === \count($packages)) {
return $packages[0];
}
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
}
/**
* Returns a list of all package names with a specific type e.g. 'library'
*
* @param string $type
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackagesByType($type)
{
$packagesByType = array();
foreach (self::getInstalled() as $installed) {
foreach ($installed['versions'] as $name => $package) {
if (isset($package['type']) && $package['type'] === $type) {
$packagesByType[] = $name;
}
}
}
return $packagesByType;
}
/**
* Checks whether the given package is installed
*
* This also returns true if the package name is provided or replaced by another package
*
* @param string $packageName
* @param bool $includeDevRequirements
* @return bool
*/
public static function isInstalled($packageName, $includeDevRequirements = true)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
}
}
return false;
}
/**
* Checks whether the given package satisfies a version constraint
*
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
*
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
*
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
* @param string $packageName
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
* @return bool
*/
public static function satisfies(VersionParser $parser, $packageName, $constraint)
{
$constraint = $parser->parseConstraints($constraint);
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
return $provided->matches($constraint);
}
/**
* Returns a version constraint representing all the range(s) which are installed for a given package
*
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
* whether a given version of a package is installed, and not just whether it exists
*
* @param string $packageName
* @return string Version constraint usable with composer/semver
*/
public static function getVersionRanges($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
$ranges = array();
if (isset($installed['versions'][$packageName]['pretty_version'])) {
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
}
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
}
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
}
if (array_key_exists('provided', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
}
return implode(' || ', $ranges);
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
*/
public static function getVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['version'])) {
return null;
}
return $installed['versions'][$packageName]['version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
*/
public static function getPrettyVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
return null;
}
return $installed['versions'][$packageName]['pretty_version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
*/
public static function getReference($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['reference'])) {
return null;
}
return $installed['versions'][$packageName]['reference'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
*/
public static function getInstallPath($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @return array
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
*/
public static function getRootPackage()
{
$installed = self::getInstalled();
return $installed[0]['root'];
}
/**
* Returns the raw installed.php data for custom implementations
*
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
* @return array[]
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
*/
public static function getRawData()
{
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
return self::$installed;
}
/**
* Returns the raw data of all installed.php which are currently loaded for custom implementations
*
* @return array[]
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
*/
public static function getAllRawData()
{
return self::getInstalled();
}
/**
* Lets you reload the static array from another file
*
* This is only useful for complex integrations in which a project needs to use
* this class but then also needs to execute another project's autoloader in process,
* and wants to ensure both projects have access to their version of installed.php.
*
* A typical case would be PHPUnit, where it would need to make sure it reads all
* the data it needs from this class, then call reload() with
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
* the project in which it runs can then also use this class safely, without
* interference between PHPUnit's dependencies and the project's dependencies.
*
* @param array[] $data A vendor/composer/installed.php data set
* @return void
*
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
*/
public static function reload($data)
{
self::$installed = $data;
self::$installedByVendor = array();
}
/**
* @return array[]
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
*/
private static function getInstalled()
{
if (null === self::$canGetVendors) {
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
}
$installed = array();
if (self::$canGetVendors) {
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
$installed[] = self::$installedByVendor[$vendorDir] = $required;
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
self::$installed = $installed[count($installed) - 1];
}
}
}
}
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
} else {
self::$installed = array();
}
}
if (self::$installed !== array()) {
$installed[] = self::$installed;
}
return $installed;
}
}

View File

@@ -1,21 +0,0 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,233 +0,0 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'WPSEO_CLI_Premium_Requirement' => $baseDir . '/cli/cli-premium-requirement.php',
'WPSEO_CLI_Redirect_Base_Command' => $baseDir . '/cli/cli-redirect-base-command.php',
'WPSEO_CLI_Redirect_Command_Namespace' => $baseDir . '/cli/cli-redirect-command-namespace.php',
'WPSEO_CLI_Redirect_Create_Command' => $baseDir . '/cli/cli-redirect-create-command.php',
'WPSEO_CLI_Redirect_Delete_Command' => $baseDir . '/cli/cli-redirect-delete-command.php',
'WPSEO_CLI_Redirect_Follow_Command' => $baseDir . '/cli/cli-redirect-follow-command.php',
'WPSEO_CLI_Redirect_Has_Command' => $baseDir . '/cli/cli-redirect-has-command.php',
'WPSEO_CLI_Redirect_List_Command' => $baseDir . '/cli/cli-redirect-list-command.php',
'WPSEO_CLI_Redirect_Update_Command' => $baseDir . '/cli/cli-redirect-update-command.php',
'WPSEO_Custom_Fields_Plugin' => $baseDir . '/classes/custom-fields-plugin.php',
'WPSEO_Executable_Redirect' => $baseDir . '/classes/redirect/executable-redirect.php',
'WPSEO_Export_Keywords_CSV' => $baseDir . '/classes/export/export-keywords-csv.php',
'WPSEO_Export_Keywords_Post_Presenter' => $baseDir . '/classes/export/export-keywords-post-presenter.php',
'WPSEO_Export_Keywords_Post_Query' => $baseDir . '/classes/export/export-keywords-post-query.php',
'WPSEO_Export_Keywords_Presenter' => $baseDir . '/classes/export/export-keywords-presenter-interface.php',
'WPSEO_Export_Keywords_Query' => $baseDir . '/classes/export/export-keywords-query-interface.php',
'WPSEO_Export_Keywords_Term_Presenter' => $baseDir . '/classes/export/export-keywords-term-presenter.php',
'WPSEO_Export_Keywords_Term_Query' => $baseDir . '/classes/export/export-keywords-term-query.php',
'WPSEO_Facebook_Profile' => $baseDir . '/src/deprecated/classes/facebook-profile.php',
'WPSEO_Metabox_Link_Suggestions' => $baseDir . '/classes/metabox-link-suggestions.php',
'WPSEO_Multi_Keyword' => $baseDir . '/classes/multi-keyword.php',
'WPSEO_Post_Watcher' => $baseDir . '/classes/post-watcher.php',
'WPSEO_Premium' => $baseDir . '/premium.php',
'WPSEO_Premium_Asset_JS_L10n' => $baseDir . '/classes/premium-asset-js-l10n.php',
'WPSEO_Premium_Assets' => $baseDir . '/classes/premium-assets.php',
'WPSEO_Premium_Expose_Shortlinks' => $baseDir . '/classes/premium-expose-shortlinks.php',
'WPSEO_Premium_Import_Manager' => $baseDir . '/classes/premium-import-manager.php',
'WPSEO_Premium_Javascript_Strings' => $baseDir . '/classes/premium-javascript-strings.php',
'WPSEO_Premium_Keyword_Export_Manager' => $baseDir . '/classes/premium-keyword-export-manager.php',
'WPSEO_Premium_Metabox' => $baseDir . '/classes/premium-metabox.php',
'WPSEO_Premium_Option' => $baseDir . '/classes/premium-option.php',
'WPSEO_Premium_Orphaned_Content_Support' => $baseDir . '/classes/premium-orphaned-content-support.php',
'WPSEO_Premium_Orphaned_Content_Utils' => $baseDir . '/classes/premium-orphaned-content-utils.php',
'WPSEO_Premium_Orphaned_Post_Filter' => $baseDir . '/classes/premium-orphaned-post-filter.php',
'WPSEO_Premium_Orphaned_Post_Query' => $baseDir . '/classes/premium-orphaned-post-query.php',
'WPSEO_Premium_Prominent_Words_Support' => $baseDir . '/classes/premium-prominent-words-support.php',
'WPSEO_Premium_Prominent_Words_Unindexed_Post_Query' => $baseDir . '/classes/premium-prominent-words-unindexed-post-query.php',
'WPSEO_Premium_Prominent_Words_Versioning' => $baseDir . '/classes/premium-prominent-words-versioning.php',
'WPSEO_Premium_Redirect_EndPoint' => $baseDir . '/classes/premium-redirect-endpoint.php',
'WPSEO_Premium_Redirect_Export_Manager' => $baseDir . '/classes/premium-redirect-export-manager.php',
'WPSEO_Premium_Redirect_Option' => $baseDir . '/classes/premium-redirect-option.php',
'WPSEO_Premium_Redirect_Service' => $baseDir . '/classes/premium-redirect-service.php',
'WPSEO_Premium_Redirect_Undo_EndPoint' => $baseDir . '/classes/redirect-undo-endpoint.php',
'WPSEO_Premium_Register_Capabilities' => $baseDir . '/classes/premium-register-capabilities.php',
'WPSEO_Premium_Stale_Cornerstone_Content_Filter' => $baseDir . '/classes/premium-stale-cornerstone-content-filter.php',
'WPSEO_Product_Premium' => $baseDir . '/classes/product-premium.php',
'WPSEO_Redirect' => $baseDir . '/classes/redirect/redirect.php',
'WPSEO_Redirect_Abstract_Loader' => $baseDir . '/classes/redirect/loaders/redirect-abstract-loader.php',
'WPSEO_Redirect_Abstract_Validation' => $baseDir . '/classes/redirect/validation/redirect-abstract-validation.php',
'WPSEO_Redirect_Accessible_Validation' => $baseDir . '/classes/redirect/validation/redirect-accessible-validation.php',
'WPSEO_Redirect_Ajax' => $baseDir . '/classes/redirect/redirect-ajax.php',
'WPSEO_Redirect_Apache_Exporter' => $baseDir . '/classes/redirect/exporters/redirect-apache-exporter.php',
'WPSEO_Redirect_CSV_Exporter' => $baseDir . '/classes/redirect/exporters/redirect-csv-exporter.php',
'WPSEO_Redirect_CSV_Loader' => $baseDir . '/classes/redirect/loaders/redirect-csv-loader.php',
'WPSEO_Redirect_Endpoint_Validation' => $baseDir . '/classes/redirect/validation/redirect-endpoint-validation.php',
'WPSEO_Redirect_Exporter' => $baseDir . '/classes/redirect/exporters/redirect-exporter-interface.php',
'WPSEO_Redirect_File_Exporter' => $baseDir . '/classes/redirect/exporters/redirect-file-exporter.php',
'WPSEO_Redirect_File_Util' => $baseDir . '/classes/redirect/redirect-file-util.php',
'WPSEO_Redirect_Form_Presenter' => $baseDir . '/classes/redirect/presenters/redirect-form-presenter.php',
'WPSEO_Redirect_Formats' => $baseDir . '/classes/redirect/redirect-formats.php',
'WPSEO_Redirect_Formatter' => $baseDir . '/classes/redirect/redirect-formatter.php',
'WPSEO_Redirect_HTAccess_Loader' => $baseDir . '/classes/redirect/loaders/redirect-htaccess-loader.php',
'WPSEO_Redirect_Htaccess_Exporter' => $baseDir . '/classes/redirect/exporters/redirect-htaccess-exporter.php',
'WPSEO_Redirect_Htaccess_Util' => $baseDir . '/classes/redirect/redirect-htaccess-util.php',
'WPSEO_Redirect_Import_Exception' => $baseDir . '/classes/redirect/redirect-import-exception.php',
'WPSEO_Redirect_Importer' => $baseDir . '/classes/redirect/redirect-importer.php',
'WPSEO_Redirect_Loader' => $baseDir . '/classes/redirect/loaders/redirect-loader-interface.php',
'WPSEO_Redirect_Manager' => $baseDir . '/classes/redirect/redirect-manager.php',
'WPSEO_Redirect_Nginx_Exporter' => $baseDir . '/classes/redirect/exporters/redirect-nginx-exporter.php',
'WPSEO_Redirect_Option' => $baseDir . '/classes/redirect/redirect-option.php',
'WPSEO_Redirect_Option_Exporter' => $baseDir . '/classes/redirect/exporters/redirect-option-exporter.php',
'WPSEO_Redirect_Page' => $baseDir . '/classes/redirect/redirect-page.php',
'WPSEO_Redirect_Page_Presenter' => $baseDir . '/classes/redirect/presenters/redirect-page-presenter.php',
'WPSEO_Redirect_Presence_Validation' => $baseDir . '/classes/redirect/validation/redirect-presence-validation.php',
'WPSEO_Redirect_Presenter' => $baseDir . '/classes/redirect/presenters/redirect-presenter-interface.php',
'WPSEO_Redirect_Quick_Edit_Presenter' => $baseDir . '/classes/redirect/presenters/redirect-quick-edit-presenter.php',
'WPSEO_Redirect_Redirection_Loader' => $baseDir . '/classes/redirect/loaders/redirect-redirection-loader.php',
'WPSEO_Redirect_Relative_Origin_Validation' => $baseDir . '/classes/redirect/validation/redirect-relative-origin-validation.php',
'WPSEO_Redirect_Safe_Redirect_Loader' => $baseDir . '/classes/redirect/loaders/redirect-safe-redirect-loader.php',
'WPSEO_Redirect_Self_Redirect_Validation' => $baseDir . '/classes/redirect/validation/redirect-self-redirect-validation.php',
'WPSEO_Redirect_Settings_Presenter' => $baseDir . '/classes/redirect/presenters/redirect-settings-presenter.php',
'WPSEO_Redirect_Simple_301_Redirect_Loader' => $baseDir . '/classes/redirect/loaders/redirect-simple-301-redirect-loader.php',
'WPSEO_Redirect_Sitemap_Filter' => $baseDir . '/classes/redirect/redirect-sitemap-filter.php',
'WPSEO_Redirect_Subdirectory_Validation' => $baseDir . '/classes/redirect/validation/redirect-subdirectory-validation.php',
'WPSEO_Redirect_Tab_Presenter' => $baseDir . '/classes/redirect/presenters/redirect-tab-presenter.php',
'WPSEO_Redirect_Table' => $baseDir . '/classes/redirect/redirect-table.php',
'WPSEO_Redirect_Table_Presenter' => $baseDir . '/classes/redirect/presenters/redirect-table-presenter.php',
'WPSEO_Redirect_Types' => $baseDir . '/classes/redirect/redirect-types.php',
'WPSEO_Redirect_Uniqueness_Validation' => $baseDir . '/classes/redirect/validation/redirect-uniqueness-validation.php',
'WPSEO_Redirect_Upgrade' => $baseDir . '/classes/redirect/redirect-upgrade.php',
'WPSEO_Redirect_Url_Formatter' => $baseDir . '/classes/redirect/redirect-url-formatter.php',
'WPSEO_Redirect_Util' => $baseDir . '/classes/redirect/redirect-util.php',
'WPSEO_Redirect_Validation' => $baseDir . '/classes/redirect/validation/redirect-validation-interface.php',
'WPSEO_Redirect_Validator' => $baseDir . '/classes/redirect/redirect-validator.php',
'WPSEO_Social_Previews' => $baseDir . '/classes/social-previews.php',
'WPSEO_Term_Watcher' => $baseDir . '/classes/term-watcher.php',
'WPSEO_Upgrade_Manager' => $baseDir . '/classes/upgrade-manager.php',
'WPSEO_Validation_Error' => $baseDir . '/classes/validation-error.php',
'WPSEO_Validation_Result' => $baseDir . '/classes/validation-result.php',
'WPSEO_Validation_Warning' => $baseDir . '/classes/validation-warning.php',
'WPSEO_Watcher' => $baseDir . '/classes/watcher.php',
'Yoast\\WP\\SEO\\Config\\Migrations\\WpYoastPremiumImprovedInternalLinking' => $baseDir . '/src/config/migrations/20190715101200_WpYoastPremiumImprovedInternalLinking.php',
'Yoast\\WP\\SEO\\Integrations\\Blocks\\Block_Patterns' => $baseDir . '/src/deprecated/integrations/blocks/block-patterns.php',
'Yoast\\WP\\SEO\\Integrations\\Blocks\\Job_Posting_Block' => $baseDir . '/src/deprecated/integrations/blocks/job-posting-block.php',
'Yoast\\WP\\SEO\\Integrations\\Blocks\\Siblings_Block' => $baseDir . '/classes/blocks/siblings-block.php',
'Yoast\\WP\\SEO\\Integrations\\Blocks\\Subpages_Block' => $baseDir . '/classes/blocks/subpages-block.php',
'Yoast\\WP\\SEO\\Integrations\\Third_Party\\TranslationsPress' => $baseDir . '/src/integrations/third-party/translationspress.php',
'Yoast\\WP\\SEO\\Integrations\\Third_Party\\Wincher_Keyphrases' => $baseDir . '/src/integrations/third-party/wincher-keyphrases.php',
'Yoast\\WP\\SEO\\Models\\Prominent_Words' => $baseDir . '/src/models/prominent-words.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\AI_Generator_Action' => $baseDir . '/src/actions/ai-generator-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Link_Suggestions_Action' => $baseDir . '/src/actions/link-suggestions-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Prominent_Words\\Complete_Action' => $baseDir . '/src/actions/prominent-words/complete-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Prominent_Words\\Content_Action' => $baseDir . '/src/actions/prominent-words/content-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Prominent_Words\\Save_Action' => $baseDir . '/src/actions/prominent-words/save-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Zapier_Action' => $baseDir . '/src/deprecated/actions/zapier-action.php',
'Yoast\\WP\\SEO\\Premium\\Addon_Installer' => $baseDir . '/src/addon-installer.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Ai_Editor_Conditional' => $baseDir . '/src/conditionals/ai-editor-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Algolia_Enabled_Conditional' => $baseDir . '/src/conditionals/algolia-enabled-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Cornerstone_Enabled_Conditional' => $baseDir . '/src/conditionals/cornerstone-enabled-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\EDD_Conditional' => $baseDir . '/src/conditionals/edd-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Inclusive_Language_Enabled_Conditional' => $baseDir . '/src/conditionals/inclusive-language-enabled-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Term_Overview_Or_Ajax_Conditional' => $baseDir . '/src/conditionals/term-overview-or-ajax-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Zapier_Enabled_Conditional' => $baseDir . '/src/deprecated/conditionals/zapier-enabled-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Config\\Badge_Group_Names' => $baseDir . '/src/config/badge-group-names.php',
'Yoast\\WP\\SEO\\Premium\\Config\\Migrations\\AddIndexOnIndexableIdAndStem' => $baseDir . '/src/config/migrations/20210827093024_AddIndexOnIndexableIdAndStem.php',
'Yoast\\WP\\SEO\\Premium\\Database\\Migration_Runner_Premium' => $baseDir . '/src/database/migration-runner-premium.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Forbidden_Property_Mutation_Exception' => $baseDir . '/src/exceptions/forbidden-property-mutation-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Bad_Request_Exception' => $baseDir . '/src/exceptions/remote-request/bad-request-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Forbidden_Exception' => $baseDir . '/src/exceptions/remote-request/forbidden-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Internal_Server_Error_Exception' => $baseDir . '/src/exceptions/remote-request/internal-server-error-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Not_Found_Exception' => $baseDir . '/src/exceptions/remote-request/not-found-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Payment_Required_Exception' => $baseDir . '/src/exceptions/remote-request/payment-required-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Remote_Request_Exception' => $baseDir . '/src/exceptions/remote-request/remote-request-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Request_Timeout_Exception' => $baseDir . '/src/exceptions/remote-request/request-timeout-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Service_Unavailable_Exception' => $baseDir . '/src/exceptions/remote-request/service-unavailable-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Too_Many_Requests_Exception' => $baseDir . '/src/exceptions/remote-request/too-many-requests-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Unauthorized_Exception' => $baseDir . '/src/exceptions/remote-request/unauthorized-exception.php',
'Yoast\\WP\\SEO\\Premium\\Generated\\Cached_Container' => $baseDir . '/src/generated/container.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\AI_Generator_Helper' => $baseDir . '/src/helpers/ai-generator-helper.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\Current_Page_Helper' => $baseDir . '/src/helpers/current-page-helper.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\Prominent_Words_Helper' => $baseDir . '/src/helpers/prominent-words-helper.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\Version_Helper' => $baseDir . '/src/helpers/version-helper.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\Zapier_Helper' => $baseDir . '/src/deprecated/helpers/zapier-helper.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Crawl_Cleanup_Permalinks' => $baseDir . '/src/deprecated/initializers/crawl-cleanup-permalinks.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Index_Now_Key' => $baseDir . '/src/initializers/index-now-key.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Introductions_Initializer' => $baseDir . '/src/initializers/introductions-initializer.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Plugin' => $baseDir . '/src/initializers/plugin.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Redirect_Handler' => $baseDir . '/src/initializers/redirect-handler.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Woocommerce' => $baseDir . '/src/initializers/woocommerce.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Wp_Cli_Initializer' => $baseDir . '/src/initializers/wp-cli-initializer.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Abstract_OpenGraph_Integration' => $baseDir . '/src/integrations/abstract-opengraph-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Ai_Consent_Integration' => $baseDir . '/src/integrations/admin/ai-consent-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Ai_Generator_Integration' => $baseDir . '/src/integrations/admin/ai-generator-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Cornerstone_Column_Integration' => $baseDir . '/src/integrations/admin/cornerstone-column-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Cornerstone_Taxonomy_Column_Integration' => $baseDir . '/src/integrations/admin/cornerstone-taxonomy-column-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Crawl_Settings_Integration' => $baseDir . '/src/deprecated/integrations/admin/crawl-settings-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Inclusive_Language_Column_Integration' => $baseDir . '/src/integrations/admin/inclusive-language-column-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Inclusive_Language_Filter_Integration' => $baseDir . '/src/integrations/admin/inclusive-language-filter-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Inclusive_Language_Taxonomy_Column_Integration' => $baseDir . '/src/integrations/admin/inclusive-language-taxonomy-column-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Integrations_Page' => $baseDir . '/src/deprecated/integrations/admin/integrations-page.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Keyword_Integration' => $baseDir . '/src/integrations/admin/keyword-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Metabox_Formatter_Integration' => $baseDir . '/src/integrations/admin/metabox-formatter-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Plugin_Links_Integration' => $baseDir . '/src/integrations/admin/plugin-links-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Prominent_Words\\Indexing_Integration' => $baseDir . '/src/integrations/admin/prominent-words/indexing-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Prominent_Words\\Metabox_Integration' => $baseDir . '/src/integrations/admin/prominent-words/metabox-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Related_Keyphrase_Filter_Integration' => $baseDir . '/src/integrations/admin/related-keyphrase-filter-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Replacement_Variables_Integration' => $baseDir . '/src/integrations/admin/replacement-variables-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Settings_Integration' => $baseDir . '/src/integrations/admin/settings-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Thank_You_Page_Integration' => $baseDir . '/src/integrations/admin/thank-you-page-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Update_Premium_Notification' => $baseDir . '/src/integrations/admin/update-premium-notification.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\User_Profile_Integration' => $baseDir . '/src/integrations/admin/user-profile-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Workouts_Integration' => $baseDir . '/src/integrations/admin/workouts-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Zapier_Notification_Integration' => $baseDir . '/src/deprecated/integrations/admin/zapier-notification-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Alerts\\Ai_Generator_Tip_Notification' => $baseDir . '/src/integrations/alerts/ai-generator-tip-notification.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Blocks\\Estimated_Reading_Time_Block' => $baseDir . '/src/integrations/blocks/estimated-reading-time-block.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Blocks\\Related_Links_Block' => $baseDir . '/src/integrations/blocks/related-links-block.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Blocks\\Schema_Blocks' => $baseDir . '/src/deprecated/integrations/blocks/schema-blocks.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Cleanup_Integration' => $baseDir . '/src/integrations/cleanup-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Front_End\\Crawl_Cleanup_Basic' => $baseDir . '/src/deprecated/integrations/front-end/crawl-cleanup-basic.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Front_End\\Crawl_Cleanup_Rss' => $baseDir . '/src/deprecated/integrations/front-end/crawl-cleanup-rss.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Front_End\\Crawl_Cleanup_Searches' => $baseDir . '/src/deprecated/integrations/front-end/crawl-cleanup-searches.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Front_End\\Robots_Txt_Integration' => $baseDir . '/src/integrations/front-end/robots-txt-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Frontend_Inspector' => $baseDir . '/src/integrations/frontend-inspector.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Index_Now_Ping' => $baseDir . '/src/integrations/index-now-ping.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Missing_Indexables_Count_Integration' => $baseDir . '/src/integrations/missing-indexables-count-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_Author_Archive' => $baseDir . '/src/integrations/opengraph-author-archive.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_Date_Archive' => $baseDir . '/src/integrations/opengraph-date-archive.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_PostType_Archive' => $baseDir . '/src/integrations/opengraph-posttype-archive.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_Post_Type' => $baseDir . '/src/integrations/opengraph-post-type.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_Term_Archive' => $baseDir . '/src/integrations/opengraph-term-archive.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Publishing_Principles_Schema_Integration' => $baseDir . '/src/integrations/publishing-principles-schema-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Routes\\AI_Generator_Route' => $baseDir . '/src/integrations/routes/ai-generator-route.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Routes\\Workouts_Routes_Integration' => $baseDir . '/src/integrations/routes/workouts-routes-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Algolia' => $baseDir . '/src/integrations/third-party/algolia.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\EDD' => $baseDir . '/src/integrations/third-party/edd.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Elementor_Premium' => $baseDir . '/src/integrations/third-party/elementor-premium.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Mastodon' => $baseDir . '/src/integrations/third-party/mastodon.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Zapier' => $baseDir . '/src/deprecated/integrations/third-party/zapier.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Zapier_Classic_Editor' => $baseDir . '/src/deprecated/integrations/third-party/zapier-classic-editor.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Zapier_Trigger' => $baseDir . '/src/deprecated/integrations/third-party/zapier-trigger.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Upgrade_Integration' => $baseDir . '/src/integrations/upgrade-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\User_Profile_Integration' => $baseDir . '/src/integrations/user-profile-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Watchers\\Premium_Option_Wpseo_Watcher' => $baseDir . '/src/deprecated/integrations/watchers/premium-option-wpseo-watcher.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Watchers\\Prominent_Words_Watcher' => $baseDir . '/src/integrations/watchers/prominent-words-watcher.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Watchers\\Zapier_APIKey_Reset_Watcher' => $baseDir . '/src/deprecated/integrations/watchers/zapier-apikey-reset-watcher.php',
'Yoast\\WP\\SEO\\Premium\\Main' => $baseDir . '/src/main.php',
'Yoast\\WP\\SEO\\Premium\\Presenters\\Icons\\Checkmark_Icon_Presenter' => $baseDir . '/src/presenters/icons/checkmark-icon-presenter.php',
'Yoast\\WP\\SEO\\Premium\\Presenters\\Icons\\Cross_Icon_Presenter' => $baseDir . '/src/presenters/icons/cross-icon-presenter.php',
'Yoast\\WP\\SEO\\Premium\\Presenters\\Icons\\Icon_Presenter' => $baseDir . '/src/presenters/icons/icon-presenter.php',
'Yoast\\WP\\SEO\\Premium\\Presenters\\Mastodon_Link_Presenter' => $baseDir . '/src/presenters/mastodon-link-presenter.php',
'Yoast\\WP\\SEO\\Premium\\Repositories\\Prominent_Words_Repository' => $baseDir . '/src/repositories/prominent-words-repository.php',
'Yoast\\WP\\SEO\\Premium\\Routes\\Link_Suggestions_Route' => $baseDir . '/src/routes/link-suggestions-route.php',
'Yoast\\WP\\SEO\\Premium\\Routes\\Prominent_Words_Route' => $baseDir . '/src/routes/prominent-words-route.php',
'Yoast\\WP\\SEO\\Premium\\Routes\\Workouts_Route' => $baseDir . '/src/routes/workouts-route.php',
'Yoast\\WP\\SEO\\Premium\\Routes\\Zapier_Route' => $baseDir . '/src/deprecated/routes/zapier-route.php',
'Yoast\\WP\\SEO\\Premium\\Surfaces\\Helpers_Surface' => $baseDir . '/src/surfaces/helpers-surface.php',
'Yoast\\WP\\SEO\\Premium\\WordPress\\Wrapper' => $baseDir . '/src/wordpress/wrapper.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Block_Pattern' => $baseDir . '/src/deprecated/schema-templates/block-patterns/block-pattern.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Block_Pattern_Categories' => $baseDir . '/src/deprecated/schema-templates/block-patterns/block-pattern-categories.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Block_Pattern_Keywords' => $baseDir . '/src/deprecated/schema-templates/block-patterns/block-pattern-keywords.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Job_Posting_Base_Pattern' => $baseDir . '/src/deprecated/schema-templates/block-patterns/job-posting-base-pattern.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Job_Posting_One_Column' => $baseDir . '/src/deprecated/schema-templates/block-patterns/job-posting-one-column.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Job_Posting_Two_Columns' => $baseDir . '/src/deprecated/schema-templates/block-patterns/job-posting-two-columns.php',
);

View File

@@ -1,9 +0,0 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -1,10 +0,0 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Composer\\Installers\\' => array($vendorDir . '/composer/installers/src/Composer/Installers'),
);

View File

@@ -1,48 +0,0 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit0c422f20871bcbf1c73c1006dcf06201
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInit0c422f20871bcbf1c73c1006dcf06201', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit0c422f20871bcbf1c73c1006dcf06201', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit0c422f20871bcbf1c73c1006dcf06201::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->setClassMapAuthoritative(true);
$loader->register(true);
return $loader;
}
}

View File

@@ -1,259 +0,0 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInit0c422f20871bcbf1c73c1006dcf06201
{
public static $prefixLengthsPsr4 = array (
'C' =>
array (
'Composer\\Installers\\' => 20,
),
);
public static $prefixDirsPsr4 = array (
'Composer\\Installers\\' =>
array (
0 => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers',
),
);
public static $classMap = array (
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'WPSEO_CLI_Premium_Requirement' => __DIR__ . '/../..' . '/cli/cli-premium-requirement.php',
'WPSEO_CLI_Redirect_Base_Command' => __DIR__ . '/../..' . '/cli/cli-redirect-base-command.php',
'WPSEO_CLI_Redirect_Command_Namespace' => __DIR__ . '/../..' . '/cli/cli-redirect-command-namespace.php',
'WPSEO_CLI_Redirect_Create_Command' => __DIR__ . '/../..' . '/cli/cli-redirect-create-command.php',
'WPSEO_CLI_Redirect_Delete_Command' => __DIR__ . '/../..' . '/cli/cli-redirect-delete-command.php',
'WPSEO_CLI_Redirect_Follow_Command' => __DIR__ . '/../..' . '/cli/cli-redirect-follow-command.php',
'WPSEO_CLI_Redirect_Has_Command' => __DIR__ . '/../..' . '/cli/cli-redirect-has-command.php',
'WPSEO_CLI_Redirect_List_Command' => __DIR__ . '/../..' . '/cli/cli-redirect-list-command.php',
'WPSEO_CLI_Redirect_Update_Command' => __DIR__ . '/../..' . '/cli/cli-redirect-update-command.php',
'WPSEO_Custom_Fields_Plugin' => __DIR__ . '/../..' . '/classes/custom-fields-plugin.php',
'WPSEO_Executable_Redirect' => __DIR__ . '/../..' . '/classes/redirect/executable-redirect.php',
'WPSEO_Export_Keywords_CSV' => __DIR__ . '/../..' . '/classes/export/export-keywords-csv.php',
'WPSEO_Export_Keywords_Post_Presenter' => __DIR__ . '/../..' . '/classes/export/export-keywords-post-presenter.php',
'WPSEO_Export_Keywords_Post_Query' => __DIR__ . '/../..' . '/classes/export/export-keywords-post-query.php',
'WPSEO_Export_Keywords_Presenter' => __DIR__ . '/../..' . '/classes/export/export-keywords-presenter-interface.php',
'WPSEO_Export_Keywords_Query' => __DIR__ . '/../..' . '/classes/export/export-keywords-query-interface.php',
'WPSEO_Export_Keywords_Term_Presenter' => __DIR__ . '/../..' . '/classes/export/export-keywords-term-presenter.php',
'WPSEO_Export_Keywords_Term_Query' => __DIR__ . '/../..' . '/classes/export/export-keywords-term-query.php',
'WPSEO_Facebook_Profile' => __DIR__ . '/../..' . '/src/deprecated/classes/facebook-profile.php',
'WPSEO_Metabox_Link_Suggestions' => __DIR__ . '/../..' . '/classes/metabox-link-suggestions.php',
'WPSEO_Multi_Keyword' => __DIR__ . '/../..' . '/classes/multi-keyword.php',
'WPSEO_Post_Watcher' => __DIR__ . '/../..' . '/classes/post-watcher.php',
'WPSEO_Premium' => __DIR__ . '/../..' . '/premium.php',
'WPSEO_Premium_Asset_JS_L10n' => __DIR__ . '/../..' . '/classes/premium-asset-js-l10n.php',
'WPSEO_Premium_Assets' => __DIR__ . '/../..' . '/classes/premium-assets.php',
'WPSEO_Premium_Expose_Shortlinks' => __DIR__ . '/../..' . '/classes/premium-expose-shortlinks.php',
'WPSEO_Premium_Import_Manager' => __DIR__ . '/../..' . '/classes/premium-import-manager.php',
'WPSEO_Premium_Javascript_Strings' => __DIR__ . '/../..' . '/classes/premium-javascript-strings.php',
'WPSEO_Premium_Keyword_Export_Manager' => __DIR__ . '/../..' . '/classes/premium-keyword-export-manager.php',
'WPSEO_Premium_Metabox' => __DIR__ . '/../..' . '/classes/premium-metabox.php',
'WPSEO_Premium_Option' => __DIR__ . '/../..' . '/classes/premium-option.php',
'WPSEO_Premium_Orphaned_Content_Support' => __DIR__ . '/../..' . '/classes/premium-orphaned-content-support.php',
'WPSEO_Premium_Orphaned_Content_Utils' => __DIR__ . '/../..' . '/classes/premium-orphaned-content-utils.php',
'WPSEO_Premium_Orphaned_Post_Filter' => __DIR__ . '/../..' . '/classes/premium-orphaned-post-filter.php',
'WPSEO_Premium_Orphaned_Post_Query' => __DIR__ . '/../..' . '/classes/premium-orphaned-post-query.php',
'WPSEO_Premium_Prominent_Words_Support' => __DIR__ . '/../..' . '/classes/premium-prominent-words-support.php',
'WPSEO_Premium_Prominent_Words_Unindexed_Post_Query' => __DIR__ . '/../..' . '/classes/premium-prominent-words-unindexed-post-query.php',
'WPSEO_Premium_Prominent_Words_Versioning' => __DIR__ . '/../..' . '/classes/premium-prominent-words-versioning.php',
'WPSEO_Premium_Redirect_EndPoint' => __DIR__ . '/../..' . '/classes/premium-redirect-endpoint.php',
'WPSEO_Premium_Redirect_Export_Manager' => __DIR__ . '/../..' . '/classes/premium-redirect-export-manager.php',
'WPSEO_Premium_Redirect_Option' => __DIR__ . '/../..' . '/classes/premium-redirect-option.php',
'WPSEO_Premium_Redirect_Service' => __DIR__ . '/../..' . '/classes/premium-redirect-service.php',
'WPSEO_Premium_Redirect_Undo_EndPoint' => __DIR__ . '/../..' . '/classes/redirect-undo-endpoint.php',
'WPSEO_Premium_Register_Capabilities' => __DIR__ . '/../..' . '/classes/premium-register-capabilities.php',
'WPSEO_Premium_Stale_Cornerstone_Content_Filter' => __DIR__ . '/../..' . '/classes/premium-stale-cornerstone-content-filter.php',
'WPSEO_Product_Premium' => __DIR__ . '/../..' . '/classes/product-premium.php',
'WPSEO_Redirect' => __DIR__ . '/../..' . '/classes/redirect/redirect.php',
'WPSEO_Redirect_Abstract_Loader' => __DIR__ . '/../..' . '/classes/redirect/loaders/redirect-abstract-loader.php',
'WPSEO_Redirect_Abstract_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-abstract-validation.php',
'WPSEO_Redirect_Accessible_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-accessible-validation.php',
'WPSEO_Redirect_Ajax' => __DIR__ . '/../..' . '/classes/redirect/redirect-ajax.php',
'WPSEO_Redirect_Apache_Exporter' => __DIR__ . '/../..' . '/classes/redirect/exporters/redirect-apache-exporter.php',
'WPSEO_Redirect_CSV_Exporter' => __DIR__ . '/../..' . '/classes/redirect/exporters/redirect-csv-exporter.php',
'WPSEO_Redirect_CSV_Loader' => __DIR__ . '/../..' . '/classes/redirect/loaders/redirect-csv-loader.php',
'WPSEO_Redirect_Endpoint_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-endpoint-validation.php',
'WPSEO_Redirect_Exporter' => __DIR__ . '/../..' . '/classes/redirect/exporters/redirect-exporter-interface.php',
'WPSEO_Redirect_File_Exporter' => __DIR__ . '/../..' . '/classes/redirect/exporters/redirect-file-exporter.php',
'WPSEO_Redirect_File_Util' => __DIR__ . '/../..' . '/classes/redirect/redirect-file-util.php',
'WPSEO_Redirect_Form_Presenter' => __DIR__ . '/../..' . '/classes/redirect/presenters/redirect-form-presenter.php',
'WPSEO_Redirect_Formats' => __DIR__ . '/../..' . '/classes/redirect/redirect-formats.php',
'WPSEO_Redirect_Formatter' => __DIR__ . '/../..' . '/classes/redirect/redirect-formatter.php',
'WPSEO_Redirect_HTAccess_Loader' => __DIR__ . '/../..' . '/classes/redirect/loaders/redirect-htaccess-loader.php',
'WPSEO_Redirect_Htaccess_Exporter' => __DIR__ . '/../..' . '/classes/redirect/exporters/redirect-htaccess-exporter.php',
'WPSEO_Redirect_Htaccess_Util' => __DIR__ . '/../..' . '/classes/redirect/redirect-htaccess-util.php',
'WPSEO_Redirect_Import_Exception' => __DIR__ . '/../..' . '/classes/redirect/redirect-import-exception.php',
'WPSEO_Redirect_Importer' => __DIR__ . '/../..' . '/classes/redirect/redirect-importer.php',
'WPSEO_Redirect_Loader' => __DIR__ . '/../..' . '/classes/redirect/loaders/redirect-loader-interface.php',
'WPSEO_Redirect_Manager' => __DIR__ . '/../..' . '/classes/redirect/redirect-manager.php',
'WPSEO_Redirect_Nginx_Exporter' => __DIR__ . '/../..' . '/classes/redirect/exporters/redirect-nginx-exporter.php',
'WPSEO_Redirect_Option' => __DIR__ . '/../..' . '/classes/redirect/redirect-option.php',
'WPSEO_Redirect_Option_Exporter' => __DIR__ . '/../..' . '/classes/redirect/exporters/redirect-option-exporter.php',
'WPSEO_Redirect_Page' => __DIR__ . '/../..' . '/classes/redirect/redirect-page.php',
'WPSEO_Redirect_Page_Presenter' => __DIR__ . '/../..' . '/classes/redirect/presenters/redirect-page-presenter.php',
'WPSEO_Redirect_Presence_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-presence-validation.php',
'WPSEO_Redirect_Presenter' => __DIR__ . '/../..' . '/classes/redirect/presenters/redirect-presenter-interface.php',
'WPSEO_Redirect_Quick_Edit_Presenter' => __DIR__ . '/../..' . '/classes/redirect/presenters/redirect-quick-edit-presenter.php',
'WPSEO_Redirect_Redirection_Loader' => __DIR__ . '/../..' . '/classes/redirect/loaders/redirect-redirection-loader.php',
'WPSEO_Redirect_Relative_Origin_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-relative-origin-validation.php',
'WPSEO_Redirect_Safe_Redirect_Loader' => __DIR__ . '/../..' . '/classes/redirect/loaders/redirect-safe-redirect-loader.php',
'WPSEO_Redirect_Self_Redirect_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-self-redirect-validation.php',
'WPSEO_Redirect_Settings_Presenter' => __DIR__ . '/../..' . '/classes/redirect/presenters/redirect-settings-presenter.php',
'WPSEO_Redirect_Simple_301_Redirect_Loader' => __DIR__ . '/../..' . '/classes/redirect/loaders/redirect-simple-301-redirect-loader.php',
'WPSEO_Redirect_Sitemap_Filter' => __DIR__ . '/../..' . '/classes/redirect/redirect-sitemap-filter.php',
'WPSEO_Redirect_Subdirectory_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-subdirectory-validation.php',
'WPSEO_Redirect_Tab_Presenter' => __DIR__ . '/../..' . '/classes/redirect/presenters/redirect-tab-presenter.php',
'WPSEO_Redirect_Table' => __DIR__ . '/../..' . '/classes/redirect/redirect-table.php',
'WPSEO_Redirect_Table_Presenter' => __DIR__ . '/../..' . '/classes/redirect/presenters/redirect-table-presenter.php',
'WPSEO_Redirect_Types' => __DIR__ . '/../..' . '/classes/redirect/redirect-types.php',
'WPSEO_Redirect_Uniqueness_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-uniqueness-validation.php',
'WPSEO_Redirect_Upgrade' => __DIR__ . '/../..' . '/classes/redirect/redirect-upgrade.php',
'WPSEO_Redirect_Url_Formatter' => __DIR__ . '/../..' . '/classes/redirect/redirect-url-formatter.php',
'WPSEO_Redirect_Util' => __DIR__ . '/../..' . '/classes/redirect/redirect-util.php',
'WPSEO_Redirect_Validation' => __DIR__ . '/../..' . '/classes/redirect/validation/redirect-validation-interface.php',
'WPSEO_Redirect_Validator' => __DIR__ . '/../..' . '/classes/redirect/redirect-validator.php',
'WPSEO_Social_Previews' => __DIR__ . '/../..' . '/classes/social-previews.php',
'WPSEO_Term_Watcher' => __DIR__ . '/../..' . '/classes/term-watcher.php',
'WPSEO_Upgrade_Manager' => __DIR__ . '/../..' . '/classes/upgrade-manager.php',
'WPSEO_Validation_Error' => __DIR__ . '/../..' . '/classes/validation-error.php',
'WPSEO_Validation_Result' => __DIR__ . '/../..' . '/classes/validation-result.php',
'WPSEO_Validation_Warning' => __DIR__ . '/../..' . '/classes/validation-warning.php',
'WPSEO_Watcher' => __DIR__ . '/../..' . '/classes/watcher.php',
'Yoast\\WP\\SEO\\Config\\Migrations\\WpYoastPremiumImprovedInternalLinking' => __DIR__ . '/../..' . '/src/config/migrations/20190715101200_WpYoastPremiumImprovedInternalLinking.php',
'Yoast\\WP\\SEO\\Integrations\\Blocks\\Block_Patterns' => __DIR__ . '/../..' . '/src/deprecated/integrations/blocks/block-patterns.php',
'Yoast\\WP\\SEO\\Integrations\\Blocks\\Job_Posting_Block' => __DIR__ . '/../..' . '/src/deprecated/integrations/blocks/job-posting-block.php',
'Yoast\\WP\\SEO\\Integrations\\Blocks\\Siblings_Block' => __DIR__ . '/../..' . '/classes/blocks/siblings-block.php',
'Yoast\\WP\\SEO\\Integrations\\Blocks\\Subpages_Block' => __DIR__ . '/../..' . '/classes/blocks/subpages-block.php',
'Yoast\\WP\\SEO\\Integrations\\Third_Party\\TranslationsPress' => __DIR__ . '/../..' . '/src/integrations/third-party/translationspress.php',
'Yoast\\WP\\SEO\\Integrations\\Third_Party\\Wincher_Keyphrases' => __DIR__ . '/../..' . '/src/integrations/third-party/wincher-keyphrases.php',
'Yoast\\WP\\SEO\\Models\\Prominent_Words' => __DIR__ . '/../..' . '/src/models/prominent-words.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\AI_Generator_Action' => __DIR__ . '/../..' . '/src/actions/ai-generator-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Link_Suggestions_Action' => __DIR__ . '/../..' . '/src/actions/link-suggestions-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Prominent_Words\\Complete_Action' => __DIR__ . '/../..' . '/src/actions/prominent-words/complete-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Prominent_Words\\Content_Action' => __DIR__ . '/../..' . '/src/actions/prominent-words/content-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Prominent_Words\\Save_Action' => __DIR__ . '/../..' . '/src/actions/prominent-words/save-action.php',
'Yoast\\WP\\SEO\\Premium\\Actions\\Zapier_Action' => __DIR__ . '/../..' . '/src/deprecated/actions/zapier-action.php',
'Yoast\\WP\\SEO\\Premium\\Addon_Installer' => __DIR__ . '/../..' . '/src/addon-installer.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Ai_Editor_Conditional' => __DIR__ . '/../..' . '/src/conditionals/ai-editor-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Algolia_Enabled_Conditional' => __DIR__ . '/../..' . '/src/conditionals/algolia-enabled-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Cornerstone_Enabled_Conditional' => __DIR__ . '/../..' . '/src/conditionals/cornerstone-enabled-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\EDD_Conditional' => __DIR__ . '/../..' . '/src/conditionals/edd-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Inclusive_Language_Enabled_Conditional' => __DIR__ . '/../..' . '/src/conditionals/inclusive-language-enabled-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Term_Overview_Or_Ajax_Conditional' => __DIR__ . '/../..' . '/src/conditionals/term-overview-or-ajax-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Conditionals\\Zapier_Enabled_Conditional' => __DIR__ . '/../..' . '/src/deprecated/conditionals/zapier-enabled-conditional.php',
'Yoast\\WP\\SEO\\Premium\\Config\\Badge_Group_Names' => __DIR__ . '/../..' . '/src/config/badge-group-names.php',
'Yoast\\WP\\SEO\\Premium\\Config\\Migrations\\AddIndexOnIndexableIdAndStem' => __DIR__ . '/../..' . '/src/config/migrations/20210827093024_AddIndexOnIndexableIdAndStem.php',
'Yoast\\WP\\SEO\\Premium\\Database\\Migration_Runner_Premium' => __DIR__ . '/../..' . '/src/database/migration-runner-premium.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Forbidden_Property_Mutation_Exception' => __DIR__ . '/../..' . '/src/exceptions/forbidden-property-mutation-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Bad_Request_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/bad-request-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Forbidden_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/forbidden-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Internal_Server_Error_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/internal-server-error-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Not_Found_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/not-found-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Payment_Required_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/payment-required-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Remote_Request_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/remote-request-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Request_Timeout_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/request-timeout-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Service_Unavailable_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/service-unavailable-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Too_Many_Requests_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/too-many-requests-exception.php',
'Yoast\\WP\\SEO\\Premium\\Exceptions\\Remote_Request\\Unauthorized_Exception' => __DIR__ . '/../..' . '/src/exceptions/remote-request/unauthorized-exception.php',
'Yoast\\WP\\SEO\\Premium\\Generated\\Cached_Container' => __DIR__ . '/../..' . '/src/generated/container.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\AI_Generator_Helper' => __DIR__ . '/../..' . '/src/helpers/ai-generator-helper.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\Current_Page_Helper' => __DIR__ . '/../..' . '/src/helpers/current-page-helper.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\Prominent_Words_Helper' => __DIR__ . '/../..' . '/src/helpers/prominent-words-helper.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\Version_Helper' => __DIR__ . '/../..' . '/src/helpers/version-helper.php',
'Yoast\\WP\\SEO\\Premium\\Helpers\\Zapier_Helper' => __DIR__ . '/../..' . '/src/deprecated/helpers/zapier-helper.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Crawl_Cleanup_Permalinks' => __DIR__ . '/../..' . '/src/deprecated/initializers/crawl-cleanup-permalinks.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Index_Now_Key' => __DIR__ . '/../..' . '/src/initializers/index-now-key.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Introductions_Initializer' => __DIR__ . '/../..' . '/src/initializers/introductions-initializer.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Plugin' => __DIR__ . '/../..' . '/src/initializers/plugin.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Redirect_Handler' => __DIR__ . '/../..' . '/src/initializers/redirect-handler.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Woocommerce' => __DIR__ . '/../..' . '/src/initializers/woocommerce.php',
'Yoast\\WP\\SEO\\Premium\\Initializers\\Wp_Cli_Initializer' => __DIR__ . '/../..' . '/src/initializers/wp-cli-initializer.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Abstract_OpenGraph_Integration' => __DIR__ . '/../..' . '/src/integrations/abstract-opengraph-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Ai_Consent_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/ai-consent-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Ai_Generator_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/ai-generator-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Cornerstone_Column_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/cornerstone-column-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Cornerstone_Taxonomy_Column_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/cornerstone-taxonomy-column-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Crawl_Settings_Integration' => __DIR__ . '/../..' . '/src/deprecated/integrations/admin/crawl-settings-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Inclusive_Language_Column_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/inclusive-language-column-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Inclusive_Language_Filter_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/inclusive-language-filter-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Inclusive_Language_Taxonomy_Column_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/inclusive-language-taxonomy-column-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Integrations_Page' => __DIR__ . '/../..' . '/src/deprecated/integrations/admin/integrations-page.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Keyword_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/keyword-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Metabox_Formatter_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/metabox-formatter-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Plugin_Links_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/plugin-links-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Prominent_Words\\Indexing_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/prominent-words/indexing-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Prominent_Words\\Metabox_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/prominent-words/metabox-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Related_Keyphrase_Filter_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/related-keyphrase-filter-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Replacement_Variables_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/replacement-variables-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Settings_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/settings-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Thank_You_Page_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/thank-you-page-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Update_Premium_Notification' => __DIR__ . '/../..' . '/src/integrations/admin/update-premium-notification.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\User_Profile_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/user-profile-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Workouts_Integration' => __DIR__ . '/../..' . '/src/integrations/admin/workouts-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Admin\\Zapier_Notification_Integration' => __DIR__ . '/../..' . '/src/deprecated/integrations/admin/zapier-notification-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Alerts\\Ai_Generator_Tip_Notification' => __DIR__ . '/../..' . '/src/integrations/alerts/ai-generator-tip-notification.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Blocks\\Estimated_Reading_Time_Block' => __DIR__ . '/../..' . '/src/integrations/blocks/estimated-reading-time-block.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Blocks\\Related_Links_Block' => __DIR__ . '/../..' . '/src/integrations/blocks/related-links-block.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Blocks\\Schema_Blocks' => __DIR__ . '/../..' . '/src/deprecated/integrations/blocks/schema-blocks.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Cleanup_Integration' => __DIR__ . '/../..' . '/src/integrations/cleanup-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Front_End\\Crawl_Cleanup_Basic' => __DIR__ . '/../..' . '/src/deprecated/integrations/front-end/crawl-cleanup-basic.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Front_End\\Crawl_Cleanup_Rss' => __DIR__ . '/../..' . '/src/deprecated/integrations/front-end/crawl-cleanup-rss.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Front_End\\Crawl_Cleanup_Searches' => __DIR__ . '/../..' . '/src/deprecated/integrations/front-end/crawl-cleanup-searches.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Front_End\\Robots_Txt_Integration' => __DIR__ . '/../..' . '/src/integrations/front-end/robots-txt-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Frontend_Inspector' => __DIR__ . '/../..' . '/src/integrations/frontend-inspector.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Index_Now_Ping' => __DIR__ . '/../..' . '/src/integrations/index-now-ping.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Missing_Indexables_Count_Integration' => __DIR__ . '/../..' . '/src/integrations/missing-indexables-count-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_Author_Archive' => __DIR__ . '/../..' . '/src/integrations/opengraph-author-archive.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_Date_Archive' => __DIR__ . '/../..' . '/src/integrations/opengraph-date-archive.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_PostType_Archive' => __DIR__ . '/../..' . '/src/integrations/opengraph-posttype-archive.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_Post_Type' => __DIR__ . '/../..' . '/src/integrations/opengraph-post-type.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\OpenGraph_Term_Archive' => __DIR__ . '/../..' . '/src/integrations/opengraph-term-archive.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Publishing_Principles_Schema_Integration' => __DIR__ . '/../..' . '/src/integrations/publishing-principles-schema-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Routes\\AI_Generator_Route' => __DIR__ . '/../..' . '/src/integrations/routes/ai-generator-route.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Routes\\Workouts_Routes_Integration' => __DIR__ . '/../..' . '/src/integrations/routes/workouts-routes-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Algolia' => __DIR__ . '/../..' . '/src/integrations/third-party/algolia.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\EDD' => __DIR__ . '/../..' . '/src/integrations/third-party/edd.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Elementor_Premium' => __DIR__ . '/../..' . '/src/integrations/third-party/elementor-premium.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Mastodon' => __DIR__ . '/../..' . '/src/integrations/third-party/mastodon.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Zapier' => __DIR__ . '/../..' . '/src/deprecated/integrations/third-party/zapier.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Zapier_Classic_Editor' => __DIR__ . '/../..' . '/src/deprecated/integrations/third-party/zapier-classic-editor.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Third_Party\\Zapier_Trigger' => __DIR__ . '/../..' . '/src/deprecated/integrations/third-party/zapier-trigger.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Upgrade_Integration' => __DIR__ . '/../..' . '/src/integrations/upgrade-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\User_Profile_Integration' => __DIR__ . '/../..' . '/src/integrations/user-profile-integration.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Watchers\\Premium_Option_Wpseo_Watcher' => __DIR__ . '/../..' . '/src/deprecated/integrations/watchers/premium-option-wpseo-watcher.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Watchers\\Prominent_Words_Watcher' => __DIR__ . '/../..' . '/src/integrations/watchers/prominent-words-watcher.php',
'Yoast\\WP\\SEO\\Premium\\Integrations\\Watchers\\Zapier_APIKey_Reset_Watcher' => __DIR__ . '/../..' . '/src/deprecated/integrations/watchers/zapier-apikey-reset-watcher.php',
'Yoast\\WP\\SEO\\Premium\\Main' => __DIR__ . '/../..' . '/src/main.php',
'Yoast\\WP\\SEO\\Premium\\Presenters\\Icons\\Checkmark_Icon_Presenter' => __DIR__ . '/../..' . '/src/presenters/icons/checkmark-icon-presenter.php',
'Yoast\\WP\\SEO\\Premium\\Presenters\\Icons\\Cross_Icon_Presenter' => __DIR__ . '/../..' . '/src/presenters/icons/cross-icon-presenter.php',
'Yoast\\WP\\SEO\\Premium\\Presenters\\Icons\\Icon_Presenter' => __DIR__ . '/../..' . '/src/presenters/icons/icon-presenter.php',
'Yoast\\WP\\SEO\\Premium\\Presenters\\Mastodon_Link_Presenter' => __DIR__ . '/../..' . '/src/presenters/mastodon-link-presenter.php',
'Yoast\\WP\\SEO\\Premium\\Repositories\\Prominent_Words_Repository' => __DIR__ . '/../..' . '/src/repositories/prominent-words-repository.php',
'Yoast\\WP\\SEO\\Premium\\Routes\\Link_Suggestions_Route' => __DIR__ . '/../..' . '/src/routes/link-suggestions-route.php',
'Yoast\\WP\\SEO\\Premium\\Routes\\Prominent_Words_Route' => __DIR__ . '/../..' . '/src/routes/prominent-words-route.php',
'Yoast\\WP\\SEO\\Premium\\Routes\\Workouts_Route' => __DIR__ . '/../..' . '/src/routes/workouts-route.php',
'Yoast\\WP\\SEO\\Premium\\Routes\\Zapier_Route' => __DIR__ . '/../..' . '/src/deprecated/routes/zapier-route.php',
'Yoast\\WP\\SEO\\Premium\\Surfaces\\Helpers_Surface' => __DIR__ . '/../..' . '/src/surfaces/helpers-surface.php',
'Yoast\\WP\\SEO\\Premium\\WordPress\\Wrapper' => __DIR__ . '/../..' . '/src/wordpress/wrapper.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Block_Pattern' => __DIR__ . '/../..' . '/src/deprecated/schema-templates/block-patterns/block-pattern.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Block_Pattern_Categories' => __DIR__ . '/../..' . '/src/deprecated/schema-templates/block-patterns/block-pattern-categories.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Block_Pattern_Keywords' => __DIR__ . '/../..' . '/src/deprecated/schema-templates/block-patterns/block-pattern-keywords.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Job_Posting_Base_Pattern' => __DIR__ . '/../..' . '/src/deprecated/schema-templates/block-patterns/job-posting-base-pattern.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Job_Posting_One_Column' => __DIR__ . '/../..' . '/src/deprecated/schema-templates/block-patterns/job-posting-one-column.php',
'Yoast\\WP\\SEO\\Schema_Templates\\Block_Patterns\\Job_Posting_Two_Columns' => __DIR__ . '/../..' . '/src/deprecated/schema-templates/block-patterns/job-posting-two-columns.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit0c422f20871bcbf1c73c1006dcf06201::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0c422f20871bcbf1c73c1006dcf06201::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit0c422f20871bcbf1c73c1006dcf06201::$classMap;
}, null, ClassLoader::class);
}
}

View File

@@ -1,434 +0,0 @@
<?php return array(
'root' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '7638f02c7c98ab75f11390f9d3fa7c31703e398b',
'name' => 'yoast/wordpress-seo-premium',
'dev' => true,
),
'versions' => array(
'antecedent/patchwork' => array(
'pretty_version' => '2.1.26',
'version' => '2.1.26.0',
'type' => 'library',
'install_path' => __DIR__ . '/../antecedent/patchwork',
'aliases' => array(),
'reference' => 'f2dae0851b2eae4c51969af740fdd0356d7f8f55',
'dev_requirement' => true,
),
'brain/monkey' => array(
'pretty_version' => '2.6.1',
'version' => '2.6.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../brain/monkey',
'aliases' => array(),
'reference' => 'a31c84515bb0d49be9310f52ef1733980ea8ffbb',
'dev_requirement' => true,
),
'composer/installers' => array(
'pretty_version' => 'v2.2.0',
'version' => '2.2.0.0',
'type' => 'composer-plugin',
'install_path' => __DIR__ . '/./installers',
'aliases' => array(),
'reference' => 'c29dc4b93137acb82734f672c37e029dfbd95b35',
'dev_requirement' => false,
),
'cordoval/hamcrest-php' => array(
'dev_requirement' => true,
'replaced' => array(
0 => '*',
),
),
'davedevelopment/hamcrest-php' => array(
'dev_requirement' => true,
'replaced' => array(
0 => '*',
),
),
'dealerdirect/phpcodesniffer-composer-installer' => array(
'pretty_version' => 'v1.0.0',
'version' => '1.0.0.0',
'type' => 'composer-plugin',
'install_path' => __DIR__ . '/../dealerdirect/phpcodesniffer-composer-installer',
'aliases' => array(),
'reference' => '4be43904336affa5c2f70744a348312336afd0da',
'dev_requirement' => true,
),
'doctrine/instantiator' => array(
'pretty_version' => '1.5.0',
'version' => '1.5.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../doctrine/instantiator',
'aliases' => array(),
'reference' => '0a0fa9780f5d4e507415a065172d26a98d02047b',
'dev_requirement' => true,
),
'grogy/php-parallel-lint' => array(
'dev_requirement' => true,
'replaced' => array(
0 => '*',
),
),
'hamcrest/hamcrest-php' => array(
'pretty_version' => 'v2.0.1',
'version' => '2.0.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../hamcrest/hamcrest-php',
'aliases' => array(),
'reference' => '8c3d0a3f6af734494ad8f6fbbee0ba92422859f3',
'dev_requirement' => true,
),
'jakub-onderka/php-console-color' => array(
'dev_requirement' => true,
'replaced' => array(
0 => '*',
),
),
'jakub-onderka/php-console-highlighter' => array(
'dev_requirement' => true,
'replaced' => array(
0 => '*',
),
),
'jakub-onderka/php-parallel-lint' => array(
'dev_requirement' => true,
'replaced' => array(
0 => '*',
),
),
'kodova/hamcrest-php' => array(
'dev_requirement' => true,
'replaced' => array(
0 => '*',
),
),
'mockery/mockery' => array(
'pretty_version' => '1.3.6',
'version' => '1.3.6.0',
'type' => 'library',
'install_path' => __DIR__ . '/../mockery/mockery',
'aliases' => array(),
'reference' => 'dc206df4fa314a50bbb81cf72239a305c5bbd5c0',
'dev_requirement' => true,
),
'myclabs/deep-copy' => array(
'pretty_version' => '1.11.1',
'version' => '1.11.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../myclabs/deep-copy',
'aliases' => array(),
'reference' => '7284c22080590fb39f2ffa3e9057f10a4ddd0e0c',
'dev_requirement' => true,
),
'phar-io/manifest' => array(
'pretty_version' => '2.0.3',
'version' => '2.0.3.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phar-io/manifest',
'aliases' => array(),
'reference' => '97803eca37d319dfa7826cc2437fc020857acb53',
'dev_requirement' => true,
),
'phar-io/version' => array(
'pretty_version' => '3.2.1',
'version' => '3.2.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phar-io/version',
'aliases' => array(),
'reference' => '4f7fd7836c6f332bb2933569e566a0d6c4cbed74',
'dev_requirement' => true,
),
'php-parallel-lint/php-console-color' => array(
'pretty_version' => 'v1.0.1',
'version' => '1.0.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../php-parallel-lint/php-console-color',
'aliases' => array(),
'reference' => '7adfefd530aa2d7570ba87100a99e2483a543b88',
'dev_requirement' => true,
),
'php-parallel-lint/php-console-highlighter' => array(
'pretty_version' => 'v1.0.0',
'version' => '1.0.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../php-parallel-lint/php-console-highlighter',
'aliases' => array(),
'reference' => '5b4803384d3303cf8e84141039ef56c8a123138d',
'dev_requirement' => true,
),
'php-parallel-lint/php-parallel-lint' => array(
'pretty_version' => 'v1.3.2',
'version' => '1.3.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../php-parallel-lint/php-parallel-lint',
'aliases' => array(),
'reference' => '6483c9832e71973ed29cf71bd6b3f4fde438a9de',
'dev_requirement' => true,
),
'phpcompatibility/php-compatibility' => array(
'pretty_version' => '9.3.5',
'version' => '9.3.5.0',
'type' => 'phpcodesniffer-standard',
'install_path' => __DIR__ . '/../phpcompatibility/php-compatibility',
'aliases' => array(),
'reference' => '9fb324479acf6f39452e0655d2429cc0d3914243',
'dev_requirement' => true,
),
'phpcompatibility/phpcompatibility-paragonie' => array(
'pretty_version' => '1.3.2',
'version' => '1.3.2.0',
'type' => 'phpcodesniffer-standard',
'install_path' => __DIR__ . '/../phpcompatibility/phpcompatibility-paragonie',
'aliases' => array(),
'reference' => 'bba5a9dfec7fcfbd679cfaf611d86b4d3759da26',
'dev_requirement' => true,
),
'phpcompatibility/phpcompatibility-wp' => array(
'pretty_version' => '2.1.4',
'version' => '2.1.4.0',
'type' => 'phpcodesniffer-standard',
'install_path' => __DIR__ . '/../phpcompatibility/phpcompatibility-wp',
'aliases' => array(),
'reference' => 'b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5',
'dev_requirement' => true,
),
'phpunit/php-code-coverage' => array(
'pretty_version' => '7.0.15',
'version' => '7.0.15.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpunit/php-code-coverage',
'aliases' => array(),
'reference' => '819f92bba8b001d4363065928088de22f25a3a48',
'dev_requirement' => true,
),
'phpunit/php-file-iterator' => array(
'pretty_version' => '2.0.5',
'version' => '2.0.5.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpunit/php-file-iterator',
'aliases' => array(),
'reference' => '42c5ba5220e6904cbfe8b1a1bda7c0cfdc8c12f5',
'dev_requirement' => true,
),
'phpunit/php-text-template' => array(
'pretty_version' => '1.2.1',
'version' => '1.2.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpunit/php-text-template',
'aliases' => array(),
'reference' => '31f8b717e51d9a2afca6c9f046f5d69fc27c8686',
'dev_requirement' => true,
),
'phpunit/php-timer' => array(
'pretty_version' => '2.1.3',
'version' => '2.1.3.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpunit/php-timer',
'aliases' => array(),
'reference' => '2454ae1765516d20c4ffe103d85a58a9a3bd5662',
'dev_requirement' => true,
),
'phpunit/php-token-stream' => array(
'pretty_version' => '3.1.3',
'version' => '3.1.3.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpunit/php-token-stream',
'aliases' => array(),
'reference' => '9c1da83261628cb24b6a6df371b6e312b3954768',
'dev_requirement' => true,
),
'phpunit/phpunit' => array(
'pretty_version' => '8.5.34',
'version' => '8.5.34.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpunit/phpunit',
'aliases' => array(),
'reference' => '622d0186707f39a4ae71df3bcf42d759bb868854',
'dev_requirement' => true,
),
'sebastian/code-unit-reverse-lookup' => array(
'pretty_version' => '1.0.2',
'version' => '1.0.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/code-unit-reverse-lookup',
'aliases' => array(),
'reference' => '1de8cd5c010cb153fcd68b8d0f64606f523f7619',
'dev_requirement' => true,
),
'sebastian/comparator' => array(
'pretty_version' => '3.0.5',
'version' => '3.0.5.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/comparator',
'aliases' => array(),
'reference' => '1dc7ceb4a24aede938c7af2a9ed1de09609ca770',
'dev_requirement' => true,
),
'sebastian/diff' => array(
'pretty_version' => '3.0.4',
'version' => '3.0.4.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/diff',
'aliases' => array(),
'reference' => '6296a0c086dd0117c1b78b059374d7fcbe7545ae',
'dev_requirement' => true,
),
'sebastian/environment' => array(
'pretty_version' => '4.2.4',
'version' => '4.2.4.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/environment',
'aliases' => array(),
'reference' => 'd47bbbad83711771f167c72d4e3f25f7fcc1f8b0',
'dev_requirement' => true,
),
'sebastian/exporter' => array(
'pretty_version' => '3.1.5',
'version' => '3.1.5.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/exporter',
'aliases' => array(),
'reference' => '73a9676f2833b9a7c36968f9d882589cd75511e6',
'dev_requirement' => true,
),
'sebastian/global-state' => array(
'pretty_version' => '3.0.3',
'version' => '3.0.3.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/global-state',
'aliases' => array(),
'reference' => '66783ce213de415b451b904bfef9dda0cf9aeae0',
'dev_requirement' => true,
),
'sebastian/object-enumerator' => array(
'pretty_version' => '3.0.4',
'version' => '3.0.4.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/object-enumerator',
'aliases' => array(),
'reference' => 'e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2',
'dev_requirement' => true,
),
'sebastian/object-reflector' => array(
'pretty_version' => '1.1.2',
'version' => '1.1.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/object-reflector',
'aliases' => array(),
'reference' => '9b8772b9cbd456ab45d4a598d2dd1a1bced6363d',
'dev_requirement' => true,
),
'sebastian/recursion-context' => array(
'pretty_version' => '3.0.1',
'version' => '3.0.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/recursion-context',
'aliases' => array(),
'reference' => '367dcba38d6e1977be014dc4b22f47a484dac7fb',
'dev_requirement' => true,
),
'sebastian/resource-operations' => array(
'pretty_version' => '2.0.2',
'version' => '2.0.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/resource-operations',
'aliases' => array(),
'reference' => '31d35ca87926450c44eae7e2611d45a7a65ea8b3',
'dev_requirement' => true,
),
'sebastian/type' => array(
'pretty_version' => '1.1.4',
'version' => '1.1.4.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/type',
'aliases' => array(),
'reference' => '0150cfbc4495ed2df3872fb31b26781e4e077eb4',
'dev_requirement' => true,
),
'sebastian/version' => array(
'pretty_version' => '2.0.1',
'version' => '2.0.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/version',
'aliases' => array(),
'reference' => '99732be0ddb3361e16ad77b68ba41efc8e979019',
'dev_requirement' => true,
),
'squizlabs/php_codesniffer' => array(
'pretty_version' => '3.7.2',
'version' => '3.7.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../squizlabs/php_codesniffer',
'aliases' => array(),
'reference' => 'ed8e00df0a83aa96acf703f8c2979ff33341f879',
'dev_requirement' => true,
),
'theseer/tokenizer' => array(
'pretty_version' => '1.2.1',
'version' => '1.2.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../theseer/tokenizer',
'aliases' => array(),
'reference' => '34a41e998c2183e22995f158c581e7b5e755ab9e',
'dev_requirement' => true,
),
'wp-coding-standards/wpcs' => array(
'pretty_version' => '2.3.0',
'version' => '2.3.0.0',
'type' => 'phpcodesniffer-standard',
'install_path' => __DIR__ . '/../wp-coding-standards/wpcs',
'aliases' => array(),
'reference' => '7da1894633f168fe244afc6de00d141f27517b62',
'dev_requirement' => true,
),
'yoast/phpunit-polyfills' => array(
'pretty_version' => '1.1.0',
'version' => '1.1.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../yoast/phpunit-polyfills',
'aliases' => array(),
'reference' => '224e4a1329c03d8bad520e3fc4ec980034a4b212',
'dev_requirement' => true,
),
'yoast/wordpress-seo' => array(
'pretty_version' => '21.5',
'version' => '21.5.0.0',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../yoast/wordpress-seo',
'aliases' => array(),
'reference' => 'd363a7ed6130eafb06566071c1e4617779960cb7',
'dev_requirement' => false,
),
'yoast/wordpress-seo-premium' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '7638f02c7c98ab75f11390f9d3fa7c31703e398b',
'dev_requirement' => false,
),
'yoast/wp-test-utils' => array(
'pretty_version' => '1.2.0',
'version' => '1.2.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../yoast/wp-test-utils',
'aliases' => array(),
'reference' => '2e0f62e0281e4859707c5f13b7da1422aa1c8f7b',
'dev_requirement' => true,
),
'yoast/yoastcs' => array(
'pretty_version' => '2.3.1',
'version' => '2.3.1.0',
'type' => 'phpcodesniffer-standard',
'install_path' => __DIR__ . '/../yoast/yoastcs',
'aliases' => array(),
'reference' => '8ed5af5ce8ef362a88cfe67faf0d9e4503ca7470',
'dev_requirement' => true,
),
),
);

View File

@@ -1,26 +0,0 @@
<?php
// platform_check.php @generated by Composer
$issues = array();
if (!(PHP_VERSION_ID >= 70205)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.5". You are running ' . PHP_VERSION . '.';
}
if ($issues) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
} elseif (!headers_sent()) {
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
}
}
trigger_error(
'Composer detected issues in your platform: ' . implode(' ', $issues),
E_USER_ERROR
);
}

View File

@@ -1,85 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* A WordPress integration that listens for whether the SEO changes have been saved successfully.
*/
class WPSEO_Admin_Settings_Changed_Listener implements WPSEO_WordPress_Integration {
/**
* Have the Yoast SEO settings been saved.
*
* @var bool
*/
private static $settings_saved = false;
/**
* Registers all hooks to WordPress.
*
* @return void
*/
public function register_hooks() {
add_action( 'admin_init', [ $this, 'intercept_save_update_notification' ] );
}
/**
* Checks and overwrites the wp_settings_errors global to determine whether the Yoast SEO settings have been saved.
*/
public function intercept_save_update_notification() {
global $pagenow;
if ( $pagenow !== 'admin.php' || ! YoastSEO()->helpers->current_page->is_yoast_seo_page() ) {
return;
}
// Variable name is the same as the global that is set by get_settings_errors.
$wp_settings_errors = get_settings_errors();
foreach ( $wp_settings_errors as $key => $wp_settings_error ) {
if ( ! $this->is_settings_updated_notification( $wp_settings_error ) ) {
continue;
}
self::$settings_saved = true;
unset( $wp_settings_errors[ $key ] );
// phpcs:ignore WordPress.WP.GlobalVariablesOverride -- Overwrite the global with the list excluding the Changed saved message.
$GLOBALS['wp_settings_errors'] = $wp_settings_errors;
break;
}
}
/**
* Checks whether the settings notification is a settings_updated notification.
*
* @param array $wp_settings_error The settings object.
*
* @return bool Whether this is a settings updated settings notification.
*/
public function is_settings_updated_notification( $wp_settings_error ) {
return ! empty( $wp_settings_error['code'] ) && $wp_settings_error['code'] === 'settings_updated';
}
/**
* Get whether the settings have successfully been saved
*
* @return bool Whether the settings have successfully been saved.
*/
public function have_settings_been_saved() {
return self::$settings_saved;
}
/**
* Renders a success message if the Yoast SEO settings have been saved.
*/
public function show_success_message() {
if ( $this->have_settings_been_saved() ) {
echo '<p class="wpseo-message"><span class="dashicons dashicons-yes"></span>',
esc_html__( 'Settings saved.', 'wordpress-seo' ),
'</p>';
}
}
}

View File

@@ -1,395 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
if ( ! defined( 'WPSEO_VERSION' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
/**
* Convenience function to JSON encode and echo results and then die.
*
* @param array $results Results array for encoding.
*/
function wpseo_ajax_json_echo_die( $results ) {
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
echo WPSEO_Utils::format_json_encode( $results );
die();
}
/**
* Function used from AJAX calls, takes it variables from $_POST, dies on exit.
*/
function wpseo_set_option() {
if ( ! current_user_can( 'manage_options' ) ) {
die( '-1' );
}
check_ajax_referer( 'wpseo-setoption' );
if ( ! isset( $_POST['option'] ) || ! is_string( $_POST['option'] ) ) {
die( '-1' );
}
$option = sanitize_text_field( wp_unslash( $_POST['option'] ) );
if ( $option !== 'page_comments' ) {
die( '-1' );
}
update_option( $option, 0 );
die( '1' );
}
add_action( 'wp_ajax_wpseo_set_option', 'wpseo_set_option' );
/**
* Since 3.2 Notifications are dismissed in the Notification Center.
*/
add_action( 'wp_ajax_yoast_dismiss_notification', [ 'Yoast_Notification_Center', 'ajax_dismiss_notification' ] );
/**
* Function used to remove the admin notices for several purposes, dies on exit.
*/
function wpseo_set_ignore() {
if ( ! current_user_can( 'manage_options' ) ) {
die( '-1' );
}
check_ajax_referer( 'wpseo-ignore' );
if ( ! isset( $_POST['option'] ) || ! is_string( $_POST['option'] ) ) {
die( '-1' );
}
$ignore_key = sanitize_text_field( wp_unslash( $_POST['option'] ) );
WPSEO_Options::set( 'ignore_' . $ignore_key, true );
die( '1' );
}
add_action( 'wp_ajax_wpseo_set_ignore', 'wpseo_set_ignore' );
/**
* Save an individual SEO title from the Bulk Editor.
*/
function wpseo_save_title() {
wpseo_save_what( 'title' );
}
add_action( 'wp_ajax_wpseo_save_title', 'wpseo_save_title' );
/**
* Save an individual meta description from the Bulk Editor.
*/
function wpseo_save_description() {
wpseo_save_what( 'metadesc' );
}
add_action( 'wp_ajax_wpseo_save_metadesc', 'wpseo_save_description' );
/**
* Save titles & descriptions.
*
* @param string $what Type of item to save (title, description).
*/
function wpseo_save_what( $what ) {
check_ajax_referer( 'wpseo-bulk-editor' );
if ( ! isset( $_POST['new_value'], $_POST['wpseo_post_id'], $_POST['existing_value'] ) || ! is_string( $_POST['new_value'] ) || ! is_string( $_POST['existing_value'] ) ) {
die( '-1' );
}
$new = sanitize_text_field( wp_unslash( $_POST['new_value'] ) );
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are casting the unsafe value to an integer.
$post_id = (int) wp_unslash( $_POST['wpseo_post_id'] );
$original = sanitize_text_field( wp_unslash( $_POST['existing_value'] ) );
if ( $post_id === 0 ) {
die( '-1' );
}
$results = wpseo_upsert_new( $what, $post_id, $new, $original );
wpseo_ajax_json_echo_die( $results );
}
/**
* Helper function to update a post's meta data, returning relevant information
* about the information updated and the results or the meta update.
*
* @param int $post_id Post ID.
* @param string $new_meta_value New meta value to record.
* @param string $orig_meta_value Original meta value.
* @param string $meta_key Meta key string.
* @param string $return_key Return key string to use in results.
*
* @return array
*/
function wpseo_upsert_meta( $post_id, $new_meta_value, $orig_meta_value, $meta_key, $return_key ) {
$post_id = intval( $post_id );
$sanitized_new_meta_value = wp_strip_all_tags( $new_meta_value );
$orig_meta_value = wp_strip_all_tags( $orig_meta_value );
$upsert_results = [
'status' => 'success',
'post_id' => $post_id,
"new_{$return_key}" => $sanitized_new_meta_value,
"original_{$return_key}" => $orig_meta_value,
];
$the_post = get_post( $post_id );
if ( empty( $the_post ) ) {
$upsert_results['status'] = 'failure';
$upsert_results['results'] = __( 'Post doesn\'t exist.', 'wordpress-seo' );
return $upsert_results;
}
$post_type_object = get_post_type_object( $the_post->post_type );
if ( ! $post_type_object ) {
$upsert_results['status'] = 'failure';
$upsert_results['results'] = sprintf(
/* translators: %s expands to post type. */
__( 'Post has an invalid Content Type: %s.', 'wordpress-seo' ),
$the_post->post_type
);
return $upsert_results;
}
if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) {
$upsert_results['status'] = 'failure';
$upsert_results['results'] = sprintf(
/* translators: %s expands to post type name. */
__( 'You can\'t edit %s.', 'wordpress-seo' ),
$post_type_object->label
);
return $upsert_results;
}
if ( ! current_user_can( $post_type_object->cap->edit_others_posts ) && (int) $the_post->post_author !== get_current_user_id() ) {
$upsert_results['status'] = 'failure';
$upsert_results['results'] = sprintf(
/* translators: %s expands to the name of a post type (plural). */
__( 'You can\'t edit %s that aren\'t yours.', 'wordpress-seo' ),
$post_type_object->label
);
return $upsert_results;
}
if ( $sanitized_new_meta_value === $orig_meta_value && $sanitized_new_meta_value !== $new_meta_value ) {
$upsert_results['status'] = 'failure';
$upsert_results['results'] = __( 'You have used HTML in your value which is not allowed.', 'wordpress-seo' );
return $upsert_results;
}
$res = update_post_meta( $post_id, $meta_key, $sanitized_new_meta_value );
$upsert_results['status'] = ( $res !== false ) ? 'success' : 'failure';
$upsert_results['results'] = $res;
return $upsert_results;
}
/**
* Save all titles sent from the Bulk Editor.
*/
function wpseo_save_all_titles() {
wpseo_save_all( 'title' );
}
add_action( 'wp_ajax_wpseo_save_all_titles', 'wpseo_save_all_titles' );
/**
* Save all description sent from the Bulk Editor.
*/
function wpseo_save_all_descriptions() {
wpseo_save_all( 'metadesc' );
}
add_action( 'wp_ajax_wpseo_save_all_descriptions', 'wpseo_save_all_descriptions' );
/**
* Utility function to save values.
*
* @param string $what Type of item so save.
*/
function wpseo_save_all( $what ) {
check_ajax_referer( 'wpseo-bulk-editor' );
$results = [];
if ( ! isset( $_POST['items'], $_POST['existingItems'] ) ) {
wpseo_ajax_json_echo_die( $results );
}
$new_values = array_map( [ 'WPSEO_Utils', 'sanitize_text_field' ], wp_unslash( (array) $_POST['items'] ) );
$original_values = array_map( [ 'WPSEO_Utils', 'sanitize_text_field' ], wp_unslash( (array) $_POST['existingItems'] ) );
foreach ( $new_values as $post_id => $new_value ) {
$original_value = $original_values[ $post_id ];
$results[] = wpseo_upsert_new( $what, $post_id, $new_value, $original_value );
}
wpseo_ajax_json_echo_die( $results );
}
/**
* Insert a new value.
*
* @param string $what Item type (such as title).
* @param int $post_id Post ID.
* @param string $new_value New value to record.
* @param string $original Original value.
*
* @return string
*/
function wpseo_upsert_new( $what, $post_id, $new_value, $original ) {
$meta_key = WPSEO_Meta::$meta_prefix . $what;
return wpseo_upsert_meta( $post_id, $new_value, $original, $meta_key, $what );
}
/**
* Retrieves the post ids where the keyword is used before as well as the types of those posts.
*/
function ajax_get_keyword_usage_and_post_types() {
check_ajax_referer( 'wpseo-keyword-usage-and-post-types', 'nonce' );
if ( ! isset( $_POST['post_id'], $_POST['keyword'] ) || ! is_string( $_POST['keyword'] ) ) {
die( '-1' );
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- We are casting to an integer.
$post_id = (int) wp_unslash( $_POST['post_id'] );
if ( $post_id === 0 || ! current_user_can( 'edit_post', $post_id ) ) {
die( '-1' );
}
$keyword = sanitize_text_field( wp_unslash( $_POST['keyword'] ) );
$post_ids = WPSEO_Meta::keyword_usage( $keyword, $post_id );
if ( ! empty( $post_ids ) ) {
$post_types = WPSEO_Meta::post_types_for_ids( $post_ids );
}
else {
$post_types = [];
}
$return_object = [
'keyword_usage' => $post_ids,
'post_types' => $post_types,
];
wp_die(
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
WPSEO_Utils::format_json_encode( $return_object )
);
}
add_action( 'wp_ajax_get_focus_keyword_usage_and_post_types', 'ajax_get_keyword_usage_and_post_types' );
/**
* Retrieves the keyword for the keyword doubles of the termpages.
*/
function ajax_get_term_keyword_usage() {
check_ajax_referer( 'wpseo-keyword-usage', 'nonce' );
if ( ! isset( $_POST['post_id'], $_POST['keyword'], $_POST['taxonomy'] ) || ! is_string( $_POST['keyword'] ) || ! is_string( $_POST['taxonomy'] ) ) {
wp_die( -1 );
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are casting the unsafe input to an integer.
$post_id = (int) wp_unslash( $_POST['post_id'] );
if ( $post_id === 0 ) {
wp_die( -1 );
}
$keyword = sanitize_text_field( wp_unslash( $_POST['keyword'] ) );
$taxonomy_name = sanitize_text_field( wp_unslash( $_POST['taxonomy'] ) );
$taxonomy = get_taxonomy( $taxonomy_name );
if ( ! $taxonomy ) {
wp_die( 0 );
}
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
wp_die( -1 );
}
$usage = WPSEO_Taxonomy_Meta::get_keyword_usage( $keyword, $post_id, $taxonomy_name );
// Normalize the result so it is the same as the post keyword usage AJAX request.
$usage = $usage[ $keyword ];
wp_die(
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
WPSEO_Utils::format_json_encode( $usage )
);
}
add_action( 'wp_ajax_get_term_keyword_usage', 'ajax_get_term_keyword_usage' );
/**
* Registers hooks for all AJAX integrations.
*
* @return void
*/
function wpseo_register_ajax_integrations() {
$integrations = [ new Yoast_Network_Admin() ];
foreach ( $integrations as $integration ) {
$integration->register_ajax_hooks();
}
}
wpseo_register_ajax_integrations();
new WPSEO_Shortcode_Filter();
new WPSEO_Taxonomy_Columns();
/* ********************* DEPRECATED FUNCTIONS ********************* */
/**
* Retrieves the keyword for the keyword doubles.
*/
function ajax_get_keyword_usage() {
_deprecated_function( __METHOD__, 'WPSEO 20.4' );
check_ajax_referer( 'wpseo-keyword-usage', 'nonce' );
if ( ! isset( $_POST['post_id'], $_POST['keyword'] ) || ! is_string( $_POST['keyword'] ) ) {
die( '-1' );
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- We are casting to an integer.
$post_id = (int) wp_unslash( $_POST['post_id'] );
if ( $post_id === 0 || ! current_user_can( 'edit_post', $post_id ) ) {
die( '-1' );
}
$keyword = sanitize_text_field( wp_unslash( $_POST['keyword'] ) );
wp_die(
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
WPSEO_Utils::format_json_encode( WPSEO_Meta::keyword_usage( $keyword, $post_id ) )
);
}

View File

@@ -1,52 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Ajax
*/
/**
* Class WPSEO_Shortcode_Filter.
*
* Used for parsing WP shortcodes with AJAX.
*/
class WPSEO_Shortcode_Filter {
/**
* Initialize the AJAX hooks.
*/
public function __construct() {
add_action( 'wp_ajax_wpseo_filter_shortcodes', [ $this, 'do_filter' ] );
}
/**
* Parse the shortcodes.
*/
public function do_filter() {
check_ajax_referer( 'wpseo-filter-shortcodes', 'nonce' );
if ( ! isset( $_POST['data'] ) || ! is_array( $_POST['data'] ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: WPSEO_Utils::format_json_encode is considered safe.
wp_die( WPSEO_Utils::format_json_encode( [] ) );
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: $shortcodes is getting sanitized later, before it's used.
$shortcodes = wp_unslash( $_POST['data'] );
$parsed_shortcodes = [];
foreach ( $shortcodes as $shortcode ) {
if ( $shortcode !== sanitize_text_field( $shortcode ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: WPSEO_Utils::format_json_encode is considered safe.
wp_die( WPSEO_Utils::format_json_encode( [] ) );
}
$parsed_shortcodes[] = [
'shortcode' => $shortcode,
'output' => do_shortcode( $shortcode ),
];
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: WPSEO_Utils::format_json_encode is considered safe.
wp_die( WPSEO_Utils::format_json_encode( $parsed_shortcodes ) );
}
}

View File

@@ -1,91 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Ajax
*/
/**
* This class will catch the request to dismiss the target notice (set by notice_name)
* and will store the dismiss status as an user meta in the database.
*/
class Yoast_Dismissable_Notice_Ajax {
/**
* Notice type toggle value for user notices.
*
* @var string
*/
const FOR_USER = 'user_meta';
/**
* Notice type toggle value for network notices.
*
* @var string
*/
const FOR_NETWORK = 'site_option';
/**
* Notice type toggle value for site notices.
*
* @var string
*/
const FOR_SITE = 'option';
/**
* Name of the notice that will be dismissed.
*
* @var string
*/
private $notice_name;
/**
* The type of the current notice.
*
* @var string
*/
private $notice_type;
/**
* Initialize the hooks for the AJAX request.
*
* @param string $notice_name The name for the hook to catch the notice.
* @param string $notice_type The notice type.
*/
public function __construct( $notice_name, $notice_type = self::FOR_USER ) {
$this->notice_name = $notice_name;
$this->notice_type = $notice_type;
add_action( 'wp_ajax_wpseo_dismiss_' . $notice_name, [ $this, 'dismiss_notice' ] );
}
/**
* Handles the dismiss notice request.
*/
public function dismiss_notice() {
check_ajax_referer( 'wpseo-dismiss-' . $this->notice_name );
$this->save_dismissed();
wp_die( 'true' );
}
/**
* Storing the dismissed value in the database. The target location is based on the set notification type.
*/
private function save_dismissed() {
if ( $this->notice_type === self::FOR_SITE ) {
update_option( 'wpseo_dismiss_' . $this->notice_name, 1 );
return;
}
if ( $this->notice_type === self::FOR_NETWORK ) {
update_site_option( 'wpseo_dismiss_' . $this->notice_name, 1 );
return;
}
update_user_meta( get_current_user_id(), 'wpseo_dismiss_' . $this->notice_name, 1 );
}
}

View File

@@ -1,122 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Ajax
*/
/**
* Class Yoast_Plugin_Conflict_Ajax.
*/
class Yoast_Plugin_Conflict_Ajax {
/**
* Option identifier where dismissed conflicts are stored.
*
* @var string
*/
private $option_name = 'wpseo_dismissed_conflicts';
/**
* List of notification identifiers that have been dismissed.
*
* @var array
*/
private $dismissed_conflicts = [];
/**
* Initialize the hooks for the AJAX request.
*/
public function __construct() {
add_action( 'wp_ajax_wpseo_dismiss_plugin_conflict', [ $this, 'dismiss_notice' ] );
}
/**
* Handles the dismiss notice request.
*/
public function dismiss_notice() {
check_ajax_referer( 'dismiss-plugin-conflict' );
if ( ! isset( $_POST['data'] ) || ! is_array( $_POST['data'] ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: WPSEO_Utils::format_json_encode is considered safe.
wp_die( WPSEO_Utils::format_json_encode( [] ) );
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: $conflict_data is getting sanitized later.
$conflict_data = wp_unslash( $_POST['data'] );
$conflict_data = [
'section' => sanitize_text_field( $conflict_data['section'] ),
'plugins' => sanitize_text_field( $conflict_data['plugins'] ),
];
$this->dismissed_conflicts = $this->get_dismissed_conflicts( $conflict_data['section'] );
$this->compare_plugins( $conflict_data['plugins'] );
$this->save_dismissed_conflicts( $conflict_data['section'] );
wp_die( 'true' );
}
/**
* Getting the user option from the database.
*
* @return bool|array
*/
private function get_dismissed_option() {
return get_user_meta( get_current_user_id(), $this->option_name, true );
}
/**
* Getting the dismissed conflicts from the database
*
* @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
*
* @return array
*/
private function get_dismissed_conflicts( $plugin_section ) {
$dismissed_conflicts = $this->get_dismissed_option();
if ( is_array( $dismissed_conflicts ) && array_key_exists( $plugin_section, $dismissed_conflicts ) ) {
return $dismissed_conflicts[ $plugin_section ];
}
return [];
}
/**
* Storing the conflicting plugins as an user option in the database.
*
* @param string $plugin_section Plugin conflict type (such as Open Graph or sitemap).
*/
private function save_dismissed_conflicts( $plugin_section ) {
$dismissed_conflicts = $this->get_dismissed_option();
$dismissed_conflicts[ $plugin_section ] = $this->dismissed_conflicts;
update_user_meta( get_current_user_id(), $this->option_name, $dismissed_conflicts );
}
/**
* Loop through the plugins to compare them with the already stored dismissed plugin conflicts.
*
* @param array $posted_plugins Plugin set to check.
*/
public function compare_plugins( array $posted_plugins ) {
foreach ( $posted_plugins as $posted_plugin ) {
$this->compare_plugin( $posted_plugin );
}
}
/**
* Check if plugin is already dismissed, if not store it in the array that will be saved later.
*
* @param string $posted_plugin Plugin to check against dismissed conflicts.
*/
private function compare_plugin( $posted_plugin ) {
if ( ! in_array( $posted_plugin, $this->dismissed_conflicts, true ) ) {
$this->dismissed_conflicts[] = $posted_plugin;
}
}
}

View File

@@ -1,89 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Capabilities
*/
/**
* Abstract Capability Manager shared code.
*/
abstract class WPSEO_Abstract_Capability_Manager implements WPSEO_Capability_Manager {
/**
* Registered capabilities.
*
* @var array
*/
protected $capabilities = [];
/**
* Registers a capability.
*
* @param string $capability Capability to register.
* @param array $roles Roles to add the capability to.
* @param bool $overwrite Optional. Use add or overwrite as registration method.
*/
public function register( $capability, array $roles, $overwrite = false ) {
if ( $overwrite || ! isset( $this->capabilities[ $capability ] ) ) {
$this->capabilities[ $capability ] = $roles;
return;
}
// Combine configurations.
$this->capabilities[ $capability ] = array_merge( $roles, $this->capabilities[ $capability ] );
// Remove doubles.
$this->capabilities[ $capability ] = array_unique( $this->capabilities[ $capability ] );
}
/**
* Returns the list of registered capabilitities.
*
* @return string[] Registered capabilities.
*/
public function get_capabilities() {
return array_keys( $this->capabilities );
}
/**
* Returns a list of WP_Role roles.
*
* The string array of role names are converted to actual WP_Role objects.
* These are needed to be able to use the API on them.
*
* @param array $roles Roles to retrieve the objects for.
*
* @return WP_Role[] List of WP_Role objects.
*/
protected function get_wp_roles( array $roles ) {
$wp_roles = array_map( 'get_role', $roles );
return array_filter( $wp_roles );
}
/**
* Filter capability roles.
*
* @param string $capability Capability to filter roles for.
* @param array $roles List of roles which can be filtered.
*
* @return array Filtered list of roles for the capability.
*/
protected function filter_roles( $capability, array $roles ) {
/**
* Filter: Allow changing roles that a capability is added to.
*
* @api array $roles The default roles to be filtered.
*/
$filtered = apply_filters( $capability . '_roles', $roles );
// Make sure we have the expected type.
if ( ! is_array( $filtered ) ) {
return [];
}
return $filtered;
}
}

View File

@@ -1,35 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Capabilities
*/
/**
* Capability Manager Factory.
*/
class WPSEO_Capability_Manager_Factory {
/**
* Returns the Manager to use.
*
* @param string $plugin_type Whether it's Free or Premium.
*
* @return WPSEO_Capability_Manager Manager to use.
*/
public static function get( $plugin_type = 'free' ) {
static $manager = [];
if ( ! array_key_exists( $plugin_type, $manager ) ) {
if ( function_exists( 'wpcom_vip_add_role_caps' ) ) {
$manager[ $plugin_type ] = new WPSEO_Capability_Manager_VIP();
}
if ( ! function_exists( 'wpcom_vip_add_role_caps' ) ) {
$manager[ $plugin_type ] = new WPSEO_Capability_Manager_WP();
}
}
return $manager[ $plugin_type ];
}
}

View File

@@ -1,119 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Capabilities
*/
/**
* Integrates Yoast SEO capabilities with third party role manager plugins.
*
* Integrates with: Members
* Integrates with: User Role Editor
*/
class WPSEO_Capability_Manager_Integration implements WPSEO_WordPress_Integration {
/**
* Capability manager to use.
*
* @var WPSEO_Capability_Manager
*/
public $manager;
/**
* WPSEO_Capability_Manager_Integration constructor.
*
* @param WPSEO_Capability_Manager $manager The capability manager to use.
*/
public function __construct( WPSEO_Capability_Manager $manager ) {
$this->manager = $manager;
}
/**
* Registers the hooks.
*
* @return void
*/
public function register_hooks() {
add_filter( 'members_get_capabilities', [ $this, 'get_capabilities' ] );
add_action( 'members_register_cap_groups', [ $this, 'action_members_register_cap_group' ] );
add_filter( 'ure_capabilities_groups_tree', [ $this, 'filter_ure_capabilities_groups_tree' ] );
add_filter( 'ure_custom_capability_groups', [ $this, 'filter_ure_custom_capability_groups' ], 10, 2 );
}
/**
* Get the Yoast SEO capabilities.
* Optionally append them to an existing array.
*
* @param array $caps Optional existing capability list.
* @return array
*/
public function get_capabilities( array $caps = [] ) {
if ( ! did_action( 'wpseo_register_capabilities' ) ) {
do_action( 'wpseo_register_capabilities' );
}
return array_merge( $caps, $this->manager->get_capabilities() );
}
/**
* Add capabilities to its own group in the Members plugin.
*
* @see members_register_cap_group()
*/
public function action_members_register_cap_group() {
if ( ! function_exists( 'members_register_cap_group' ) ) {
return;
}
// Register the yoast group.
$args = [
'label' => esc_html__( 'Yoast SEO', 'wordpress-seo' ),
'caps' => $this->get_capabilities(),
'icon' => 'dashicons-admin-plugins',
'diff_added' => true,
];
members_register_cap_group( 'wordpress-seo', $args );
}
/**
* Adds Yoast SEO capability group in the User Role Editor plugin.
*
* @see URE_Capabilities_Groups_Manager::get_groups_tree()
*
* @param array $groups Current groups.
*
* @return array Filtered list of capabilty groups.
*/
public function filter_ure_capabilities_groups_tree( $groups = [] ) {
$groups = (array) $groups;
$groups['wordpress-seo'] = [
'caption' => 'Yoast SEO',
'parent' => 'custom',
'level' => 3,
];
return $groups;
}
/**
* Adds capabilities to the Yoast SEO group in the User Role Editor plugin.
*
* @see URE_Capabilities_Groups_Manager::get_cap_groups()
*
* @param array $groups Current capability groups.
* @param string $cap_id Capability identifier.
*
* @return array List of filtered groups.
*/
public function filter_ure_custom_capability_groups( $groups = [], $cap_id = '' ) {
if ( in_array( $cap_id, $this->get_capabilities(), true ) ) {
$groups = (array) $groups;
$groups[] = 'wordpress-seo';
}
return $groups;
}
}

View File

@@ -1,73 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Capabilities
*/
/**
* VIP implementation of the Capability Manager.
*/
final class WPSEO_Capability_Manager_VIP extends WPSEO_Abstract_Capability_Manager {
/**
* Adds the registered capabilities to the system.
*
* @return void
*/
public function add() {
$role_capabilities = [];
foreach ( $this->capabilities as $capability => $roles ) {
$role_capabilities = $this->get_role_capabilities( $role_capabilities, $capability, $roles );
}
foreach ( $role_capabilities as $role => $capabilities ) {
wpcom_vip_add_role_caps( $role, $capabilities );
}
}
/**
* Removes the registered capabilities from the system
*
* @return void
*/
public function remove() {
// Remove from any role it has been added to.
$roles = wp_roles()->get_names();
$roles = array_keys( $roles );
$role_capabilities = [];
foreach ( array_keys( $this->capabilities ) as $capability ) {
// Allow filtering of roles.
$role_capabilities = $this->get_role_capabilities( $role_capabilities, $capability, $roles );
}
foreach ( $role_capabilities as $role => $capabilities ) {
wpcom_vip_remove_role_caps( $role, $capabilities );
}
}
/**
* Returns the roles which the capability is registered on.
*
* @param array $role_capabilities List of all roles with their capabilities.
* @param string $capability Capability to filter roles for.
* @param array $roles List of default roles.
*
* @return array List of capabilities.
*/
protected function get_role_capabilities( $role_capabilities, $capability, $roles ) {
// Allow filtering of roles.
$filtered_roles = $this->filter_roles( $capability, $roles );
foreach ( $filtered_roles as $role ) {
if ( ! isset( $add_role_caps[ $role ] ) ) {
$role_capabilities[ $role ] = [];
}
$role_capabilities[ $role ][] = $capability;
}
return $role_capabilities;
}
}

View File

@@ -1,51 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Capabilities
*/
/**
* Default WordPress capability manager implementation.
*/
final class WPSEO_Capability_Manager_WP extends WPSEO_Abstract_Capability_Manager {
/**
* Adds the capabilities to the roles.
*
* @return void
*/
public function add() {
foreach ( $this->capabilities as $capability => $roles ) {
$filtered_roles = $this->filter_roles( $capability, $roles );
$wp_roles = $this->get_wp_roles( $filtered_roles );
foreach ( $wp_roles as $wp_role ) {
$wp_role->add_cap( $capability );
}
}
}
/**
* Unregisters the capabilities from the system.
*
* @return void
*/
public function remove() {
// Remove from any roles it has been added to.
$roles = wp_roles()->get_names();
$roles = array_keys( $roles );
foreach ( $this->capabilities as $capability => $_roles ) {
$registered_roles = array_unique( array_merge( $roles, $this->capabilities[ $capability ] ) );
// Allow filtering of roles.
$filtered_roles = $this->filter_roles( $capability, $registered_roles );
$wp_roles = $this->get_wp_roles( $filtered_roles );
foreach ( $wp_roles as $wp_role ) {
$wp_role->remove_cap( $capability );
}
}
}
}

View File

@@ -1,38 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Capabilities
*/
/**
* Capability Manager interface.
*/
interface WPSEO_Capability_Manager {
/**
* Registers a capability.
*
* @param string $capability Capability to register.
* @param array $roles Roles to add the capability to.
* @param bool $overwrite Optional. Use add or overwrite as registration method.
*/
public function register( $capability, array $roles, $overwrite = false );
/**
* Adds the registerd capabilities to the system.
*/
public function add();
/**
* Removes the registered capabilities from the system.
*/
public function remove();
/**
* Returns the list of registered capabilities.
*
* @return string[] List of registered capabilities.
*/
public function get_capabilities();
}

View File

@@ -1,100 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Capabilities
*/
/**
* Capability Utils collection.
*/
class WPSEO_Capability_Utils {
/**
* Checks if the user has the proper capabilities.
*
* @param string $capability Capability to check.
*
* @return bool True if the user has the proper rights.
*/
public static function current_user_can( $capability ) {
if ( $capability === 'wpseo_manage_options' ) {
return self::has( $capability );
}
return self::has_any( [ 'wpseo_manage_options', $capability ] );
}
/**
* Retrieves the users that have the specified capability.
*
* @param string $capability The name of the capability.
*
* @return array The users that have the capability.
*/
public static function get_applicable_users( $capability ) {
$applicable_roles = self::get_applicable_roles( $capability );
if ( $applicable_roles === [] ) {
return [];
}
return get_users( [ 'role__in' => $applicable_roles ] );
}
/**
* Retrieves the roles that have the specified capability.
*
* @param string $capability The name of the capability.
*
* @return array The names of the roles that have the capability.
*/
public static function get_applicable_roles( $capability ) {
$roles = wp_roles();
$role_names = $roles->get_names();
$applicable_roles = [];
foreach ( array_keys( $role_names ) as $role_name ) {
$role = $roles->get_role( $role_name );
if ( ! $role ) {
continue;
}
// Add role if it has the capability.
if ( array_key_exists( $capability, $role->capabilities ) && $role->capabilities[ $capability ] === true ) {
$applicable_roles[] = $role_name;
}
}
return $applicable_roles;
}
/**
* Checks if the current user has at least one of the supplied capabilities.
*
* @param array $capabilities Capabilities to check against.
*
* @return bool True if the user has at least one capability.
*/
protected static function has_any( array $capabilities ) {
foreach ( $capabilities as $capability ) {
if ( self::has( $capability ) ) {
return true;
}
}
return false;
}
/**
* Checks if the user has a certain capability.
*
* @param string $capability Capability to check against.
*
* @return bool True if the user has the capability.
*/
protected static function has( $capability ) {
return current_user_can( $capability );
}
}

View File

@@ -1,111 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Capabilities
*/
/**
* Capabilities registration class.
*/
class WPSEO_Register_Capabilities implements WPSEO_WordPress_Integration {
/**
* Registers the hooks.
*
* @return void
*/
public function register_hooks() {
add_action( 'wpseo_register_capabilities', [ $this, 'register' ] );
if ( is_multisite() ) {
add_action( 'user_has_cap', [ $this, 'filter_user_has_wpseo_manage_options_cap' ], 10, 4 );
}
/**
* Maybe add manage_privacy_options capability for wpseo_manager user role.
*/
add_filter( 'map_meta_cap', [ $this, 'map_meta_cap_for_seo_manager' ], 10, 2 );
}
/**
* Registers the capabilities.
*
* @return void
*/
public function register() {
$manager = WPSEO_Capability_Manager_Factory::get();
$manager->register( 'wpseo_bulk_edit', [ 'editor', 'wpseo_editor', 'wpseo_manager' ] );
$manager->register( 'wpseo_edit_advanced_metadata', [ 'editor', 'wpseo_editor', 'wpseo_manager' ] );
$manager->register( 'wpseo_manage_options', [ 'administrator', 'wpseo_manager' ] );
$manager->register( 'view_site_health_checks', [ 'wpseo_manager' ] );
}
/**
* Revokes the 'wpseo_manage_options' capability from administrator users if it should
* only be granted to network administrators.
*
* @param array $allcaps An array of all the user's capabilities.
* @param array $caps Actual capabilities being checked.
* @param array $args Optional parameters passed to has_cap(), typically object ID.
* @param WP_User $user The user object.
*
* @return array Possibly modified array of the user's capabilities.
*/
public function filter_user_has_wpseo_manage_options_cap( $allcaps, $caps, $args, $user ) {
// We only need to do something if 'wpseo_manage_options' is being checked.
if ( ! in_array( 'wpseo_manage_options', $caps, true ) ) {
return $allcaps;
}
// If the user does not have 'wpseo_manage_options' anyway, we don't need to revoke access.
if ( empty( $allcaps['wpseo_manage_options'] ) ) {
return $allcaps;
}
// If the user does not have 'delete_users', they are not an administrator.
if ( empty( $allcaps['delete_users'] ) ) {
return $allcaps;
}
$options = WPSEO_Options::get_instance();
if ( $options->get( 'access' ) === 'superadmin' && ! is_super_admin( $user->ID ) ) {
unset( $allcaps['wpseo_manage_options'] );
}
return $allcaps;
}
/**
* Maybe add manage_privacy_options capability for wpseo_manager user role.
*
* @param string[] $caps Primitive capabilities required of the user.
* @param string[] $cap Capability being checked.
*
* @return string[] Filtered primitive capabilities required of the user.
*/
public function map_meta_cap_for_seo_manager( $caps, $cap ) {
$user = wp_get_current_user();
// No multisite support.
if ( is_multisite() ) {
return $caps;
}
// User must be of role wpseo_manager.
if ( ! in_array( 'wpseo_manager', $user->roles, true ) ) {
return $caps;
}
// Remove manage_options cap requirement if requested cap is manage_privacy_options.
if ( $cap === 'manage_privacy_options' ) {
return array_diff( $caps, [ 'manage_options' ] );
}
return $caps;
}
}

View File

@@ -1,75 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Represents a way to determine the analysis worker asset location.
*/
final class WPSEO_Admin_Asset_Analysis_Worker_Location implements WPSEO_Admin_Asset_Location {
/**
* Holds the asset's location.
*
* @var WPSEO_Admin_Asset_Location
*/
private $asset_location;
/**
* Holds the asset itself.
*
* @var WPSEO_Admin_Asset
*/
private $asset;
/**
* Constructs the location of the analysis worker asset.
*
* @param string $flat_version The flat version of the asset.
* @param string $name The name of the analysis worker asset.
*/
public function __construct( $flat_version = '', $name = 'analysis-worker' ) {
if ( $flat_version === '' ) {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$flat_version = $asset_manager->flatten_version( WPSEO_VERSION );
}
$analysis_worker = $name . '-' . $flat_version . '.js';
$this->asset_location = WPSEO_Admin_Asset_Manager::create_default_location();
$this->asset = new WPSEO_Admin_Asset(
[
'name' => $name,
'src' => $analysis_worker,
]
);
}
/**
* Retrieves the analysis worker asset.
*
* @return WPSEO_Admin_Asset The analysis worker asset.
*/
public function get_asset() {
return $this->asset;
}
/**
* Determines the URL of the asset on the dev server.
*
* @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
* @param string $type The type of asset. Usually JS or CSS.
*
* @return string The URL of the asset.
*/
public function get_url( WPSEO_Admin_Asset $asset, $type ) {
$scheme = wp_parse_url( $asset->get_src(), PHP_URL_SCHEME );
if ( in_array( $scheme, [ 'http', 'https' ], true ) ) {
return $asset->get_src();
}
return $this->asset_location->get_url( $asset, $type );
}
}

View File

@@ -1,71 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Changes the asset paths to dev server paths.
*/
final class WPSEO_Admin_Asset_Dev_Server_Location implements WPSEO_Admin_Asset_Location {
/**
* Holds the dev server's default URL.
*
* @var string
*/
const DEFAULT_URL = 'http://localhost:8080';
/**
* Holds the url where the server is located.
*
* @var string
*/
private $url;
/**
* Class constructor.
*
* @param string|null $url Where the dev server is located.
*/
public function __construct( $url = null ) {
if ( $url === null ) {
$url = self::DEFAULT_URL;
}
$this->url = $url;
}
/**
* Determines the URL of the asset on the dev server.
*
* @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
* @param string $type The type of asset. Usually JS or CSS.
*
* @return string The URL of the asset.
*/
public function get_url( WPSEO_Admin_Asset $asset, $type ) {
if ( $type === WPSEO_Admin_Asset::TYPE_CSS ) {
return $this->get_default_url( $asset, $type );
}
$path = sprintf( 'js/dist/%s%s.js', $asset->get_src(), $asset->get_suffix() );
return trailingslashit( $this->url ) . $path;
}
/**
* Determines the URL of the asset not using the dev server.
*
* @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
* @param string $type The type of asset.
*
* @return string The URL of the asset file.
*/
public function get_default_url( WPSEO_Admin_Asset $asset, $type ) {
$default_location = new WPSEO_Admin_Asset_SEO_Location( WPSEO_FILE );
return $default_location->get_url( $asset, $type );
}
}

View File

@@ -1,22 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Represents a way to determine an assets location.
*/
interface WPSEO_Admin_Asset_Location {
/**
* Determines the URL of the asset on the dev server.
*
* @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
* @param string $type The type of asset. Usually JS or CSS.
*
* @return string The URL of the asset.
*/
public function get_url( WPSEO_Admin_Asset $asset, $type );
}

View File

@@ -1,675 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* This class registers all the necessary styles and scripts.
*
* Also has methods for the enqueing of scripts and styles.
* It automatically adds a prefix to the handle.
*/
class WPSEO_Admin_Asset_Manager {
/**
* Prefix for naming the assets.
*
* @var string
*/
const PREFIX = 'yoast-seo-';
/**
* Class that manages the assets' location.
*
* @var WPSEO_Admin_Asset_Location
*/
protected $asset_location;
/**
* Prefix for naming the assets.
*
* @var string
*/
private $prefix;
/**
* Constructs a manager of assets. Needs a location to know where to register assets at.
*
* @param WPSEO_Admin_Asset_Location|null $asset_location The provider of the asset location.
* @param string $prefix The prefix for naming assets.
*/
public function __construct( WPSEO_Admin_Asset_Location $asset_location = null, $prefix = self::PREFIX ) {
if ( $asset_location === null ) {
$asset_location = self::create_default_location();
}
$this->asset_location = $asset_location;
$this->prefix = $prefix;
}
/**
* Enqueues scripts.
*
* @param string $script The name of the script to enqueue.
*/
public function enqueue_script( $script ) {
wp_enqueue_script( $this->prefix . $script );
}
/**
* Enqueues styles.
*
* @param string $style The name of the style to enqueue.
*/
public function enqueue_style( $style ) {
wp_enqueue_style( $this->prefix . $style );
}
/**
* Enqueues the appropriate language for the user.
*/
public function enqueue_user_language_script() {
$this->enqueue_script( 'language-' . YoastSEO()->helpers->language->get_researcher_language() );
}
/**
* Registers scripts based on it's parameters.
*
* @param WPSEO_Admin_Asset $script The script to register.
*/
public function register_script( WPSEO_Admin_Asset $script ) {
$url = $script->get_src() ? $this->get_url( $script, WPSEO_Admin_Asset::TYPE_JS ) : false;
wp_register_script(
$this->prefix . $script->get_name(),
$url,
$script->get_deps(),
$script->get_version(),
$script->is_in_footer()
);
if ( in_array( 'wp-i18n', $script->get_deps(), true ) ) {
wp_set_script_translations( $this->prefix . $script->get_name(), 'wordpress-seo' );
}
}
/**
* Registers styles based on it's parameters.
*
* @param WPSEO_Admin_Asset $style The style to register.
*/
public function register_style( WPSEO_Admin_Asset $style ) {
wp_register_style(
$this->prefix . $style->get_name(),
$this->get_url( $style, WPSEO_Admin_Asset::TYPE_CSS ),
$style->get_deps(),
$style->get_version(),
$style->get_media()
);
}
/**
* Calls the functions that register scripts and styles with the scripts and styles to be registered as arguments.
*/
public function register_assets() {
$this->register_scripts( $this->scripts_to_be_registered() );
$this->register_styles( $this->styles_to_be_registered() );
}
/**
* Registers all the scripts passed to it.
*
* @param array $scripts The scripts passed to it.
*/
public function register_scripts( $scripts ) {
foreach ( $scripts as $script ) {
$script = new WPSEO_Admin_Asset( $script );
$this->register_script( $script );
}
}
/**
* Registers all the styles it receives.
*
* @param array $styles Styles that need to be registered.
*/
public function register_styles( $styles ) {
foreach ( $styles as $style ) {
$style = new WPSEO_Admin_Asset( $style );
$this->register_style( $style );
}
}
/**
* Localizes the script.
*
* @param string $handle The script handle.
* @param string $object_name The object name.
* @param array $data The l10n data.
*/
public function localize_script( $handle, $object_name, $data ) {
\wp_localize_script( $this->prefix . $handle, $object_name, $data );
}
/**
* Adds an inline script.
*
* @param string $handle The script handle.
* @param string $data The l10n data.
* @param string $position Optional. Whether to add the inline script before the handle or after.
*/
public function add_inline_script( $handle, $data, $position = 'after' ) {
\wp_add_inline_script( $this->prefix . $handle, $data, $position );
}
/**
* A list of styles that shouldn't be registered but are needed in other locations in the plugin.
*
* @return array
*/
public function special_styles() {
$flat_version = $this->flatten_version( WPSEO_VERSION );
$asset_args = [
'name' => 'inside-editor',
'src' => 'inside-editor-' . $flat_version,
];
return [ 'inside-editor' => new WPSEO_Admin_Asset( $asset_args ) ];
}
/**
* Flattens a version number for use in a filename.
*
* @param string $version The original version number.
*
* @return string The flattened version number.
*/
public function flatten_version( $version ) {
$parts = explode( '.', $version );
if ( count( $parts ) === 2 && preg_match( '/^\d+$/', $parts[1] ) === 1 ) {
$parts[] = '0';
}
return implode( '', $parts );
}
/**
* Creates a default location object for use in the admin asset manager.
*
* @return WPSEO_Admin_Asset_Location The location to use in the asset manager.
*/
public static function create_default_location() {
if ( defined( 'YOAST_SEO_DEV_SERVER' ) && YOAST_SEO_DEV_SERVER ) {
$url = defined( 'YOAST_SEO_DEV_SERVER_URL' ) ? YOAST_SEO_DEV_SERVER_URL : WPSEO_Admin_Asset_Dev_Server_Location::DEFAULT_URL;
return new WPSEO_Admin_Asset_Dev_Server_Location( $url );
}
return new WPSEO_Admin_Asset_SEO_Location( WPSEO_FILE, false );
}
/**
* Checks if the given script is enqueued.
*
* @param string $script The script to check.
*
* @return bool True when the script is enqueued.
*/
public function is_script_enqueued( $script ) {
return \wp_script_is( $this->prefix . $script );
}
/**
* Returns the scripts that need to be registered.
*
* @todo Data format is not self-documenting. Needs explanation inline. R.
*
* @return array The scripts that need to be registered.
*/
protected function scripts_to_be_registered() {
$header_scripts = [
'admin-global',
'block-editor',
'classic-editor',
'post-edit',
'help-scout-beacon',
'redirect-old-features-tab',
];
$additional_dependencies = [
'analysis-worker' => [ self::PREFIX . 'analysis-package' ],
'api-client' => [ 'wp-api' ],
'crawl-settings' => [ 'jquery' ],
'dashboard-widget' => [ self::PREFIX . 'api-client' ],
'wincher-dashboard-widget' => [ self::PREFIX . 'api-client' ],
'editor-modules' => [ 'jquery' ],
'elementor' => [
self::PREFIX . 'api-client',
self::PREFIX . 'externals-components',
self::PREFIX . 'externals-contexts',
self::PREFIX . 'externals-redux',
],
'indexation' => [
'jquery-ui-core',
'jquery-ui-progressbar',
],
'first-time-configuration' => [
self::PREFIX . 'api-client',
self::PREFIX . 'externals-components',
self::PREFIX . 'externals-contexts',
self::PREFIX . 'externals-redux',
],
'integrations-page' => [
self::PREFIX . 'api-client',
self::PREFIX . 'externals-components',
self::PREFIX . 'externals-contexts',
self::PREFIX . 'externals-redux',
],
'post-edit' => [
self::PREFIX . 'api-client',
self::PREFIX . 'block-editor',
self::PREFIX . 'externals-components',
self::PREFIX . 'externals-contexts',
self::PREFIX . 'externals-redux',
],
'reindex-links' => [
'jquery-ui-core',
'jquery-ui-progressbar',
],
'settings' => [
'jquery-ui-core',
'jquery-ui-progressbar',
self::PREFIX . 'api-client',
self::PREFIX . 'externals-components',
self::PREFIX . 'externals-contexts',
self::PREFIX . 'externals-redux',
],
'term-edit' => [
self::PREFIX . 'api-client',
self::PREFIX . 'classic-editor',
self::PREFIX . 'externals-components',
self::PREFIX . 'externals-contexts',
self::PREFIX . 'externals-redux',
],
];
$plugin_scripts = $this->load_generated_asset_file(
[
'asset_file' => __DIR__ . '/../src/generated/assets/plugin.php',
'ext_length' => 3,
'additional_deps' => $additional_dependencies,
'header_scripts' => $header_scripts,
]
);
$external_scripts = $this->load_generated_asset_file(
[
'asset_file' => __DIR__ . '/../src/generated/assets/externals.php',
'ext_length' => 3,
'suffix' => '-package',
'base_dir' => 'externals/',
'additional_deps' => $additional_dependencies,
'header_scripts' => $header_scripts,
]
);
$language_scripts = $this->load_generated_asset_file(
[
'asset_file' => __DIR__ . '/../src/generated/assets/languages.php',
'ext_length' => 3,
'suffix' => '-language',
'base_dir' => 'languages/',
'additional_deps' => $additional_dependencies,
'header_scripts' => $header_scripts,
]
);
$renamed_scripts = $this->load_renamed_scripts();
$scripts = array_merge(
$plugin_scripts,
$external_scripts,
$language_scripts,
$renamed_scripts
);
$scripts['installation-success'] = [
'name' => 'installation-success',
'src' => 'installation-success.js',
'deps' => [
'wp-a11y',
'wp-dom-ready',
'wp-components',
'wp-element',
'wp-i18n',
self::PREFIX . 'yoast-components',
self::PREFIX . 'externals-components',
],
'version' => $scripts['installation-success']['version'],
];
$scripts['post-edit-classic'] = [
'name' => 'post-edit-classic',
'src' => $scripts['post-edit']['src'],
'deps' => array_map(
static function( $dep ) {
if ( $dep === self::PREFIX . 'block-editor' ) {
return self::PREFIX . 'classic-editor';
}
return $dep;
},
$scripts['post-edit']['deps']
),
'in_footer' => ! in_array( 'post-edit-classic', $header_scripts, true ),
'version' => $scripts['post-edit']['version'],
];
$scripts['workouts'] = [
'name' => 'workouts',
'src' => 'workouts.js',
'deps' => [
'clipboard',
'lodash',
'wp-api-fetch',
'wp-a11y',
'wp-components',
'wp-compose',
'wp-data',
'wp-dom-ready',
'wp-element',
'wp-i18n',
self::PREFIX . 'externals-components',
self::PREFIX . 'externals-contexts',
self::PREFIX . 'externals-redux',
self::PREFIX . 'analysis',
self::PREFIX . 'react-select',
self::PREFIX . 'yoast-components',
],
'version' => $scripts['workouts']['version'],
];
// Add the current language to every script that requires the analysis package.
foreach ( $scripts as $name => $script ) {
if ( substr( $name, -8 ) === 'language' ) {
continue;
}
if ( in_array( self::PREFIX . 'analysis-package', $script['deps'], true ) ) {
$scripts[ $name ]['deps'][] = self::PREFIX . YoastSEO()->helpers->language->get_researcher_language() . '-language';
}
}
return $scripts;
}
/**
* Loads a generated asset file.
*
* @param array $args {
* The arguments.
*
* @type string $asset_file The asset file to load.
* @type int $ext_length The length of the extension, including suffix, of the filename.
* @type string $suffix Optional. The suffix of the asset name.
* @type array<string, string[]> $additional_deps Optional. The additional dependencies assets may have.
* @type string $base_dir Optional. The base directory of the asset.
* @type string[] $header_scripts Optional. The script names that should be in the header.
* }
*
* @return array {
* The scripts to be registered.
*
* @type string $name The name of the asset.
* @type string $src The src of the asset.
* @type string[] $deps The dependenies of the asset.
* @type bool $in_footer Whether or not the asset should be in the footer.
* }
*/
protected function load_generated_asset_file( $args ) {
$args = wp_parse_args(
$args,
[
'suffix' => '',
'additional_deps' => [],
'base_dir' => '',
'header_scripts' => [],
]
);
$scripts = [];
$assets = require $args['asset_file'];
foreach ( $assets as $file => $data ) {
$name = substr( $file, 0, -$args['ext_length'] );
$name = strtolower( preg_replace( '/([A-Z])/', '-$1', $name ) );
$name .= $args['suffix'];
$deps = $data['dependencies'];
if ( isset( $args['additional_deps'][ $name ] ) ) {
$deps = array_merge( $deps, $args['additional_deps'][ $name ] );
}
$scripts[ $name ] = [
'name' => $name,
'src' => $args['base_dir'] . $file,
'deps' => $deps,
'in_footer' => ! in_array( $name, $args['header_scripts'], true ),
'version' => $data['version'],
];
}
return $scripts;
}
/**
* Loads the scripts that should be renamed for BC.
*
* @return array {
* The scripts to be registered.
*
* @type string $name The name of the asset.
* @type string $src The src of the asset.
* @type string[] $deps The dependenies of the asset.
* @type bool $in_footer Whether or not the asset should be in the footer.
* }
*/
protected function load_renamed_scripts() {
$scripts = [];
$renamed_scripts = [
'admin-global-script' => 'admin-global',
'analysis' => 'analysis-package',
'analysis-report' => 'analysis-report-package',
'api' => 'api-client',
'commons' => 'commons-package',
'edit-page' => 'edit-page-script',
'draft-js' => 'draft-js-package',
'feature-flag' => 'feature-flag-package',
'helpers' => 'helpers-package',
'jed' => 'jed-package',
'legacy-components' => 'components-package',
'network-admin-script' => 'network-admin',
'redux' => 'redux-package',
'replacement-variable-editor' => 'replacement-variable-editor-package',
'search-metadata-previews' => 'search-metadata-previews-package',
'social-metadata-forms' => 'social-metadata-forms-package',
'styled-components' => 'styled-components-package',
'style-guide' => 'style-guide-package',
'yoast-components' => 'components-new-package',
];
foreach ( $renamed_scripts as $original => $replacement ) {
$scripts[] = [
'name' => $original,
'src' => false,
'deps' => [ self::PREFIX . $replacement ],
];
}
return $scripts;
}
/**
* Returns the styles that need to be registered.
*
* @todo Data format is not self-documenting. Needs explanation inline. R.
*
* @return array Styles that need to be registered.
*/
protected function styles_to_be_registered() {
$flat_version = $this->flatten_version( WPSEO_VERSION );
return [
[
'name' => 'admin-css',
'src' => 'yst_plugin_tools-' . $flat_version,
'deps' => [ self::PREFIX . 'toggle-switch' ],
],
[
'name' => 'toggle-switch',
'src' => 'toggle-switch-' . $flat_version,
],
[
'name' => 'dismissible',
'src' => 'wpseo-dismissible-' . $flat_version,
],
[
'name' => 'notifications',
'src' => 'notifications-' . $flat_version,
],
[
'name' => 'alert',
'src' => 'alerts-' . $flat_version,
],
[
'name' => 'edit-page',
'src' => 'edit-page-' . $flat_version,
],
[
'name' => 'featured-image',
'src' => 'featured-image-' . $flat_version,
],
[
'name' => 'metabox-css',
'src' => 'metabox-' . $flat_version,
'deps' => [
self::PREFIX . 'admin-css',
self::PREFIX . 'tailwind',
'wp-components',
],
],
[
'name' => 'ai-generator',
'src' => 'ai-generator-' . $flat_version,
'deps' => [
self::PREFIX . 'tailwind',
self::PREFIX . 'introductions',
],
],
[
'name' => 'introductions',
'src' => 'introductions-' . $flat_version,
'deps' => [ self::PREFIX . 'tailwind' ],
],
[
'name' => 'wp-dashboard',
'src' => 'dashboard-' . $flat_version,
],
[
'name' => 'scoring',
'src' => 'yst_seo_score-' . $flat_version,
],
[
'name' => 'adminbar',
'src' => 'adminbar-' . $flat_version,
'deps' => [
'admin-bar',
],
],
[
'name' => 'primary-category',
'src' => 'metabox-primary-category-' . $flat_version,
],
[
'name' => 'admin-global',
'src' => 'admin-global-' . $flat_version,
],
[
'name' => 'extensions',
'src' => 'yoast-extensions-' . $flat_version,
'deps' => [
'wp-components',
],
],
[
'name' => 'filter-explanation',
'src' => 'filter-explanation-' . $flat_version,
],
[
'name' => 'monorepo',
'src' => 'monorepo-' . $flat_version,
],
[
'name' => 'structured-data-blocks',
'src' => 'structured-data-blocks-' . $flat_version,
'deps' => [ 'wp-edit-blocks' ],
],
[
'name' => 'elementor',
'src' => 'elementor-' . $flat_version,
],
[
'name' => 'tailwind',
'src' => 'tailwind-' . $flat_version,
],
[
'name' => 'new-settings',
'src' => 'new-settings-' . $flat_version,
'deps' => [ self::PREFIX . 'tailwind' ],
],
[
'name' => 'black-friday-banner',
'src' => 'black-friday-banner-' . $flat_version,
'deps' => [ self::PREFIX . 'tailwind' ],
],
[
'name' => 'academy',
'src' => 'academy-' . $flat_version,
'deps' => [ self::PREFIX . 'tailwind' ],
],
[
'name' => 'support',
'src' => 'support-' . $flat_version,
'deps' => [ self::PREFIX . 'tailwind' ],
],
[
'name' => 'workouts',
'src' => 'workouts-' . $flat_version,
'deps' => [
self::PREFIX . 'monorepo',
],
],
[
'name' => 'first-time-configuration',
'src' => 'first-time-configuration-' . $flat_version,
'deps' => [ self::PREFIX . 'tailwind' ],
],
[
'name' => 'inside-editor',
'src' => 'inside-editor-' . $flat_version,
],
];
}
/**
* Determines the URL of the asset.
*
* @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
* @param string $type The type of asset. Usually JS or CSS.
*
* @return string The URL of the asset.
*/
protected function get_url( WPSEO_Admin_Asset $asset, $type ) {
$scheme = wp_parse_url( $asset->get_src(), PHP_URL_SCHEME );
if ( in_array( $scheme, [ 'http', 'https' ], true ) ) {
return $asset->get_src();
}
return $this->asset_location->get_url( $asset, $type );
}
}

View File

@@ -1,86 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Determines the location of an asset within the SEO plugin.
*/
final class WPSEO_Admin_Asset_SEO_Location implements WPSEO_Admin_Asset_Location {
/**
* Path to the plugin file.
*
* @var string
*/
protected $plugin_file;
/**
* Whether or not to add the file suffix to the asset.
*
* @var bool
*/
protected $add_suffix = true;
/**
* The plugin file to base the asset location upon.
*
* @param string $plugin_file The plugin file string.
* @param bool $add_suffix Optional. Whether or not a file suffix should be added.
*/
public function __construct( $plugin_file, $add_suffix = true ) {
$this->plugin_file = $plugin_file;
$this->add_suffix = $add_suffix;
}
/**
* Determines the URL of the asset on the dev server.
*
* @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
* @param string $type The type of asset. Usually JS or CSS.
*
* @return string The URL of the asset.
*/
public function get_url( WPSEO_Admin_Asset $asset, $type ) {
$path = $this->get_path( $asset, $type );
if ( empty( $path ) ) {
return '';
}
return plugins_url( $path, $this->plugin_file );
}
/**
* Determines the path relative to the plugin folder of an asset.
*
* @param WPSEO_Admin_Asset $asset The asset to determine the path for.
* @param string $type The type of asset.
*
* @return string The path to the asset file.
*/
protected function get_path( WPSEO_Admin_Asset $asset, $type ) {
$relative_path = '';
$rtl_suffix = '';
switch ( $type ) {
case WPSEO_Admin_Asset::TYPE_JS:
$relative_path = 'js/dist/' . $asset->get_src();
if ( $this->add_suffix ) {
$relative_path .= $asset->get_suffix() . '.js';
}
break;
case WPSEO_Admin_Asset::TYPE_CSS:
// Path and suffix for RTL stylesheets.
if ( is_rtl() && $asset->has_rtl() ) {
$rtl_suffix = '-rtl';
}
$relative_path = 'css/dist/' . $asset->get_src() . $rtl_suffix . $asset->get_suffix() . '.css';
break;
}
return $relative_path;
}
}

View File

@@ -1,63 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Localizes JavaScript files.
*/
final class WPSEO_Admin_Asset_Yoast_Components_L10n {
/**
* Represents the asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
protected $asset_manager;
/**
* WPSEO_Admin_Asset_Yoast_Components_L10n constructor.
*/
public function __construct() {
$this->asset_manager = new WPSEO_Admin_Asset_Manager();
}
/**
* Localizes the given script with the JavaScript translations.
*
* @param string $script_handle The script handle to localize for.
*
* @return void
*/
public function localize_script( $script_handle ) {
$translations = [
'yoast-components' => $this->get_translations( 'yoast-components' ),
'wordpress-seo' => $this->get_translations( 'wordpress-seojs' ),
'yoast-schema-blocks' => $this->get_translations( 'yoast-schema-blocks' ),
];
$this->asset_manager->localize_script( $script_handle, 'wpseoYoastJSL10n', $translations );
}
/**
* Returns translations necessary for JS files.
*
* @param string $component The component to retrieve the translations for.
* @return object|null The translations in a Jed format for JS files.
*/
protected function get_translations( $component ) {
$locale = \get_user_locale();
$file = WPSEO_PATH . 'languages/' . $component . '-' . $locale . '.json';
if ( file_exists( $file ) ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Retrieving a local file.
$file = file_get_contents( $file );
if ( is_string( $file ) && $file !== '' ) {
return json_decode( $file, true );
}
}
return null;
}
}

View File

@@ -1,227 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Determines the editor specific replacement variables.
*/
class WPSEO_Admin_Editor_Specific_Replace_Vars {
/**
* Holds the editor specific replacements variables.
*
* @var array The editor specific replacement variables.
*/
protected $replacement_variables = [
// Posts types.
'page' => [ 'id', 'pt_single', 'pt_plural', 'parent_title' ],
'post' => [ 'id', 'term404', 'pt_single', 'pt_plural' ],
// Custom post type.
'custom_post_type' => [ 'id', 'term404', 'pt_single', 'pt_plural', 'parent_title' ],
// Settings - archive pages.
'custom-post-type_archive' => [ 'pt_single', 'pt_plural' ],
// Taxonomies.
'category' => [ 'term_title', 'term_description', 'category_description', 'parent_title', 'term_hierarchy' ],
'post_tag' => [ 'term_title', 'term_description', 'tag_description' ],
'post_format' => [ 'term_title' ],
// Custom taxonomy.
'term-in-custom-taxonomy' => [ 'term_title', 'term_description', 'category_description', 'parent_title', 'term_hierarchy' ],
// Settings - special pages.
'search' => [ 'searchphrase' ],
];
/**
* WPSEO_Admin_Editor_Specific_Replace_Vars constructor.
*/
public function __construct() {
$this->add_for_page_types(
[ 'page', 'post', 'custom_post_type' ],
WPSEO_Custom_Fields::get_custom_fields()
);
$this->add_for_page_types(
[ 'post', 'term-in-custom-taxonomy' ],
WPSEO_Custom_Taxonomies::get_custom_taxonomies()
);
}
/**
* Retrieves the editor specific replacement variables.
*
* @return array The editor specific replacement variables.
*/
public function get() {
/**
* Filter: Adds the possibility to add extra editor specific replacement variables.
*
* @api array $replacement_variables Array of editor specific replace vars.
*/
$replacement_variables = apply_filters(
'wpseo_editor_specific_replace_vars',
$this->replacement_variables
);
if ( ! is_array( $replacement_variables ) ) {
$replacement_variables = $this->replacement_variables;
}
return array_filter( $replacement_variables, 'is_array' );
}
/**
* Retrieves the generic replacement variable names.
*
* Which are the replacement variables without the editor specific ones.
*
* @param array $replacement_variables Possibly generic replacement variables.
*
* @return array The generic replacement variable names.
*/
public function get_generic( $replacement_variables ) {
$shared_variables = array_diff(
$this->extract_names( $replacement_variables ),
$this->get_unique_replacement_variables()
);
return array_values( $shared_variables );
}
/**
* Determines the page type of the current term.
*
* @param string $taxonomy The taxonomy name.
*
* @return string The page type.
*/
public function determine_for_term( $taxonomy ) {
$replacement_variables = $this->get();
if ( array_key_exists( $taxonomy, $replacement_variables ) ) {
return $taxonomy;
}
return 'term-in-custom-taxonomy';
}
/**
* Determines the page type of the current post.
*
* @param WP_Post $post A WordPress post instance.
*
* @return string The page type.
*/
public function determine_for_post( $post ) {
if ( $post instanceof WP_Post === false ) {
return 'post';
}
$replacement_variables = $this->get();
if ( array_key_exists( $post->post_type, $replacement_variables ) ) {
return $post->post_type;
}
return 'custom_post_type';
}
/**
* Determines the page type for a post type.
*
* @param string $post_type The name of the post_type.
* @param string $fallback The page type to fall back to.
*
* @return string The page type.
*/
public function determine_for_post_type( $post_type, $fallback = 'custom_post_type' ) {
if ( ! $this->has_for_page_type( $post_type ) ) {
return $fallback;
}
return $post_type;
}
/**
* Determines the page type for an archive page.
*
* @param string $name The name of the archive.
* @param string $fallback The page type to fall back to.
*
* @return string The page type.
*/
public function determine_for_archive( $name, $fallback = 'custom-post-type_archive' ) {
$page_type = $name . '_archive';
if ( ! $this->has_for_page_type( $page_type ) ) {
return $fallback;
}
return $page_type;
}
/**
* Adds the replavement variables for the given page types.
*
* @param array $page_types Page types to add variables for.
* @param array $replacement_variables_to_add The variables to add.
*
* @return void
*/
protected function add_for_page_types( array $page_types, array $replacement_variables_to_add ) {
if ( empty( $replacement_variables_to_add ) ) {
return;
}
$replacement_variables_to_add = array_fill_keys( $page_types, $replacement_variables_to_add );
$replacement_variables = $this->replacement_variables;
$this->replacement_variables = array_merge_recursive( $replacement_variables, $replacement_variables_to_add );
}
/**
* Extracts the names from the given replacements variables.
*
* @param array $replacement_variables Replacement variables to extract the name from.
*
* @return array Extracted names.
*/
protected function extract_names( $replacement_variables ) {
$extracted_names = [];
foreach ( $replacement_variables as $replacement_variable ) {
if ( empty( $replacement_variable['name'] ) ) {
continue;
}
$extracted_names[] = $replacement_variable['name'];
}
return $extracted_names;
}
/**
* Returns whether the given page type has editor specific replace vars.
*
* @param string $page_type The page type to check.
*
* @return bool True if there are associated editor specific replace vars.
*/
protected function has_for_page_type( $page_type ) {
$replacement_variables = $this->get();
return ( ! empty( $replacement_variables[ $page_type ] ) && is_array( $replacement_variables[ $page_type ] ) );
}
/**
* Merges all editor specific replacement variables into one array and removes duplicates.
*
* @return array The list of unique editor specific replacement variables.
*/
protected function get_unique_replacement_variables() {
$merged_replacement_variables = call_user_func_array( 'array_merge', array_values( $this->get() ) );
return array_unique( $merged_replacement_variables );
}
}

View File

@@ -1,105 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Handles the Gutenberg Compatibility notification showing and hiding.
*/
class WPSEO_Admin_Gutenberg_Compatibility_Notification implements WPSEO_WordPress_Integration {
/**
* Notification ID to use.
*
* @var string
*/
private $notification_id = 'wpseo-outdated-gutenberg-plugin';
/**
* Instance of gutenberg compatibility checker.
*
* @var WPSEO_Gutenberg_Compatibility
*/
protected $compatibility_checker;
/**
* Instance of Yoast Notification Center.
*
* @var Yoast_Notification_Center
*/
protected $notification_center;
/**
* WPSEO_Admin_Gutenberg_Compatibility_Notification constructor.
*/
public function __construct() {
$this->compatibility_checker = new WPSEO_Gutenberg_Compatibility();
$this->notification_center = Yoast_Notification_Center::get();
}
/**
* Registers all hooks to WordPress.
*
* @return void
*/
public function register_hooks() {
add_action( 'admin_init', [ $this, 'manage_notification' ] );
}
/**
* Manages if the notification should be shown or removed.
*
* @return void
*/
public function manage_notification() {
/**
* Filter: 'yoast_display_gutenberg_compat_notification' - Allows developer to disable the Gutenberg compatibility
* notification.
*
* @api bool
*/
$display_notification = apply_filters( 'yoast_display_gutenberg_compat_notification', true );
if (
! $this->compatibility_checker->is_installed()
|| $this->compatibility_checker->is_fully_compatible()
|| ! $display_notification
) {
$this->notification_center->remove_notification_by_id( $this->notification_id );
return;
}
$this->add_notification();
}
/**
* Adds the notification to the notificaton center.
*
* @return void
*/
protected function add_notification() {
$level = $this->compatibility_checker->is_below_minimum() ? Yoast_Notification::ERROR : Yoast_Notification::WARNING;
$message = sprintf(
/* translators: %1$s expands to Yoast SEO, %2$s expands to the installed version, %3$s expands to Gutenberg */
__( '%1$s detected you are using version %2$s of %3$s, please update to the latest version to prevent compatibility issues.', 'wordpress-seo' ),
'Yoast SEO',
$this->compatibility_checker->get_installed_version(),
'Gutenberg'
);
$notification = new Yoast_Notification(
$message,
[
'id' => $this->notification_id,
'type' => $level,
'priority' => 1,
]
);
$this->notification_center->add_notification( $notification );
}
}

View File

@@ -1,104 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Generates the HTML for an inline Help Button and Panel.
*/
class WPSEO_Admin_Help_Panel {
/**
* Unique identifier of the element the inline help refers to, used as an identifier in the html.
*
* @var string
*/
private $id;
/**
* The Help Button text. Needs a properly escaped string.
*
* @var string
*/
private $help_button_text;
/**
* The Help Panel content. Needs a properly escaped string (might contain HTML).
*
* @var string
*/
private $help_content;
/**
* Optional Whether to print out a container div element for the Help Panel, used for styling.
*
* @var string
*/
private $wrapper;
/**
* Constructor.
*
* @param string $id Unique identifier of the element the inline help refers to, used as
* an identifier in the html.
* @param string $help_button_text The Help Button text. Needs a properly escaped string.
* @param string $help_content The Help Panel content. Needs a properly escaped string (might contain HTML).
* @param string $wrapper Optional Whether to print out a container div element for the Help Panel,
* used for styling.
* Pass a `has-wrapper` value to print out the container. Default: no container.
*/
public function __construct( $id, $help_button_text, $help_content, $wrapper = '' ) {
$this->id = $id;
$this->help_button_text = $help_button_text;
$this->help_content = $help_content;
$this->wrapper = $wrapper;
}
/**
* Returns the html for the Help Button.
*
* @return string
*/
public function get_button_html() {
if ( ! $this->id || ! $this->help_button_text || ! $this->help_content ) {
return '';
}
return sprintf(
' <button type="button" class="yoast_help yoast-help-button dashicons" id="%1$s-help-toggle" aria-expanded="false" aria-controls="%1$s-help"><span class="yoast-help-icon" aria-hidden="true"></span><span class="screen-reader-text">%2$s</span></button>',
esc_attr( $this->id ),
$this->help_button_text
);
}
/**
* Returns the html for the Help Panel.
*
* @return string
*/
public function get_panel_html() {
if ( ! $this->id || ! $this->help_button_text || ! $this->help_content ) {
return '';
}
$wrapper_start = '';
$wrapper_end = '';
if ( $this->wrapper === 'has-wrapper' ) {
$wrapper_start = '<div class="yoast-seo-help-container">';
$wrapper_end = '</div>';
}
return sprintf(
'%1$s<p id="%2$s-help" class="yoast-help-panel">%3$s</p>%4$s',
$wrapper_start,
esc_attr( $this->id ),
$this->help_content,
$wrapper_end
);
}
}

View File

@@ -1,361 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Performs the load on admin side.
*/
class WPSEO_Admin_Init {
/**
* Holds the global `$pagenow` variable's value.
*
* @var string
*/
private $pagenow;
/**
* Holds the asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
private $asset_manager;
/**
* Class constructor.
*/
public function __construct() {
$GLOBALS['wpseo_admin'] = new WPSEO_Admin();
$this->pagenow = $GLOBALS['pagenow'];
$this->asset_manager = new WPSEO_Admin_Asset_Manager();
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_dismissible' ] );
add_action( 'admin_init', [ $this, 'unsupported_php_notice' ], 15 );
add_action( 'admin_init', [ $this, 'remove_translations_notification' ], 15 );
add_action( 'admin_init', [ $this->asset_manager, 'register_assets' ] );
add_action( 'admin_init', [ $this, 'show_hook_deprecation_warnings' ] );
add_action( 'admin_init', [ 'WPSEO_Plugin_Conflict', 'hook_check_for_plugin_conflicts' ] );
add_action( 'admin_notices', [ $this, 'permalink_settings_notice' ] );
add_action( 'post_submitbox_misc_actions', [ $this, 'add_publish_box_section' ] );
$this->load_meta_boxes();
$this->load_taxonomy_class();
$this->load_admin_page_class();
$this->load_admin_user_class();
$this->load_xml_sitemaps_admin();
$this->load_plugin_suggestions();
}
/**
* Enqueue our styling for dismissible yoast notifications.
*/
public function enqueue_dismissible() {
$this->asset_manager->enqueue_style( 'dismissible' );
}
/**
* Removes any notification for incomplete translations.
*
* @return void
*/
public function remove_translations_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification_by_id( 'i18nModuleTranslationAssistance' );
}
/**
* Creates an unsupported PHP version notification in the notification center.
*
* @return void
*/
public function unsupported_php_notice() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification_by_id( 'wpseo-dismiss-unsupported-php' );
}
/**
* Gets the latest released major WordPress version from the WordPress stable-check api.
*
* @return float|int The latest released major WordPress version. 0 when the stable-check API doesn't respond.
*/
private function get_latest_major_wordpress_version() {
$core_updates = get_core_updates( [ 'dismissed' => true ] );
if ( $core_updates === false ) {
return 0;
}
$wp_version_latest = get_bloginfo( 'version' );
foreach ( $core_updates as $update ) {
if ( $update->response === 'upgrade' && version_compare( $update->version, $wp_version_latest, '>' ) ) {
$wp_version_latest = $update->version;
}
}
// Strip the patch version and convert to a float.
return (float) $wp_version_latest;
}
/**
* Helper to verify if the user is currently visiting one of our admin pages.
*
* @return bool
*/
private function on_wpseo_admin_page() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( ! isset( $_GET['page'] ) || ! is_string( $_GET['page'] ) ) {
return false;
}
if ( $this->pagenow !== 'admin.php' ) {
return false;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$current_page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
return strpos( $current_page, 'wpseo' ) === 0;
}
/**
* Whether we should load the meta box classes.
*
* @return bool true if we should load the meta box classes, false otherwise.
*/
private function should_load_meta_boxes() {
/**
* Filter: 'wpseo_always_register_metaboxes_on_admin' - Allow developers to change whether
* the WPSEO metaboxes are only registered on the typical pages (lean loading) or always
* registered when in admin.
*
* @api bool Whether to always register the metaboxes or not. Defaults to false.
*/
if ( apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) ) {
return true;
}
// If we are in a post editor.
if ( WPSEO_Metabox::is_post_overview( $this->pagenow ) || WPSEO_Metabox::is_post_edit( $this->pagenow ) ) {
return true;
}
// If we are doing an inline save.
if ( check_ajax_referer( 'inlineeditnonce', '_inline_edit', false ) && isset( $_POST['action'] ) && sanitize_text_field( wp_unslash( $_POST['action'] ) ) === 'inline-save' ) {
return true;
}
return false;
}
/**
* Determine whether we should load the meta box class and if so, load it.
*/
private function load_meta_boxes() {
if ( $this->should_load_meta_boxes() ) {
$GLOBALS['wpseo_metabox'] = new WPSEO_Metabox();
$GLOBALS['wpseo_meta_columns'] = new WPSEO_Meta_Columns();
}
}
/**
* Determine if we should load our taxonomy edit class and if so, load it.
*/
private function load_taxonomy_class() {
if (
WPSEO_Taxonomy::is_term_edit( $this->pagenow )
|| WPSEO_Taxonomy::is_term_overview( $this->pagenow )
) {
new WPSEO_Taxonomy();
}
}
/**
* Determine if we should load our admin pages class and if so, load it.
*
* Loads admin page class for all admin pages starting with `wpseo_`.
*/
private function load_admin_user_class() {
if ( in_array( $this->pagenow, [ 'user-edit.php', 'profile.php' ], true )
&& current_user_can( 'edit_users' )
) {
new WPSEO_Admin_User_Profile();
}
}
/**
* Determine if we should load our admin pages class and if so, load it.
*
* Loads admin page class for all admin pages starting with `wpseo_`.
*/
private function load_admin_page_class() {
if ( $this->on_wpseo_admin_page() ) {
// For backwards compatabilty, this still needs a global, for now...
$GLOBALS['wpseo_admin_pages'] = new WPSEO_Admin_Pages();
$page = null;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['page'] ) && is_string( $_GET['page'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
}
// Only renders Yoast SEO Premium upsells when the page is a Yoast SEO page.
if ( $page !== null && WPSEO_Utils::is_yoast_seo_free_page( $page ) ) {
$this->register_premium_upsell_admin_block();
}
}
}
/**
* Loads the plugin suggestions.
*/
private function load_plugin_suggestions() {
$suggestions = new WPSEO_Suggested_Plugins( new WPSEO_Plugin_Availability(), Yoast_Notification_Center::get() );
$suggestions->register_hooks();
}
/**
* Registers the Premium Upsell Admin Block.
*
* @return void
*/
private function register_premium_upsell_admin_block() {
if ( ! YoastSEO()->helpers->product->is_premium() ) {
$upsell_block = new WPSEO_Premium_Upsell_Admin_Block( 'wpseo_admin_promo_footer' );
$upsell_block->register_hooks();
}
}
/**
* See if we should start our XML Sitemaps Admin class.
*/
private function load_xml_sitemaps_admin() {
if ( WPSEO_Options::get( 'enable_xml_sitemap', false ) ) {
new WPSEO_Sitemaps_Admin();
}
}
/**
* Shows deprecation warnings to the user if a plugin has registered a filter we have deprecated.
*/
public function show_hook_deprecation_warnings() {
global $wp_filter;
if ( wp_doing_ajax() ) {
return;
}
// WordPress hooks that have been deprecated since a Yoast SEO version.
$deprecated_filters = [
'wpseo_genesis_force_adjacent_rel_home' => [
'version' => '9.4',
'alternative' => null,
],
'wpseo_opengraph' => [
'version' => '14.0',
'alternative' => null,
],
'wpseo_twitter' => [
'version' => '14.0',
'alternative' => null,
],
'wpseo_twitter_taxonomy_image' => [
'version' => '14.0',
'alternative' => null,
],
'wpseo_twitter_metatag_key' => [
'version' => '14.0',
'alternative' => null,
],
'wp_seo_get_bc_ancestors' => [
'version' => '14.0',
'alternative' => 'wpseo_breadcrumb_links',
],
'validate_facebook_app_id_api_response_code' => [
'version' => '15.5',
'alternative' => null,
],
'validate_facebook_app_id_api_response_body' => [
'version' => '15.5',
'alternative' => null,
],
];
// Determine which filters have been registered.
$deprecated_notices = array_intersect(
array_keys( $deprecated_filters ),
array_keys( $wp_filter )
);
// Show notice for each deprecated filter or action that has been registered.
foreach ( $deprecated_notices as $deprecated_filter ) {
$deprecation_info = $deprecated_filters[ $deprecated_filter ];
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Only uses the hardcoded values from above.
_deprecated_hook(
$deprecated_filter,
'WPSEO ' . $deprecation_info['version'],
$deprecation_info['alternative']
);
// phpcs:enable
}
}
/**
* Check if the permalink uses %postname%.
*
* @return bool
*/
private function has_postname_in_permalink() {
return ( strpos( get_option( 'permalink_structure' ), '%postname%' ) !== false );
}
/**
* Shows a notice on the permalink settings page.
*/
public function permalink_settings_notice() {
global $pagenow;
if ( $pagenow === 'options-permalink.php' ) {
printf(
'<div class="notice notice-warning"><p><strong>%1$s</strong><br>%2$s<br><a href="%3$s" target="_blank">%4$s</a></p></div>',
esc_html__( 'WARNING:', 'wordpress-seo' ),
sprintf(
/* translators: %1$s and %2$s expand to <em> items to emphasize the word in the middle. */
esc_html__( 'Changing your permalinks settings can seriously impact your search engine visibility. It should almost %1$s never %2$s be done on a live website.', 'wordpress-seo' ),
'<em>',
'</em>'
),
esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/why-permalinks/' ) ),
// The link's content.
esc_html__( 'Learn about why permalinks are important for SEO.', 'wordpress-seo' )
);
}
}
/**
* Adds a custom Yoast section within the Classic Editor publish box.
*
* @param \WP_Post $post The current post object.
*
* @return void
*/
public function add_publish_box_section( $post ) {
if ( in_array( $this->pagenow, [ 'post.php', 'post-new.php' ], true ) ) {
?>
<div id="yoast-seo-publishbox-section"></div>
<?php
/**
* Fires after the post time/date setting in the Publish meta box.
*
* @api \WP_Post The current post object.
*/
do_action( 'wpseo_publishbox_misc_actions', $post );
}
}
}

View File

@@ -1,112 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Handles the media purge notification showing and hiding.
*/
class WPSEO_Admin_Media_Purge_Notification implements WPSEO_WordPress_Integration {
/**
* Notification ID to use.
*
* @var string
*/
private $notification_id = 'wpseo_media_purge';
/**
* Registers all hooks to WordPress.
*
* @return void
*/
public function register_hooks() {
add_action( 'admin_init', [ $this, 'manage_notification' ] );
add_filter( 'wpseo_option_tab-metas_media', [ $this, 'output_hidden_setting' ] );
// Dismissing is just setting the relevancy to false, which cancels out any functionality.
if ( YoastSEO()->helpers->current_page->is_yoast_seo_page() && filter_input( INPUT_GET, 'dismiss' ) === $this->notification_id ) {
WPSEO_Options::set( 'is-media-purge-relevant', false );
}
}
/**
* Adds a hidden setting to the media tab.
*
* To make sure the setting is not reverted to the default when -anything-
* is saved on the entire page (not just the media tab).
*
* @param string|null $input Current filter value.
*
* @return string|null
*/
public function output_hidden_setting( $input ) {
$form = Yoast_Form::get_instance();
$form->hidden( 'is-media-purge-relevant' );
return $input;
}
/**
* Manages if the notification should be shown or removed.
*
* @return void
*/
public function manage_notification() {
$this->remove_notification();
}
/**
* Retrieves the notification that should be shown or removed.
*
* @return Yoast_Notification The notification to use.
*/
private function get_notification() {
$content = sprintf(
/* translators: %1$s expands to the link to the article, %2$s closes the link tag. */
__( 'Your site\'s settings currently allow attachment URLs on your site to exist. Please read %1$sthis post about a potential issue%2$s with attachment URLs and check whether you have the correct setting for your site.', 'wordpress-seo' ),
'<a href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/2r8' ) ) . '" rel="noopener noreferrer" target="_blank">',
'</a>'
);
$content .= '<br><br>';
$content .= sprintf(
/* translators: %1$s dismiss link open tag, %2$s closes the link tag. */
__( 'If you know what this means and you do not want to see this message anymore, you can %1$sdismiss this message%2$s.', 'wordpress-seo' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_dashboard&dismiss=' . $this->notification_id ) ) . '">',
'</a>'
);
return new Yoast_Notification(
$content,
[
'type' => Yoast_Notification::ERROR,
'id' => $this->notification_id,
'capabilities' => 'wpseo_manage_options',
'priority' => 1,
]
);
}
/**
* Adds the notification to the notificaton center.
*
* @return void
*/
private function add_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->add_notification( $this->get_notification() );
}
/**
* Removes the notification from the notification center.
*
* @return void
*/
private function remove_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification( $this->get_notification() );
}
}

View File

@@ -1,205 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Determines the recommended replacement variables based on the context.
*/
class WPSEO_Admin_Recommended_Replace_Vars {
/**
* The recommended replacement variables.
*
* @var array
*/
protected $recommended_replace_vars = [
// Posts types.
'page' => [ 'sitename', 'title', 'sep', 'primary_category' ],
'post' => [ 'sitename', 'title', 'sep', 'primary_category' ],
// Homepage.
'homepage' => [ 'sitename', 'sitedesc', 'sep' ],
// Custom post type.
'custom_post_type' => [ 'sitename', 'title', 'sep' ],
// Taxonomies.
'category' => [ 'sitename', 'term_title', 'sep', 'term_hierarchy' ],
'post_tag' => [ 'sitename', 'term_title', 'sep' ],
'post_format' => [ 'sitename', 'term_title', 'sep', 'page' ],
// Custom taxonomy.
'term-in-custom-taxonomy' => [ 'sitename', 'term_title', 'sep', 'term_hierarchy' ],
// Settings - archive pages.
'author_archive' => [ 'sitename', 'title', 'sep', 'page' ],
'date_archive' => [ 'sitename', 'sep', 'date', 'page' ],
'custom-post-type_archive' => [ 'sitename', 'title', 'sep', 'page' ],
// Settings - special pages.
'search' => [ 'sitename', 'searchphrase', 'sep', 'page' ],
'404' => [ 'sitename', 'sep' ],
];
/**
* Determines the page type of the current term.
*
* @param string $taxonomy The taxonomy name.
*
* @return string The page type.
*/
public function determine_for_term( $taxonomy ) {
$recommended_replace_vars = $this->get_recommended_replacevars();
if ( array_key_exists( $taxonomy, $recommended_replace_vars ) ) {
return $taxonomy;
}
return 'term-in-custom-taxonomy';
}
/**
* Determines the page type of the current post.
*
* @param WP_Post $post A WordPress post instance.
*
* @return string The page type.
*/
public function determine_for_post( $post ) {
if ( $post instanceof WP_Post === false ) {
return 'post';
}
if ( $post->post_type === 'page' && $this->is_homepage( $post ) ) {
return 'homepage';
}
$recommended_replace_vars = $this->get_recommended_replacevars();
if ( array_key_exists( $post->post_type, $recommended_replace_vars ) ) {
return $post->post_type;
}
return 'custom_post_type';
}
/**
* Determines the page type for a post type.
*
* @param string $post_type The name of the post_type.
* @param string $fallback The page type to fall back to.
*
* @return string The page type.
*/
public function determine_for_post_type( $post_type, $fallback = 'custom_post_type' ) {
$page_type = $post_type;
$recommended_replace_vars = $this->get_recommended_replacevars();
$has_recommended_replacevars = $this->has_recommended_replace_vars( $recommended_replace_vars, $page_type );
if ( ! $has_recommended_replacevars ) {
return $fallback;
}
return $page_type;
}
/**
* Determines the page type for an archive page.
*
* @param string $name The name of the archive.
* @param string $fallback The page type to fall back to.
*
* @return string The page type.
*/
public function determine_for_archive( $name, $fallback = 'custom-post-type_archive' ) {
$page_type = $name . '_archive';
$recommended_replace_vars = $this->get_recommended_replacevars();
$has_recommended_replacevars = $this->has_recommended_replace_vars( $recommended_replace_vars, $page_type );
if ( ! $has_recommended_replacevars ) {
return $fallback;
}
return $page_type;
}
/**
* Retrieves the recommended replacement variables for the given page type.
*
* @param string $page_type The page type.
*
* @return array The recommended replacement variables.
*/
public function get_recommended_replacevars_for( $page_type ) {
$recommended_replace_vars = $this->get_recommended_replacevars();
$has_recommended_replace_vars = $this->has_recommended_replace_vars( $recommended_replace_vars, $page_type );
if ( ! $has_recommended_replace_vars ) {
return [];
}
return $recommended_replace_vars[ $page_type ];
}
/**
* Retrieves the recommended replacement variables.
*
* @return array The recommended replacement variables.
*/
public function get_recommended_replacevars() {
/**
* Filter: Adds the possibility to add extra recommended replacement variables.
*
* @api array $additional_replace_vars Empty array to add the replacevars to.
*/
$recommended_replace_vars = apply_filters( 'wpseo_recommended_replace_vars', $this->recommended_replace_vars );
if ( ! is_array( $recommended_replace_vars ) ) {
return $this->recommended_replace_vars;
}
return $recommended_replace_vars;
}
/**
* Returns whether the given page type has recommended replace vars.
*
* @param array $recommended_replace_vars The recommended replace vars
* to check in.
* @param string $page_type The page type to check.
*
* @return bool True if there are associated recommended replace vars.
*/
private function has_recommended_replace_vars( $recommended_replace_vars, $page_type ) {
if ( ! isset( $recommended_replace_vars[ $page_type ] ) ) {
return false;
}
if ( ! is_array( $recommended_replace_vars[ $page_type ] ) ) {
return false;
}
return true;
}
/**
* Determines whether or not a post is the homepage.
*
* @param WP_Post $post The WordPress global post object.
*
* @return bool True if the given post is the homepage.
*/
private function is_homepage( $post ) {
if ( $post instanceof WP_Post === false ) {
return false;
}
/*
* The page on front returns a string with normal WordPress interaction, while the post ID is an int.
* This way we make sure we always compare strings.
*/
$post_id = (int) $post->ID;
$page_on_front = (int) get_option( 'page_on_front' );
return get_option( 'show_on_front' ) === 'page' && $page_on_front === $post_id;
}
}

View File

@@ -1,78 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
* @since 1.8.0
*/
/**
* Customizes user profile.
*/
class WPSEO_Admin_User_Profile {
/**
* Class constructor.
*/
public function __construct() {
add_action( 'show_user_profile', [ $this, 'user_profile' ] );
add_action( 'edit_user_profile', [ $this, 'user_profile' ] );
add_action( 'personal_options_update', [ $this, 'process_user_option_update' ] );
add_action( 'edit_user_profile_update', [ $this, 'process_user_option_update' ] );
add_action( 'update_user_meta', [ $this, 'clear_author_sitemap_cache' ], 10, 3 );
}
/**
* Clear author sitemap cache when settings are changed.
*
* @since 3.1
*
* @param int $meta_id The ID of the meta option changed.
* @param int $object_id The ID of the user.
* @param string $meta_key The key of the meta field changed.
*/
public function clear_author_sitemap_cache( $meta_id, $object_id, $meta_key ) {
if ( $meta_key === '_yoast_wpseo_profile_updated' ) {
WPSEO_Sitemaps_Cache::clear( [ 'author' ] );
}
}
/**
* Updates the user metas that (might) have been set on the user profile page.
*
* @param int $user_id User ID of the updated user.
*/
public function process_user_option_update( $user_id ) {
update_user_meta( $user_id, '_yoast_wpseo_profile_updated', time() );
if ( ! check_admin_referer( 'wpseo_user_profile_update', 'wpseo_nonce' ) ) {
return;
}
$wpseo_author_title = isset( $_POST['wpseo_author_title'] ) ? sanitize_text_field( wp_unslash( $_POST['wpseo_author_title'] ) ) : '';
$wpseo_author_metadesc = isset( $_POST['wpseo_author_metadesc'] ) ? sanitize_text_field( wp_unslash( $_POST['wpseo_author_metadesc'] ) ) : '';
$wpseo_noindex_author = isset( $_POST['wpseo_noindex_author'] ) ? sanitize_text_field( wp_unslash( $_POST['wpseo_noindex_author'] ) ) : '';
$wpseo_content_analysis_disable = isset( $_POST['wpseo_content_analysis_disable'] ) ? sanitize_text_field( wp_unslash( $_POST['wpseo_content_analysis_disable'] ) ) : '';
$wpseo_keyword_analysis_disable = isset( $_POST['wpseo_keyword_analysis_disable'] ) ? sanitize_text_field( wp_unslash( $_POST['wpseo_keyword_analysis_disable'] ) ) : '';
$wpseo_inclusive_language_analysis_disable = isset( $_POST['wpseo_inclusive_language_analysis_disable'] ) ? sanitize_text_field( wp_unslash( $_POST['wpseo_inclusive_language_analysis_disable'] ) ) : '';
update_user_meta( $user_id, 'wpseo_title', $wpseo_author_title );
update_user_meta( $user_id, 'wpseo_metadesc', $wpseo_author_metadesc );
update_user_meta( $user_id, 'wpseo_noindex_author', $wpseo_noindex_author );
update_user_meta( $user_id, 'wpseo_content_analysis_disable', $wpseo_content_analysis_disable );
update_user_meta( $user_id, 'wpseo_keyword_analysis_disable', $wpseo_keyword_analysis_disable );
update_user_meta( $user_id, 'wpseo_inclusive_language_analysis_disable', $wpseo_inclusive_language_analysis_disable );
}
/**
* Add the inputs needed for SEO values to the User Profile page.
*
* @param WP_User $user User instance to output for.
*/
public function user_profile( $user ) {
wp_nonce_field( 'wpseo_user_profile_update', 'wpseo_nonce' );
require_once WPSEO_PATH . 'admin/views/user-profile.php';
}
}

View File

@@ -1,82 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Represents the utils for the admin.
*/
class WPSEO_Admin_Utils {
/**
* Gets the install URL for the passed plugin slug.
*
* @param string $slug The slug to create an install link for.
*
* @return string The install URL. Empty string if the current user doesn't have the proper capabilities.
*/
public static function get_install_url( $slug ) {
if ( ! current_user_can( 'install_plugins' ) ) {
return '';
}
return wp_nonce_url(
self_admin_url( 'update.php?action=install-plugin&plugin=' . dirname( $slug ) ),
'install-plugin_' . dirname( $slug )
);
}
/**
* Gets the activation URL for the passed plugin slug.
*
* @param string $slug The slug to create an activation link for.
*
* @return string The activation URL. Empty string if the current user doesn't have the proper capabilities.
*/
public static function get_activation_url( $slug ) {
if ( ! current_user_can( 'install_plugins' ) ) {
return '';
}
return wp_nonce_url(
self_admin_url( 'plugins.php?action=activate&plugin_status=all&paged=1&s&plugin=' . $slug ),
'activate-plugin_' . $slug
);
}
/**
* Creates a link if the passed plugin is deemend a directly-installable plugin.
*
* @param array $plugin The plugin to create the link for.
*
* @return string The link to the plugin install. Returns the title if the plugin is deemed a Premium product.
*/
public static function get_install_link( $plugin ) {
$install_url = self::get_install_url( $plugin['slug'] );
if ( $install_url === '' || ( isset( $plugin['premium'] ) && $plugin['premium'] === true ) ) {
return $plugin['title'];
}
return sprintf(
'<a href="%s">%s</a>',
$install_url,
$plugin['title']
);
}
/**
* Gets a visually hidden accessible message for links that open in a new browser tab.
*
* @return string The visually hidden accessible message.
*/
public static function get_new_tab_message() {
return sprintf(
'<span class="screen-reader-text">%s</span>',
/* translators: Hidden accessibility text. */
esc_html__( '(Opens in a new browser tab)', 'wordpress-seo' )
);
}
}

View File

@@ -1,384 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
use Yoast\WP\SEO\Integrations\Settings_Integration;
/**
* Class that holds most of the admin functionality for Yoast SEO.
*/
class WPSEO_Admin {
/**
* The page identifier used in WordPress to register the admin page.
*
* !DO NOT CHANGE THIS!
*
* @var string
*/
const PAGE_IDENTIFIER = 'wpseo_dashboard';
/**
* Array of classes that add admin functionality.
*
* @var array
*/
protected $admin_features;
/**
* Class constructor.
*/
public function __construct() {
$integrations = [];
global $pagenow;
$wpseo_menu = new WPSEO_Menu();
$wpseo_menu->register_hooks();
if ( is_multisite() ) {
WPSEO_Options::maybe_set_multisite_defaults( false );
}
if ( WPSEO_Options::get( 'stripcategorybase' ) === true ) {
add_action( 'created_category', [ $this, 'schedule_rewrite_flush' ] );
add_action( 'edited_category', [ $this, 'schedule_rewrite_flush' ] );
add_action( 'delete_category', [ $this, 'schedule_rewrite_flush' ] );
}
if ( WPSEO_Options::get( 'disable-attachment' ) === true ) {
add_filter( 'wpseo_accessible_post_types', [ 'WPSEO_Post_Type', 'filter_attachment_post_type' ] );
}
add_filter( 'plugin_action_links_' . WPSEO_BASENAME, [ $this, 'add_action_link' ], 10, 2 );
add_filter( 'network_admin_plugin_action_links_' . WPSEO_BASENAME, [ $this, 'add_action_link' ], 10, 2 );
add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_global_style' ] );
add_filter( 'user_contactmethods', [ $this, 'update_contactmethods' ], 10, 1 );
add_action( 'after_switch_theme', [ $this, 'switch_theme' ] );
add_action( 'switch_theme', [ $this, 'switch_theme' ] );
add_filter( 'set-screen-option', [ $this, 'save_bulk_edit_options' ], 10, 3 );
add_action( 'admin_init', [ 'WPSEO_Plugin_Conflict', 'hook_check_for_plugin_conflicts' ], 10, 1 );
add_action( 'admin_init', [ $this, 'map_manage_options_cap' ] );
WPSEO_Sitemaps_Cache::register_clear_on_option_update( 'wpseo' );
WPSEO_Sitemaps_Cache::register_clear_on_option_update( 'home' );
if ( YoastSEO()->helpers->current_page->is_yoast_seo_page() ) {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
}
$this->set_upsell_notice();
$this->initialize_cornerstone_content();
if ( WPSEO_Utils::is_plugin_network_active() ) {
$integrations[] = new Yoast_Network_Admin();
}
$this->admin_features = [
'dashboard_widget' => new Yoast_Dashboard_Widget(),
'wincher_dashboard_widget' => new Wincher_Dashboard_Widget(),
];
if ( WPSEO_Metabox::is_post_overview( $pagenow ) || WPSEO_Metabox::is_post_edit( $pagenow ) ) {
$this->admin_features['primary_category'] = new WPSEO_Primary_Term_Admin();
}
$integrations[] = new WPSEO_Yoast_Columns();
$integrations[] = new WPSEO_Statistic_Integration();
$integrations[] = new WPSEO_Capability_Manager_Integration( WPSEO_Capability_Manager_Factory::get() );
$integrations[] = new WPSEO_Admin_Gutenberg_Compatibility_Notification();
$integrations[] = new WPSEO_Expose_Shortlinks();
$integrations[] = new WPSEO_MyYoast_Proxy();
$integrations[] = new WPSEO_Schema_Person_Upgrade_Notification();
$integrations[] = new WPSEO_Tracking( 'https://tracking.yoast.com/stats', ( WEEK_IN_SECONDS * 2 ) );
$integrations[] = new WPSEO_Admin_Settings_Changed_Listener();
$integrations = array_merge(
$integrations,
$this->get_admin_features(),
$this->initialize_cornerstone_content()
);
foreach ( $integrations as $integration ) {
$integration->register_hooks();
}
}
/**
* Schedules a rewrite flush to happen at shutdown.
*/
public function schedule_rewrite_flush() {
// Bail if this is a multisite installation and the site has been switched.
if ( is_multisite() && ms_is_switched() ) {
return;
}
add_action( 'shutdown', 'flush_rewrite_rules' );
}
/**
* Returns all the classes for the admin features.
*
* @return array
*/
public function get_admin_features() {
return $this->admin_features;
}
/**
* Register assets needed on admin pages.
*/
public function enqueue_assets() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form data.
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
if ( $page === 'wpseo_licenses' ) {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_style( 'extensions' );
}
}
/**
* Returns the manage_options capability.
*
* @return string The capability to use.
*/
public function get_manage_options_cap() {
/**
* Filter: 'wpseo_manage_options_capability' - Allow changing the capability users need to view the settings pages.
*
* @api string unsigned The capability.
*/
return apply_filters( 'wpseo_manage_options_capability', 'wpseo_manage_options' );
}
/**
* Maps the manage_options cap on saving an options page to wpseo_manage_options.
*/
public function map_manage_options_cap() {
// phpcs:ignore WordPress.Security -- The variable is only used in strpos and thus safe to not unslash or sanitize.
$option_page = ! empty( $_POST['option_page'] ) ? $_POST['option_page'] : '';
if ( strpos( $option_page, 'yoast_wpseo' ) === 0 || strpos( $option_page, Settings_Integration::PAGE ) === 0 ) {
add_filter( 'option_page_capability_' . $option_page, [ $this, 'get_manage_options_cap' ] );
}
}
/**
* Adds the ability to choose how many posts are displayed per page
* on the bulk edit pages.
*/
public function bulk_edit_options() {
$option = 'per_page';
$args = [
'label' => __( 'Posts', 'wordpress-seo' ),
'default' => 10,
'option' => 'wpseo_posts_per_page',
];
add_screen_option( $option, $args );
}
/**
* Saves the posts per page limit for bulk edit pages.
*
* @param int $status Status value to pass through.
* @param string $option Option name.
* @param int $value Count value to check.
*
* @return int
*/
public function save_bulk_edit_options( $status, $option, $value ) {
if ( $option && ( $value > 0 && $value < 1000 ) === 'wpseo_posts_per_page' ) {
return $value;
}
return $status;
}
/**
* Adds links to Premium Support and FAQ under the plugin in the plugin overview page.
*
* @param array $links Array of links for the plugins, adapted when the current plugin is found.
* @param string $file The filename for the current plugin, which the filter loops through.
*
* @return array
*/
public function add_action_link( $links, $file ) {
$first_time_configuration_notice_helper = \YoastSEO()->helpers->first_time_configuration_notice;
if ( $file === WPSEO_BASENAME && WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
if ( is_network_admin() ) {
$settings_url = network_admin_url( 'admin.php?page=' . self::PAGE_IDENTIFIER );
}
else {
$settings_url = admin_url( 'admin.php?page=' . self::PAGE_IDENTIFIER );
}
$settings_link = '<a href="' . esc_url( $settings_url ) . '">' . __( 'Settings', 'wordpress-seo' ) . '</a>';
array_unshift( $links, $settings_link );
}
// Add link to docs.
$faq_link = '<a href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yc' ) ) . '" target="_blank">' . __( 'FAQ', 'wordpress-seo' ) . '</a>';
array_unshift( $links, $faq_link );
if ( $first_time_configuration_notice_helper->first_time_configuration_not_finished() && ! is_network_admin() ) {
$configuration_title = ( ! $first_time_configuration_notice_helper->should_show_alternate_message() ) ? 'first-time configuration' : 'SEO configuration';
/* translators: CTA to finish the first time configuration. %s: Either first-time SEO configuration or SEO configuration. */
$message = sprintf( __( 'Finish your %s', 'wordpress-seo' ), $configuration_title );
$ftc_link = '<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) ) . '" target="_blank">' . $message . '</a>';
array_unshift( $links, $ftc_link );
}
$addon_manager = new WPSEO_Addon_Manager();
if ( YoastSEO()->helpers->product->is_premium() ) {
// Remove Free 'deactivate' link if Premium is active as well. We don't want users to deactivate Free when Premium is active.
unset( $links['deactivate'] );
$no_deactivation_explanation = '<span style="color: #32373c">' . sprintf(
/* translators: %s expands to Yoast SEO Premium. */
__( 'Required by %s', 'wordpress-seo' ),
'Yoast SEO Premium'
) . '</span>';
array_unshift( $links, $no_deactivation_explanation );
if ( $addon_manager->has_valid_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG ) ) {
return $links;
}
// Add link to where premium can be activated.
$activation_link = '<a style="font-weight: bold;" href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/activate-my-yoast' ) ) . '" target="_blank">' . __( 'Activate your subscription', 'wordpress-seo' ) . '</a>';
array_unshift( $links, $activation_link );
return $links;
}
// Add link to premium landing page.
$premium_link = '<a style="font-weight: bold;" href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/1yb' ) ) . '" target="_blank" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2">' . __( 'Get Premium', 'wordpress-seo' ) . '</a>';
array_unshift( $links, $premium_link );
return $links;
}
/**
* Enqueues the (tiny) global JS needed for the plugin.
*/
public function config_page_scripts() {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_script( 'admin-global' );
$asset_manager->localize_script( 'admin-global', 'wpseoAdminGlobalL10n', $this->localize_admin_global_script() );
}
/**
* Enqueues the (tiny) global stylesheet needed for the plugin.
*/
public function enqueue_global_style() {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_style( 'admin-global' );
}
/**
* Filter the $contactmethods array and add a set of social profiles.
*
* These are used with the Facebook author, rel="author" and Twitter cards implementation.
*
* @param array $contactmethods Currently set contactmethods.
*
* @return array Contactmethods with added contactmethods.
*/
public function update_contactmethods( $contactmethods ) {
$contactmethods['facebook'] = __( 'Facebook profile URL', 'wordpress-seo' );
$contactmethods['instagram'] = __( 'Instagram profile URL', 'wordpress-seo' );
$contactmethods['linkedin'] = __( 'LinkedIn profile URL', 'wordpress-seo' );
$contactmethods['myspace'] = __( 'MySpace profile URL', 'wordpress-seo' );
$contactmethods['pinterest'] = __( 'Pinterest profile URL', 'wordpress-seo' );
$contactmethods['soundcloud'] = __( 'SoundCloud profile URL', 'wordpress-seo' );
$contactmethods['tumblr'] = __( 'Tumblr profile URL', 'wordpress-seo' );
$contactmethods['twitter'] = __( 'Twitter username (without @)', 'wordpress-seo' );
$contactmethods['youtube'] = __( 'YouTube profile URL', 'wordpress-seo' );
$contactmethods['wikipedia'] = __( 'Wikipedia page about you', 'wordpress-seo' ) . '<br/><small>' . __( '(if one exists)', 'wordpress-seo' ) . '</small>';
return $contactmethods;
}
/**
* Log the updated timestamp for user profiles when theme is changed.
*/
public function switch_theme() {
$users = get_users( [ 'capability' => [ 'edit_posts' ] ] );
if ( is_array( $users ) && $users !== [] ) {
foreach ( $users as $user ) {
update_user_meta( $user->ID, '_yoast_wpseo_profile_updated', time() );
}
}
}
/**
* Localization for the dismiss urls.
*
* @return array
*/
private function localize_admin_global_script() {
return array_merge(
[
'isRtl' => is_rtl(),
'variable_warning' => sprintf(
/* translators: %1$s: '%%term_title%%' variable used in titles and meta's template that's not compatible with the given template, %2$s: expands to 'HelpScout beacon' */
__( 'Warning: the variable %1$s cannot be used in this template. See the %2$s for more info.', 'wordpress-seo' ),
'<code>%s</code>',
'HelpScout beacon'
),
/* translators: %s: expends to Yoast SEO */
'help_video_iframe_title' => sprintf( __( '%s video tutorial', 'wordpress-seo' ), 'Yoast SEO' ),
'scrollable_table_hint' => __( 'Scroll to see the table content.', 'wordpress-seo' ),
'wincher_is_logged_in' => WPSEO_Options::get( 'wincher_integration_active', true ) ? YoastSEO()->helpers->wincher->login_status() : false,
],
YoastSEO()->helpers->wincher->get_admin_global_links()
);
}
/**
* Sets the upsell notice.
*/
protected function set_upsell_notice() {
$upsell = new WPSEO_Product_Upsell_Notice();
$upsell->dismiss_notice_listener();
$upsell->initialize();
}
/**
* Whether we are on the admin dashboard page.
*
* @return bool
*/
protected function on_dashboard_page() {
return $GLOBALS['pagenow'] === 'index.php';
}
/**
* Loads the cornerstone filter.
*
* @return WPSEO_WordPress_Integration[] The integrations to initialize.
*/
protected function initialize_cornerstone_content() {
if ( ! WPSEO_Options::get( 'enable_cornerstone_content' ) ) {
return [];
}
return [
'cornerstone_filter' => new WPSEO_Cornerstone_Filter(),
];
}
}

View File

@@ -1,255 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Represents a WPSEO asset
*/
class WPSEO_Admin_Asset {
/**
* Constant used to identify file type as a JS file.
*
* @var string
*/
const TYPE_JS = 'js';
/**
* Constant used to identify file type as a CSS file.
*
* @var string
*/
const TYPE_CSS = 'css';
/**
* The name option identifier.
*
* @var string
*/
const NAME = 'name';
/**
* The source option identifier.
*
* @var string
*/
const SRC = 'src';
/**
* The dependencies option identifier.
*
* @var string
*/
const DEPS = 'deps';
/**
* The version option identifier.
*
* @var string
*/
const VERSION = 'version';
/* Style specific. */
/**
* The media option identifier.
*
* @var string
*/
const MEDIA = 'media';
/**
* The rtl option identifier.
*
* @var string
*/
const RTL = 'rtl';
/* Script specific. */
/**
* The "in footer" option identifier.
*
* @var string
*/
const IN_FOOTER = 'in_footer';
/**
* Asset identifier.
*
* @var string
*/
protected $name;
/**
* Path to the asset.
*
* @var string
*/
protected $src;
/**
* Asset dependencies.
*
* @var string|array
*/
protected $deps;
/**
* Asset version.
*
* @var string
*/
protected $version;
/**
* For CSS Assets. The type of media for which this stylesheet has been defined.
*
* See https://www.w3.org/TR/CSS2/media.html#media-types.
*
* @var string
*/
protected $media;
/**
* For JS Assets. Whether or not the script should be loaded in the footer.
*
* @var bool
*/
protected $in_footer;
/**
* For CSS Assets. Whether this stylesheet is a right-to-left stylesheet.
*
* @var bool
*/
protected $rtl;
/**
* File suffix.
*
* @var string
*/
protected $suffix;
/**
* Default asset arguments.
*
* @var array
*/
private $defaults = [
'deps' => [],
'in_footer' => true,
'rtl' => true,
'media' => 'all',
'version' => '',
'suffix' => '',
];
/**
* Constructs an instance of the WPSEO_Admin_Asset class.
*
* @param array $args The arguments for this asset.
*
* @throws InvalidArgumentException Throws when no name or src has been provided.
*/
public function __construct( array $args ) {
if ( ! isset( $args['name'] ) ) {
throw new InvalidArgumentException( 'name is a required argument' );
}
if ( ! isset( $args['src'] ) ) {
throw new InvalidArgumentException( 'src is a required argument' );
}
$args = array_merge( $this->defaults, $args );
$this->name = $args['name'];
$this->src = $args['src'];
$this->deps = $args['deps'];
$this->version = $args['version'];
$this->media = $args['media'];
$this->in_footer = $args['in_footer'];
$this->rtl = $args['rtl'];
$this->suffix = $args['suffix'];
}
/**
* Returns the asset identifier.
*
* @return string
*/
public function get_name() {
return $this->name;
}
/**
* Returns the path to the asset.
*
* @return string
*/
public function get_src() {
return $this->src;
}
/**
* Returns the asset dependencies.
*
* @return array|string
*/
public function get_deps() {
return $this->deps;
}
/**
* Returns the asset version.
*
* @return string|null
*/
public function get_version() {
if ( ! empty( $this->version ) ) {
return $this->version;
}
return null;
}
/**
* Returns the media type for CSS assets.
*
* @return string
*/
public function get_media() {
return $this->media;
}
/**
* Returns whether a script asset should be loaded in the footer of the page.
*
* @return bool
*/
public function is_in_footer() {
return $this->in_footer;
}
/**
* Returns whether this CSS has a RTL counterpart.
*
* @return bool
*/
public function has_rtl() {
return $this->rtl;
}
/**
* Returns the file suffix.
*
* @return string
*/
public function get_suffix() {
return $this->suffix;
}
}

View File

@@ -1,80 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Bulk Editor
* @since 1.5.0
*/
/**
* Implements table for bulk description editing.
*/
class WPSEO_Bulk_Description_List_Table extends WPSEO_Bulk_List_Table {
/**
* Current type for this class will be (meta) description.
*
* @var string
*/
protected $page_type = 'description';
/**
* Settings with are used in __construct.
*
* @var array
*/
protected $settings = [
'singular' => 'wpseo_bulk_description',
'plural' => 'wpseo_bulk_descriptions',
'ajax' => true,
];
/**
* The field in the database where meta field is saved.
*
* @var string
*/
protected $target_db_field = 'metadesc';
/**
* The columns shown on the table.
*
* @return array
*/
public function get_columns() {
$columns = [
'col_existing_yoast_seo_metadesc' => __( 'Existing Yoast Meta Description', 'wordpress-seo' ),
'col_new_yoast_seo_metadesc' => __( 'New Yoast Meta Description', 'wordpress-seo' ),
];
return $this->merge_columns( $columns );
}
/**
* Parse the metadescription.
*
* @param string $column_name Column name.
* @param object $record Data object.
* @param string $attributes HTML attributes.
*
* @return string
*/
protected function parse_page_specific_column( $column_name, $record, $attributes ) {
switch ( $column_name ) {
case 'col_new_yoast_seo_metadesc':
return sprintf(
'<textarea id="%1$s" name="%1$s" class="wpseo-new-metadesc" data-id="%2$s" aria-labelledby="col_new_yoast_seo_metadesc"></textarea>',
esc_attr( 'wpseo-new-metadesc-' . $record->ID ),
esc_attr( $record->ID )
);
case 'col_existing_yoast_seo_metadesc':
// @todo Inconsistent return/echo behavior R.
// I traced the escaping of the attributes to WPSEO_Bulk_List_Table::column_attributes. Alexander.
// The output of WPSEO_Bulk_List_Table::parse_meta_data_field is properly escaped.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $this->parse_meta_data_field( $record->ID, $attributes );
break;
}
}
}

View File

@@ -1,89 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Bulk Editor
* @since 1.5.0
*/
/**
* Implements table for bulk title editing.
*/
class WPSEO_Bulk_Title_Editor_List_Table extends WPSEO_Bulk_List_Table {
/**
* Current type for this class will be title.
*
* @var string
*/
protected $page_type = 'title';
/**
* Settings with are used in __construct.
*
* @var array
*/
protected $settings = [
'singular' => 'wpseo_bulk_title',
'plural' => 'wpseo_bulk_titles',
'ajax' => true,
];
/**
* The field in the database where meta field is saved.
*
* @var string
*/
protected $target_db_field = 'title';
/**
* The columns shown on the table.
*
* @return array
*/
public function get_columns() {
$columns = [
/* translators: %1$s expands to Yoast SEO */
'col_existing_yoast_seo_title' => sprintf( __( 'Existing %1$s Title', 'wordpress-seo' ), 'Yoast SEO' ),
/* translators: %1$s expands to Yoast SEO */
'col_new_yoast_seo_title' => sprintf( __( 'New %1$s Title', 'wordpress-seo' ), 'Yoast SEO' ),
];
return $this->merge_columns( $columns );
}
/**
* Parse the title columns.
*
* @param string $column_name Column name.
* @param object $record Data object.
* @param string $attributes HTML attributes.
*
* @return string
*/
protected function parse_page_specific_column( $column_name, $record, $attributes ) {
// Fill meta data if exists in $this->meta_data.
$meta_data = ( ! empty( $this->meta_data[ $record->ID ] ) ) ? $this->meta_data[ $record->ID ] : [];
switch ( $column_name ) {
case 'col_existing_yoast_seo_title':
// @todo Inconsistent return/echo behavior R.
// I traced the escaping of the attributes to WPSEO_Bulk_List_Table::column_attributes.
// The output of WPSEO_Bulk_List_Table::parse_meta_data_field is properly escaped.
// phpcs:ignore WordPress.Security.EscapeOutput
echo $this->parse_meta_data_field( $record->ID, $attributes );
break;
case 'col_new_yoast_seo_title':
return sprintf(
'<input type="text" id="%1$s" name="%1$s" class="wpseo-new-title" data-id="%2$s" aria-labelledby="col_new_yoast_seo_title" />',
'wpseo-new-title-' . $record->ID,
$record->ID
);
}
unset( $meta_data );
}
}

View File

@@ -1,52 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Collects the data from the added collection objects.
*/
class WPSEO_Collector {
/**
* Holds the collections.
*
* @var WPSEO_Collection[]
*/
protected $collections = [];
/**
* Adds a collection object to the collections.
*
* @param WPSEO_Collection $collection The collection object to add.
*/
public function add_collection( WPSEO_Collection $collection ) {
$this->collections[] = $collection;
}
/**
* Collects the data from the collection objects.
*
* @return array The collected data.
*/
public function collect() {
$data = [];
foreach ( $this->collections as $collection ) {
$data = array_merge( $data, $collection->get() );
}
return $data;
}
/**
* Returns the collected data as a JSON encoded string.
*
* @return false|string The encode string.
*/
public function get_as_json() {
return WPSEO_Utils::format_json_encode( $this->collect() );
}
}

View File

@@ -1,174 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
use Yoast\WP\SEO\Integrations\Academy_Integration;
use Yoast\WP\SEO\Integrations\Settings_Integration;
use Yoast\WP\SEO\Integrations\Support_Integration;
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
/**
* Class WPSEO_Admin_Pages.
*
* Class with functionality for the Yoast SEO admin pages.
*/
class WPSEO_Admin_Pages {
/**
* The option in use for the current admin page.
*
* @var string
*/
public $currentoption = 'wpseo';
/**
* Holds the asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
private $asset_manager;
/**
* Class constructor, which basically only hooks the init function on the init hook.
*/
public function __construct() {
add_action( 'init', [ $this, 'init' ], 20 );
$this->asset_manager = new WPSEO_Admin_Asset_Manager();
}
/**
* Make sure the needed scripts are loaded for admin pages.
*/
public function init() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
if ( \in_array( $page, [ Settings_Integration::PAGE, Academy_Integration::PAGE, Support_Integration::PAGE ], true ) ) {
// Bail, this is managed in the applicable integration.
return;
}
add_action( 'admin_enqueue_scripts', [ $this, 'config_page_scripts' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'config_page_styles' ] );
}
/**
* Loads the required styles for the config page.
*/
public function config_page_styles() {
wp_enqueue_style( 'dashboard' );
wp_enqueue_style( 'thickbox' );
wp_enqueue_style( 'global' );
wp_enqueue_style( 'wp-admin' );
$this->asset_manager->enqueue_style( 'admin-css' );
$this->asset_manager->enqueue_style( 'monorepo' );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
if ( $page === 'wpseo_licenses' ) {
$this->asset_manager->enqueue_style( 'tailwind' );
}
}
/**
* Loads the required scripts for the config page.
*/
public function config_page_scripts() {
$this->asset_manager->enqueue_script( 'settings' );
wp_enqueue_script( 'dashboard' );
wp_enqueue_script( 'thickbox' );
$alert_dismissal_action = YoastSEO()->classes->get( \Yoast\WP\SEO\Actions\Alert_Dismissal_Action::class );
$dismissed_alerts = $alert_dismissal_action->all_dismissed();
$woocommerce_conditional = new WooCommerce_Conditional();
$script_data = [
'userLanguageCode' => WPSEO_Language_Utils::get_language( \get_user_locale() ),
'dismissedAlerts' => $dismissed_alerts,
'isRtl' => is_rtl(),
'isPremium' => YoastSEO()->helpers->product->is_premium(),
'isWooCommerceActive' => $woocommerce_conditional->is_met(),
'currentPromotions' => YoastSEO()->classes->get( Yoast\WP\SEO\Promotions\Application\Promotion_Manager::class )->get_current_promotions(),
'webinarIntroSettingsUrl' => WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-settings' ),
'webinarIntroFirstTimeConfigUrl' => $this->get_webinar_shortlink(),
'linkParams' => WPSEO_Shortlinker::get_query_params(),
'pluginUrl' => \plugins_url( '', \WPSEO_FILE ),
];
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
if ( in_array( $page, [ WPSEO_Admin::PAGE_IDENTIFIER, 'wpseo_workouts' ], true ) ) {
wp_enqueue_media();
$script_data['media'] = [
'choose_image' => __( 'Use Image', 'wordpress-seo' ),
];
$script_data['userEditUrl'] = add_query_arg( 'user_id', '{user_id}', admin_url( 'user-edit.php' ) );
}
if ( $page === 'wpseo_tools' ) {
$this->enqueue_tools_scripts();
}
$this->asset_manager->localize_script( 'settings', 'wpseoScriptData', $script_data );
$this->asset_manager->enqueue_user_language_script();
}
/**
* Retrieves some variables that are needed for replacing variables in JS.
*
* @deprecated 20.3
* @codeCoverageIgnore
*
* @return array The replacement and recommended replacement variables.
*/
public function get_replace_vars_script_data() {
_deprecated_function( __METHOD__, 'Yoast SEO 20.3' );
$replace_vars = new WPSEO_Replace_Vars();
$recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars();
$editor_specific_replace_vars = new WPSEO_Admin_Editor_Specific_Replace_Vars();
$replace_vars_list = $replace_vars->get_replacement_variables_list();
return [
'replace_vars' => $replace_vars_list,
'recommended_replace_vars' => $recommended_replace_vars->get_recommended_replacevars(),
'editor_specific_replace_vars' => $editor_specific_replace_vars->get(),
'shared_replace_vars' => $editor_specific_replace_vars->get_generic( $replace_vars_list ),
'hidden_replace_vars' => $replace_vars->get_hidden_replace_vars(),
];
}
/**
* Enqueues and handles all the tool dependencies.
*/
private function enqueue_tools_scripts() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$tool = isset( $_GET['tool'] ) && is_string( $_GET['tool'] ) ? sanitize_text_field( wp_unslash( $_GET['tool'] ) ) : '';
if ( empty( $tool ) ) {
$this->asset_manager->enqueue_script( 'yoast-seo' );
}
if ( $tool === 'bulk-editor' ) {
$this->asset_manager->enqueue_script( 'bulk-editor' );
}
}
/**
* Returns the appropriate shortlink for the Webinar.
*
* @return string The shortlink for the Webinar.
*/
private function get_webinar_shortlink() {
if ( YoastSEO()->helpers->product->is_premium() ) {
return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config-premium' );
}
return WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-first-time-config' );
}
}

View File

@@ -1,229 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Customizer
*/
/**
* Class with functionality to support WP SEO settings in WordPress Customizer.
*/
class WPSEO_Customizer {
/**
* Holds the customize manager.
*
* @var WP_Customize_Manager
*/
protected $wp_customize;
/**
* Template for the setting IDs used for the customizer.
*
* @var string
*/
private $setting_template = 'wpseo_titles[%s]';
/**
* Default arguments for the breadcrumbs customizer settings object.
*
* @var array
*/
private $default_setting_args = [
'default' => '',
'type' => 'option',
'transport' => 'refresh',
];
/**
* Default arguments for the breadcrumbs customizer control object.
*
* @var array
*/
private $default_control_args = [
'label' => '',
'type' => 'text',
'section' => 'wpseo_breadcrumbs_customizer_section',
'settings' => '',
'context' => '',
];
/**
* Construct Method.
*/
public function __construct() {
add_action( 'customize_register', [ $this, 'wpseo_customize_register' ] );
}
/**
* Function to support WordPress Customizer.
*
* @param WP_Customize_Manager $wp_customize Manager class instance.
*/
public function wpseo_customize_register( $wp_customize ) {
if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
return;
}
$this->wp_customize = $wp_customize;
$this->breadcrumbs_section();
$this->breadcrumbs_blog_show_setting();
$this->breadcrumbs_separator_setting();
$this->breadcrumbs_home_setting();
$this->breadcrumbs_prefix_setting();
$this->breadcrumbs_archiveprefix_setting();
$this->breadcrumbs_searchprefix_setting();
$this->breadcrumbs_404_setting();
}
/**
* Add the breadcrumbs section to the customizer.
*/
private function breadcrumbs_section() {
$section_args = [
/* translators: %s is the name of the plugin */
'title' => sprintf( __( '%s Breadcrumbs', 'wordpress-seo' ), 'Yoast SEO' ),
'priority' => 999,
'active_callback' => [ $this, 'breadcrumbs_active_callback' ],
];
$this->wp_customize->add_section( 'wpseo_breadcrumbs_customizer_section', $section_args );
}
/**
* Returns whether or not the breadcrumbs are active.
*
* @return bool
*/
public function breadcrumbs_active_callback() {
return current_theme_supports( 'yoast-seo-breadcrumbs' ) || WPSEO_Options::get( 'breadcrumbs-enable' );
}
/**
* Adds the breadcrumbs show blog checkbox.
*/
private function breadcrumbs_blog_show_setting() {
$index = 'breadcrumbs-display-blog-page';
$control_args = [
'label' => __( 'Show blog page in breadcrumbs', 'wordpress-seo' ),
'type' => 'checkbox',
'active_callback' => [ $this, 'breadcrumbs_blog_show_active_cb' ],
];
$this->add_setting_and_control( $index, $control_args );
}
/**
* Returns whether or not to show the breadcrumbs blog show option.
*
* @return bool
*/
public function breadcrumbs_blog_show_active_cb() {
return get_option( 'show_on_front' ) === 'page';
}
/**
* Adds the breadcrumbs separator text field.
*/
private function breadcrumbs_separator_setting() {
$index = 'breadcrumbs-sep';
$control_args = [
'label' => __( 'Breadcrumbs separator:', 'wordpress-seo' ),
];
$id = 'wpseo-breadcrumbs-separator';
$this->add_setting_and_control( $index, $control_args, $id );
}
/**
* Adds the breadcrumbs home anchor text field.
*/
private function breadcrumbs_home_setting() {
$index = 'breadcrumbs-home';
$control_args = [
'label' => __( 'Anchor text for the homepage:', 'wordpress-seo' ),
];
$this->add_setting_and_control( $index, $control_args );
}
/**
* Adds the breadcrumbs prefix text field.
*/
private function breadcrumbs_prefix_setting() {
$index = 'breadcrumbs-prefix';
$control_args = [
'label' => __( 'Prefix for breadcrumbs:', 'wordpress-seo' ),
];
$this->add_setting_and_control( $index, $control_args );
}
/**
* Adds the breadcrumbs archive prefix text field.
*/
private function breadcrumbs_archiveprefix_setting() {
$index = 'breadcrumbs-archiveprefix';
$control_args = [
'label' => __( 'Prefix for archive pages:', 'wordpress-seo' ),
];
$this->add_setting_and_control( $index, $control_args );
}
/**
* Adds the breadcrumbs search prefix text field.
*/
private function breadcrumbs_searchprefix_setting() {
$index = 'breadcrumbs-searchprefix';
$control_args = [
'label' => __( 'Prefix for search result pages:', 'wordpress-seo' ),
];
$this->add_setting_and_control( $index, $control_args );
}
/**
* Adds the breadcrumb 404 prefix text field.
*/
private function breadcrumbs_404_setting() {
$index = 'breadcrumbs-404crumb';
$control_args = [
'label' => __( 'Breadcrumb for 404 pages:', 'wordpress-seo' ),
];
$this->add_setting_and_control( $index, $control_args );
}
/**
* Adds the customizer setting and control.
*
* @param string $index Array key index to use for the customizer setting.
* @param array $control_args Customizer control object arguments.
* Only those different from the default need to be passed.
* @param string|null $id Optional. Customizer control object ID.
* Will default to 'wpseo-' . $index.
* @param array $custom_settings Optional. Customizer setting arguments.
* Only those different from the default need to be passed.
*/
private function add_setting_and_control( $index, $control_args, $id = null, $custom_settings = [] ) {
$setting = sprintf( $this->setting_template, $index );
$control_args = array_merge( $this->default_control_args, $control_args );
$control_args['settings'] = $setting;
$settings_args = $this->default_setting_args;
if ( ! empty( $custom_settings ) ) {
$settings_args = array_merge( $settings_args, $custom_settings );
}
if ( ! isset( $id ) ) {
$id = 'wpseo-' . $index;
}
$this->wp_customize->add_setting( $setting, $settings_args );
$control = new WP_Customize_Control( $this->wp_customize, $id, $control_args );
$this->wp_customize->add_control( $control );
}
}

View File

@@ -1,298 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Represents the proxy for communicating with the database.
*/
class WPSEO_Database_Proxy {
/**
* Holds the table name.
*
* @var string
*/
protected $table_name;
/**
* Determines whether to suppress errors or not.
*
* @var bool
*/
protected $suppress_errors = true;
/**
* Determines if this table is multisite.
*
* @var bool
*/
protected $is_multisite_table = false;
/**
* Holds the last suppressed state.
*
* @var bool
*/
protected $last_suppressed_state;
/**
* Holds the WordPress database object.
*
* @var wpdb
*/
protected $database;
/**
* Sets the class attributes and registers the table.
*
* @param wpdb $database The database object.
* @param string $table_name The table name that is represented.
* @param bool $suppress_errors Should the errors be suppressed.
* @param bool $is_multisite_table Should the table be global in multisite.
*/
public function __construct( $database, $table_name, $suppress_errors = true, $is_multisite_table = false ) {
$this->table_name = $table_name;
$this->suppress_errors = (bool) $suppress_errors;
$this->is_multisite_table = (bool) $is_multisite_table;
$this->database = $database;
// If the table prefix was provided, strip it as it's handled automatically.
$table_prefix = $this->get_table_prefix();
if ( ! empty( $table_prefix ) && strpos( $this->table_name, $table_prefix ) === 0 ) {
$this->table_prefix = substr( $this->table_name, strlen( $table_prefix ) );
}
if ( ! $this->is_table_registered() ) {
$this->register_table();
}
}
/**
* Inserts data into the database.
*
* @param array $data Data to insert.
* @param array|string|null $format Formats for the data.
*
* @return false|int Total amount of inserted rows or false on error.
*/
public function insert( array $data, $format = null ) {
$this->pre_execution();
$result = $this->database->insert( $this->get_table_name(), $data, $format );
$this->post_execution();
return $result;
}
/**
* Updates data in the database.
*
* @param array $data Data to update on the table.
* @param array $where Where condition as key => value array.
* @param array|string|null $format Optional. Data prepare format.
* @param array|string|null $where_format Optional. Where prepare format.
*
* @return false|int False when the update request is invalid, int on number of rows changed.
*/
public function update( array $data, array $where, $format = null, $where_format = null ) {
$this->pre_execution();
$result = $this->database->update( $this->get_table_name(), $data, $where, $format, $where_format );
$this->post_execution();
return $result;
}
/**
* Upserts data in the database.
*
* Performs an insert into and if key is duplicate it will update the existing record.
*
* @param array $data Data to update on the table.
* @param array|null $where Unused. Where condition as key => value array.
* @param array|string|null $format Optional. Data prepare format.
* @param array|string|null $where_format Optional. Where prepare format.
*
* @return false|int False when the upsert request is invalid, int on number of rows changed.
*/
public function upsert( array $data, array $where = null, $format = null, $where_format = null ) {
if ( $where_format !== null ) {
_deprecated_argument( __METHOD__, '7.7.0', 'The where_format argument is deprecated' );
}
$this->pre_execution();
$update = [];
$keys = [];
$columns = array_keys( $data );
foreach ( $columns as $column ) {
$keys[] = '`' . $column . '`';
$update[] = sprintf( '`%1$s` = VALUES(`%1$s`)', $column );
}
$query = sprintf(
'INSERT INTO `%1$s` (%2$s) VALUES ( %3$s ) ON DUPLICATE KEY UPDATE %4$s',
$this->get_table_name(),
implode( ', ', $keys ),
implode( ', ', array_fill( 0, count( $data ), '%s' ) ),
implode( ', ', $update )
);
$result = $this->database->query(
$this->database->prepare(
$query,
array_values( $data )
)
);
$this->post_execution();
return $result;
}
/**
* Deletes a record from the database.
*
* @param array $where Where clauses for the query.
* @param array|string|null $format Formats for the data.
*
* @return false|int
*/
public function delete( array $where, $format = null ) {
$this->pre_execution();
$result = $this->database->delete( $this->get_table_name(), $where, $format );
$this->post_execution();
return $result;
}
/**
* Executes the given query and returns the results.
*
* @param string $query The query to execute.
*
* @return array|object|null The resultset
*/
public function get_results( $query ) {
$this->pre_execution();
$results = $this->database->get_results( $query );
$this->post_execution();
return $results;
}
/**
* Creates a table to the database.
*
* @param array $columns The columns to create.
* @param array $indexes The indexes to use.
*
* @return bool True when creation is successful.
*/
public function create_table( array $columns, array $indexes = [] ) {
$create_table = sprintf(
'CREATE TABLE IF NOT EXISTS %1$s ( %2$s ) %3$s',
$this->get_table_name(),
implode( ',', array_merge( $columns, $indexes ) ),
$this->database->get_charset_collate()
);
$this->pre_execution();
$is_created = (bool) $this->database->query( $create_table );
$this->post_execution();
return $is_created;
}
/**
* Checks if there is an error.
*
* @return bool Returns true when there is an error.
*/
public function has_error() {
return ( $this->database->last_error !== '' );
}
/**
* Executed before a query will be ran.
*/
protected function pre_execution() {
if ( $this->suppress_errors ) {
$this->last_suppressed_state = $this->database->suppress_errors();
}
}
/**
* Executed after a query has been ran.
*/
protected function post_execution() {
if ( $this->suppress_errors ) {
$this->database->suppress_errors( $this->last_suppressed_state );
}
}
/**
* Returns the full table name.
*
* @return string Full table name including prefix.
*/
public function get_table_name() {
return $this->get_table_prefix() . $this->table_name;
}
/**
* Returns the prefix to use for the table.
*
* @return string The table prefix depending on the database context.
*/
protected function get_table_prefix() {
if ( $this->is_multisite_table ) {
return $this->database->base_prefix;
}
return $this->database->get_blog_prefix();
}
/**
* Registers the table with WordPress.
*
* @return void
*/
protected function register_table() {
$table_name = $this->table_name;
$full_table_name = $this->get_table_name();
$this->database->$table_name = $full_table_name;
if ( $this->is_multisite_table ) {
$this->database->ms_global_tables[] = $table_name;
return;
}
$this->database->tables[] = $table_name;
}
/**
* Checks if the table has been registered with WordPress.
*
* @return bool True if the table is registered, false otherwise.
*/
protected function is_table_registered() {
if ( $this->is_multisite_table ) {
return in_array( $this->table_name, $this->database->ms_global_tables, true );
}
return in_array( $this->table_name, $this->database->tables, true );
}
}

View File

@@ -1,150 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Export
*/
/**
* Class WPSEO_Export.
*
* Class with functionality to export the WP SEO settings.
*/
class WPSEO_Export {
/**
* Holds the nonce action.
*
* @var string
*/
const NONCE_ACTION = 'wpseo_export';
/**
* Holds the export data.
*
* @var string
*/
private $export = '';
/**
* Holds whether the export was a success.
*
* @var bool
*/
public $success;
/**
* Handles the export request.
*/
public function export() {
check_admin_referer( self::NONCE_ACTION );
$this->export_settings();
$this->output();
}
/**
* Outputs the export.
*/
public function output() {
if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) ) {
esc_html_e( 'You do not have the required rights to export settings.', 'wordpress-seo' );
return;
}
echo '<p id="wpseo-settings-export-desc">';
printf(
/* translators: %1$s expands to Import settings */
esc_html__(
'Copy all these settings to another site\'s %1$s tab and click "%1$s" there.',
'wordpress-seo'
),
esc_html__(
'Import settings',
'wordpress-seo'
)
);
echo '</p>';
/* translators: %1$s expands to Yoast SEO */
echo '<label for="wpseo-settings-export" class="yoast-inline-label">' . sprintf( __( 'Your %1$s settings:', 'wordpress-seo' ), 'Yoast SEO' ) . '</label><br />';
echo '<textarea id="wpseo-settings-export" rows="20" cols="100" aria-describedby="wpseo-settings-export-desc">' . esc_textarea( $this->export ) . '</textarea>';
}
/**
* Exports the current site's WP SEO settings.
*/
private function export_settings() {
$this->export_header();
foreach ( WPSEO_Options::get_option_names() as $opt_group ) {
$this->write_opt_group( $opt_group );
}
}
/**
* Writes the header of the export.
*/
private function export_header() {
$header = sprintf(
/* translators: %1$s expands to Yoast SEO, %2$s expands to Yoast.com */
esc_html__( 'These are settings for the %1$s plugin by %2$s', 'wordpress-seo' ),
'Yoast SEO',
'Yoast.com'
);
$this->write_line( '; ' . $header );
}
/**
* Writes a line to the export.
*
* @param string $line Line string.
* @param bool $newline_first Boolean flag whether to prepend with new line.
*/
private function write_line( $line, $newline_first = false ) {
if ( $newline_first ) {
$this->export .= PHP_EOL;
}
$this->export .= $line . PHP_EOL;
}
/**
* Writes an entire option group to the export.
*
* @param string $opt_group Option group name.
*/
private function write_opt_group( $opt_group ) {
$this->write_line( '[' . $opt_group . ']', true );
$options = get_option( $opt_group );
if ( ! is_array( $options ) ) {
return;
}
foreach ( $options as $key => $elem ) {
if ( is_array( $elem ) ) {
$count = count( $elem );
for ( $i = 0; $i < $count; $i++ ) {
$elem_check = isset( $elem[ $i ] ) ? $elem[ $i ] : null;
$this->write_setting( $key . '[]', $elem_check );
}
}
else {
$this->write_setting( $key, $elem );
}
}
}
/**
* Writes a settings line to the export.
*
* @param string $key Key string.
* @param string $val Value string.
*/
private function write_setting( $key, $val ) {
if ( is_string( $val ) ) {
$val = '"' . $val . '"';
}
$this->write_line( $key . ' = ' . $val );
}
}

View File

@@ -1,140 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Exposes shortlinks in a global, so that we can pass them to our Javascript components.
*/
class WPSEO_Expose_Shortlinks implements WPSEO_WordPress_Integration {
/**
* Array containing the keys and shortlinks.
*
* @var array
*/
private $shortlinks = [
'shortlinks.advanced.allow_search_engines' => 'https://yoa.st/allow-search-engines',
'shortlinks.advanced.follow_links' => 'https://yoa.st/follow-links',
'shortlinks.advanced.meta_robots' => 'https://yoa.st/meta-robots-advanced',
'shortlinks.advanced.breadcrumbs_title' => 'https://yoa.st/breadcrumbs-title',
'shortlinks.metabox.schema.explanation' => 'https://yoa.st/400',
'shortlinks.metabox.schema.page_type' => 'https://yoa.st/402',
'shortlinks.sidebar.schema.explanation' => 'https://yoa.st/401',
'shortlinks.sidebar.schema.page_type' => 'https://yoa.st/403',
'shortlinks.focus_keyword_info' => 'https://yoa.st/focus-keyword',
'shortlinks.nofollow_sponsored' => 'https://yoa.st/nofollow-sponsored',
'shortlinks.snippet_preview_info' => 'https://yoa.st/snippet-preview',
'shortlinks.cornerstone_content_info' => 'https://yoa.st/1i9',
'shortlinks.upsell.social_preview.social' => 'https://yoa.st/social-preview-facebook',
'shortlinks.upsell.social_preview.twitter' => 'https://yoa.st/social-preview-twitter',
'shortlinks.upsell.sidebar.news' => 'https://yoa.st/get-news-sidebar',
'shortlinks.upsell.sidebar.focus_keyword_synonyms_button' => 'https://yoa.st/keyword-synonyms-popup-sidebar',
'shortlinks.upsell.sidebar.premium_seo_analysis_button' => 'https://yoa.st/premium-seo-analysis-sidebar',
'shortlinks.upsell.sidebar.focus_keyword_additional_button' => 'https://yoa.st/add-keywords-popup-sidebar',
'shortlinks.upsell.sidebar.additional_link' => 'https://yoa.st/textlink-keywords-sidebar',
'shortlinks.upsell.sidebar.additional_button' => 'https://yoa.st/add-keywords-sidebar',
'shortlinks.upsell.sidebar.keyphrase_distribution' => 'https://yoa.st/keyphrase-distribution-sidebar',
'shortlinks.upsell.sidebar.word_complexity' => 'https://yoa.st/word-complexity-sidebar',
'shortlinks.upsell.sidebar.internal_linking_suggestions' => 'https://yoa.st/internal-linking-suggestions-sidebar',
'shortlinks.upsell.metabox.news' => 'https://yoa.st/get-news-metabox',
'shortlinks.upsell.metabox.go_premium' => 'https://yoa.st/pe-premium-page',
'shortlinks.upsell.metabox.focus_keyword_synonyms_button' => 'https://yoa.st/keyword-synonyms-popup',
'shortlinks.upsell.metabox.premium_seo_analysis_button' => 'https://yoa.st/premium-seo-analysis-metabox',
'shortlinks.upsell.metabox.focus_keyword_additional_button' => 'https://yoa.st/add-keywords-popup',
'shortlinks.upsell.metabox.additional_link' => 'https://yoa.st/textlink-keywords-metabox',
'shortlinks.upsell.metabox.additional_button' => 'https://yoa.st/add-keywords-metabox',
'shortlinks.upsell.metabox.keyphrase_distribution' => 'https://yoa.st/keyphrase-distribution-metabox',
'shortlinks.upsell.metabox.word_complexity' => 'https://yoa.st/word-complexity-metabox',
'shortlinks.upsell.metabox.internal_linking_suggestions' => 'https://yoa.st/internal-linking-suggestions-metabox',
'shortlinks.upsell.gsc.create_redirect_button' => 'https://yoa.st/redirects',
'shortlinks.readability_analysis_info' => 'https://yoa.st/readability-analysis',
'shortlinks.inclusive_language_analysis_info' => 'https://yoa.st/inclusive-language-analysis',
'shortlinks.activate_premium_info' => 'https://yoa.st/activate-subscription',
'shortlinks.upsell.sidebar.morphology_upsell_metabox' => 'https://yoa.st/morphology-upsell-metabox',
'shortlinks.upsell.sidebar.morphology_upsell_sidebar' => 'https://yoa.st/morphology-upsell-sidebar',
'shortlinks.semrush.volume_help' => 'https://yoa.st/3-v',
'shortlinks.semrush.trend_help' => 'https://yoa.st/3-v',
'shortlinks.semrush.prices' => 'https://yoa.st/semrush-prices',
'shortlinks.semrush.premium_landing_page' => 'https://yoa.st/413',
'shortlinks.wincher.seo_performance' => 'https://yoa.st/wincher-integration',
'shortlinks-insights-estimated_reading_time' => 'https://yoa.st/4fd',
'shortlinks-insights-flesch_reading_ease' => 'https://yoa.st/34r',
'shortlinks-insights-flesch_reading_ease_sidebar' => 'https://yoa.st/4mf',
'shortlinks-insights-flesch_reading_ease_metabox' => 'https://yoa.st/4mg',
'shortlinks-insights-flesch_reading_ease_article' => 'https://yoa.st/34s',
'shortlinks-insights-keyword_research_link' => 'https://yoa.st/keyword-research-metabox',
'shortlinks-insights-upsell-sidebar-prominent_words' => 'https://yoa.st/prominent-words-upsell-sidebar',
'shortlinks-insights-upsell-metabox-prominent_words' => 'https://yoa.st/prominent-words-upsell-metabox',
'shortlinks-insights-upsell-elementor-prominent_words' => 'https://yoa.st/prominent-words-upsell-elementor',
'shortlinks-insights-word_count' => 'https://yoa.st/word-count',
'shortlinks-insights-upsell-sidebar-text_formality' => 'https://yoa.st/formality-upsell-sidebar',
'shortlinks-insights-upsell-metabox-text_formality' => 'https://yoa.st/formality-upsell-metabox',
'shortlinks-insights-upsell-elementor-text_formality' => 'https://yoa.st/formality-upsell-elementor',
'shortlinks-insights-text_formality_info_free' => 'https://yoa.st/formality-free',
'shortlinks-insights-text_formality_info_premium' => 'https://yoa.st/formality',
];
/**
* Registers all hooks to WordPress.
*
* @return void
*/
public function register_hooks() {
add_filter( 'wpseo_admin_l10n', [ $this, 'expose_shortlinks' ] );
}
/**
* Adds shortlinks to the passed array.
*
* @param array $input The array to add shortlinks to.
*
* @return array The passed array with the additional shortlinks.
*/
public function expose_shortlinks( $input ) {
foreach ( $this->get_shortlinks() as $key => $shortlink ) {
$input[ $key ] = WPSEO_Shortlinker::get( $shortlink );
}
$input['default_query_params'] = WPSEO_Shortlinker::get_query_params();
return $input;
}
/**
* Retrieves the shortlinks.
*
* @return array The shortlinks.
*/
private function get_shortlinks() {
if ( ! $this->is_term_edit() ) {
return $this->shortlinks;
}
$shortlinks = $this->shortlinks;
$shortlinks['shortlinks.upsell.metabox.focus_keyword_synonyms_button'] = 'https://yoa.st/keyword-synonyms-popup-term';
$shortlinks['shortlinks.upsell.metabox.focus_keyword_additional_button'] = 'https://yoa.st/add-keywords-popup-term';
$shortlinks['shortlinks.upsell.metabox.additional_link'] = 'https://yoa.st/textlink-keywords-metabox-term';
$shortlinks['shortlinks.upsell.metabox.additional_button'] = 'https://yoa.st/add-keywords-metabox-term';
$shortlinks['shortlinks.upsell.sidebar.morphology_upsell_metabox'] = 'https://yoa.st/morphology-upsell-metabox-term';
$shortlinks['shortlinks.upsell.metabox.keyphrase_distribution'] = 'https://yoa.st/keyphrase-distribution-metabox-term';
$shortlinks['shortlinks.upsell.metabox.word_complexity'] = 'https://yoa.st/word-complexity-metabox-term';
$shortlinks['shortlinks.upsell.metabox.internal_linking_suggestions'] = 'https://yoa.st/internal-linking-suggestions-metabox-term';
return $shortlinks;
}
/**
* Checks if the current page is a term edit page.
*
* @return bool True when page is term edit.
*/
private function is_term_edit() {
global $pagenow;
return WPSEO_Taxonomy::is_term_edit( $pagenow );
}
}

View File

@@ -1,107 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Gutenberg_Compatibility
*/
/**
* Class WPSEO_Gutenberg_Compatibility
*/
class WPSEO_Gutenberg_Compatibility {
/**
* The currently released version of Gutenberg.
*
* @var string
*/
const CURRENT_RELEASE = '16.8.1';
/**
* The minimally supported version of Gutenberg by the plugin.
*
* @var string
*/
const MINIMUM_SUPPORTED = '16.8.1';
/**
* Holds the current version.
*
* @var string
*/
protected $current_version = '';
/**
* WPSEO_Gutenberg_Compatibility constructor.
*/
public function __construct() {
$this->current_version = $this->detect_installed_gutenberg_version();
}
/**
* Determines whether or not Gutenberg is installed.
*
* @return bool Whether or not Gutenberg is installed.
*/
public function is_installed() {
return $this->current_version !== '';
}
/**
* Determines whether or not the currently installed version of Gutenberg is below the minimum supported version.
*
* @return bool True if the currently installed version is below the minimum supported version. False otherwise.
*/
public function is_below_minimum() {
return version_compare( $this->current_version, $this->get_minimum_supported_version(), '<' );
}
/**
* Gets the currently installed version.
*
* @return string The currently installed version.
*/
public function get_installed_version() {
return $this->current_version;
}
/**
* Determines whether or not the currently installed version of Gutenberg is the latest, fully compatible version.
*
* @return bool Whether or not the currently installed version is fully compatible.
*/
public function is_fully_compatible() {
return version_compare( $this->current_version, $this->get_latest_release(), '>=' );
}
/**
* Gets the latest released version of Gutenberg.
*
* @return string The latest release.
*/
protected function get_latest_release() {
return self::CURRENT_RELEASE;
}
/**
* Gets the minimum supported version of Gutenberg.
*
* @return string The minumum supported release.
*/
protected function get_minimum_supported_version() {
return self::MINIMUM_SUPPORTED;
}
/**
* Detects the currently installed Gutenberg version.
*
* @return string The currently installed Gutenberg version. Empty if the version couldn't be detected.
*/
protected function detect_installed_gutenberg_version() {
if ( defined( 'GUTENBERG_VERSION' ) ) {
return GUTENBERG_VERSION;
}
return '';
}
}

View File

@@ -1,265 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Class WPSEO_HelpScout
*/
class WPSEO_HelpScout implements WPSEO_WordPress_Integration {
/**
* The id for the beacon.
*
* @var string
*/
protected $beacon_id;
/**
* The pages where the beacon is loaded.
*
* @var array
*/
protected $pages;
/**
* The products the beacon is loaded for.
*
* @var array
*/
protected $products;
/**
* Whether to asks the user's consent before loading in HelpScout.
*
* @var bool
*/
protected $ask_consent;
/**
* WPSEO_HelpScout constructor.
*
* @param string $beacon_id The beacon id.
* @param array $pages The pages where the beacon is loaded.
* @param array $products The products the beacon is loaded for.
* @param bool $ask_consent Optional. Whether to ask for consent before loading in HelpScout.
*/
public function __construct( $beacon_id, array $pages, array $products, $ask_consent = false ) {
$this->beacon_id = $beacon_id;
$this->pages = $pages;
$this->products = $products;
$this->ask_consent = $ask_consent;
}
/**
* {@inheritDoc}
*/
public function register_hooks() {
if ( ! $this->is_beacon_page() ) {
return;
}
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_help_scout_script' ] );
add_action( 'admin_footer', [ $this, 'output_beacon_js' ] );
}
/**
* Enqueues the HelpScout script.
*/
public function enqueue_help_scout_script() {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_script( 'help-scout-beacon' );
}
/**
* Outputs a small piece of javascript for the beacon.
*/
public function output_beacon_js() {
printf(
'<script type="text/javascript">window.%1$s(\'%2$s\', %3$s)</script>',
( $this->ask_consent ) ? 'wpseoHelpScoutBeaconConsent' : 'wpseoHelpScoutBeacon',
esc_html( $this->beacon_id ),
WPSEO_Utils::format_json_encode( $this->get_session_data() )
);
}
/**
* Checks if the current page is a page containing the beacon.
*
* @return bool
*/
private function is_beacon_page() {
return in_array( $this->get_current_page(), $this->pages, true );
}
/**
* Retrieves the value of the current page.
*
* @return string The current page.
*/
private function get_current_page() {
$page = filter_input( INPUT_GET, 'page' );
if ( isset( $page ) && $page !== false ) {
return $page;
}
return '';
}
/**
* Retrieves the identifying data.
*
* @return string The data to pass as identifying data.
*/
protected function get_session_data() {
/** @noinspection PhpUnusedLocalVariableInspection */
// Do not make these strings translatable! They are for our support agents, the user won't see them!
$current_user = wp_get_current_user();
$data = [
'name' => trim( $current_user->user_firstname . ' ' . $current_user->user_lastname ),
'email' => $current_user->user_email,
'WordPress Version' => $this->get_wordpress_version(),
'Server' => $this->get_server_info(),
'<a href="' . admin_url( 'themes.php' ) . '">Theme</a>' => $this->get_theme_info(),
'<a href="' . admin_url( 'plugins.php' ) . '">Plugins</a>' => $this->get_active_plugins(),
];
if ( ! empty( $this->products ) ) {
$addon_manager = new WPSEO_Addon_Manager();
foreach ( $this->products as $product ) {
$subscription = $addon_manager->get_subscription( $product );
if ( ! $subscription ) {
continue;
}
$data[ $subscription->product->name ] = $this->get_product_info( $subscription );
}
}
return WPSEO_Utils::format_json_encode( $data );
}
/**
* Returns basic info about the server software.
*
* @return string
*/
private function get_server_info() {
$server_tracking_data = new WPSEO_Tracking_Server_Data();
$server_data = $server_tracking_data->get();
$server_data = $server_data['server'];
$fields_to_use = [
'IP' => 'ip',
'Hostname' => 'Hostname',
'OS' => 'os',
'PHP' => 'PhpVersion',
'CURL' => 'CurlVersion',
];
$server_data['CurlVersion'] = $server_data['CurlVersion']['version'] . '(SSL Support' . $server_data['CurlVersion']['sslSupport'] . ')';
$server_info = '<table>';
foreach ( $fields_to_use as $label => $field_to_use ) {
if ( isset( $server_data[ $field_to_use ] ) ) {
$server_info .= sprintf( '<tr><td>%1$s</td><td>%2$s</td></tr>', esc_html( $label ), esc_html( $server_data[ $field_to_use ] ) );
}
}
$server_info .= '</table>';
return $server_info;
}
/**
* Returns info about the Yoast SEO plugin version and license.
*
* @param object $plugin The plugin.
*
* @return string The product info.
*/
private function get_product_info( $plugin ) {
if ( empty( $plugin ) ) {
return '';
}
$product_info = '<table>';
$product_info .= '<tr><td>Version</td><td>' . $plugin->product->version . '</td></tr>';
$product_info .= '<tr><td>Expiration date</td><td>' . $plugin->expiry_date . '</td></tr>';
$product_info .= '</table>';
return $product_info;
}
/**
* Returns the WordPress version + a suffix if current WP is multi site.
*
* @return string The WordPress version string.
*/
private function get_wordpress_version() {
global $wp_version;
$wordpress_version = $wp_version;
if ( is_multisite() ) {
$wordpress_version .= ' MULTI-SITE';
}
return $wordpress_version;
}
/**
* Returns a formatted HTML string for the current theme.
*
* @return string The theme info as string.
*/
private function get_theme_info() {
$theme = wp_get_theme();
$theme_info = sprintf(
'<a href="%1$s">%2$s</a> v%3$s by %4$s',
esc_attr( $theme->display( 'ThemeURI' ) ),
esc_html( $theme->display( 'Name' ) ),
esc_html( $theme->display( 'Version' ) ),
esc_html( $theme->display( 'Author' ) )
);
if ( is_child_theme() ) {
$theme_info .= sprintf( '<br />Child theme of: %1$s', esc_html( $theme->display( 'Template' ) ) );
}
return $theme_info;
}
/**
* Returns a formatted HTML list of all active plugins.
*
* @return string The active plugins.
*/
private function get_active_plugins() {
$updates_available = get_site_transient( 'update_plugins' );
$active_plugins = '';
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
$plugin_data = get_plugin_data( $plugin );
$plugin_file = str_replace( trailingslashit( WP_PLUGIN_DIR ), '', $plugin );
if ( isset( $updates_available->response[ $plugin_file ] ) ) {
$active_plugins .= '<i class="icon-close1"></i> ';
}
$active_plugins .= sprintf(
'<a href="%1$s">%2$s</a> v%3$s',
esc_attr( $plugin_data['PluginURI'] ),
esc_html( $plugin_data['Name'] ),
esc_html( $plugin_data['Version'] )
);
}
return $active_plugins;
}
}

View File

@@ -1,832 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
use Yoast\WP\SEO\Context\Meta_Tags_Context;
use Yoast\WP\SEO\Helpers\Score_Icon_Helper;
use Yoast\WP\SEO\Integrations\Admin\Admin_Columns_Cache_Integration;
use Yoast\WP\SEO\Surfaces\Values\Meta;
/**
* Class WPSEO_Meta_Columns.
*/
class WPSEO_Meta_Columns {
/**
* Holds the context objects for each indexable.
*
* @var Meta_Tags_Context[]
*/
protected $context = [];
/**
* Holds the SEO analysis.
*
* @var WPSEO_Metabox_Analysis_SEO
*/
private $analysis_seo;
/**
* Holds the readability analysis.
*
* @var WPSEO_Metabox_Analysis_Readability
*/
private $analysis_readability;
/**
* Admin columns cache.
*
* @var Admin_Columns_Cache_Integration
*/
private $admin_columns_cache;
/**
* Holds the Score_Icon_Helper.
*
* @var Score_Icon_Helper
*/
private $score_icon_helper;
/**
* When page analysis is enabled, just initialize the hooks.
*/
public function __construct() {
if ( apply_filters( 'wpseo_use_page_analysis', true ) === true ) {
add_action( 'admin_init', [ $this, 'setup_hooks' ] );
}
$this->analysis_seo = new WPSEO_Metabox_Analysis_SEO();
$this->analysis_readability = new WPSEO_Metabox_Analysis_Readability();
$this->admin_columns_cache = YoastSEO()->classes->get( Admin_Columns_Cache_Integration::class );
$this->score_icon_helper = YoastSEO()->helpers->score_icon;
}
/**
* Sets up up the hooks.
*/
public function setup_hooks() {
$this->set_post_type_hooks();
if ( $this->analysis_seo->is_enabled() ) {
add_action( 'restrict_manage_posts', [ $this, 'posts_filter_dropdown' ] );
}
if ( $this->analysis_readability->is_enabled() ) {
add_action( 'restrict_manage_posts', [ $this, 'posts_filter_dropdown_readability' ] );
}
add_filter( 'request', [ $this, 'column_sort_orderby' ] );
add_filter( 'default_hidden_columns', [ $this, 'column_hidden' ], 10, 1 );
}
/**
* Adds the column headings for the SEO plugin for edit posts / pages overview.
*
* @param array $columns Already existing columns.
*
* @return array Array containing the column headings.
*/
public function column_heading( $columns ) {
if ( $this->display_metabox() === false ) {
return $columns;
}
$added_columns = [];
if ( $this->analysis_seo->is_enabled() ) {
$added_columns['wpseo-score'] = '<span class="yoast-column-seo-score yoast-column-header-has-tooltip" data-tooltip-text="' .
esc_attr__( 'SEO score', 'wordpress-seo' ) .
'"><span class="screen-reader-text">' .
__( 'SEO score', 'wordpress-seo' ) .
'</span></span></span>';
}
if ( $this->analysis_readability->is_enabled() ) {
$added_columns['wpseo-score-readability'] = '<span class="yoast-column-readability yoast-column-header-has-tooltip" data-tooltip-text="' .
esc_attr__( 'Readability score', 'wordpress-seo' ) .
'"><span class="screen-reader-text">' .
__( 'Readability score', 'wordpress-seo' ) .
'</span></span></span>';
}
$added_columns['wpseo-title'] = __( 'SEO Title', 'wordpress-seo' );
$added_columns['wpseo-metadesc'] = __( 'Meta Desc.', 'wordpress-seo' );
if ( $this->analysis_seo->is_enabled() ) {
$added_columns['wpseo-focuskw'] = __( 'Keyphrase', 'wordpress-seo' );
}
return array_merge( $columns, $added_columns );
}
/**
* Displays the column content for the given column.
*
* @param string $column_name Column to display the content for.
* @param int $post_id Post to display the column content for.
*/
public function column_content( $column_name, $post_id ) {
if ( $this->display_metabox() === false ) {
return;
}
switch ( $column_name ) {
case 'wpseo-score':
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Correctly escaped in render_score_indicator() method.
echo $this->parse_column_score( $post_id );
return;
case 'wpseo-score-readability':
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Correctly escaped in render_score_indicator() method.
echo $this->parse_column_score_readability( $post_id );
return;
case 'wpseo-title':
$meta = $this->get_meta( $post_id );
if ( $meta ) {
echo esc_html( $meta->title );
}
return;
case 'wpseo-metadesc':
$metadesc_val = '';
$meta = $this->get_meta( $post_id );
if ( $meta ) {
$metadesc_val = $meta->meta_description;
}
if ( $metadesc_val === '' ) {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">',
/* translators: Hidden accessibility text. */
esc_html__( 'Meta description not set.', 'wordpress-seo' ),
'</span>';
return;
}
echo esc_html( $metadesc_val );
return;
case 'wpseo-focuskw':
$focuskw_val = WPSEO_Meta::get_value( 'focuskw', $post_id );
if ( $focuskw_val === '' ) {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">',
/* translators: Hidden accessibility text. */
esc_html__( 'Focus keyphrase not set.', 'wordpress-seo' ),
'</span>';
return;
}
echo esc_html( $focuskw_val );
return;
}
}
/**
* Indicates which of the SEO columns are sortable.
*
* @param array $columns Appended with their orderby variable.
*
* @return array Array containing the sortable columns.
*/
public function column_sort( $columns ) {
if ( $this->display_metabox() === false ) {
return $columns;
}
$columns['wpseo-metadesc'] = 'wpseo-metadesc';
if ( $this->analysis_seo->is_enabled() ) {
$columns['wpseo-focuskw'] = 'wpseo-focuskw';
$columns['wpseo-score'] = 'wpseo-score';
}
if ( $this->analysis_readability->is_enabled() ) {
$columns['wpseo-score-readability'] = 'wpseo-score-readability';
}
return $columns;
}
/**
* Hides the SEO title, meta description and focus keyword columns if the user hasn't chosen which columns to hide.
*
* @param array $hidden The hidden columns.
*
* @return array Array containing the columns to hide.
*/
public function column_hidden( $hidden ) {
if ( ! is_array( $hidden ) ) {
$hidden = [];
}
array_push( $hidden, 'wpseo-title', 'wpseo-metadesc' );
if ( $this->analysis_seo->is_enabled() ) {
$hidden[] = 'wpseo-focuskw';
}
return $hidden;
}
/**
* Adds a dropdown that allows filtering on the posts SEO Quality.
*/
public function posts_filter_dropdown() {
if ( ! $this->can_display_filter() ) {
return;
}
$ranks = WPSEO_Rank::get_all_ranks();
/* translators: Hidden accessibility text. */
echo '<label class="screen-reader-text" for="wpseo-filter">' . esc_html__( 'Filter by SEO Score', 'wordpress-seo' ) . '</label>';
echo '<select name="seo_filter" id="wpseo-filter">';
// phpcs:ignore WordPress.Security.EscapeOutput -- Output is correctly escaped in the generate_option() method.
echo $this->generate_option( '', __( 'All SEO Scores', 'wordpress-seo' ) );
foreach ( $ranks as $rank ) {
$selected = selected( $this->get_current_seo_filter(), $rank->get_rank(), false );
// phpcs:ignore WordPress.Security.EscapeOutput -- Output is correctly escaped in the generate_option() method.
echo $this->generate_option( $rank->get_rank(), $rank->get_drop_down_label(), $selected );
}
echo '</select>';
}
/**
* Adds a dropdown that allows filtering on the posts Readability Quality.
*
* @return void
*/
public function posts_filter_dropdown_readability() {
if ( ! $this->can_display_filter() ) {
return;
}
$ranks = WPSEO_Rank::get_all_readability_ranks();
/* translators: Hidden accessibility text. */
echo '<label class="screen-reader-text" for="wpseo-readability-filter">' . esc_html__( 'Filter by Readability Score', 'wordpress-seo' ) . '</label>';
echo '<select name="readability_filter" id="wpseo-readability-filter">';
// phpcs:ignore WordPress.Security.EscapeOutput -- Output is correctly escaped in the generate_option() method.
echo $this->generate_option( '', __( 'All Readability Scores', 'wordpress-seo' ) );
foreach ( $ranks as $rank ) {
$selected = selected( $this->get_current_readability_filter(), $rank->get_rank(), false );
// phpcs:ignore WordPress.Security.EscapeOutput -- Output is correctly escaped in the generate_option() method.
echo $this->generate_option( $rank->get_rank(), $rank->get_drop_down_readability_labels(), $selected );
}
echo '</select>';
}
/**
* Generates an <option> element.
*
* @param string $value The option's value.
* @param string $label The option's label.
* @param string $selected HTML selected attribute for an option.
*
* @return string The generated <option> element.
*/
protected function generate_option( $value, $label, $selected = '' ) {
return '<option ' . $selected . ' value="' . esc_attr( $value ) . '">' . esc_html( $label ) . '</option>';
}
/**
* Returns the meta object for a given post ID.
*
* @param int $post_id The post ID.
*
* @return Meta The meta object.
*/
protected function get_meta( $post_id ) {
$indexable = $this->admin_columns_cache->get_indexable( $post_id );
return YoastSEO()->meta->for_indexable( $indexable, 'Post_Type' );
}
/**
* Determines the SEO score filter to be later used in the meta query, based on the passed SEO filter.
*
* @param string $seo_filter The SEO filter to use to determine what further filter to apply.
*
* @return array The SEO score filter.
*/
protected function determine_seo_filters( $seo_filter ) {
if ( $seo_filter === WPSEO_Rank::NO_FOCUS ) {
return $this->create_no_focus_keyword_filter();
}
if ( $seo_filter === WPSEO_Rank::NO_INDEX ) {
return $this->create_no_index_filter();
}
$rank = new WPSEO_Rank( $seo_filter );
return $this->create_seo_score_filter( $rank->get_starting_score(), $rank->get_end_score() );
}
/**
* Determines the Readability score filter to the meta query, based on the passed Readability filter.
*
* @param string $readability_filter The Readability filter to use to determine what further filter to apply.
*
* @return array The Readability score filter.
*/
protected function determine_readability_filters( $readability_filter ) {
$rank = new WPSEO_Rank( $readability_filter );
return $this->create_readability_score_filter( $rank->get_starting_score(), $rank->get_end_score() );
}
/**
* Creates a keyword filter for the meta query, based on the passed Keyword filter.
*
* @param string $keyword_filter The keyword filter to use.
*
* @return array The keyword filter.
*/
protected function get_keyword_filter( $keyword_filter ) {
return [
'post_type' => get_query_var( 'post_type', 'post' ),
'key' => WPSEO_Meta::$meta_prefix . 'focuskw',
'value' => sanitize_text_field( $keyword_filter ),
];
}
/**
* Determines whether the passed filter is considered to be valid.
*
* @param mixed $filter The filter to check against.
*
* @return bool Whether the filter is considered valid.
*/
protected function is_valid_filter( $filter ) {
return ! empty( $filter ) && is_string( $filter );
}
/**
* Collects the filters and merges them into a single array.
*
* @return array Array containing all the applicable filters.
*/
protected function collect_filters() {
$active_filters = [];
$seo_filter = $this->get_current_seo_filter();
$readability_filter = $this->get_current_readability_filter();
$current_keyword_filter = $this->get_current_keyword_filter();
if ( $this->is_valid_filter( $seo_filter ) ) {
$active_filters = array_merge(
$active_filters,
$this->determine_seo_filters( $seo_filter )
);
}
if ( $this->is_valid_filter( $readability_filter ) ) {
$active_filters = array_merge(
$active_filters,
$this->determine_readability_filters( $readability_filter )
);
}
if ( $this->is_valid_filter( $current_keyword_filter ) ) {
/**
* Adapt the meta query used to filter the post overview on keyphrase.
*
* @internal
*
* @api array $keyword_filter The current keyword filter.
*
* @param array $keyphrase The keyphrase used in the filter.
*/
$keyphrase_filter = \apply_filters(
'wpseo_change_keyphrase_filter_in_request',
$this->get_keyword_filter( $current_keyword_filter ),
$current_keyword_filter
);
if ( \is_array( $keyphrase_filter ) ) {
$active_filters = array_merge(
$active_filters,
[ $keyphrase_filter ]
);
}
}
/**
* Adapt the active applicable filters on the posts overview.
*
* @internal
*
* @param array $active_filters The current applicable filters.
*/
return \apply_filters( 'wpseo_change_applicable_filters', $active_filters );
}
/**
* Modify the query based on the filters that are being passed.
*
* @param array $vars Query variables that need to be modified based on the filters.
*
* @return array Array containing the meta query to use for filtering the posts overview.
*/
public function column_sort_orderby( $vars ) {
$collected_filters = $this->collect_filters();
$order_by_column = $vars['orderby'];
if ( isset( $order_by_column ) ) {
// Based on the selected column, create a meta query.
$order_by = $this->filter_order_by( $order_by_column );
/**
* Adapt the order by part of the query on the posts overview.
*
* @internal
*
* @param array $order_by The current order by.
* @param string $order_by_column The current order by column.
*/
$order_by = \apply_filters( 'wpseo_change_order_by', $order_by, $order_by_column );
$vars = array_merge( $vars, $order_by );
}
return $this->build_filter_query( $vars, $collected_filters );
}
/**
* Retrieves the meta robots query values to be used within the meta query.
*
* @return array Array containing the query parameters regarding meta robots.
*/
protected function get_meta_robots_query_values() {
return [
'relation' => 'OR',
[
'key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',
'compare' => 'NOT EXISTS',
],
[
'key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',
'value' => '1',
'compare' => '!=',
],
];
}
/**
* Determines the score filters to be used. If more than one is passed, it created an AND statement for the query.
*
* @param array $score_filters Array containing the score filters.
*
* @return array Array containing the score filters that need to be applied to the meta query.
*/
protected function determine_score_filters( $score_filters ) {
if ( count( $score_filters ) > 1 ) {
return array_merge( [ 'relation' => 'AND' ], $score_filters );
}
return $score_filters;
}
/**
* Retrieves the post type from the $_GET variable.
*
* @return string|null The sanitized current post type or null when the variable is not set in $_GET.
*/
public function get_current_post_type() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['post_type'] ) && is_string( $_GET['post_type'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
return sanitize_text_field( wp_unslash( $_GET['post_type'] ) );
}
return null;
}
/**
* Retrieves the SEO filter from the $_GET variable.
*
* @return string|null The sanitized seo filter or null when the variable is not set in $_GET.
*/
public function get_current_seo_filter() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['seo_filter'] ) && is_string( $_GET['seo_filter'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
return sanitize_text_field( wp_unslash( $_GET['seo_filter'] ) );
}
return null;
}
/**
* Retrieves the Readability filter from the $_GET variable.
*
* @return string|null The sanitized readability filter or null when the variable is not set in $_GET.
*/
public function get_current_readability_filter() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['readability_filter'] ) && is_string( $_GET['readability_filter'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
return sanitize_text_field( wp_unslash( $_GET['readability_filter'] ) );
}
return null;
}
/**
* Retrieves the keyword filter from the $_GET variable.
*
* @return string|null The sanitized seo keyword filter or null when the variable is not set in $_GET.
*/
public function get_current_keyword_filter() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['seo_kw_filter'] ) && is_string( $_GET['seo_kw_filter'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
return sanitize_text_field( wp_unslash( $_GET['seo_kw_filter'] ) );
}
return null;
}
/**
* Uses the vars to create a complete filter query that can later be executed to filter out posts.
*
* @param array $vars Array containing the variables that will be used in the meta query.
* @param array $filters Array containing the filters that we need to apply in the meta query.
*
* @return array Array containing the complete filter query.
*/
protected function build_filter_query( $vars, $filters ) {
// If no filters were applied, just return everything.
if ( count( $filters ) === 0 ) {
return $vars;
}
$result = [ 'meta_query' => [] ];
$result['meta_query'] = array_merge( $result['meta_query'], [ $this->determine_score_filters( $filters ) ] );
$current_seo_filter = $this->get_current_seo_filter();
// This only applies for the SEO score filter because it can because the SEO score can be altered by the no-index option.
if ( $this->is_valid_filter( $current_seo_filter ) && ! in_array( $current_seo_filter, [ WPSEO_Rank::NO_INDEX, WPSEO_Rank::NO_FOCUS ], true ) ) {
$result['meta_query'] = array_merge( $result['meta_query'], [ $this->get_meta_robots_query_values() ] );
}
return array_merge( $vars, $result );
}
/**
* Creates a Readability score filter.
*
* @param number $low The lower boundary of the score.
* @param number $high The higher boundary of the score.
*
* @return array The Readability Score filter.
*/
protected function create_readability_score_filter( $low, $high ) {
return [
[
'key' => WPSEO_Meta::$meta_prefix . 'content_score',
'value' => [ $low, $high ],
'type' => 'numeric',
'compare' => 'BETWEEN',
],
];
}
/**
* Creates an SEO score filter.
*
* @param number $low The lower boundary of the score.
* @param number $high The higher boundary of the score.
*
* @return array The SEO score filter.
*/
protected function create_seo_score_filter( $low, $high ) {
return [
[
'key' => WPSEO_Meta::$meta_prefix . 'linkdex',
'value' => [ $low, $high ],
'type' => 'numeric',
'compare' => 'BETWEEN',
],
];
}
/**
* Creates a filter to retrieve posts that were set to no-index.
*
* @return array Array containin the no-index filter.
*/
protected function create_no_index_filter() {
return [
[
'key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',
'value' => '1',
'compare' => '=',
],
];
}
/**
* Creates a filter to retrieve posts that have no keyword set.
*
* @return array Array containing the no focus keyword filter.
*/
protected function create_no_focus_keyword_filter() {
return [
[
'key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',
'value' => 'needs-a-value-anyway',
'compare' => 'NOT EXISTS',
],
[
'key' => WPSEO_Meta::$meta_prefix . 'linkdex',
'value' => 'needs-a-value-anyway',
'compare' => 'NOT EXISTS',
],
];
}
/**
* Determines whether a particular post_id is of an indexable post type.
*
* @param string $post_id The post ID to check.
*
* @return bool Whether or not it is indexable.
*/
protected function is_indexable( $post_id ) {
if ( ! empty( $post_id ) && ! $this->uses_default_indexing( $post_id ) ) {
return WPSEO_Meta::get_value( 'meta-robots-noindex', $post_id ) === '2';
}
$post = get_post( $post_id );
if ( is_object( $post ) ) {
// If the option is false, this means we want to index it.
return WPSEO_Options::get( 'noindex-' . $post->post_type, false ) === false;
}
return true;
}
/**
* Determines whether the given post ID uses the default indexing settings.
*
* @param int $post_id The post ID to check.
*
* @return bool Whether or not the default indexing is being used for the post.
*/
protected function uses_default_indexing( $post_id ) {
return WPSEO_Meta::get_value( 'meta-robots-noindex', $post_id ) === '0';
}
/**
* Returns filters when $order_by is matched in the if-statement.
*
* @param string $order_by The ID of the column by which to order the posts.
*
* @return array Array containing the order filters.
*/
private function filter_order_by( $order_by ) {
switch ( $order_by ) {
case 'wpseo-metadesc':
return [
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Reason: Only used when user requests sorting.
'meta_key' => WPSEO_Meta::$meta_prefix . 'metadesc',
'orderby' => 'meta_value',
];
case 'wpseo-focuskw':
return [
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Reason: Only used when user requests sorting.
'meta_key' => WPSEO_Meta::$meta_prefix . 'focuskw',
'orderby' => 'meta_value',
];
case 'wpseo-score':
return [
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Reason: Only used when user requests sorting.
'meta_key' => WPSEO_Meta::$meta_prefix . 'linkdex',
'orderby' => 'meta_value_num',
];
case 'wpseo-score-readability':
return [
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Reason: Only used when user requests sorting.
'meta_key' => WPSEO_Meta::$meta_prefix . 'content_score',
'orderby' => 'meta_value_num',
];
}
return [];
}
/**
* Parses the score column.
*
* @param int $post_id The ID of the post for which to show the score.
*
* @return string The HTML for the SEO score indicator.
*/
private function parse_column_score( $post_id ) {
$meta = $this->get_meta( $post_id );
if ( $meta ) {
return $this->score_icon_helper->for_seo( $meta->indexable, '', __( 'Post is set to noindex.', 'wordpress-seo' ) );
}
}
/**
* Parsing the readability score column.
*
* @param int $post_id The ID of the post for which to show the readability score.
*
* @return string The HTML for the readability score indicator.
*/
private function parse_column_score_readability( $post_id ) {
$meta = $this->get_meta( $post_id );
if ( $meta ) {
return $this->score_icon_helper->for_readability( $meta->indexable->readability_score );
}
}
/**
* Sets up the hooks for the post_types.
*/
private function set_post_type_hooks() {
$post_types = WPSEO_Post_Type::get_accessible_post_types();
if ( ! is_array( $post_types ) || $post_types === [] ) {
return;
}
foreach ( $post_types as $post_type ) {
if ( $this->display_metabox( $post_type ) === false ) {
continue;
}
add_filter( 'manage_' . $post_type . '_posts_columns', [ $this, 'column_heading' ], 10, 1 );
add_action( 'manage_' . $post_type . '_posts_custom_column', [ $this, 'column_content' ], 10, 2 );
add_action( 'manage_edit-' . $post_type . '_sortable_columns', [ $this, 'column_sort' ], 10, 2 );
}
unset( $post_type );
}
/**
* Wraps the WPSEO_Metabox check to determine whether the metabox should be displayed either by
* choice of the admin or because the post type is not a public post type.
*
* @since 7.0
*
* @param string|null $post_type Optional. The post type to test, defaults to the current post post_type.
*
* @return bool Whether or not the meta box (and associated columns etc) should be hidden.
*/
private function display_metabox( $post_type = null ) {
$current_post_type = $this->get_current_post_type();
if ( ! isset( $post_type ) && ! empty( $current_post_type ) ) {
$post_type = $current_post_type;
}
return WPSEO_Utils::is_metabox_active( $post_type, 'post_type' );
}
/**
* Determines whether or not filter dropdowns should be displayed.
*
* @return bool Whether or the current page can display the filter drop downs.
*/
public function can_display_filter() {
if ( $GLOBALS['pagenow'] === 'upload.php' ) {
return false;
}
if ( $this->display_metabox() === false ) {
return false;
}
$screen = get_current_screen();
if ( $screen === null ) {
return false;
}
return WPSEO_Post_Type::is_post_type_accessible( $screen->post_type );
}
}

View File

@@ -1,219 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Loads the MyYoast proxy.
*
* This class registers a proxy page on `admin.php`. Which is reached with the `page=PAGE_IDENTIFIER` parameter.
* It will read external files and serves them like they are located locally.
*/
class WPSEO_MyYoast_Proxy implements WPSEO_WordPress_Integration {
/**
* The page identifier used in WordPress to register the MyYoast proxy page.
*
* @var string
*/
const PAGE_IDENTIFIER = 'wpseo_myyoast_proxy';
/**
* The cache control's max age. Used in the header of a successful proxy response.
*
* @var int
*/
const CACHE_CONTROL_MAX_AGE = DAY_IN_SECONDS;
/**
* Registers the hooks when the user is on the right page.
*
* @codeCoverageIgnore
*
* @return void
*/
public function register_hooks() {
if ( ! $this->is_proxy_page() ) {
return;
}
// Register the page for the proxy.
add_action( 'admin_menu', [ $this, 'add_proxy_page' ] );
add_action( 'admin_init', [ $this, 'handle_proxy_page' ] );
}
/**
* Registers the proxy page. It does not actually add a link to the dashboard.
*
* @codeCoverageIgnore
*
* @return void
*/
public function add_proxy_page() {
add_dashboard_page( '', '', 'read', self::PAGE_IDENTIFIER, '' );
}
/**
* Renders the requested proxy page and exits to prevent the WordPress UI from loading.
*
* @codeCoverageIgnore
*
* @return void
*/
public function handle_proxy_page() {
$this->render_proxy_page();
// Prevent the WordPress UI from loading.
exit;
}
/**
* Renders the requested proxy page.
*
* This is separated from the exits to be able to test it.
*
* @return void
*/
public function render_proxy_page() {
$proxy_options = $this->determine_proxy_options();
if ( $proxy_options === [] ) {
// Do not accept any other file than implemented.
$this->set_header( 'HTTP/1.0 501 Requested file not implemented' );
return;
}
// Set the headers before serving the remote file.
$this->set_header( 'Content-Type: ' . $proxy_options['content_type'] );
$this->set_header( 'Cache-Control: max-age=' . self::CACHE_CONTROL_MAX_AGE );
try {
echo $this->get_remote_url_body( $proxy_options['url'] );
}
catch ( Exception $e ) {
/*
* Reset the file headers because the loading failed.
*
* Note: Due to supporting PHP 5.2 `header_remove` can not be used here.
* Overwrite the headers instead.
*/
$this->set_header( 'Content-Type: text/plain' );
$this->set_header( 'Cache-Control: max-age=0' );
$this->set_header( 'HTTP/1.0 500 ' . $e->getMessage() );
}
}
/**
* Tries to load the given url via `wp_remote_get`.
*
* @codeCoverageIgnore
*
* @param string $url The url to load.
*
* @return string The body of the response.
*
* @throws Exception When `wp_remote_get` returned an error.
* @throws Exception When the response code is not 200.
*/
protected function get_remote_url_body( $url ) {
$response = wp_remote_get( $url );
if ( $response instanceof WP_Error ) {
throw new Exception( 'Unable to retrieve file from MyYoast' );
}
if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
throw new Exception( 'Received unexpected response from MyYoast' );
}
return wp_remote_retrieve_body( $response );
}
/**
* Determines the proxy options based on the file and plugin version arguments.
*
* When the file is known it returns an array like this:
* <code>
* $array = array(
* 'content_type' => 'the content type'
* 'url' => 'the url, possibly with the plugin version'
* )
* </code>
*
* @return array Empty for an unknown file. See format above for known files.
*/
protected function determine_proxy_options() {
if ( $this->get_proxy_file() === 'research-webworker' ) {
return [
'content_type' => 'text/javascript; charset=UTF-8',
'url' => 'https://my.yoast.com/api/downloads/file/analysis-worker?plugin_version=' . $this->get_plugin_version(),
];
}
return [];
}
/**
* Checks if the current page is the MyYoast proxy page.
*
* @codeCoverageIgnore
*
* @return bool True when the page request parameter equals the proxy page.
*/
protected function is_proxy_page() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$page = isset( $_GET['page'] ) && is_string( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
return $page === self::PAGE_IDENTIFIER;
}
/**
* Returns the proxy file from the HTTP request parameters.
*
* @codeCoverageIgnore
*
* @return string The sanitized file request parameter or an empty string if it does not exist.
*/
protected function get_proxy_file() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['file'] ) && is_string( $_GET['file'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
return sanitize_text_field( wp_unslash( $_GET['file'] ) );
}
return '';
}
/**
* Returns the plugin version from the HTTP request parameters.
*
* @codeCoverageIgnore
*
* @return string The sanitized plugin_version request parameter or an empty string if it does not exist.
*/
protected function get_plugin_version() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['plugin_version'] ) && is_string( $_GET['plugin_version'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$plugin_version = sanitize_text_field( wp_unslash( $_GET['plugin_version'] ) );
// Replace slashes to secure against requiring a file from another path.
return str_replace( [ '/', '\\' ], '_', $plugin_version );
}
return '';
}
/**
* Sets the HTTP header.
*
* This is a tiny helper function to enable better testing.
*
* @codeCoverageIgnore
*
* @param string $header The header to set.
*
* @return void
*/
protected function set_header( $header ) {
header( $header );
}
}

View File

@@ -1,112 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Options\Tabs
*/
/**
* Class WPSEO_Option_Tab.
*/
class WPSEO_Option_Tab {
/**
* Name of the tab.
*
* @var string
*/
private $name;
/**
* Label of the tab.
*
* @var string
*/
private $label;
/**
* Optional arguments.
*
* @var array
*/
private $arguments;
/**
* WPSEO_Option_Tab constructor.
*
* @param string $name Name of the tab.
* @param string $label Localized label of the tab.
* @param array $arguments Optional arguments.
*/
public function __construct( $name, $label, array $arguments = [] ) {
$this->name = sanitize_title( $name );
$this->label = $label;
$this->arguments = $arguments;
}
/**
* Gets the name.
*
* @return string The name.
*/
public function get_name() {
return $this->name;
}
/**
* Gets the label.
*
* @return string The label.
*/
public function get_label() {
return $this->label;
}
/**
* Retrieves whether the tab needs a save button.
*
* @return bool True whether the tabs needs a save button.
*/
public function has_save_button() {
return (bool) $this->get_argument( 'save_button', true );
}
/**
* Retrieves whether the tab hosts beta functionalities.
*
* @return bool True whether the tab hosts beta functionalities.
*/
public function is_beta() {
return (bool) $this->get_argument( 'beta', false );
}
/**
* Retrieves whether the tab hosts premium functionalities.
*
* @return bool True whether the tab hosts premium functionalities.
*/
public function is_premium() {
return (bool) $this->get_argument( 'premium', false );
}
/**
* Gets the option group.
*
* @return string The option group.
*/
public function get_opt_group() {
return $this->get_argument( 'opt_group' );
}
/**
* Retrieves the variable from the supplied arguments.
*
* @param string $variable Variable to retrieve.
* @param string|mixed $default_value Default to use when variable not found.
*
* @return mixed|string The retrieved variable.
*/
protected function get_argument( $variable, $default_value = '' ) {
return array_key_exists( $variable, $this->arguments ) ? $this->arguments[ $variable ] : $default_value;
}
}

View File

@@ -1,92 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Options\Tabs
*/
use Yoast\WP\SEO\Presenters\Admin\Beta_Badge_Presenter;
use Yoast\WP\SEO\Presenters\Admin\Premium_Badge_Presenter;
/**
* Class WPSEO_Option_Tabs_Formatter.
*/
class WPSEO_Option_Tabs_Formatter {
/**
* Retrieves the path to the view of the tab.
*
* @param WPSEO_Option_Tabs $option_tabs Option Tabs to get base from.
* @param WPSEO_Option_Tab $tab Tab to get name from.
*
* @return string
*/
public function get_tab_view( WPSEO_Option_Tabs $option_tabs, WPSEO_Option_Tab $tab ) {
return WPSEO_PATH . 'admin/views/tabs/' . $option_tabs->get_base() . '/' . $tab->get_name() . '.php';
}
/**
* Outputs the option tabs.
*
* @param WPSEO_Option_Tabs $option_tabs Option Tabs to get tabs from.
*/
public function run( WPSEO_Option_Tabs $option_tabs ) {
echo '<h2 class="nav-tab-wrapper" id="wpseo-tabs">';
foreach ( $option_tabs->get_tabs() as $tab ) {
$label = esc_html( $tab->get_label() );
if ( $tab->is_beta() ) {
$label = '<span style="margin-right:4px;">' . $label . '</span>' . new Beta_Badge_Presenter( $tab->get_name() );
}
elseif ( $tab->is_premium() ) {
$label = '<span style="margin-right:4px;">' . $label . '</span>' . new Premium_Badge_Presenter( $tab->get_name() );
}
printf(
'<a class="nav-tab" id="%1$s" href="%2$s">%3$s</a>',
esc_attr( $tab->get_name() . '-tab' ),
esc_url( '#top#' . $tab->get_name() ),
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: we do this on purpose
$label
);
}
echo '</h2>';
foreach ( $option_tabs->get_tabs() as $tab ) {
$identifier = $tab->get_name();
$class = 'wpseotab ' . ( $tab->has_save_button() ? 'save' : 'nosave' );
printf( '<div id="%1$s" class="%2$s">', esc_attr( $identifier ), esc_attr( $class ) );
$tab_filter_name = sprintf( '%s_%s', $option_tabs->get_base(), $tab->get_name() );
/**
* Allows to override the content that is display on the specific option tab.
*
* @internal For internal Yoast SEO use only.
*
* @api string|null The content that should be displayed for this tab. Leave empty for default behaviour.
*
* @param WPSEO_Option_Tabs $option_tabs The registered option tabs.
* @param WPSEO_Option_Tab $tab The tab that is being displayed.
*/
$option_tab_content = apply_filters( 'wpseo_option_tab-' . $tab_filter_name, null, $option_tabs, $tab );
if ( ! empty( $option_tab_content ) ) {
echo wp_kses_post( $option_tab_content );
}
if ( empty( $option_tab_content ) ) {
// Output the settings view for all tabs.
$tab_view = $this->get_tab_view( $option_tabs, $tab );
if ( is_file( $tab_view ) ) {
$yform = Yoast_Form::get_instance();
require $tab_view;
}
}
echo '</div>';
}
}
}

View File

@@ -1,122 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Options\Tabs
*/
/**
* Class WPSEO_Option_Tabs.
*/
class WPSEO_Option_Tabs {
/**
* Tabs base.
*
* @var string
*/
private $base;
/**
* The tabs in this group.
*
* @var array
*/
private $tabs = [];
/**
* Name of the active tab.
*
* @var string
*/
private $active_tab = '';
/**
* WPSEO_Option_Tabs constructor.
*
* @codeCoverageIgnore
*
* @param string $base Base of the tabs.
* @param string $active_tab Currently active tab.
*/
public function __construct( $base, $active_tab = '' ) {
$this->base = sanitize_title( $base );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$tab = isset( $_GET['tab'] ) && is_string( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
$this->active_tab = empty( $tab ) ? $active_tab : $tab;
}
/**
* Get the base.
*
* @return string
*/
public function get_base() {
return $this->base;
}
/**
* Add a tab.
*
* @param WPSEO_Option_Tab $tab Tab to add.
*
* @return $this
*/
public function add_tab( WPSEO_Option_Tab $tab ) {
$this->tabs[] = $tab;
return $this;
}
/**
* Get active tab.
*
* @return WPSEO_Option_Tab|null Get the active tab.
*/
public function get_active_tab() {
if ( empty( $this->active_tab ) ) {
return null;
}
$active_tabs = array_filter( $this->tabs, [ $this, 'is_active_tab' ] );
if ( ! empty( $active_tabs ) ) {
$active_tabs = array_values( $active_tabs );
if ( count( $active_tabs ) === 1 ) {
return $active_tabs[0];
}
}
return null;
}
/**
* Is the tab the active tab.
*
* @param WPSEO_Option_Tab $tab Tab to check for active tab.
*
* @return bool
*/
public function is_active_tab( WPSEO_Option_Tab $tab ) {
return ( $tab->get_name() === $this->active_tab );
}
/**
* Get all tabs.
*
* @return WPSEO_Option_Tab[]
*/
public function get_tabs() {
return $this->tabs;
}
/**
* Display the tabs.
*
* @param Yoast_Form $yform Yoast Form needed in the views.
*/
public function display( Yoast_Form $yform ) {
$formatter = new WPSEO_Option_Tabs_Formatter();
$formatter->run( $this, $yform );
}
}

View File

@@ -1,141 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Class WPSEO_presenter_paper.
*/
class WPSEO_Paper_Presenter {
/**
* Title of the paper.
*
* @var string
*/
private $title;
/**
* The view variables.
*
* @var array
*/
private $settings;
/**
* The path to the view file.
*
* @var string
*/
private $view_file;
/**
* WPSEO_presenter_paper constructor.
*
* @param string $title The title of the paper.
* @param string|null $view_file Optional. The path to the view file. Use the content setting
* if do not wish to use a view file.
* @param array $settings Optional. Settings for the paper.
*/
public function __construct( $title, $view_file = null, array $settings = [] ) {
$defaults = [
'paper_id' => null,
'paper_id_prefix' => 'wpseo-',
'collapsible' => false,
'collapsible_header_class' => '',
'expanded' => false,
'help_text' => '',
'title_after' => '',
'class' => '',
'content' => '',
'view_data' => [],
];
$this->settings = wp_parse_args( $settings, $defaults );
$this->title = $title;
$this->view_file = $view_file;
}
/**
* Renders the collapsible paper and returns it as a string.
*
* @return string The rendered paper.
*/
public function get_output() {
$view_variables = $this->get_view_variables();
extract( $view_variables, EXTR_SKIP );
$content = $this->settings['content'];
if ( $this->view_file !== null ) {
ob_start();
require $this->view_file;
$content = ob_get_clean();
}
ob_start();
require WPSEO_PATH . 'admin/views/paper-collapsible.php';
$rendered_output = ob_get_clean();
return $rendered_output;
}
/**
* Retrieves the view variables.
*
* @return array The view variables.
*/
private function get_view_variables() {
if ( $this->settings['help_text'] instanceof WPSEO_Admin_Help_Panel === false ) {
$this->settings['help_text'] = new WPSEO_Admin_Help_Panel( '', '', '' );
}
$view_variables = [
'class' => $this->settings['class'],
'collapsible' => $this->settings['collapsible'],
'collapsible_config' => $this->collapsible_config(),
'collapsible_header_class' => $this->settings['collapsible_header_class'],
'title_after' => $this->settings['title_after'],
'help_text' => $this->settings['help_text'],
'view_file' => $this->view_file,
'title' => $this->title,
'paper_id' => $this->settings['paper_id'],
'paper_id_prefix' => $this->settings['paper_id_prefix'],
'yform' => Yoast_Form::get_instance(),
];
return array_merge( $this->settings['view_data'], $view_variables );
}
/**
* Retrieves the collapsible config based on the settings.
*
* @return array The config.
*/
protected function collapsible_config() {
if ( empty( $this->settings['collapsible'] ) ) {
return [
'toggle_icon' => '',
'class' => '',
'expanded' => '',
];
}
if ( ! empty( $this->settings['expanded'] ) ) {
return [
'toggle_icon' => 'dashicons-arrow-up-alt2',
'class' => 'toggleable-container',
'expanded' => 'true',
];
}
return [
'toggle_icon' => 'dashicons-arrow-down-alt2',
'class' => 'toggleable-container toggleable-container-hidden',
'expanded' => 'false',
];
}
}

View File

@@ -1,310 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Plugin_Availability
*/
/**
* Class WPSEO_Plugin_Availability
*/
class WPSEO_Plugin_Availability {
/**
* Holds the plugins.
*
* @var array
*/
protected $plugins = [];
/**
* Registers the plugins so we can access them.
*/
public function register() {
$this->register_yoast_plugins();
$this->register_yoast_plugins_status();
}
/**
* Registers all the available Yoast SEO plugins.
*/
protected function register_yoast_plugins() {
$this->plugins = [
'yoast-seo-premium' => [
'url' => WPSEO_Shortlinker::get( 'https://yoa.st/1y7' ),
'title' => 'Yoast SEO Premium',
'description' => sprintf(
/* translators: %1$s expands to Yoast SEO */
__( 'The premium version of %1$s with more features & support.', 'wordpress-seo' ),
'Yoast SEO'
),
'installed' => false,
'slug' => 'wordpress-seo-premium/wp-seo-premium.php',
'version_sync' => true,
'premium' => true,
],
'video-seo-for-wordpress-seo-by-yoast' => [
'url' => WPSEO_Shortlinker::get( 'https://yoa.st/1y8' ),
'title' => 'Video SEO',
'description' => __( 'Optimize your videos to show them off in search results and get more clicks!', 'wordpress-seo' ),
'installed' => false,
'slug' => 'wpseo-video/video-seo.php',
'version_sync' => true,
'premium' => true,
],
'yoast-news-seo' => [
'url' => WPSEO_Shortlinker::get( 'https://yoa.st/1y9' ),
'title' => 'News SEO',
'description' => __( 'Are you in Google News? Increase your traffic from Google News by optimizing for it!', 'wordpress-seo' ),
'installed' => false,
'slug' => 'wpseo-news/wpseo-news.php',
'version_sync' => true,
'premium' => true,
],
'local-seo-for-yoast-seo' => [
'url' => WPSEO_Shortlinker::get( 'https://yoa.st/1ya' ),
'title' => 'Local SEO',
'description' => __( 'Rank better locally and in Google Maps, without breaking a sweat!', 'wordpress-seo' ),
'installed' => false,
'slug' => 'wordpress-seo-local/local-seo.php',
'version_sync' => true,
'premium' => true,
],
'yoast-woocommerce-seo' => [
'url' => WPSEO_Shortlinker::get( 'https://yoa.st/1o0' ),
'title' => 'Yoast WooCommerce SEO',
'description' => sprintf(
/* translators: %1$s expands to Yoast SEO */
__( 'Seamlessly integrate WooCommerce with %1$s and get extra features!', 'wordpress-seo' ),
'Yoast SEO'
),
'_dependencies' => [
'WooCommerce' => [
'slug' => 'woocommerce/woocommerce.php',
],
],
'installed' => false,
'slug' => 'wpseo-woocommerce/wpseo-woocommerce.php',
'version_sync' => true,
'premium' => true,
],
];
}
/**
* Sets certain plugin properties based on WordPress' status.
*/
protected function register_yoast_plugins_status() {
foreach ( $this->plugins as $name => $plugin ) {
$plugin_slug = $plugin['slug'];
$plugin_path = WP_PLUGIN_DIR . '/' . $plugin_slug;
if ( file_exists( $plugin_path ) ) {
$plugin_data = get_plugin_data( $plugin_path, false, false );
$this->plugins[ $name ]['installed'] = true;
$this->plugins[ $name ]['version'] = $plugin_data['Version'];
$this->plugins[ $name ]['active'] = is_plugin_active( $plugin_slug );
}
}
}
/**
* Checks whether or not a plugin is known within the Yoast SEO collection.
*
* @param string $plugin The plugin to search for.
*
* @return bool Whether or not the plugin is exists.
*/
protected function plugin_exists( $plugin ) {
return isset( $this->plugins[ $plugin ] );
}
/**
* Gets all the possibly available plugins.
*
* @return array Array containing the information about the plugins.
*/
public function get_plugins() {
return $this->plugins;
}
/**
* Gets a specific plugin. Returns an empty array if it cannot be found.
*
* @param string $plugin The plugin to search for.
*
* @return array The plugin properties.
*/
public function get_plugin( $plugin ) {
if ( ! $this->plugin_exists( $plugin ) ) {
return [];
}
return $this->plugins[ $plugin ];
}
/**
* Gets the version of the plugin.
*
* @param array $plugin The information available about the plugin.
*
* @return string The version associated with the plugin.
*/
public function get_version( $plugin ) {
if ( ! isset( $plugin['version'] ) ) {
return '';
}
return $plugin['version'];
}
/**
* Checks if there are dependencies available for the plugin.
*
* @param array $plugin The information available about the plugin.
*
* @return bool Whether or not there is a dependency present.
*/
public function has_dependencies( $plugin ) {
return ( isset( $plugin['_dependencies'] ) && ! empty( $plugin['_dependencies'] ) );
}
/**
* Gets the dependencies for the plugin.
*
* @param array $plugin The information available about the plugin.
*
* @return array Array containing all the dependencies associated with the plugin.
*/
public function get_dependencies( $plugin ) {
if ( ! $this->has_dependencies( $plugin ) ) {
return [];
}
return $plugin['_dependencies'];
}
/**
* Checks if all dependencies are satisfied.
*
* @param array $plugin The information available about the plugin.
*
* @return bool Whether or not the dependencies are satisfied.
*/
public function dependencies_are_satisfied( $plugin ) {
if ( ! $this->has_dependencies( $plugin ) ) {
return true;
}
$dependencies = $this->get_dependencies( $plugin );
$installed_dependencies = array_filter( $dependencies, [ $this, 'is_dependency_available' ] );
return count( $installed_dependencies ) === count( $dependencies );
}
/**
* Checks whether or not one of the plugins is properly installed and usable.
*
* @param array $plugin The information available about the plugin.
*
* @return bool Whether or not the plugin is properly installed.
*/
public function is_installed( $plugin ) {
if ( empty( $plugin ) ) {
return false;
}
return $this->is_available( $plugin );
}
/**
* Gets all installed plugins.
*
* @return array The installed plugins.
*/
public function get_installed_plugins() {
$installed = [];
foreach ( $this->plugins as $plugin_key => $plugin ) {
if ( $this->is_installed( $plugin ) ) {
$installed[ $plugin_key ] = $plugin;
}
}
return $installed;
}
/**
* Checks for the availability of the plugin.
*
* @param array $plugin The information available about the plugin.
*
* @return bool Whether or not the plugin is available.
*/
public function is_available( $plugin ) {
return isset( $plugin['installed'] ) && $plugin['installed'] === true;
}
/**
* Checks whether a dependency is available.
*
* @param array $dependency The information about the dependency to look for.
*
* @return bool Whether or not the dependency is available.
*/
public function is_dependency_available( $dependency ) {
return isset( get_plugins()[ $dependency['slug'] ] );
}
/**
* Gets the names of the dependencies.
*
* @param array $plugin The plugin to get the dependency names from.
*
* @return array Array containing the names of the associated dependencies.
*/
public function get_dependency_names( $plugin ) {
if ( ! $this->has_dependencies( $plugin ) ) {
return [];
}
return array_keys( $plugin['_dependencies'] );
}
/**
* Gets an array of plugins that have defined dependencies.
*
* @return array Array of the plugins that have dependencies.
*/
public function get_plugins_with_dependencies() {
return array_filter( $this->plugins, [ $this, 'has_dependencies' ] );
}
/**
* Determines whether or not a plugin is active.
*
* @param string $plugin The plugin slug to check.
*
* @return bool Whether or not the plugin is active.
*/
public function is_active( $plugin ) {
return is_plugin_active( $plugin );
}
/**
* Determines whether or not a plugin is a Premium product.
*
* @param array $plugin The plugin to check.
*
* @return bool Whether or not the plugin is a Premium product.
*/
public function is_premium( $plugin ) {
return isset( $plugin['premium'] ) && $plugin['premium'] === true;
}
}

View File

@@ -1,92 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
* @since 1.7.0
*/
use Yoast\WP\SEO\Config\Conflicting_Plugins;
/**
* Contains list of conflicting plugins.
*/
class WPSEO_Plugin_Conflict extends Yoast_Plugin_Conflict {
/**
* The plugins must be grouped per section.
*
* It's possible to check for each section if there are conflicting plugin.
*
* NOTE: when changing this array, be sure to update the array in Conflicting_Plugins_Service too.
*
* @var array
*/
protected $plugins = [
// The plugin which are writing OG metadata.
'open_graph' => Conflicting_Plugins::OPEN_GRAPH_PLUGINS,
'xml_sitemaps' => Conflicting_Plugins::XML_SITEMAPS_PLUGINS,
'cloaking' => Conflicting_Plugins::CLOAKING_PLUGINS,
'seo' => Conflicting_Plugins::SEO_PLUGINS,
];
/**
* Overrides instance to set with this class as class.
*
* @param string $class_name Optional class name.
*
* @return Yoast_Plugin_Conflict
*/
public static function get_instance( $class_name = __CLASS__ ) {
return parent::get_instance( $class_name );
}
/**
* After activating any plugin, this method will be executed by a hook.
*
* If the activated plugin is conflicting with ours a notice will be shown.
*
* @param string|bool $plugin Optional plugin basename to check.
*/
public static function hook_check_for_plugin_conflicts( $plugin = false ) {
// The instance of the plugin.
$instance = self::get_instance();
// Only add the plugin as an active plugin if $plugin isn't false.
if ( $plugin && is_string( $plugin ) ) {
$instance->add_active_plugin( $instance->find_plugin_category( $plugin ), $plugin );
}
$plugin_sections = [];
// Only check for open graph problems when they are enabled.
if ( WPSEO_Options::get( 'opengraph' ) ) {
/* translators: %1$s expands to Yoast SEO, %2$s: 'Facebook' plugin name of possibly conflicting plugin with regard to creating OpenGraph output. */
$plugin_sections['open_graph'] = __( 'Both %1$s and %2$s create Open Graph output, which might make Facebook, Twitter, LinkedIn and other social networks use the wrong texts and images when your pages are being shared.', 'wordpress-seo' )
. '<br/><br/>'
. '<a class="button" href="' . admin_url( 'admin.php?page=wpseo_page_settings#/site-features#card-wpseo_social-opengraph' ) . '">'
/* translators: %1$s expands to Yoast SEO. */
. sprintf( __( 'Configure %1$s\'s Open Graph settings', 'wordpress-seo' ), 'Yoast SEO' )
. '</a>';
}
// Only check for XML conflicts if sitemaps are enabled.
if ( WPSEO_Options::get( 'enable_xml_sitemap' ) ) {
/* translators: %1$s expands to Yoast SEO, %2$s: 'Google XML Sitemaps' plugin name of possibly conflicting plugin with regard to the creation of sitemaps. */
$plugin_sections['xml_sitemaps'] = __( 'Both %1$s and %2$s can create XML sitemaps. Having two XML sitemaps is not beneficial for search engines and might slow down your site.', 'wordpress-seo' )
. '<br/><br/>'
. '<a class="button" href="' . admin_url( 'admin.php?page=wpseo_page_settings#/site-features#card-wpseo-enable_xml_sitemap' ) . '">'
/* translators: %1$s expands to Yoast SEO. */
. sprintf( __( 'Toggle %1$s\'s XML Sitemap', 'wordpress-seo' ), 'Yoast SEO' )
. '</a>';
}
/* translators: %2$s expands to 'RS Head Cleaner' plugin name of possibly conflicting plugin with regard to differentiating output between search engines and normal users. */
$plugin_sections['cloaking'] = __( 'The plugin %2$s changes your site\'s output and in doing that differentiates between search engines and normal users, a process that\'s called cloaking. We highly recommend that you disable it.', 'wordpress-seo' );
/* translators: %1$s expands to Yoast SEO, %2$s: 'SEO' plugin name of possibly conflicting plugin with regard to the creation of duplicate SEO meta. */
$plugin_sections['seo'] = __( 'Both %1$s and %2$s manage the SEO of your site. Running two SEO plugins at the same time is detrimental.', 'wordpress-seo' );
$instance->check_plugin_conflicts( $plugin_sections );
}
}

View File

@@ -1,105 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Class WPSEO_Premium_popup.
*/
class WPSEO_Premium_Popup {
/**
* An unique identifier for the popup
*
* @var string
*/
private $identifier = '';
/**
* The heading level of the title of the popup.
*
* @var string
*/
private $heading_level = '';
/**
* The title of the popup.
*
* @var string
*/
private $title = '';
/**
* The content of the popup.
*
* @var string
*/
private $content = '';
/**
* The URL for where the button should link to.
*
* @var string
*/
private $url = '';
/**
* Wpseo_Premium_Popup constructor.
*
* @param string $identifier An unique identifier for the popup.
* @param string $heading_level The heading level for the title of the popup.
* @param string $title The title of the popup.
* @param string $content The content of the popup.
* @param string $url The URL for where the button should link to.
*/
public function __construct( $identifier, $heading_level, $title, $content, $url ) {
$this->identifier = $identifier;
$this->heading_level = $heading_level;
$this->title = $title;
$this->content = $content;
$this->url = $url;
}
/**
* Returns the premium popup as an HTML string.
*
* @param bool $popup Show this message as a popup show it straight away.
*
* @return string
*/
public function get_premium_message( $popup = true ) {
// Don't show in Premium.
if ( defined( 'WPSEO_PREMIUM_FILE' ) ) {
return '';
}
$assets_uri = trailingslashit( plugin_dir_url( WPSEO_FILE ) );
/* translators: %s expands to Yoast SEO Premium */
$cta_text = esc_html( sprintf( __( 'Get %s', 'wordpress-seo' ), 'Yoast SEO Premium' ) );
/* translators: Hidden accessibility text. */
$new_tab_message = '<span class="screen-reader-text">' . esc_html__( '(Opens in a new browser tab)', 'wordpress-seo' ) . '</span>';
$caret_icon = '<span aria-hidden="true" class="yoast-button-upsell__caret"></span>';
$classes = '';
if ( $popup ) {
$classes = ' hidden';
}
$micro_copy = __( '1 year free support and updates included!', 'wordpress-seo' );
$popup = <<<EO_POPUP
<div id="wpseo-{$this->identifier}-popup" class="wpseo-premium-popup wp-clearfix$classes">
<img class="alignright wpseo-premium-popup-icon" src="{$assets_uri}packages/js/images/Yoast_SEO_Icon.svg" width="150" height="150" alt="Yoast SEO"/>
<{$this->heading_level} id="wpseo-contact-support-popup-title" class="wpseo-premium-popup-title">{$this->title}</{$this->heading_level}>
{$this->content}
<a id="wpseo-{$this->identifier}-popup-button" class="yoast-button-upsell" href="{$this->url}" target="_blank">
{$cta_text} {$new_tab_message} {$caret_icon}
</a><br/>
<small>{$micro_copy}</small>
</div>
EO_POPUP;
return $popup;
}
}

View File

@@ -1,136 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
/**
* Class WPSEO_Premium_Upsell_Admin_Block
*/
class WPSEO_Premium_Upsell_Admin_Block {
/**
* Hook to display the block on.
*
* @var string
*/
protected $hook;
/**
* Identifier to use in the dismissal functionality.
*
* @var string
*/
protected $identifier = 'premium_upsell';
/**
* Registers which hook the block will be displayed on.
*
* @param string $hook Hook to display the block on.
*/
public function __construct( $hook ) {
$this->hook = $hook;
}
/**
* Registers WordPress hooks.
*
* @return void
*/
public function register_hooks() {
add_action( $this->hook, [ $this, 'render' ] );
}
/**
* Renders the upsell block.
*
* @return void
*/
public function render() {
$url = WPSEO_Shortlinker::get( 'https://yoa.st/17h' );
$arguments = [
'<strong>' . esc_html__( 'Use AI', 'wordpress-seo' ) . '</strong>: ' . esc_html__( 'Quickly create titles & meta descriptions', 'wordpress-seo' ),
'<strong>' . esc_html__( 'No more dead links', 'wordpress-seo' ) . '</strong>: ' . esc_html__( 'Easy redirect manager', 'wordpress-seo' ),
'<strong>' . esc_html__( 'Superfast internal linking suggestions', 'wordpress-seo' ) . '</strong>',
'<strong>' . esc_html__( 'Social media preview', 'wordpress-seo' ) . '</strong>: ' . esc_html__( 'Facebook & Twitter', 'wordpress-seo' ),
'<strong>' . esc_html__( 'Multiple keyphrases', 'wordpress-seo' ) . '</strong>: ' . esc_html__( 'Increase your SEO reach', 'wordpress-seo' ),
'<strong>' . esc_html__( 'SEO Workouts', 'wordpress-seo' ) . '</strong>: ' . esc_html__( 'Get guided in routine SEO tasks', 'wordpress-seo' ),
'<strong>' . esc_html__( '24/7 email support', 'wordpress-seo' ) . '</strong>',
'<strong>' . esc_html__( 'No ads!', 'wordpress-seo' ) . '</strong>',
];
$arguments_html = implode( '', array_map( [ $this, 'get_argument_html' ], $arguments ) );
$class = $this->get_html_class();
/* translators: %s expands to Yoast SEO Premium */
$button_text = YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2023-promotion' ) ? \esc_html__( 'Claim your 30% off now!', 'wordpress-seo' ) : sprintf( esc_html__( 'Get %s', 'wordpress-seo' ), 'Yoast SEO Premium' );
/* translators: Hidden accessibility text. */
$button_text .= '<span class="screen-reader-text">' . esc_html__( '(Opens in a new browser tab)', 'wordpress-seo' ) . '</span>' .
'<span aria-hidden="true" class="yoast-button-upsell__caret"></span>';
$upgrade_button = sprintf(
'<a id="%1$s" class="yoast-button-upsell" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2" href="%2$s" target="_blank">%3$s</a>',
esc_attr( 'wpseo-' . $this->identifier . '-popup-button' ),
esc_url( $url ),
$button_text
);
echo '<div class="' . esc_attr( $class ) . '">';
if ( YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2023-promotion' ) ) {
$bf_label = \esc_html__( 'BLACK FRIDAY', 'wordpress-seo' );
$sale_label = \esc_html__( '30% OFF', 'wordpress-seo' );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped above.
echo "<div class='black-friday-container'><span>$bf_label</span> <span style='margin-left: auto;'>$sale_label</span> </div>";
}
echo '<div class="' . esc_attr( $class . '--container' ) . '">';
echo '<h2 class="' . esc_attr( $class . '--header' ) . '">' .
sprintf(
/* translators: %s expands to Yoast SEO Premium */
esc_html__( 'Upgrade to %s', 'wordpress-seo' ),
'Yoast SEO Premium'
) .
'</h2>';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Correctly escaped in $this->get_argument_html() method.
echo '<ul class="' . esc_attr( $class . '--motivation' ) . '">' . $arguments_html . '</ul>';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Correctly escaped in $upgrade_button and $button_text above.
echo '<p>' . $upgrade_button . '</p>';
echo '</div>';
echo '</div>';
}
/**
* Formats the argument to a HTML list item.
*
* @param string $argument The argument to format.
*
* @return string Formatted argument in HTML.
*/
protected function get_argument_html( $argument ) {
$class = $this->get_html_class();
return sprintf(
'<li><div class="%1$s">%2$s</div></li>',
esc_attr( $class . '--argument' ),
$argument
);
}
/**
* Returns the HTML base class to use.
*
* @return string The HTML base class.
*/
protected function get_html_class() {
return 'yoast_' . $this->identifier;
}
}

View File

@@ -1,269 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Adds the UI to change the primary term for a post.
*/
class WPSEO_Primary_Term_Admin implements WPSEO_WordPress_Integration {
/**
* Constructor.
*/
public function register_hooks() {
add_filter( 'wpseo_content_meta_section_content', [ $this, 'add_input_fields' ] );
add_action( 'admin_footer', [ $this, 'wp_footer' ], 10 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
}
/**
* Gets the current post ID.
*
* @return int The post ID.
*/
protected function get_current_id() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information, We are casting to an integer.
$post_id = isset( $_GET['post'] ) && is_string( $_GET['post'] ) ? (int) wp_unslash( $_GET['post'] ) : 0;
if ( $post_id === 0 && isset( $GLOBALS['post_ID'] ) ) {
$post_id = (int) $GLOBALS['post_ID'];
}
return $post_id;
}
/**
* Adds hidden fields for primary taxonomies.
*
* @param string $content The metabox content.
*
* @return string The HTML content.
*/
public function add_input_fields( $content ) {
$taxonomies = $this->get_primary_term_taxonomies();
foreach ( $taxonomies as $taxonomy ) {
$content .= $this->primary_term_field( $taxonomy->name );
$content .= wp_nonce_field( 'save-primary-term', WPSEO_Meta::$form_prefix . 'primary_' . $taxonomy->name . '_nonce', false, false );
}
return $content;
}
/**
* Generates the HTML for a hidden field for a primary taxonomy.
*
* @param string $taxonomy_name The taxonomy's slug.
*
* @return string The HTML for a hidden primary taxonomy field.
*/
protected function primary_term_field( $taxonomy_name ) {
return sprintf(
'<input class="yoast-wpseo-primary-term" type="hidden" id="%1$s" name="%2$s" value="%3$s" />',
esc_attr( $this->generate_field_id( $taxonomy_name ) ),
esc_attr( $this->generate_field_name( $taxonomy_name ) ),
esc_attr( $this->get_primary_term( $taxonomy_name ) )
);
}
/**
* Generates an id for a primary taxonomy's hidden field.
*
* @param string $taxonomy_name The taxonomy's slug.
*
* @return string The field id.
*/
protected function generate_field_id( $taxonomy_name ) {
return 'yoast-wpseo-primary-' . $taxonomy_name;
}
/**
* Generates a name for a primary taxonomy's hidden field.
*
* @param string $taxonomy_name The taxonomy's slug.
*
* @return string The field id.
*/
protected function generate_field_name( $taxonomy_name ) {
return WPSEO_Meta::$form_prefix . 'primary_' . $taxonomy_name . '_term';
}
/**
* Adds primary term templates.
*/
public function wp_footer() {
$taxonomies = $this->get_primary_term_taxonomies();
if ( ! empty( $taxonomies ) ) {
$this->include_js_templates();
}
}
/**
* Enqueues all the assets needed for the primary term interface.
*
* @return void
*/
public function enqueue_assets() {
global $pagenow;
if ( ! WPSEO_Metabox::is_post_edit( $pagenow ) ) {
return;
}
$taxonomies = $this->get_primary_term_taxonomies();
// Only enqueue if there are taxonomies that need a primary term.
if ( empty( $taxonomies ) ) {
return;
}
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_style( 'primary-category' );
$mapped_taxonomies = $this->get_mapped_taxonomies_for_js( $taxonomies );
$data = [
'taxonomies' => $mapped_taxonomies,
];
$asset_manager->localize_script( 'post-edit', 'wpseoPrimaryCategoryL10n', $data );
$asset_manager->localize_script( 'post-edit-classic', 'wpseoPrimaryCategoryL10n', $data );
}
/**
* Gets the id of the primary term.
*
* @param string $taxonomy_name Taxonomy name for the term.
*
* @return int primary term id
*/
protected function get_primary_term( $taxonomy_name ) {
$primary_term = new WPSEO_Primary_Term( $taxonomy_name, $this->get_current_id() );
return $primary_term->get_primary_term();
}
/**
* Returns all the taxonomies for which the primary term selection is enabled.
*
* @param int|null $post_id Default current post ID.
* @return array
*/
protected function get_primary_term_taxonomies( $post_id = null ) {
if ( $post_id === null ) {
$post_id = $this->get_current_id();
}
$taxonomies = wp_cache_get( 'primary_term_taxonomies_' . $post_id, 'wpseo' );
if ( $taxonomies !== false ) {
return $taxonomies;
}
$taxonomies = $this->generate_primary_term_taxonomies( $post_id );
wp_cache_set( 'primary_term_taxonomies_' . $post_id, $taxonomies, 'wpseo' );
return $taxonomies;
}
/**
* Includes templates file.
*/
protected function include_js_templates() {
include_once WPSEO_PATH . 'admin/views/js-templates-primary-term.php';
}
/**
* Generates the primary term taxonomies.
*
* @param int $post_id ID of the post.
*
* @return array
*/
protected function generate_primary_term_taxonomies( $post_id ) {
$post_type = get_post_type( $post_id );
$all_taxonomies = get_object_taxonomies( $post_type, 'objects' );
$all_taxonomies = array_filter( $all_taxonomies, [ $this, 'filter_hierarchical_taxonomies' ] );
/**
* Filters which taxonomies for which the user can choose the primary term.
*
* @api array $taxonomies An array of taxonomy objects that are primary_term enabled.
*
* @param string $post_type The post type for which to filter the taxonomies.
* @param array $all_taxonomies All taxonomies for this post types, even ones that don't have primary term
* enabled.
*/
$taxonomies = (array) apply_filters( 'wpseo_primary_term_taxonomies', $all_taxonomies, $post_type, $all_taxonomies );
return $taxonomies;
}
/**
* Creates a map of taxonomies for localization.
*
* @param array $taxonomies The taxononmies that should be mapped.
*
* @return array The mapped taxonomies.
*/
protected function get_mapped_taxonomies_for_js( $taxonomies ) {
return array_map( [ $this, 'map_taxonomies_for_js' ], $taxonomies );
}
/**
* Returns an array suitable for use in the javascript.
*
* @param stdClass $taxonomy The taxonomy to map.
*
* @return array The mapped taxonomy.
*/
private function map_taxonomies_for_js( $taxonomy ) {
$primary_term = $this->get_primary_term( $taxonomy->name );
if ( empty( $primary_term ) ) {
$primary_term = '';
}
$terms = get_terms(
[
'taxonomy' => $taxonomy->name,
'update_term_meta_cache' => false,
'fields' => 'id=>name',
]
);
$mapped_terms_for_js = [];
foreach ( $terms as $id => $name ) {
$mapped_terms_for_js[] = [
'id' => $id,
'name' => $name,
];
}
return [
'title' => $taxonomy->labels->singular_name,
'name' => $taxonomy->name,
'primary' => $primary_term,
'singularLabel' => $taxonomy->labels->singular_name,
'fieldId' => $this->generate_field_id( $taxonomy->name ),
'restBase' => ( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name,
'terms' => $mapped_terms_for_js,
];
}
/**
* Returns whether or not a taxonomy is hierarchical.
*
* @param stdClass $taxonomy Taxonomy object.
*
* @return bool
*/
private function filter_hierarchical_taxonomies( $taxonomy ) {
return (bool) $taxonomy->hierarchical;
}
}

View File

@@ -1,215 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Represents the upsell notice.
*/
class WPSEO_Product_Upsell_Notice {
/**
* Holds the name of the user meta key.
*
* The value of this database field holds whether the user has dismissed this notice or not.
*
* @var string
*/
const USER_META_DISMISSED = 'wpseo-remove-upsell-notice';
/**
* Holds the option name.
*
* @var string
*/
const OPTION_NAME = 'wpseo';
/**
* Holds the options.
*
* @var array
*/
protected $options;
/**
* Sets the options, because they always have to be there on instance.
*/
public function __construct() {
$this->options = $this->get_options();
}
/**
* Checks if the notice should be added or removed.
*/
public function initialize() {
$this->remove_notification();
}
/**
* Sets the upgrade notice.
*/
public function set_upgrade_notice() {
if ( $this->has_first_activated_on() ) {
return;
}
$this->set_first_activated_on();
$this->add_notification();
}
/**
* Listener for the upsell notice.
*/
public function dismiss_notice_listener() {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are validating a nonce here.
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'dismiss-5star-upsell' ) ) {
return;
}
$dismiss_upsell = isset( $_GET['yoast_dismiss'] ) && is_string( $_GET['yoast_dismiss'] ) ? sanitize_text_field( wp_unslash( $_GET['yoast_dismiss'] ) ) : '';
if ( $dismiss_upsell !== 'upsell' ) {
return;
}
$this->dismiss_notice();
if ( wp_safe_redirect( admin_url( 'admin.php?page=wpseo_dashboard' ) ) ) {
exit;
}
}
/**
* When the notice should be shown.
*
* @return bool
*/
protected function should_add_notification() {
return ( $this->options['first_activated_on'] < strtotime( '-2weeks' ) );
}
/**
* Checks if the options has a first activated on date value.
*
* @return bool
*/
protected function has_first_activated_on() {
return $this->options['first_activated_on'] !== false;
}
/**
* Sets the first activated on.
*/
protected function set_first_activated_on() {
$this->options['first_activated_on'] = strtotime( '-2weeks' );
$this->save_options();
}
/**
* Adds a notification to the notification center.
*/
protected function add_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->add_notification( $this->get_notification() );
}
/**
* Removes a notification to the notification center.
*/
protected function remove_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification( $this->get_notification() );
}
/**
* Returns a premium upsell section if using the free plugin.
*
* @return string
*/
protected function get_premium_upsell_section() {
if ( ! YoastSEO()->helpers->product->is_premium() ) {
return sprintf(
/* translators: %1$s expands anchor to premium plugin page, %2$s expands to </a> */
__( 'By the way, did you know we also have a %1$sPremium plugin%2$s? It offers advanced features, like a redirect manager and support for multiple keyphrases. It also comes with 24/7 personal support.', 'wordpress-seo' ),
"<a href='" . WPSEO_Shortlinker::get( 'https://yoa.st/premium-notification' ) . "'>",
'</a>'
);
}
return '';
}
/**
* Gets the notification value.
*
* @return Yoast_Notification
*/
protected function get_notification() {
$message = sprintf(
/* translators: %1$s expands to Yoast SEO, %2$s is a link start tag to the plugin page on WordPress.org, %3$s is the link closing tag. */
__( 'We\'ve noticed you\'ve been using %1$s for some time now; we hope you love it! We\'d be thrilled if you could %2$sgive us a 5 stars rating on WordPress.org%3$s!', 'wordpress-seo' ),
'Yoast SEO',
'<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/rate-yoast-seo' ) . '">',
'</a>'
) . "\n\n";
$message .= sprintf(
/* translators: %1$s is a link start tag to the bugreport guidelines on the Yoast help center, %2$s is the link closing tag. */
__( 'If you are experiencing issues, %1$splease file a bug report%2$s and we\'ll do our best to help you out.', 'wordpress-seo' ),
'<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/bugreport' ) . '">',
'</a>'
) . "\n\n";
$message .= $this->get_premium_upsell_section() . "\n\n";
$message .= '<a class="button" href="' . wp_nonce_url( admin_url( '?page=' . WPSEO_Admin::PAGE_IDENTIFIER . '&yoast_dismiss=upsell' ), 'dismiss-5star-upsell' ) . '">' . __( 'Please don\'t show me this notification anymore', 'wordpress-seo' ) . '</a>';
$notification = new Yoast_Notification(
$message,
[
'type' => Yoast_Notification::WARNING,
'id' => 'wpseo-upsell-notice',
'capabilities' => 'wpseo_manage_options',
'priority' => 0.8,
]
);
return $notification;
}
/**
* Dismisses the notice.
*
* @return bool
*/
protected function is_notice_dismissed() {
return get_user_meta( get_current_user_id(), self::USER_META_DISMISSED, true ) === '1';
}
/**
* Dismisses the notice.
*/
protected function dismiss_notice() {
update_user_meta( get_current_user_id(), self::USER_META_DISMISSED, true );
}
/**
* Returns the set options.
*
* @return mixed
*/
protected function get_options() {
return get_option( self::OPTION_NAME );
}
/**
* Saves the options to the database.
*/
protected function save_options() {
update_option( self::OPTION_NAME, $this->options );
}
}

View File

@@ -1,156 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* This class handles a post request being send to a given endpoint.
*/
class WPSEO_Remote_Request {
/**
* Holds the post method.
*
* @var string
*/
const METHOD_POST = 'post';
/**
* Holds the get method.
*
* @var string
*/
const METHOD_GET = 'get';
/**
* Holds the endpoint to send the request to.
*
* @var string
*/
protected $endpoint = '';
/**
* Holds the arguments to use in this request.
*
* @var array
*/
protected $args = [
'blocking' => false,
'timeout' => 2,
];
/**
* Holds the response error.
*
* @var WP_Error|null
*/
protected $response_error;
/**
* Holds the response body.
*
* @var mixed
*/
protected $response_body;
/**
* Sets the endpoint and arguments.
*
* @param string $endpoint The endpoint to send the request to.
* @param array $args The arguments to use in this request.
*/
public function __construct( $endpoint, array $args = [] ) {
$this->endpoint = $endpoint;
$this->args = wp_parse_args( $this->args, $args );
}
/**
* Sets the request body.
*
* @param mixed $body The body to set.
*/
public function set_body( $body ) {
$this->args['body'] = $body;
}
/**
* Sends the data to the given endpoint.
*
* @param string $method The type of request to send.
*
* @return bool True when sending data has been successful.
*/
public function send( $method = self::METHOD_POST ) {
switch ( $method ) {
case self::METHOD_POST:
$response = $this->post();
break;
case self::METHOD_GET:
$response = $this->get();
break;
default:
/* translators: %1$s expands to the request method */
$response = new WP_Error( 1, sprintf( __( 'Request method %1$s is not valid.', 'wordpress-seo' ), $method ) );
break;
}
return $this->process_response( $response );
}
/**
* Returns the value of the response error.
*
* @return WP_Error|null The response error.
*/
public function get_response_error() {
return $this->response_error;
}
/**
* Returns the response body.
*
* @return mixed The response body.
*/
public function get_response_body() {
return $this->response_body;
}
/**
* Processes the given response.
*
* @param mixed $response The response to process.
*
* @return bool True when response is valid.
*/
protected function process_response( $response ) {
if ( $response instanceof WP_Error ) {
$this->response_error = $response;
return false;
}
$this->response_body = wp_remote_retrieve_body( $response );
return ( wp_remote_retrieve_response_code( $response ) === 200 );
}
/**
* Performs a post request to the specified endpoint with set arguments.
*
* @return WP_Error|array The response or WP_Error on failure.
*/
protected function post() {
return wp_remote_post( $this->endpoint, $this->args );
}
/**
* Performs a post request to the specified endpoint with set arguments.
*
* @return WP_Error|array The response or WP_Error on failure.
*/
protected function get() {
return wp_remote_get( $this->endpoint, $this->args );
}
}

View File

@@ -1,77 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Notifies the user to update the Search Appearance settings when the site is set to represent a Person,
* but no person (name) has been chosen.
*/
class WPSEO_Schema_Person_Upgrade_Notification implements WPSEO_WordPress_Integration {
/**
* Registers all hooks to WordPress
*
* @return void
*/
public function register_hooks() {
add_action( 'admin_init', [ $this, 'handle_notification' ] );
}
/**
* Handles if the notification should be added or removed.
*/
public function handle_notification() {
$company_or_person_user_id = WPSEO_Options::get( 'company_or_person_user_id', false );
if ( WPSEO_Options::get( 'company_or_person' ) === 'person' && empty( $company_or_person_user_id ) ) {
$this->add_notification();
return;
}
$this->remove_notification();
}
/**
* Adds a notification to the notification center.
*/
protected function add_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->add_notification( $this->get_notification() );
}
/**
* Removes a notification to the notification center.
*/
protected function remove_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification( $this->get_notification() );
}
/**
* Gets the notification object.
*
* @return Yoast_Notification
*/
protected function get_notification() {
$message = sprintf(
/* translators: %1$s is a link start tag to the Search Appearance settings, %2$s is the link closing tag. */
__( 'You have previously set your site to represent a person. Weve improved our functionality around Schema and the Knowledge Graph, so you should go in and %1$scomplete those settings%2$s.', 'wordpress-seo' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_page_settings#/site-representation' ) ) . '">',
'</a>'
);
$notification = new Yoast_Notification(
$message,
[
'type' => Yoast_Notification::WARNING,
'id' => 'wpseo-schema-person-upgrade',
'capabilities' => 'wpseo_manage_options',
'priority' => 0.8,
]
);
return $notification;
}
}

View File

@@ -1,139 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Suggested_Plugins
*/
/**
* Class WPSEO_Suggested_Plugins
*/
class WPSEO_Suggested_Plugins implements WPSEO_WordPress_Integration {
/**
* Holds the availability checker.
*
* @var WPSEO_Plugin_Availability
*/
protected $availability_checker;
/**
* Holds the notification center.
*
* @var Yoast_Notification_Center
*/
protected $notification_center;
/**
* WPSEO_Suggested_Plugins constructor.
*
* @param WPSEO_Plugin_Availability $availability_checker The availability checker to use.
* @param Yoast_Notification_Center $notification_center The notification center to add notifications to.
*/
public function __construct( WPSEO_Plugin_Availability $availability_checker, Yoast_Notification_Center $notification_center ) {
$this->availability_checker = $availability_checker;
$this->notification_center = $notification_center;
}
/**
* Registers all hooks to WordPress.
*
* @return void
*/
public function register_hooks() {
add_action( 'admin_init', [ $this->availability_checker, 'register' ] );
add_action( 'admin_init', [ $this, 'add_notifications' ] );
}
/**
* Adds notifications (when necessary).
*
* @return void
*/
public function add_notifications() {
$checker = $this->availability_checker;
// Get all Yoast plugins that have dependencies.
$plugins = $checker->get_plugins_with_dependencies();
foreach ( $plugins as $plugin_name => $plugin ) {
if ( ! $checker->dependencies_are_satisfied( $plugin ) ) {
continue;
}
$notification = $this->get_yoast_seo_suggested_plugins_notification( $plugin_name, $plugin );
if ( ! $checker->is_installed( $plugin ) ) {
$this->notification_center->add_notification( $notification );
continue;
}
$this->notification_center->remove_notification( $notification );
}
}
/**
* Build Yoast SEO suggested plugins notification.
*
* @param string $name The plugin name to use for the unique ID.
* @param array $plugin The plugin to retrieve the data from.
*
* @return Yoast_Notification The notification containing the suggested plugin.
*/
protected function get_yoast_seo_suggested_plugins_notification( $name, $plugin ) {
$message = $this->create_install_suggested_plugin_message( $plugin );
if ( $this->availability_checker->is_installed( $plugin ) && ! $this->availability_checker->is_active( $plugin['slug'] ) ) {
$message = '';
}
return new Yoast_Notification(
$message,
[
'id' => 'wpseo-suggested-plugin-' . $name,
'type' => Yoast_Notification::WARNING,
'capabilities' => [ 'install_plugins' ],
]
);
}
/**
* Creates a message to suggest the installation of a particular plugin.
*
* @param array $suggested_plugin The suggested plugin.
*
* @return string The install suggested plugin message.
*/
protected function create_install_suggested_plugin_message( $suggested_plugin ) {
/* translators: %1$s expands to an opening strong tag, %2$s expands to the dependency name, %3$s expands to a closing strong tag, %4$s expands to an opening anchor tag, %5$s expands to a closing anchor tag. */
$message = __( 'It looks like you aren\'t using our %1$s%2$s addon%3$s. %4$sUpgrade today%5$s to unlock more tools and SEO features to make your products stand out in search results.', 'wordpress-seo' );
$install_link = WPSEO_Admin_Utils::get_install_link( $suggested_plugin );
return sprintf(
$message,
'<strong>',
$install_link,
'</strong>',
$this->create_more_information_link( $suggested_plugin['url'], $suggested_plugin['title'] ),
'</a>'
);
}
/**
* Creates a more information link that directs the user to WordPress.org Plugin repository.
*
* @param string $url The URL to the plugin's page.
* @param string $name The name of the plugin.
*
* @return string The more information link.
*/
protected function create_more_information_link( $url, $name ) {
return sprintf(
'<a href="%s" aria-label="%s" target="_blank" rel="noopener noreferrer">',
$url,
/* translators: Hidden accessibility text; %1$s expands to the dependency name */
sprintf( __( 'More information about %1$s', 'wordpress-seo' ), $name )
);
}
}

View File

@@ -1,128 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Wincher dashboard widget.
*/
class Wincher_Dashboard_Widget implements WPSEO_WordPress_Integration {
/**
* Holds an instance of the admin asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
protected $asset_manager;
/**
* Wincher_Dashboard_Widget constructor.
*/
public function __construct() {
$this->asset_manager = new WPSEO_Admin_Asset_Manager();
}
/**
* Register WordPress hooks.
*/
public function register_hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_wincher_dashboard_assets' ] );
add_action( 'admin_init', [ $this, 'queue_wincher_dashboard_widget' ] );
}
/**
* Adds the Wincher dashboard widget if it should be shown.
*
* @return void
*/
public function queue_wincher_dashboard_widget() {
if ( $this->show_widget() ) {
add_action( 'wp_dashboard_setup', [ $this, 'add_wincher_dashboard_widget' ] );
}
}
/**
* Adds the Wincher dashboard widget to WordPress.
*/
public function add_wincher_dashboard_widget() {
add_filter( 'postbox_classes_dashboard_wpseo-wincher-dashboard-overview', [ $this, 'wpseo_wincher_dashboard_overview_class' ] );
wp_add_dashboard_widget(
'wpseo-wincher-dashboard-overview',
/* translators: %1$s expands to Yoast SEO, %2$s to Wincher */
sprintf( __( '%1$s / %2$s: Top Keyphrases', 'wordpress-seo' ), 'Yoast SEO', 'Wincher' ),
[ $this, 'display_wincher_dashboard_widget' ]
);
}
/**
* Adds CSS classes to the dashboard widget.
*
* @param array $classes An array of postbox CSS classes.
*
* @return array
*/
public function wpseo_wincher_dashboard_overview_class( $classes ) {
$classes[] = 'yoast wpseo-wincherdashboard-overview';
return $classes;
}
/**
* Displays the Wincher dashboard widget.
*/
public function display_wincher_dashboard_widget() {
echo '<div id="yoast-seo-wincher-dashboard-widget"></div>';
}
/**
* Enqueues assets for the dashboard if the current page is the dashboard.
*/
public function enqueue_wincher_dashboard_assets() {
if ( ! $this->is_dashboard_screen() ) {
return;
}
$this->asset_manager->localize_script( 'wincher-dashboard-widget', 'wpseoWincherDashboardWidgetL10n', $this->localize_wincher_dashboard_script() );
$this->asset_manager->enqueue_script( 'wincher-dashboard-widget' );
$this->asset_manager->enqueue_style( 'wp-dashboard' );
$this->asset_manager->enqueue_style( 'monorepo' );
}
/**
* Translates strings used in the Wincher dashboard widget.
*
* @return array The translated strings.
*/
public function localize_wincher_dashboard_script() {
return [
'wincher_is_logged_in' => YoastSEO()->helpers->wincher->login_status(),
'wincher_website_id' => WPSEO_Options::get( 'wincher_website_id', '' ),
];
}
/**
* Checks if the current screen is the dashboard screen.
*
* @return bool Whether or not this is the dashboard screen.
*/
private function is_dashboard_screen() {
$current_screen = get_current_screen();
return ( $current_screen instanceof WP_Screen && $current_screen->id === 'dashboard' );
}
/**
* Returns true when the Wincher dashboard widget should be shown.
*
* @return bool
*/
private function show_widget() {
$analysis_seo = new WPSEO_Metabox_Analysis_SEO();
$user_can_edit = $analysis_seo->is_enabled() && current_user_can( 'edit_posts' );
$is_wincher_active = YoastSEO()->helpers->wincher->is_active();
return $user_can_edit && $is_wincher_active;
}
}

View File

@@ -1,113 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Represents the yoast columns.
*/
class WPSEO_Yoast_Columns implements WPSEO_WordPress_Integration {
/**
* Registers all hooks to WordPress.
*/
public function register_hooks() {
add_action( 'load-edit.php', [ $this, 'add_help_tab' ] );
}
/**
* Adds the help tab to the help center for current screen.
*/
public function add_help_tab() {
$link_columns_present = $this->display_links();
$meta_columns_present = $this->display_meta_columns();
if ( ! ( $link_columns_present || $meta_columns_present ) ) {
return;
}
$help_tab_content = sprintf(
/* translators: %1$s: Yoast SEO */
__( '%1$s adds several columns to this page.', 'wordpress-seo' ),
'Yoast SEO'
);
if ( $meta_columns_present ) {
$help_tab_content .= ' ' . sprintf(
/* translators: %1$s: Link to article about content analysis, %2$s: Anchor closing */
__( 'We\'ve written an article about %1$show to use the SEO score and Readability score%2$s.', 'wordpress-seo' ),
'<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/16p' ) . '">',
'</a>'
);
}
if ( $link_columns_present ) {
$help_tab_content .= ' ' . sprintf(
/* translators: %1$s: Link to article about text links, %2$s: Anchor closing tag, %3$s: Emphasis open tag, %4$s: Emphasis close tag */
__( 'The links columns show the number of articles on this site linking %3$sto%4$s this article and the number of URLs linked %3$sfrom%4$s this article. Learn more about %1$show to use these features to improve your internal linking%2$s, which greatly enhances your SEO.', 'wordpress-seo' ),
'<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/16p' ) . '">',
'</a>',
'<em>',
'</em>'
);
}
$screen = get_current_screen();
$screen->add_help_tab(
[
/* translators: %s expands to Yoast */
'title' => sprintf( __( '%s Columns', 'wordpress-seo' ), 'Yoast' ),
'id' => 'yst-columns',
'content' => '<p>' . $help_tab_content . '</p>',
'priority' => 15,
]
);
}
/**
* Retrieves the post type from the $_GET variable.
*
* @return string The current post type.
*/
private function get_current_post_type() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['post_type'] ) && is_string( $_GET['post_type'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
return sanitize_text_field( wp_unslash( $_GET['post_type'] ) );
}
return '';
}
/**
* Whether we are showing link columns on this overview page.
* This depends on the post being accessible or not.
*
* @return bool Whether the linking columns are shown
*/
private function display_links() {
$current_post_type = $this->get_current_post_type();
if ( empty( $current_post_type ) ) {
return false;
}
return WPSEO_Post_Type::is_post_type_accessible( $current_post_type );
}
/**
* Wraps the WPSEO_Metabox check to determine whether the metabox should be displayed either by
* choice of the admin or because the post type is not a public post type.
*
* @return bool Whether the meta box (and associated columns etc) should be hidden.
*/
private function display_meta_columns() {
$current_post_type = $this->get_current_post_type();
if ( empty( $current_post_type ) ) {
return false;
}
return WPSEO_Utils::is_metabox_active( $current_post_type, 'post_type' );
}
}

View File

@@ -1,152 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Class to change or add WordPress dashboard widgets.
*/
class Yoast_Dashboard_Widget implements WPSEO_WordPress_Integration {
/**
* Holds the cache transient key.
*
* @var string
*/
const CACHE_TRANSIENT_KEY = 'wpseo-dashboard-totals';
/**
* Holds an instance of the admin asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
protected $asset_manager;
/**
* Holds the dashboard statistics.
*
* @var WPSEO_Statistics
*/
protected $statistics;
/**
* Yoast_Dashboard_Widget constructor.
*
* @param WPSEO_Statistics|null $statistics WPSEO_Statistics instance.
*/
public function __construct( WPSEO_Statistics $statistics = null ) {
if ( $statistics === null ) {
$statistics = new WPSEO_Statistics();
}
$this->statistics = $statistics;
$this->asset_manager = new WPSEO_Admin_Asset_Manager();
}
/**
* Register WordPress hooks.
*/
public function register_hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_dashboard_assets' ] );
add_action( 'admin_init', [ $this, 'queue_dashboard_widget' ] );
}
/**
* Adds the dashboard widget if it should be shown.
*
* @return void
*/
public function queue_dashboard_widget() {
if ( $this->show_widget() ) {
add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] );
}
}
/**
* Adds dashboard widget to WordPress.
*/
public function add_dashboard_widget() {
add_filter( 'postbox_classes_dashboard_wpseo-dashboard-overview', [ $this, 'wpseo_dashboard_overview_class' ] );
wp_add_dashboard_widget(
'wpseo-dashboard-overview',
/* translators: %s is the plugin name */
sprintf( __( '%s Posts Overview', 'wordpress-seo' ), 'Yoast SEO' ),
[ $this, 'display_dashboard_widget' ]
);
}
/**
* Adds CSS classes to the dashboard widget.
*
* @param array $classes An array of postbox CSS classes.
*
* @return array
*/
public function wpseo_dashboard_overview_class( $classes ) {
$classes[] = 'yoast wpseo-dashboard-overview';
return $classes;
}
/**
* Displays the dashboard widget.
*/
public function display_dashboard_widget() {
echo '<div id="yoast-seo-dashboard-widget"></div>';
}
/**
* Enqueues assets for the dashboard if the current page is the dashboard.
*/
public function enqueue_dashboard_assets() {
if ( ! $this->is_dashboard_screen() ) {
return;
}
$this->asset_manager->localize_script( 'dashboard-widget', 'wpseoDashboardWidgetL10n', $this->localize_dashboard_script() );
$this->asset_manager->enqueue_script( 'dashboard-widget' );
$this->asset_manager->enqueue_style( 'wp-dashboard' );
$this->asset_manager->enqueue_style( 'monorepo' );
}
/**
* Translates strings used in the dashboard widget.
*
* @return array The translated strings.
*/
public function localize_dashboard_script() {
return [
'feed_header' => sprintf(
/* translators: %1$s resolves to Yoast.com */
__( 'Latest blog posts on %1$s', 'wordpress-seo' ),
'Yoast.com'
),
'feed_footer' => __( 'Read more like this on our SEO blog', 'wordpress-seo' ),
'wp_version' => substr( $GLOBALS['wp_version'], 0, 3 ) . '-' . ( is_plugin_active( 'classic-editor/classic-editor.php' ) ? '1' : '0' ),
'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION,
];
}
/**
* Checks if the current screen is the dashboard screen.
*
* @return bool Whether or not this is the dashboard screen.
*/
private function is_dashboard_screen() {
$current_screen = get_current_screen();
return ( $current_screen instanceof WP_Screen && $current_screen->id === 'dashboard' );
}
/**
* Returns true when the dashboard widget should be shown.
*
* @return bool
*/
private function show_widget() {
$analysis_seo = new WPSEO_Metabox_Analysis_SEO();
return $analysis_seo->is_enabled() && current_user_can( 'edit_posts' );
}
}

View File

@@ -1,326 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Implements server-side user input validation.
*
* @since 12.0
*/
class Yoast_Input_Validation {
/**
* The error descriptions.
*
* @since 12.1
*
* @var array
*/
private static $error_descriptions = [];
/**
* Check whether an option group is a Yoast SEO setting.
*
* The normal pattern is 'yoast' . $option_name . 'options'.
*
* @since 12.0
*
* @param string $group_name The option group name.
*
* @return bool Whether or not it's an Yoast SEO option group.
*/
public static function is_yoast_option_group_name( $group_name ) {
return ( strpos( $group_name, 'yoast' ) !== false );
}
/**
* Adds an error message to the document title when submitting a settings
* form and errors are returned.
*
* Uses the WordPress `admin_title` filter in the WPSEO_Option subclasses.
*
* @since 12.0
*
* @param string $admin_title The page title, with extra context added.
*
* @return string The modified or original admin title.
*/
public static function add_yoast_admin_document_title_errors( $admin_title ) {
$errors = get_settings_errors();
$error_count = 0;
foreach ( $errors as $error ) {
// For now, filter the admin title only in the Yoast SEO settings pages.
if ( self::is_yoast_option_group_name( $error['setting'] ) && $error['code'] !== 'settings_updated' ) {
++$error_count;
}
}
if ( $error_count > 0 ) {
return sprintf(
/* translators: %1$s: amount of errors, %2$s: the admin page title */
_n( 'The form contains %1$s error. %2$s', 'The form contains %1$s errors. %2$s', $error_count, 'wordpress-seo' ),
number_format_i18n( $error_count ),
$admin_title
);
}
return $admin_title;
}
/**
* Checks whether a specific form input field was submitted with an invalid value.
*
* @since 12.1
*
* @param string $error_code Must be the same slug-name used for the field variable and for `add_settings_error()`.
*
* @return bool Whether or not the submitted input field contained an invalid value.
*/
public static function yoast_form_control_has_error( $error_code ) {
$errors = get_settings_errors();
foreach ( $errors as $error ) {
if ( $error['code'] === $error_code ) {
return true;
}
}
return false;
}
/**
* Sets the error descriptions.
*
* @since 12.1
*
* @param array $descriptions An associative array of error descriptions.
* For each entry, the key must be the setting variable.
*/
public static function set_error_descriptions( $descriptions = [] ) {
$defaults = [
'baiduverify' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Baidu verification codes can only contain letters, numbers, hyphens, and underscores. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'baiduverify' )
),
'facebook_site' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Please check the format of the Facebook Page URL you entered. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'facebook_site' )
),
'googleverify' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Google verification codes can only contain letters, numbers, hyphens, and underscores. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'googleverify' )
),
'instagram_url' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Please check the format of the Instagram URL you entered. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'instagram_url' )
),
'linkedin_url' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Please check the format of the LinkedIn URL you entered. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'linkedin_url' )
),
'msverify' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Bing confirmation codes can only contain letters from A to F, numbers, hyphens, and underscores. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'msverify' )
),
'myspace_url' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Please check the format of the MySpace URL you entered. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'myspace_url' )
),
'pinterest_url' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Please check the format of the Pinterest URL you entered. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'pinterest_url' )
),
'pinterestverify' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Pinterest confirmation codes can only contain letters from A to F, numbers, hyphens, and underscores. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'pinterestverify' )
),
'twitter_site' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Twitter usernames can only contain letters, numbers, and underscores. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'twitter_site' )
),
'wikipedia_url' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Please check the format of the Wikipedia URL you entered. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'wikipedia_url' )
),
'yandexverify' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Yandex confirmation codes can only contain letters from A to F, numbers, hyphens, and underscores. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'yandexverify' )
),
'youtube_url' => sprintf(
/* translators: %s: additional message with the submitted invalid value */
esc_html__( 'Please check the format of the YouTube URL you entered. %s', 'wordpress-seo' ),
self::get_dirty_value_message( 'youtube_url' )
),
];
$descriptions = wp_parse_args( $descriptions, $defaults );
self::$error_descriptions = $descriptions;
}
/**
* Gets all the error descriptions.
*
* @since 12.1
*
* @return array An associative array of error descriptions.
*/
public static function get_error_descriptions() {
return self::$error_descriptions;
}
/**
* Gets a specific error description.
*
* @since 12.1
*
* @param string $error_code Code of the error set via `add_settings_error()`, normally the variable name.
*
* @return string|null The error description.
*/
public static function get_error_description( $error_code ) {
if ( ! isset( self::$error_descriptions[ $error_code ] ) ) {
return null;
}
return self::$error_descriptions[ $error_code ];
}
/**
* Gets the aria-invalid HTML attribute based on the submitted invalid value.
*
* @since 12.1
*
* @param string $error_code Code of the error set via `add_settings_error()`, normally the variable name.
*
* @return string The aria-invalid HTML attribute or empty string.
*/
public static function get_the_aria_invalid_attribute( $error_code ) {
if ( self::yoast_form_control_has_error( $error_code ) ) {
return ' aria-invalid="true"';
}
return '';
}
/**
* Gets the aria-describedby HTML attribute based on the submitted invalid value.
*
* @since 12.1
*
* @param string $error_code Code of the error set via `add_settings_error()`, normally the variable name.
*
* @return string The aria-describedby HTML attribute or empty string.
*/
public static function get_the_aria_describedby_attribute( $error_code ) {
if ( self::yoast_form_control_has_error( $error_code ) && self::get_error_description( $error_code ) ) {
return ' aria-describedby="' . esc_attr( $error_code ) . '-error-description"';
}
return '';
}
/**
* Gets the error description wrapped in a HTML paragraph.
*
* @since 12.1
*
* @param string $error_code Code of the error set via `add_settings_error()`, normally the variable name.
*
* @return string The error description HTML or empty string.
*/
public static function get_the_error_description( $error_code ) {
$error_description = self::get_error_description( $error_code );
if ( self::yoast_form_control_has_error( $error_code ) && $error_description ) {
return '<p id="' . esc_attr( $error_code ) . '-error-description" class="yoast-input-validation__error-description">' . $error_description . '</p>';
}
return '';
}
/**
* Adds the submitted invalid value to the WordPress `$wp_settings_errors` global.
*
* @since 12.1
*
* @param string $error_code Code of the error set via `add_settings_error()`, normally the variable name.
* @param string $dirty_value The submitted invalid value.
*
* @return void
*/
public static function add_dirty_value_to_settings_errors( $error_code, $dirty_value ) {
global $wp_settings_errors;
if ( ! is_array( $wp_settings_errors ) ) {
return;
}
foreach ( $wp_settings_errors as $index => $error ) {
if ( $error['code'] === $error_code ) {
// phpcs:ignore WordPress.WP.GlobalVariablesOverride -- This is a deliberate action.
$wp_settings_errors[ $index ]['yoast_dirty_value'] = $dirty_value;
}
}
}
/**
* Gets an invalid submitted value.
*
* @since 12.1
*
* @param string $error_code Code of the error set via `add_settings_error()`, normally the variable name.
*
* @return string The submitted invalid input field value.
*/
public static function get_dirty_value( $error_code ) {
$errors = get_settings_errors();
foreach ( $errors as $error ) {
if ( $error['code'] === $error_code && isset( $error['yoast_dirty_value'] ) ) {
return $error['yoast_dirty_value'];
}
}
return '';
}
/**
* Gets a specific invalid value message.
*
* @since 12.1
*
* @param string $error_code Code of the error set via `add_settings_error()`, normally the variable name.
*
* @return string The error invalid value message or empty string.
*/
public static function get_dirty_value_message( $error_code ) {
$dirty_value = self::get_dirty_value( $error_code );
if ( $dirty_value ) {
return sprintf(
/* translators: %s: form value as submitted. */
esc_html__( 'The submitted value was: %s', 'wordpress-seo' ),
esc_html( $dirty_value )
);
}
return '';
}
}

View File

@@ -1,334 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Internals
*/
/**
* Multisite utility class for network admin functionality.
*/
class Yoast_Network_Admin implements WPSEO_WordPress_AJAX_Integration, WPSEO_WordPress_Integration {
/**
* Action identifier for updating plugin network options.
*
* @var string
*/
const UPDATE_OPTIONS_ACTION = 'yoast_handle_network_options';
/**
* Action identifier for restoring a site.
*
* @var string
*/
const RESTORE_SITE_ACTION = 'yoast_restore_site';
/**
* Gets the available sites as choices, e.g. for a dropdown.
*
* @param bool $include_empty Optional. Whether to include an initial placeholder choice.
* Default false.
* @param bool $show_title Optional. Whether to show the title for each site. This requires
* switching through the sites, so has performance implications for
* sites that do not use a persistent cache.
* Default false.
*
* @return array Choices as $site_id => $site_label pairs.
*/
public function get_site_choices( $include_empty = false, $show_title = false ) {
$choices = [];
if ( $include_empty ) {
$choices['-'] = __( 'None', 'wordpress-seo' );
}
$criteria = [
'deleted' => 0,
'network_id' => get_current_network_id(),
];
$sites = get_sites( $criteria );
foreach ( $sites as $site ) {
$site_name = $site->domain . $site->path;
if ( $show_title ) {
$site_name = $site->blogname . ' (' . $site->domain . $site->path . ')';
}
$choices[ $site->blog_id ] = $site->blog_id . ': ' . $site_name;
$site_states = $this->get_site_states( $site );
if ( ! empty( $site_states ) ) {
$choices[ $site->blog_id ] .= ' [' . implode( ', ', $site_states ) . ']';
}
}
return $choices;
}
/**
* Gets the states of a site.
*
* @param WP_Site $site Site object.
*
* @return array Array of $state_slug => $state_label pairs.
*/
public function get_site_states( $site ) {
$available_states = [
'public' => __( 'public', 'wordpress-seo' ),
'archived' => __( 'archived', 'wordpress-seo' ),
'mature' => __( 'mature', 'wordpress-seo' ),
'spam' => __( 'spam', 'wordpress-seo' ),
'deleted' => __( 'deleted', 'wordpress-seo' ),
];
$site_states = [];
foreach ( $available_states as $state_slug => $state_label ) {
if ( $site->$state_slug === '1' ) {
$site_states[ $state_slug ] = $state_label;
}
}
return $site_states;
}
/**
* Handles a request to update plugin network options.
*
* This method works similar to how option updates are handled in `wp-admin/options.php` and
* `wp-admin/network/settings.php`.
*
* @return void
*/
public function handle_update_options_request() {
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: Nonce verification will happen in verify_request below.
if ( ! isset( $_POST['network_option_group'] ) || ! is_string( $_POST['network_option_group'] ) ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: Nonce verification will happen in verify_request below.
$option_group = sanitize_text_field( wp_unslash( $_POST['network_option_group'] ) );
if ( empty( $option_group ) ) {
return;
}
$this->verify_request( "{$option_group}-network-options" );
$whitelist_options = Yoast_Network_Settings_API::get()->get_whitelist_options( $option_group );
if ( empty( $whitelist_options ) ) {
add_settings_error( $option_group, 'settings_updated', __( 'You are not allowed to modify unregistered network settings.', 'wordpress-seo' ), 'error' );
$this->terminate_request();
return;
}
// phpcs:disable WordPress.Security.NonceVerification -- Nonce verified via `verify_request()` above.
foreach ( $whitelist_options as $option_name ) {
$value = null;
if ( isset( $_POST[ $option_name ] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: Adding sanitize_text_field around this will break the saving of settings because it expects a string: https://github.com/Yoast/wordpress-seo/issues/12440.
$value = wp_unslash( $_POST[ $option_name ] );
}
WPSEO_Options::update_site_option( $option_name, $value );
}
// phpcs:enable WordPress.Security.NonceVerification
$settings_errors = get_settings_errors();
if ( empty( $settings_errors ) ) {
add_settings_error( $option_group, 'settings_updated', __( 'Settings Updated.', 'wordpress-seo' ), 'updated' );
}
$this->terminate_request();
}
/**
* Handles a request to restore a site's default settings.
*
* @return void
*/
public function handle_restore_site_request() {
$this->verify_request( 'wpseo-network-restore', 'restore_site_nonce' );
$option_group = 'wpseo_ms';
// phpcs:ignore WordPress.Security.NonceVerification -- Nonce verified via `verify_request()` above.
$site_id = ! empty( $_POST[ $option_group ]['site_id'] ) ? (int) $_POST[ $option_group ]['site_id'] : 0;
if ( ! $site_id ) {
add_settings_error( $option_group, 'settings_updated', __( 'No site has been selected to restore.', 'wordpress-seo' ), 'error' );
$this->terminate_request();
return;
}
$site = get_site( $site_id );
if ( ! $site ) {
/* translators: %s expands to the ID of a site within a multisite network. */
add_settings_error( $option_group, 'settings_updated', sprintf( __( 'Site with ID %d not found.', 'wordpress-seo' ), $site_id ), 'error' );
}
else {
WPSEO_Options::reset_ms_blog( $site_id );
/* translators: %s expands to the name of a site within a multisite network. */
add_settings_error( $option_group, 'settings_updated', sprintf( __( '%s restored to default SEO settings.', 'wordpress-seo' ), esc_html( $site->blogname ) ), 'updated' );
}
$this->terminate_request();
}
/**
* Outputs nonce, action and option group fields for a network settings page in the plugin.
*
* @param string $option_group Option group name for the current page.
*
* @return void
*/
public function settings_fields( $option_group ) {
?>
<input type="hidden" name="network_option_group" value="<?php echo esc_attr( $option_group ); ?>" />
<input type="hidden" name="action" value="<?php echo esc_attr( self::UPDATE_OPTIONS_ACTION ); ?>" />
<?php
wp_nonce_field( "$option_group-network-options" );
}
/**
* Enqueues network admin assets.
*
* @return void
*/
public function enqueue_assets() {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_script( 'network-admin' );
$translations = [
/* translators: %s: success message */
'success_prefix' => __( 'Success: %s', 'wordpress-seo' ),
/* translators: %s: error message */
'error_prefix' => __( 'Error: %s', 'wordpress-seo' ),
];
$asset_manager->localize_script(
'network-admin',
'wpseoNetworkAdminGlobalL10n',
$translations
);
}
/**
* Hooks in the necessary actions and filters.
*
* @return void
*/
public function register_hooks() {
if ( ! $this->meets_requirements() ) {
return;
}
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
add_action( 'admin_action_' . self::UPDATE_OPTIONS_ACTION, [ $this, 'handle_update_options_request' ] );
add_action( 'admin_action_' . self::RESTORE_SITE_ACTION, [ $this, 'handle_restore_site_request' ] );
}
/**
* Hooks in the necessary AJAX actions.
*
* @return void
*/
public function register_ajax_hooks() {
add_action( 'wp_ajax_' . self::UPDATE_OPTIONS_ACTION, [ $this, 'handle_update_options_request' ] );
add_action( 'wp_ajax_' . self::RESTORE_SITE_ACTION, [ $this, 'handle_restore_site_request' ] );
}
/**
* Checks whether the requirements to use this class are met.
*
* @return bool True if requirements are met, false otherwise.
*/
public function meets_requirements() {
return is_multisite() && is_network_admin();
}
/**
* Verifies that the current request is valid.
*
* @param string $action Nonce action.
* @param string $query_arg Optional. Nonce query argument. Default '_wpnonce'.
*
* @return void
*/
public function verify_request( $action, $query_arg = '_wpnonce' ) {
$has_access = current_user_can( 'wpseo_manage_network_options' );
if ( wp_doing_ajax() ) {
check_ajax_referer( $action, $query_arg );
if ( ! $has_access ) {
wp_die( -1, 403 );
}
return;
}
check_admin_referer( $action, $query_arg );
if ( ! $has_access ) {
wp_die( esc_html__( 'You are not allowed to perform this action.', 'wordpress-seo' ) );
}
}
/**
* Terminates the current request by either redirecting back or sending an AJAX response.
*
* @return void
*/
public function terminate_request() {
if ( wp_doing_ajax() ) {
$settings_errors = get_settings_errors();
if ( ! empty( $settings_errors ) && $settings_errors[0]['type'] === 'updated' ) {
wp_send_json_success( $settings_errors, 200 );
}
wp_send_json_error( $settings_errors, 400 );
}
$this->persist_settings_errors();
$this->redirect_back( [ 'settings-updated' => 'true' ] );
}
/**
* Persists settings errors.
*
* Settings errors are stored in a transient for 30 seconds so that this transient
* can be retrieved on the next page load.
*
* @return void
*/
protected function persist_settings_errors() {
/*
* A regular transient is used here, since it is automatically cleared right after the redirect.
* A network transient would be cleaner, but would require a lot of copied code from core for
* just a minor adjustment when displaying settings errors.
*/
set_transient( 'settings_errors', get_settings_errors(), 30 );
}
/**
* Redirects back to the referer URL, with optional query arguments.
*
* @param array $query_args Optional. Query arguments to add to the redirect URL. Default none.
*
* @return void
*/
protected function redirect_back( $query_args = [] ) {
$sendback = wp_get_referer();
if ( ! empty( $query_args ) ) {
$sendback = add_query_arg( $query_args, $sendback );
}
wp_safe_redirect( $sendback );
exit;
}
}

View File

@@ -1,164 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Network
*/
/**
* Implements a network settings API for the plugin's multisite settings.
*/
class Yoast_Network_Settings_API {
/**
* Registered network settings.
*
* @var array
*/
private $registered_settings = [];
/**
* Options whitelist, keyed by option group.
*
* @var array
*/
private $whitelist_options = [];
/**
* The singleton instance of this class.
*
* @var Yoast_Network_Settings_API
*/
private static $instance = null;
/**
* Registers a network setting and its data.
*
* @param string $option_group The group the network option is part of.
* @param string $option_name The name of the network option to sanitize and save.
* @param array $args {
* Optional. Data used to describe the network setting when registered.
*
* @type callable $sanitize_callback A callback function that sanitizes the network option's value.
* @type mixed $default Default value when calling `get_network_option()`.
* }
*
* @return void
*/
public function register_setting( $option_group, $option_name, $args = [] ) {
$defaults = [
'group' => $option_group,
'sanitize_callback' => null,
];
$args = wp_parse_args( $args, $defaults );
if ( ! isset( $this->whitelist_options[ $option_group ] ) ) {
$this->whitelist_options[ $option_group ] = [];
}
$this->whitelist_options[ $option_group ][] = $option_name;
if ( ! empty( $args['sanitize_callback'] ) ) {
add_filter( "sanitize_option_{$option_name}", [ $this, 'filter_sanitize_option' ], 10, 2 );
}
if ( array_key_exists( 'default', $args ) ) {
add_filter( "default_site_option_{$option_name}", [ $this, 'filter_default_option' ], 10, 2 );
}
$this->registered_settings[ $option_name ] = $args;
}
/**
* Gets the registered settings and their data.
*
* @return array Array of $option_name => $data pairs.
*/
public function get_registered_settings() {
return $this->registered_settings;
}
/**
* Gets the whitelisted options for a given option group.
*
* @param string $option_group Option group.
*
* @return array List of option names, or empty array if unknown option group.
*/
public function get_whitelist_options( $option_group ) {
if ( ! isset( $this->whitelist_options[ $option_group ] ) ) {
return [];
}
return $this->whitelist_options[ $option_group ];
}
/**
* Filters sanitization for a network option value.
*
* This method is added as a filter to `sanitize_option_{$option}` for network options that are
* registered with a sanitize callback.
*
* @param string $value The sanitized option value.
* @param string $option The option name.
*
* @return string The filtered sanitized option value.
*/
public function filter_sanitize_option( $value, $option ) {
if ( empty( $this->registered_settings[ $option ] ) ) {
return $value;
}
return call_user_func( $this->registered_settings[ $option ]['sanitize_callback'], $value );
}
/**
* Filters the default value for a network option.
*
* This function is added as a filter to `default_site_option_{$option}` for network options that
* are registered with a default.
*
* @param mixed $default_value Existing default value to return.
* @param string $option The option name.
*
* @return mixed The filtered default value.
*/
public function filter_default_option( $default_value, $option ) {
// If a default value was manually passed to the function, allow it to override.
if ( $default_value !== false ) {
return $default_value;
}
if ( empty( $this->registered_settings[ $option ] ) ) {
return $default_value;
}
return $this->registered_settings[ $option ]['default'];
}
/**
* Checks whether the requirements to use this class are met.
*
* @return bool True if requirements are met, false otherwise.
*/
public function meets_requirements() {
return is_multisite();
}
/**
* Gets the singleton instance of this class.
*
* @return Yoast_Network_Settings_API The singleton instance.
*/
public static function get() {
if ( self::$instance === null ) {
self::$instance = new self();
}
return self::$instance;
}
}

View File

@@ -1,935 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Notifications
*/
use Yoast\WP\SEO\Presenters\Abstract_Presenter;
/**
* Handles notifications storage and display.
*/
class Yoast_Notification_Center {
/**
* Option name to store notifications on.
*
* @var string
*/
const STORAGE_KEY = 'yoast_notifications';
/**
* The singleton instance of this object.
*
* @var \Yoast_Notification_Center
*/
private static $instance = null;
/**
* Holds the notifications.
*
* @var \Yoast_Notification[][]
*/
private $notifications = [];
/**
* Notifications there are newly added.
*
* @var array
*/
private $new = [];
/**
* Notifications that were resolved this execution.
*
* @var int
*/
private $resolved = 0;
/**
* Internal storage for transaction before notifications have been retrieved from storage.
*
* @var array
*/
private $queued_transactions = [];
/**
* Internal flag for whether notifications have been retrieved from storage.
*
* @var bool
*/
private $notifications_retrieved = false;
/**
* Internal flag for whether notifications need to be updated in storage.
*
* @var bool
*/
private $notifications_need_storage = false;
/**
* Construct.
*/
private function __construct() {
add_action( 'init', [ $this, 'setup_current_notifications' ], 1 );
add_action( 'all_admin_notices', [ $this, 'display_notifications' ] );
add_action( 'wp_ajax_yoast_get_notifications', [ $this, 'ajax_get_notifications' ] );
add_action( 'wpseo_deactivate', [ $this, 'deactivate_hook' ] );
add_action( 'shutdown', [ $this, 'update_storage' ] );
}
/**
* Singleton getter.
*
* @return Yoast_Notification_Center
*/
public static function get() {
if ( self::$instance === null ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Dismiss a notification.
*/
public static function ajax_dismiss_notification() {
$notification_center = self::get();
if ( ! isset( $_POST['notification'] ) || ! is_string( $_POST['notification'] ) ) {
die( '-1' );
}
$notification_id = sanitize_text_field( wp_unslash( $_POST['notification'] ) );
if ( empty( $notification_id ) ) {
die( '-1' );
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are using the variable as a nonce.
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['nonce'] ), $notification_id ) ) {
die( '-1' );
}
$notification = $notification_center->get_notification_by_id( $notification_id );
if ( ( $notification instanceof Yoast_Notification ) === false ) {
// Permit legacy.
$options = [
'id' => $notification_id,
'dismissal_key' => $notification_id,
];
$notification = new Yoast_Notification( '', $options );
}
if ( self::maybe_dismiss_notification( $notification ) ) {
die( '1' );
}
die( '-1' );
}
/**
* Check if the user has dismissed a notification.
*
* @param Yoast_Notification $notification The notification to check for dismissal.
* @param int|null $user_id User ID to check on.
*
* @return bool
*/
public static function is_notification_dismissed( Yoast_Notification $notification, $user_id = null ) {
$user_id = self::get_user_id( $user_id );
$dismissal_key = $notification->get_dismissal_key();
// This checks both the site-specific user option and the meta value.
$current_value = get_user_option( $dismissal_key, $user_id );
// Migrate old user meta to user option on-the-fly.
if ( ! empty( $current_value )
&& metadata_exists( 'user', $user_id, $dismissal_key )
&& update_user_option( $user_id, $dismissal_key, $current_value ) ) {
delete_user_meta( $user_id, $dismissal_key );
}
return ! empty( $current_value );
}
/**
* Checks if the notification is being dismissed.
*
* @param Yoast_Notification $notification Notification to check dismissal of.
* @param string $meta_value Value to set the meta value to if dismissed.
*
* @return bool True if dismissed.
*/
public static function maybe_dismiss_notification( Yoast_Notification $notification, $meta_value = 'seen' ) {
// Only persistent notifications are dismissible.
if ( ! $notification->is_persistent() ) {
return false;
}
// If notification is already dismissed, we're done.
if ( self::is_notification_dismissed( $notification ) ) {
return true;
}
$dismissal_key = $notification->get_dismissal_key();
$notification_id = $notification->get_id();
$is_dismissing = ( $dismissal_key === self::get_user_input( 'notification' ) );
if ( ! $is_dismissing ) {
$is_dismissing = ( $notification_id === self::get_user_input( 'notification' ) );
}
// Fallback to ?dismissal_key=1&nonce=bla when JavaScript fails.
if ( ! $is_dismissing ) {
$is_dismissing = ( self::get_user_input( $dismissal_key ) === '1' );
}
if ( ! $is_dismissing ) {
return false;
}
$user_nonce = self::get_user_input( 'nonce' );
if ( wp_verify_nonce( $user_nonce, $notification_id ) === false ) {
return false;
}
return self::dismiss_notification( $notification, $meta_value );
}
/**
* Dismisses a notification.
*
* @param Yoast_Notification $notification Notification to dismiss.
* @param string $meta_value Value to save in the dismissal.
*
* @return bool True if dismissed, false otherwise.
*/
public static function dismiss_notification( Yoast_Notification $notification, $meta_value = 'seen' ) {
// Dismiss notification.
return update_user_option( get_current_user_id(), $notification->get_dismissal_key(), $meta_value ) !== false;
}
/**
* Restores a notification.
*
* @param Yoast_Notification $notification Notification to restore.
*
* @return bool True if restored, false otherwise.
*/
public static function restore_notification( Yoast_Notification $notification ) {
$user_id = get_current_user_id();
$dismissal_key = $notification->get_dismissal_key();
// Restore notification.
$restored = delete_user_option( $user_id, $dismissal_key );
// Delete unprefixed user meta too for backward-compatibility.
if ( metadata_exists( 'user', $user_id, $dismissal_key ) ) {
$restored = delete_user_meta( $user_id, $dismissal_key ) && $restored;
}
return $restored;
}
/**
* Clear dismissal information for the specified Notification.
*
* When a cause is resolved, the next time it is present we want to show
* the message again.
*
* @param string|Yoast_Notification $notification Notification to clear the dismissal of.
*
* @return bool
*/
public function clear_dismissal( $notification ) {
global $wpdb;
if ( $notification instanceof Yoast_Notification ) {
$dismissal_key = $notification->get_dismissal_key();
}
if ( is_string( $notification ) ) {
$dismissal_key = $notification;
}
if ( empty( $dismissal_key ) ) {
return false;
}
// Remove notification dismissal for all users.
$deleted = delete_metadata( 'user', 0, $wpdb->get_blog_prefix() . $dismissal_key, '', true );
// Delete unprefixed user meta too for backward-compatibility.
$deleted = delete_metadata( 'user', 0, $dismissal_key, '', true ) || $deleted;
return $deleted;
}
/**
* Retrieves notifications from the storage and merges in previous notification changes.
*
* The current user in WordPress is not loaded shortly before the 'init' hook, but the plugin
* sometimes needs to add or remove notifications before that. In such cases, the transactions
* are not actually executed, but added to a queue. That queue is then handled in this method,
* after notifications for the current user have been set up.
*
* @return void
*/
public function setup_current_notifications() {
$this->retrieve_notifications_from_storage( get_current_user_id() );
foreach ( $this->queued_transactions as $transaction ) {
list( $callback, $args ) = $transaction;
call_user_func_array( $callback, $args );
}
$this->queued_transactions = [];
}
/**
* Add notification to the cookie.
*
* @param Yoast_Notification $notification Notification object instance.
*/
public function add_notification( Yoast_Notification $notification ) {
$callback = [ $this, __FUNCTION__ ];
$args = func_get_args();
if ( $this->queue_transaction( $callback, $args ) ) {
return;
}
// Don't add if the user can't see it.
if ( ! $notification->display_for_current_user() ) {
return;
}
$notification_id = $notification->get_id();
$user_id = $notification->get_user_id();
// Empty notifications are always added.
if ( $notification_id !== '' ) {
// If notification ID exists in notifications, don't add again.
$present_notification = $this->get_notification_by_id( $notification_id, $user_id );
if ( ! is_null( $present_notification ) ) {
$this->remove_notification( $present_notification, false );
}
if ( is_null( $present_notification ) ) {
$this->new[] = $notification_id;
}
}
// Add to list.
$this->notifications[ $user_id ][] = $notification;
$this->notifications_need_storage = true;
}
/**
* Get the notification by ID and user ID.
*
* @param string $notification_id The ID of the notification to search for.
* @param int|null $user_id The ID of the user.
*
* @return Yoast_Notification|null
*/
public function get_notification_by_id( $notification_id, $user_id = null ) {
$user_id = self::get_user_id( $user_id );
$notifications = $this->get_notifications_for_user( $user_id );
foreach ( $notifications as $notification ) {
if ( $notification_id === $notification->get_id() ) {
return $notification;
}
}
return null;
}
/**
* Display the notifications.
*
* @param bool $echo_as_json True when notifications should be printed directly.
*
* @return void
*/
public function display_notifications( $echo_as_json = false ) {
// Never display notifications for network admin.
if ( is_network_admin() ) {
return;
}
$sorted_notifications = $this->get_sorted_notifications();
$notifications = array_filter( $sorted_notifications, [ $this, 'is_notification_persistent' ] );
if ( empty( $notifications ) ) {
return;
}
array_walk( $notifications, [ $this, 'remove_notification' ] );
$notifications = array_unique( $notifications );
if ( $echo_as_json ) {
$notification_json = [];
foreach ( $notifications as $notification ) {
$notification_json[] = $notification->render();
}
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
echo WPSEO_Utils::format_json_encode( $notification_json );
return;
}
foreach ( $notifications as $notification ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: Temporarily disabled, see: https://github.com/Yoast/wordpress-seo-premium/issues/2510 and https://github.com/Yoast/wordpress-seo-premium/issues/2511.
echo $notification;
}
}
/**
* Remove notification after it has been displayed.
*
* @param Yoast_Notification $notification Notification to remove.
* @param bool $resolve Resolve as fixed.
*/
public function remove_notification( Yoast_Notification $notification, $resolve = true ) {
$callback = [ $this, __FUNCTION__ ];
$args = func_get_args();
if ( $this->queue_transaction( $callback, $args ) ) {
return;
}
$index = false;
// ID of the user to show the notification for, defaults to current user id.
$user_id = $notification->get_user_id();
$notifications = $this->get_notifications_for_user( $user_id );
// Match persistent Notifications by ID, non persistent by item in the array.
if ( $notification->is_persistent() ) {
foreach ( $notifications as $current_index => $present_notification ) {
if ( $present_notification->get_id() === $notification->get_id() ) {
$index = $current_index;
break;
}
}
}
else {
$index = array_search( $notification, $notifications, true );
}
if ( $index === false ) {
return;
}
if ( $notification->is_persistent() && $resolve ) {
++$this->resolved;
$this->clear_dismissal( $notification );
}
unset( $notifications[ $index ] );
$this->notifications[ $user_id ] = array_values( $notifications );
$this->notifications_need_storage = true;
}
/**
* Removes a notification by its ID.
*
* @param string $notification_id The notification id.
* @param bool $resolve Resolve as fixed.
*
* @return void
*/
public function remove_notification_by_id( $notification_id, $resolve = true ) {
$notification = $this->get_notification_by_id( $notification_id );
if ( $notification === null ) {
return;
}
$this->remove_notification( $notification, $resolve );
$this->notifications_need_storage = true;
}
/**
* Get the notification count.
*
* @param bool $dismissed Count dismissed notifications.
*
* @return int Number of notifications
*/
public function get_notification_count( $dismissed = false ) {
$notifications = $this->get_notifications_for_user( get_current_user_id() );
$notifications = array_filter( $notifications, [ $this, 'filter_persistent_notifications' ] );
if ( ! $dismissed ) {
$notifications = array_filter( $notifications, [ $this, 'filter_dismissed_notifications' ] );
}
return count( $notifications );
}
/**
* Get the number of notifications resolved this execution.
*
* These notifications have been resolved and should be counted when active again.
*
* @return int
*/
public function get_resolved_notification_count() {
return $this->resolved;
}
/**
* Return the notifications sorted on type and priority.
*
* @return array|Yoast_Notification[] Sorted Notifications
*/
public function get_sorted_notifications() {
$notifications = $this->get_notifications_for_user( get_current_user_id() );
if ( empty( $notifications ) ) {
return [];
}
// Sort by severity, error first.
usort( $notifications, [ $this, 'sort_notifications' ] );
return $notifications;
}
/**
* AJAX display notifications.
*/
public function ajax_get_notifications() {
$echo = false;
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form data.
if ( isset( $_POST['version'] ) && is_string( $_POST['version'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are only comparing the variable in a condition.
$echo = wp_unslash( $_POST['version'] ) === '2';
}
// Display the notices.
$this->display_notifications( $echo );
// AJAX die.
exit;
}
/**
* Remove storage when the plugin is deactivated.
*/
public function deactivate_hook() {
$this->clear_notifications();
}
/**
* Returns the given user ID if it exists.
* Otherwise, this function returns the ID of the current user.
*
* @param int $user_id The user ID to check.
*
* @return int The user ID to use.
*/
private static function get_user_id( $user_id ) {
if ( $user_id ) {
return $user_id;
}
return get_current_user_id();
}
/**
* Splits the notifications on user ID.
*
* In other terms, it returns an associative array,
* mapping user ID to a list of notifications for this user.
*
* @param array|Yoast_Notification[] $notifications The notifications to split.
*
* @return array The notifications, split on user ID.
*/
private function split_on_user_id( $notifications ) {
$split_notifications = [];
foreach ( $notifications as $notification ) {
$split_notifications[ $notification->get_user_id() ][] = $notification;
}
return $split_notifications;
}
/**
* Save persistent notifications to storage.
*
* We need to be able to retrieve these so they can be dismissed at any time during the execution.
*
* @since 3.2
*
* @return void
*/
public function update_storage() {
$notifications = $this->notifications;
/**
* One array of Yoast_Notifications, merged from multiple arrays.
*
* @var Yoast_Notification[] $merged_notifications
*/
$merged_notifications = [];
if ( ! empty( $notifications ) ) {
$merged_notifications = array_merge( ...$notifications );
}
/**
* Filter: 'yoast_notifications_before_storage' - Allows developer to filter notifications before saving them.
*
* @api Yoast_Notification[] $notifications
*/
$filtered_merged_notifications = apply_filters( 'yoast_notifications_before_storage', $merged_notifications );
// The notifications were filtered and therefore need to be stored.
if ( $merged_notifications !== $filtered_merged_notifications ) {
$merged_notifications = $filtered_merged_notifications;
$this->notifications_need_storage = true;
}
$notifications = $this->split_on_user_id( $merged_notifications );
// No notifications to store, clear storage if it was previously present.
if ( empty( $notifications ) ) {
$this->remove_storage();
return;
}
// Only store notifications if changes are made.
if ( $this->notifications_need_storage ) {
array_walk( $notifications, [ $this, 'store_notifications_for_user' ] );
}
}
/**
* Stores the notifications to its respective user's storage.
*
* @param array|Yoast_Notification[] $notifications The notifications to store.
* @param int $user_id The ID of the user for which to store the notifications.
*
* @return void
*/
private function store_notifications_for_user( $notifications, $user_id ) {
$notifications_as_arrays = array_map( [ $this, 'notification_to_array' ], $notifications );
update_user_option( $user_id, self::STORAGE_KEY, $notifications_as_arrays );
}
/**
* Provide a way to verify present notifications.
*
* @return array|Yoast_Notification[] Registered notifications.
*/
public function get_notifications() {
if ( ! $this->notifications ) {
return [];
}
return array_merge( ...$this->notifications );
}
/**
* Returns the notifications for the given user.
*
* @param int $user_id The id of the user to check.
*
* @return Yoast_Notification[] The notifications for the user with the given ID.
*/
public function get_notifications_for_user( $user_id ) {
if ( array_key_exists( $user_id, $this->notifications ) ) {
return $this->notifications[ $user_id ];
}
return [];
}
/**
* Get newly added notifications.
*
* @return array
*/
public function get_new_notifications() {
return array_map( [ $this, 'get_notification_by_id' ], $this->new );
}
/**
* Get information from the User input.
*
* Note that this function does not handle nonce verification.
*
* @param string $key Key to retrieve.
*
* @return string non-sanitized value of key if set, an empty string otherwise.
*/
private static function get_user_input( $key ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Missing -- Reason: We are not processing form information and only using this variable in a comparison.
$request_method = isset( $_SERVER['REQUEST_METHOD'] ) && is_string( $_SERVER['REQUEST_METHOD'] ) ? strtoupper( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : '';
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: This function does not sanitize variables.
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- Reason: This function does not verify a nonce.
if ( $request_method === 'POST' ) {
if ( isset( $_POST[ $key ] ) && is_string( $_POST[ $key ] ) ) {
return wp_unslash( $_POST[ $key ] );
}
}
else {
if ( isset( $_GET[ $key ] ) && is_string( $_GET[ $key ] ) ) {
return wp_unslash( $_GET[ $key ] );
}
}
// phpcs:enable WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
return '';
}
/**
* Retrieve the notifications from storage and fill the relevant property.
*
* @param int $user_id The ID of the user to retrieve notifications for.
*
* @return void
*/
private function retrieve_notifications_from_storage( $user_id ) {
if ( $this->notifications_retrieved ) {
return;
}
$this->notifications_retrieved = true;
$stored_notifications = get_user_option( self::STORAGE_KEY, $user_id );
// Check if notifications are stored.
if ( empty( $stored_notifications ) ) {
return;
}
if ( is_array( $stored_notifications ) ) {
$notifications = array_map( [ $this, 'array_to_notification' ], $stored_notifications );
// Apply array_values to ensure we get a 0-indexed array.
$notifications = array_values( array_filter( $notifications, [ $this, 'filter_notification_current_user' ] ) );
$this->notifications[ $user_id ] = $notifications;
}
}
/**
* Sort on type then priority.
*
* @param Yoast_Notification $a Compare with B.
* @param Yoast_Notification $b Compare with A.
*
* @return int 1, 0 or -1 for sorting offset.
*/
private function sort_notifications( Yoast_Notification $a, Yoast_Notification $b ) {
$a_type = $a->get_type();
$b_type = $b->get_type();
if ( $a_type === $b_type ) {
return WPSEO_Utils::calc( $b->get_priority(), 'compare', $a->get_priority() );
}
if ( $a_type === 'error' ) {
return -1;
}
if ( $b_type === 'error' ) {
return 1;
}
return 0;
}
/**
* Clear local stored notifications.
*/
private function clear_notifications() {
$this->notifications = [];
$this->notifications_retrieved = false;
}
/**
* Filter out non-persistent notifications.
*
* @since 3.2
*
* @param Yoast_Notification $notification Notification to test for persistent.
*
* @return bool
*/
private function filter_persistent_notifications( Yoast_Notification $notification ) {
return $notification->is_persistent();
}
/**
* Filter out dismissed notifications.
*
* @param Yoast_Notification $notification Notification to check.
*
* @return bool
*/
private function filter_dismissed_notifications( Yoast_Notification $notification ) {
return ! self::maybe_dismiss_notification( $notification );
}
/**
* Convert Notification to array representation.
*
* @since 3.2
*
* @param Yoast_Notification $notification Notification to convert.
*
* @return array
*/
private function notification_to_array( Yoast_Notification $notification ) {
$notification_data = $notification->to_array();
if ( isset( $notification_data['nonce'] ) ) {
unset( $notification_data['nonce'] );
}
return $notification_data;
}
/**
* Convert stored array to Notification.
*
* @param array $notification_data Array to convert to Notification.
*
* @return Yoast_Notification
*/
private function array_to_notification( $notification_data ) {
if ( isset( $notification_data['options']['nonce'] ) ) {
unset( $notification_data['options']['nonce'] );
}
if ( isset( $notification_data['message'] )
&& \is_subclass_of( $notification_data['message'], Abstract_Presenter::class, false )
) {
$notification_data['message'] = $notification_data['message']->present();
}
return new Yoast_Notification(
$notification_data['message'],
$notification_data['options']
);
}
/**
* Filter notifications that should not be displayed for the current user.
*
* @param Yoast_Notification $notification Notification to test.
*
* @return bool
*/
private function filter_notification_current_user( Yoast_Notification $notification ) {
return $notification->display_for_current_user();
}
/**
* Checks if given notification is persistent.
*
* @param Yoast_Notification $notification The notification to check.
*
* @return bool True when notification is not persistent.
*/
private function is_notification_persistent( Yoast_Notification $notification ) {
return ! $notification->is_persistent();
}
/**
* Queues a notification transaction for later execution if notifications are not yet set up.
*
* @param callable $callback Callback that performs the transaction.
* @param array $args Arguments to pass to the callback.
*
* @return bool True if transaction was queued, false if it can be performed immediately.
*/
private function queue_transaction( $callback, $args ) {
if ( $this->notifications_retrieved ) {
return false;
}
$this->add_transaction_to_queue( $callback, $args );
return true;
}
/**
* Adds a notification transaction to the queue for later execution.
*
* @param callable $callback Callback that performs the transaction.
* @param array $args Arguments to pass to the callback.
*/
private function add_transaction_to_queue( $callback, $args ) {
$this->queued_transactions[] = [ $callback, $args ];
}
/**
* Removes all notifications from storage.
*
* @return bool True when notifications got removed.
*/
protected function remove_storage() {
if ( ! $this->has_stored_notifications() ) {
return false;
}
delete_user_option( get_current_user_id(), self::STORAGE_KEY );
return true;
}
/**
* Checks if there are stored notifications.
*
* @return bool True when there are stored notifications.
*/
protected function has_stored_notifications() {
$stored_notifications = $this->get_stored_notifications();
return ! empty( $stored_notifications );
}
/**
* Retrieves the stored notifications.
*
* @codeCoverageIgnore
*
* @return array|false Array with notifications or false when not set.
*/
protected function get_stored_notifications() {
return get_user_option( self::STORAGE_KEY, get_current_user_id() );
}
}

View File

@@ -1,416 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Notifications
* @since 1.5.3
*/
/**
* Implements individual notification.
*/
class Yoast_Notification {
/**
* Type of capability check.
*
* @var string
*/
const MATCH_ALL = 'all';
/**
* Type of capability check.
*
* @var string
*/
const MATCH_ANY = 'any';
/**
* Notification type.
*
* @var string
*/
const ERROR = 'error';
/**
* Notification type.
*
* @var string
*/
const WARNING = 'warning';
/**
* Notification type.
*
* @var string
*/
const UPDATED = 'updated';
/**
* Options of this Notification.
*
* Contains optional arguments:
*
* - type: The notification type, i.e. 'updated' or 'error'
* - id: The ID of the notification
* - nonce: Security nonce to use in case of dismissible notice.
* - priority: From 0 to 1, determines the order of Notifications.
* - dismissal_key: Option name to save dismissal information in, ID will be used if not supplied.
* - capabilities: Capabilities that a user must have for this Notification to show.
* - capability_check: How to check capability pass: all or any.
* - wpseo_page_only: Only display on wpseo page or on every page.
*
* @var array
*/
private $options = [];
/**
* Contains default values for the optional arguments.
*
* @var array
*/
private $defaults = [
'type' => self::UPDATED,
'id' => '',
'user' => null,
'nonce' => null,
'priority' => 0.5,
'data_json' => [],
'dismissal_key' => null,
'capabilities' => [],
'capability_check' => self::MATCH_ALL,
'yoast_branding' => false,
];
/**
* The message for the notification.
*
* @var string
*/
private $message;
/**
* Notification class constructor.
*
* @param string $message Message string.
* @param array $options Set of options.
*/
public function __construct( $message, $options = [] ) {
$this->message = $message;
$this->options = $this->normalize_options( $options );
}
/**
* Retrieve notification ID string.
*
* @return string
*/
public function get_id() {
return $this->options['id'];
}
/**
* Retrieve the user to show the notification for.
*
* @return WP_User The user to show this notification for.
*/
public function get_user() {
return $this->options['user'];
}
/**
* Retrieve the id of the user to show the notification for.
*
* Returns the id of the current user if not user has been sent.
*
* @return int The user id
*/
public function get_user_id() {
if ( $this->get_user() !== null ) {
return $this->get_user()->ID;
}
return get_current_user_id();
}
/**
* Retrieve nonce identifier.
*
* @return string|null Nonce for this Notification.
*/
public function get_nonce() {
if ( $this->options['id'] && empty( $this->options['nonce'] ) ) {
$this->options['nonce'] = wp_create_nonce( $this->options['id'] );
}
return $this->options['nonce'];
}
/**
* Make sure the nonce is up to date.
*/
public function refresh_nonce() {
if ( $this->options['id'] ) {
$this->options['nonce'] = wp_create_nonce( $this->options['id'] );
}
}
/**
* Get the type of the notification.
*
* @return string
*/
public function get_type() {
return $this->options['type'];
}
/**
* Priority of the notification.
*
* Relative to the type.
*
* @return float Returns the priority between 0 and 1.
*/
public function get_priority() {
return $this->options['priority'];
}
/**
* Get the User Meta key to check for dismissal of notification.
*
* @return string User Meta Option key that registers dismissal.
*/
public function get_dismissal_key() {
if ( empty( $this->options['dismissal_key'] ) ) {
return $this->options['id'];
}
return $this->options['dismissal_key'];
}
/**
* Is this Notification persistent.
*
* @return bool True if persistent, False if fire and forget.
*/
public function is_persistent() {
$id = $this->get_id();
return ! empty( $id );
}
/**
* Check if the notification is relevant for the current user.
*
* @return bool True if a user needs to see this notification, false if not.
*/
public function display_for_current_user() {
// If the notification is for the current page only, always show.
if ( ! $this->is_persistent() ) {
return true;
}
// If the current user doesn't match capabilities.
return $this->match_capabilities();
}
/**
* Does the current user match required capabilities.
*
* @return bool
*/
public function match_capabilities() {
// Super Admin can do anything.
if ( is_multisite() && is_super_admin( $this->options['user']->ID ) ) {
return true;
}
/**
* Filter capabilities that enable the displaying of this notification.
*
* @param array $capabilities The capabilities that must be present for this notification.
* @param Yoast_Notification $notification The notification object.
*
* @return array Array of capabilities or empty for no restrictions.
*
* @since 3.2
*/
$capabilities = apply_filters( 'wpseo_notification_capabilities', $this->options['capabilities'], $this );
// Should be an array.
if ( ! is_array( $capabilities ) ) {
$capabilities = (array) $capabilities;
}
/**
* Filter capability check to enable all or any capabilities.
*
* @param string $capability_check The type of check that will be used to determine if an capability is present.
* @param Yoast_Notification $notification The notification object.
*
* @return string self::MATCH_ALL or self::MATCH_ANY.
*
* @since 3.2
*/
$capability_check = apply_filters( 'wpseo_notification_capability_check', $this->options['capability_check'], $this );
if ( ! in_array( $capability_check, [ self::MATCH_ALL, self::MATCH_ANY ], true ) ) {
$capability_check = self::MATCH_ALL;
}
if ( ! empty( $capabilities ) ) {
$has_capabilities = array_filter( $capabilities, [ $this, 'has_capability' ] );
switch ( $capability_check ) {
case self::MATCH_ALL:
return $has_capabilities === $capabilities;
case self::MATCH_ANY:
return ! empty( $has_capabilities );
}
}
return true;
}
/**
* Array filter function to find matched capabilities.
*
* @param string $capability Capability to test.
*
* @return bool
*/
private function has_capability( $capability ) {
$user = $this->options['user'];
return $user->has_cap( $capability );
}
/**
* Return the object properties as an array.
*
* @return array
*/
public function to_array() {
return [
'message' => $this->message,
'options' => $this->options,
];
}
/**
* Adds string (view) behaviour to the notification.
*
* @return string
*/
public function __toString() {
return $this->render();
}
/**
* Renders the notification as a string.
*
* @return string The rendered notification.
*/
public function render() {
$attributes = [];
// Default notification classes.
$classes = [
'yoast-notification',
];
// Maintain WordPress visualisation of notifications when they are not persistent.
if ( ! $this->is_persistent() ) {
$classes[] = 'notice';
$classes[] = $this->get_type();
}
if ( ! empty( $classes ) ) {
$attributes['class'] = implode( ' ', $classes );
}
// Combined attribute key and value into a string.
array_walk( $attributes, [ $this, 'parse_attributes' ] );
$message = null;
if ( $this->options['yoast_branding'] ) {
$message = $this->wrap_yoast_seo_icon( $this->message );
}
if ( $message === null ) {
$message = wpautop( $this->message );
}
// Build the output DIV.
return '<div ' . implode( ' ', $attributes ) . '>' . $message . '</div>' . PHP_EOL;
}
/**
* Wraps the message with a Yoast SEO icon.
*
* @param string $message The message to wrap.
*
* @return string The wrapped message.
*/
private function wrap_yoast_seo_icon( $message ) {
$out = sprintf(
'<img src="%1$s" height="%2$d" width="%3$d" class="yoast-seo-icon" />',
esc_url( plugin_dir_url( WPSEO_FILE ) . 'packages/js/images/Yoast_SEO_Icon.svg' ),
60,
60
);
$out .= '<div class="yoast-seo-icon-wrap">';
$out .= $message;
$out .= '</div>';
return $out;
}
/**
* Get the JSON if provided.
*
* @return false|string
*/
public function get_json() {
if ( empty( $this->options['data_json'] ) ) {
return '';
}
return WPSEO_Utils::format_json_encode( $this->options['data_json'] );
}
/**
* Make sure we only have values that we can work with.
*
* @param array $options Options to normalize.
*
* @return array
*/
private function normalize_options( $options ) {
$options = wp_parse_args( $options, $this->defaults );
// Should not exceed 0 or 1.
$options['priority'] = min( 1, max( 0, $options['priority'] ) );
// Set default capabilities when not supplied.
if ( empty( $options['capabilities'] ) || $options['capabilities'] === [] ) {
$options['capabilities'] = [ 'wpseo_manage_options' ];
}
// Set to the current user if not supplied.
if ( $options['user'] === null ) {
$options['user'] = wp_get_current_user();
}
return $options;
}
/**
* Format HTML element attributes.
*
* @param string $value Attribute value.
* @param string $key Attribute name.
*/
private function parse_attributes( &$value, $key ) {
$value = sprintf( '%s="%s"', sanitize_key( $key ), esc_attr( $value ) );
}
}

View File

@@ -1,307 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Notifications
*/
/**
* Class Yoast_Notifications.
*/
class Yoast_Notifications {
/**
* Holds the admin page's ID.
*
* @var string
*/
const ADMIN_PAGE = 'wpseo_dashboard';
/**
* Total notifications count.
*
* @var int
*/
private static $notification_count = 0;
/**
* All error notifications.
*
* @var array
*/
private static $errors = [];
/**
* Active errors.
*
* @var array
*/
private static $active_errors = [];
/**
* Dismissed errors.
*
* @var array
*/
private static $dismissed_errors = [];
/**
* All warning notifications.
*
* @var array
*/
private static $warnings = [];
/**
* Active warnings.
*
* @var array
*/
private static $active_warnings = [];
/**
* Dismissed warnings.
*
* @var array
*/
private static $dismissed_warnings = [];
/**
* Yoast_Notifications constructor.
*/
public function __construct() {
$this->add_hooks();
}
/**
* Add hooks
*/
private function add_hooks() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['page'] ) && is_string( $_GET['page'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
$page = sanitize_text_field( wp_unslash( $_GET['page'] ) );
if ( $page === self::ADMIN_PAGE ) {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
}
}
// Needed for adminbar and Notifications page.
add_action( 'admin_init', [ __CLASS__, 'collect_notifications' ], 99 );
// Add AJAX hooks.
add_action( 'wp_ajax_yoast_dismiss_notification', [ $this, 'ajax_dismiss_notification' ] );
add_action( 'wp_ajax_yoast_restore_notification', [ $this, 'ajax_restore_notification' ] );
}
/**
* Enqueue assets.
*/
public function enqueue_assets() {
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_style( 'notifications' );
}
/**
* Handle ajax request to dismiss a notification.
*/
public function ajax_dismiss_notification() {
$notification = $this->get_notification_from_ajax_request();
if ( $notification ) {
$notification_center = Yoast_Notification_Center::get();
$notification_center->maybe_dismiss_notification( $notification );
$this->output_ajax_response( $notification->get_type() );
}
wp_die();
}
/**
* Handle ajax request to restore a notification.
*/
public function ajax_restore_notification() {
$notification = $this->get_notification_from_ajax_request();
if ( $notification ) {
$notification_center = Yoast_Notification_Center::get();
$notification_center->restore_notification( $notification );
$this->output_ajax_response( $notification->get_type() );
}
wp_die();
}
/**
* Create AJAX response data.
*
* @param string $type Notification type.
*/
private function output_ajax_response( $type ) {
$html = $this->get_view_html( $type );
// phpcs:disable WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
echo WPSEO_Utils::format_json_encode(
[
'html' => $html,
'total' => self::get_active_notification_count(),
]
);
// phpcs:enable -- Reason: WPSEO_Utils::format_json_encode is safe.
}
/**
* Get the HTML to return in the AJAX request.
*
* @param string $type Notification type.
*
* @return bool|string
*/
private function get_view_html( $type ) {
switch ( $type ) {
case 'error':
$view = 'errors';
break;
case 'warning':
default:
$view = 'warnings';
break;
}
// Re-collect notifications.
self::collect_notifications();
/**
* Stops PHPStorm from nagging about this variable being unused. The variable is used in the view.
*
* @noinspection PhpUnusedLocalVariableInspection
*/
$notifications_data = self::get_template_variables();
ob_start();
include WPSEO_PATH . 'admin/views/partial-notifications-' . $view . '.php';
$html = ob_get_clean();
return $html;
}
/**
* Extract the Yoast Notification from the AJAX request.
*
* This function does not handle nonce verification.
*
* @return Yoast_Notification|null A Yoast_Notification on success, null on failure.
*/
private function get_notification_from_ajax_request() {
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: This function does not handle nonce verification.
if ( ! isset( $_POST['notification'] ) || ! is_string( $_POST['notification'] ) ) {
return null;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: This function does not handle nonce verification.
$notification_id = sanitize_text_field( wp_unslash( $_POST['notification'] ) );
if ( empty( $notification_id ) ) {
return null;
}
$notification_center = Yoast_Notification_Center::get();
return $notification_center->get_notification_by_id( $notification_id );
}
/**
* Collect the notifications and group them together.
*/
public static function collect_notifications() {
$notification_center = Yoast_Notification_Center::get();
$notifications = $notification_center->get_sorted_notifications();
self::$notification_count = count( $notifications );
self::$errors = array_filter( $notifications, [ __CLASS__, 'filter_error_notifications' ] );
self::$dismissed_errors = array_filter( self::$errors, [ __CLASS__, 'filter_dismissed_notifications' ] );
self::$active_errors = array_diff( self::$errors, self::$dismissed_errors );
self::$warnings = array_filter( $notifications, [ __CLASS__, 'filter_warning_notifications' ] );
self::$dismissed_warnings = array_filter( self::$warnings, [ __CLASS__, 'filter_dismissed_notifications' ] );
self::$active_warnings = array_diff( self::$warnings, self::$dismissed_warnings );
}
/**
* Get the variables needed in the views.
*
* @return array
*/
public static function get_template_variables() {
return [
'metrics' => [
'total' => self::$notification_count,
'active' => self::get_active_notification_count(),
'errors' => count( self::$errors ),
'warnings' => count( self::$warnings ),
],
'errors' => [
'dismissed' => self::$dismissed_errors,
'active' => self::$active_errors,
],
'warnings' => [
'dismissed' => self::$dismissed_warnings,
'active' => self::$active_warnings,
],
];
}
/**
* Get the number of active notifications.
*
* @return int
*/
public static function get_active_notification_count() {
return ( count( self::$active_errors ) + count( self::$active_warnings ) );
}
/**
* Filter out any non-errors.
*
* @param Yoast_Notification $notification Notification to test.
*
* @return bool
*/
private static function filter_error_notifications( Yoast_Notification $notification ) {
return $notification->get_type() === 'error';
}
/**
* Filter out any non-warnings.
*
* @param Yoast_Notification $notification Notification to test.
*
* @return bool
*/
private static function filter_warning_notifications( Yoast_Notification $notification ) {
return $notification->get_type() !== 'error';
}
/**
* Filter out any dismissed notifications.
*
* @param Yoast_Notification $notification Notification to test.
*
* @return bool
*/
private static function filter_dismissed_notifications( Yoast_Notification $notification ) {
return Yoast_Notification_Center::is_notification_dismissed( $notification );
}
}
class_alias( Yoast_Notifications::class, 'Yoast_Alerts' );

View File

@@ -1,328 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
* @since 1.7.0
*/
/**
* Base class for handling plugin conflicts.
*/
class Yoast_Plugin_Conflict {
/**
* The plugins must be grouped per section.
*
* It's possible to check for each section if there are conflicting plugins.
*
* @var array
*/
protected $plugins = [];
/**
* All the current active plugins will be stored in this private var.
*
* @var array
*/
protected $all_active_plugins = [];
/**
* After searching for active plugins that are in $this->plugins the active plugins will be stored in this
* property.
*
* @var array
*/
protected $active_conflicting_plugins = [];
/**
* Property for holding instance of itself.
*
* @var Yoast_Plugin_Conflict
*/
protected static $instance;
/**
* For the use of singleton pattern. Create instance of itself and return this instance.
*
* @param string $class_name Give the classname to initialize. If classname is
* false (empty) it will use it's own __CLASS__.
*
* @return Yoast_Plugin_Conflict
*/
public static function get_instance( $class_name = '' ) {
if ( is_null( self::$instance ) ) {
if ( ! is_string( $class_name ) || $class_name === '' ) {
$class_name = __CLASS__;
}
self::$instance = new $class_name();
}
return self::$instance;
}
/**
* Setting instance, all active plugins and search for active plugins.
*
* Protected constructor to prevent creating a new instance of the
* *Singleton* via the `new` operator from outside this class.
*/
protected function __construct() {
// Set active plugins.
$this->all_active_plugins = get_option( 'active_plugins' );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
if ( isset( $_GET['action'] ) && is_string( $_GET['action'] ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are not processing form information and only comparing the variable in a condition.
$action = wp_unslash( $_GET['action'] );
if ( $action === 'deactivate' ) {
$this->remove_deactivated_plugin();
}
}
// Search for active plugins.
$this->search_active_plugins();
}
/**
* Check if there are conflicting plugins for given $plugin_section.
*
* @param string $plugin_section Type of plugin conflict (such as Open Graph or sitemap).
*
* @return bool
*/
public function check_for_conflicts( $plugin_section ) {
static $sections_checked;
// Return early if there are no active conflicting plugins at all.
if ( empty( $this->active_conflicting_plugins ) ) {
return false;
}
if ( $sections_checked === null ) {
$sections_checked = [];
}
if ( ! \in_array( $plugin_section, $sections_checked, true ) ) {
$sections_checked[] = $plugin_section;
return ( ! empty( $this->active_conflicting_plugins[ $plugin_section ] ) );
}
return false;
}
/**
* Checks for given $plugin_sections for conflicts.
*
* @param array $plugin_sections Set of sections.
*/
public function check_plugin_conflicts( $plugin_sections ) {
foreach ( $plugin_sections as $plugin_section => $readable_plugin_section ) {
// Check for conflicting plugins and show error if there are conflicts.
if ( $this->check_for_conflicts( $plugin_section ) ) {
$this->set_error( $plugin_section, $readable_plugin_section );
}
}
// List of all active sections.
$sections = \array_keys( $plugin_sections );
// List of all sections.
$all_plugin_sections = \array_keys( $this->plugins );
/*
* Get all sections that are inactive.
* These plugins need to be cleared.
*
* This happens when Sitemaps or OpenGraph implementations toggle active/disabled.
*/
$inactive_sections = \array_diff( $all_plugin_sections, $sections );
if ( ! empty( $inactive_sections ) ) {
foreach ( $inactive_sections as $section ) {
\array_walk( $this->plugins[ $section ], [ $this, 'clear_error' ] );
}
}
// For active sections clear errors for inactive plugins.
foreach ( $sections as $section ) {
// By default, clear errors for all plugins of the section.
$inactive_plugins = $this->plugins[ $section ];
// If there are active plugins, filter them from being cleared.
if ( isset( $this->active_conflicting_plugins[ $section ] ) ) {
$inactive_plugins = \array_diff( $this->plugins[ $section ], $this->active_conflicting_plugins[ $section ] );
}
\array_walk( $inactive_plugins, [ $this, 'clear_error' ] );
}
}
/**
* Setting an error on the screen.
*
* @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
* @param string $readable_plugin_section This is the value for the translation.
*/
protected function set_error( $plugin_section, $readable_plugin_section ) {
$notification_center = Yoast_Notification_Center::get();
foreach ( $this->active_conflicting_plugins[ $plugin_section ] as $plugin_file ) {
$plugin_name = $this->get_plugin_name( $plugin_file );
$error_message = '';
/* translators: %1$s: 'Facebook & Open Graph' plugin name(s) of possibly conflicting plugin(s), %2$s to Yoast SEO */
$error_message .= '<p>' . sprintf( __( 'The %1$s plugin might cause issues when used in conjunction with %2$s.', 'wordpress-seo' ), '<em>' . $plugin_name . '</em>', 'Yoast SEO' ) . '</p>';
$error_message .= '<p>' . sprintf( $readable_plugin_section, 'Yoast SEO', $plugin_name ) . '</p>';
/* translators: %s: 'Facebook' plugin name of possibly conflicting plugin */
$error_message .= '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=all', 'deactivate-plugin_' . $plugin_file ) . '">' . sprintf( __( 'Deactivate %s', 'wordpress-seo' ), $this->get_plugin_name( $plugin_file ) ) . '</a> ';
$identifier = $this->get_notification_identifier( $plugin_file );
// Add the message to the notifications center.
$notification_center->add_notification(
new Yoast_Notification(
$error_message,
[
'type' => Yoast_Notification::ERROR,
'id' => 'wpseo-conflict-' . $identifier,
]
)
);
}
}
/**
* Clear the notification for a plugin.
*
* @param string $plugin_file Clear the optional notification for this plugin.
*/
public function clear_error( $plugin_file ) {
$identifier = $this->get_notification_identifier( $plugin_file );
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification_by_id( 'wpseo-conflict-' . $identifier );
}
/**
* Loop through the $this->plugins to check if one of the plugins is active.
*
* This method will store the active plugins in $this->active_plugins.
*/
protected function search_active_plugins() {
foreach ( $this->plugins as $plugin_section => $plugins ) {
$this->check_plugins_active( $plugins, $plugin_section );
}
}
/**
* Loop through plugins and check if each plugin is active.
*
* @param array $plugins Set of plugins.
* @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
*/
protected function check_plugins_active( $plugins, $plugin_section ) {
foreach ( $plugins as $plugin ) {
if ( $this->check_plugin_is_active( $plugin ) ) {
$this->add_active_plugin( $plugin_section, $plugin );
}
}
}
/**
* Check if given plugin exists in array with all_active_plugins.
*
* @param string $plugin Plugin basename string.
*
* @return bool
*/
protected function check_plugin_is_active( $plugin ) {
return \in_array( $plugin, $this->all_active_plugins, true );
}
/**
* Add plugin to the list of active plugins.
*
* This method will check first if key $plugin_section exists, if not it will create an empty array
* If $plugin itself doesn't exist it will be added.
*
* @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
* @param string $plugin Plugin basename string.
*/
protected function add_active_plugin( $plugin_section, $plugin ) {
if ( ! \array_key_exists( $plugin_section, $this->active_conflicting_plugins ) ) {
$this->active_conflicting_plugins[ $plugin_section ] = [];
}
if ( ! \in_array( $plugin, $this->active_conflicting_plugins[ $plugin_section ], true ) ) {
$this->active_conflicting_plugins[ $plugin_section ][] = $plugin;
}
}
/**
* Search in $this->plugins for the given $plugin.
*
* If there is a result it will return the plugin category.
*
* @param string $plugin Plugin basename string.
*
* @return int|string
*/
protected function find_plugin_category( $plugin ) {
foreach ( $this->plugins as $plugin_section => $plugins ) {
if ( \in_array( $plugin, $plugins, true ) ) {
return $plugin_section;
}
}
}
/**
* Get plugin name from file.
*
* @param string $plugin Plugin path relative to plugins directory.
*
* @return string|bool Plugin name or false when no name is set.
*/
protected function get_plugin_name( $plugin ) {
$plugin_details = \get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
if ( $plugin_details['Name'] !== '' ) {
return $plugin_details['Name'];
}
return false;
}
/**
* When being in the deactivation process the currently deactivated plugin has to be removed.
*/
private function remove_deactivated_plugin() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: On the deactivation screen the nonce is already checked by WordPress itself.
if ( ! isset( $_GET['plugin'] ) || ! is_string( $_GET['plugin'] ) ) {
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: On the deactivation screen the nonce is already checked by WordPress itself.
$deactivated_plugin = sanitize_text_field( wp_unslash( $_GET['plugin'] ) );
$key_to_remove = \array_search( $deactivated_plugin, $this->all_active_plugins, true );
if ( $key_to_remove !== false ) {
unset( $this->all_active_plugins[ $key_to_remove ] );
}
}
/**
* Get the identifier from the plugin file.
*
* @param string $plugin_file Plugin file to get Identifier from.
*
* @return string
*/
private function get_notification_identifier( $plugin_file ) {
return \md5( $plugin_file );
}
}

View File

@@ -1,79 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Configuration_Components.
*/
class WPSEO_Configuration_Components {
/**
* List of registered components.
*
* @var WPSEO_Config_Component[]
*/
protected $components = [];
/**
* Adapter.
*
* @var WPSEO_Configuration_Options_Adapter
*/
protected $adapter;
/**
* Add default components.
*/
public function initialize() {
$this->add_component( new WPSEO_Config_Component_Mailchimp_Signup() );
$this->add_component( new WPSEO_Config_Component_Suggestions() );
}
/**
* Add a component.
*
* @param WPSEO_Config_Component $component Component to add.
*/
public function add_component( WPSEO_Config_Component $component ) {
$this->components[] = $component;
}
/**
* Sets the storage to use.
*
* @param WPSEO_Configuration_Storage $storage Storage to use.
*/
public function set_storage( WPSEO_Configuration_Storage $storage ) {
$this->set_adapter( $storage->get_adapter() );
foreach ( $this->components as $component ) {
$storage->add_field( $component->get_field() );
}
}
/**
* Sets the adapter to use.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to use.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$this->adapter = $adapter;
foreach ( $this->components as $component ) {
$adapter->add_custom_lookup(
$component->get_field()->get_identifier(),
[
$component,
'get_data',
],
[
$component,
'set_data',
]
);
}
}
}

View File

@@ -1,102 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Configuration_Endpoint.
*/
class WPSEO_Configuration_Endpoint {
/**
* Holds the REST namespace.
*
* @var string
*/
const REST_NAMESPACE = 'yoast/v1';
/**
* Holds the endpoint to retrieve from.
*
* @var string
*/
const ENDPOINT_RETRIEVE = 'configurator';
/**
* Holds the endpoint to store to.
*
* @var string
*/
const ENDPOINT_STORE = 'configurator';
/**
* Holds the capability that can retrieve from the endpoint.
*
* @var string
*/
const CAPABILITY_RETRIEVE = 'wpseo_manage_options';
/**
* Holds the capability that can store to the endpoint.
*
* @var string
*/
const CAPABILITY_STORE = 'wpseo_manage_options';
/**
* Service to use.
*
* @var WPSEO_Configuration_Service
*/
protected $service;
/**
* Sets the service to use.
*
* @param WPSEO_Configuration_Service $service Service to use.
*/
public function set_service( WPSEO_Configuration_Service $service ) {
$this->service = $service;
}
/**
* Register REST routes.
*/
public function register() {
// Register fetch config.
$route_args = [
'methods' => 'GET',
'callback' => [ $this->service, 'get_configuration' ],
'permission_callback' => [ $this, 'can_retrieve_data' ],
];
register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_RETRIEVE, $route_args );
// Register save changes.
$route_args = [
'methods' => 'POST',
'callback' => [ $this->service, 'set_configuration' ],
'permission_callback' => [ $this, 'can_save_data' ],
];
register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_STORE, $route_args );
}
/**
* Permission callback implementation.
*
* @return bool
*/
public function can_retrieve_data() {
return current_user_can( self::CAPABILITY_RETRIEVE );
}
/**
* Permission callback implementation.
*
* @return bool
*/
public function can_save_data() {
return current_user_can( self::CAPABILITY_STORE );
}
}

View File

@@ -1,205 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Configuration_Options_Adapter.
*
* Convert Configuration settings to WPSEO Options.
*
* @since 3.6
*/
class WPSEO_Configuration_Options_Adapter {
/**
* Holds the option type value that indicates: WordPress.
*
* @var string
*/
const OPTION_TYPE_WORDPRESS = 'wordpress';
/**
* Holds the option type value that indicates: Yoast.
*
* @var string
*/
const OPTION_TYPE_YOAST = 'yoast';
/**
* Holds the option type value that indicates: Custom.
*
* @var string
*/
const OPTION_TYPE_CUSTOM = 'custom';
/**
* List of registered lookups.
*
* @var array
*/
protected $lookup = [];
/**
* Add a lookup for a WordPress native option.
*
* @param string $class_name Class to bind to an option.
* @param string $option Option name to use.
*
* @throws InvalidArgumentException Thrown when invalid input is provided.
*/
public function add_wordpress_lookup( $class_name, $option ) {
if ( ! is_string( $option ) ) {
throw new InvalidArgumentException( 'WordPress option must be a string.' );
}
$this->add_lookup( $class_name, self::OPTION_TYPE_WORDPRESS, $option );
}
/**
* Add a lookup for a Yoast option.
*
* @param string $class_name Class to bind to the lookup.
* @param string $key Key in the option group to bind to.
*
* @throws InvalidArgumentException Thrown when invalid input is provided.
*/
public function add_option_lookup( $class_name, $key ) {
$test = WPSEO_Options::get( $key );
if ( is_null( $test ) ) {
/* translators: %1$s resolves to the option name passed to the lookup registration */
throw new InvalidArgumentException( sprintf( __( 'Yoast option %1$s not found.', 'wordpress-seo' ), $key ) );
}
$this->add_lookup( $class_name, self::OPTION_TYPE_YOAST, $key );
}
/**
* Add a lookup for a custom implementation.
*
* @param string $class_name Class to bind to the lookup.
* @param callable $callback_get Callback to retrieve data.
* @param callable $callback_set Callback to save data.
*
* @throws InvalidArgumentException Thrown when invalid input is provided.
*/
public function add_custom_lookup( $class_name, $callback_get, $callback_set ) {
if ( ! is_callable( $callback_get ) || ! is_callable( $callback_set ) ) {
throw new InvalidArgumentException( 'Custom option must be callable.' );
}
$this->add_lookup(
$class_name,
self::OPTION_TYPE_CUSTOM,
[ $callback_get, $callback_set ]
);
}
/**
* Add a field lookup.
*
* @param string $class_name Class to add lookup for.
* @param string $type Type of lookup.
* @param string|array $option Implementation of the lookup.
*
* @throws Exception Thrown when invalid input is provided.
*/
protected function add_lookup( $class_name, $type, $option ) {
$this->lookup[ $class_name ] = [
'type' => $type,
'option' => $option,
];
}
/**
* Get the data for the provided field.
*
* @param WPSEO_Config_Field $field Field to get data for.
*
* @return mixed
*/
public function get( WPSEO_Config_Field $field ) {
$identifier = $field->get_identifier();
// Lookup option and retrieve value.
$type = $this->get_option_type( $identifier );
$option = $this->get_option( $identifier );
switch ( $type ) {
case self::OPTION_TYPE_WORDPRESS:
return get_option( $option );
case self::OPTION_TYPE_YOAST:
return WPSEO_Options::get( $option );
case self::OPTION_TYPE_CUSTOM:
return call_user_func( $option[0] );
}
return null;
}
/**
* Save data from a field.
*
* @param WPSEO_Config_Field $field Field to use for lookup.
* @param mixed $value Value to save to the lookup of the field.
*
* @return bool
*/
public function set( WPSEO_Config_Field $field, $value ) {
$identifier = $field->get_identifier();
// Lookup option and retrieve value.
$type = $this->get_option_type( $identifier );
$option = $this->get_option( $identifier );
switch ( $type ) {
case self::OPTION_TYPE_WORDPRESS:
return update_option( $option, $value );
case self::OPTION_TYPE_YOAST:
return WPSEO_Options::set( $option, $value );
case self::OPTION_TYPE_CUSTOM:
return call_user_func( $option[1], $value );
}
return false;
}
/**
* Get the lookup type for a specific class.
*
* @param string $class_name Class to get the type of.
*
* @return string|null
*/
protected function get_option_type( $class_name ) {
if ( ! isset( $this->lookup[ $class_name ] ) ) {
return null;
}
return $this->lookup[ $class_name ]['type'];
}
/**
* Get the option for a specific class.
*
* @param string $class_name Class to get the option of.
*
* @return string|array|null
*/
protected function get_option( $class_name ) {
if ( ! isset( $this->lookup[ $class_name ] ) ) {
return null;
}
return $this->lookup[ $class_name ]['option'];
}
}

View File

@@ -1,254 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/
/**
* Loads the Yoast configuration wizard.
*/
class WPSEO_Configuration_Page {
/**
* Admin page identifier.
*
* @var string
*/
const PAGE_IDENTIFIER = 'wpseo_configurator';
/**
* Sets the hooks when the user has enough rights and is on the right page.
*/
public function set_hooks() {
if ( ! ( $this->is_config_page() && current_user_can( WPSEO_Configuration_Endpoint::CAPABILITY_RETRIEVE ) ) ) {
return;
}
if ( $this->should_add_notification() ) {
$this->add_notification();
}
// Register the page for the wizard.
add_action( 'admin_menu', [ $this, 'add_wizard_page' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
add_action( 'admin_init', [ $this, 'render_wizard_page' ] );
}
/**
* Check if the configuration is finished. If so, just remove the notification.
*/
public function catch_configuration_request() {
$configuration_page = filter_input( INPUT_GET, 'configuration' );
$page = filter_input( INPUT_GET, 'page' );
if ( ! ( $configuration_page === 'finished' && ( $page === WPSEO_Admin::PAGE_IDENTIFIER ) ) ) {
return;
}
$this->remove_notification();
$this->remove_notification_option();
wp_safe_redirect( admin_url( 'admin.php?page=' . WPSEO_Admin::PAGE_IDENTIFIER ) );
exit;
}
/**
* Registers the page for the wizard.
*/
public function add_wizard_page() {
add_dashboard_page( '', '', 'wpseo_manage_options', self::PAGE_IDENTIFIER, '' );
}
/**
* Renders the wizard page and exits to prevent the WordPress UI from loading.
*/
public function render_wizard_page() {
$this->show_wizard();
exit;
}
/**
* Enqueues the assets needed for the wizard.
*/
public function enqueue_assets() {
wp_enqueue_media();
if ( ! wp_script_is( 'wp-element', 'registered' ) && function_exists( 'gutenberg_register_scripts_and_styles' ) ) {
gutenberg_register_scripts_and_styles();
}
/*
* Print the `forms.css` WP stylesheet before any Yoast style, this way
* it's easier to override selectors with the same specificity later.
*/
wp_enqueue_style( 'forms' );
$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->register_assets();
$asset_manager->enqueue_script( 'configuration-wizard' );
$asset_manager->enqueue_style( 'yoast-components' );
$config = $this->get_config();
$asset_manager->localize_script( 'configuration-wizard', 'yoastWizardConfig', $config );
$yoast_components_l10n = new WPSEO_Admin_Asset_Yoast_Components_L10n();
$yoast_components_l10n->localize_script( 'configuration-wizard' );
}
/**
* Setup Wizard Header.
*/
public function show_wizard() {
$this->enqueue_assets();
$dashboard_url = admin_url( '/admin.php?page=wpseo_dashboard' );
$wizard_title = sprintf(
/* translators: %s expands to Yoast SEO. */
__( '%s &rsaquo; Configuration Wizard', 'wordpress-seo' ),
'Yoast SEO'
);
?>
<!DOCTYPE html>
<!--[if IE 9]>
<html class="ie9" <?php language_attributes(); ?> >
<![endif]-->
<!--[if !(IE 9) ]><!-->
<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><?php echo esc_html( $wizard_title ); ?></title>
<?php
wp_print_head_scripts();
wp_print_styles( 'yoast-seo-yoast-components' );
/**
* Is called before the closing </head> tag in the Yoast Configuration wizard.
*
* Allows users to add their own scripts or styles.
*
* @since 4.0
*/
do_action( 'wpseo_configuration_wizard_head' );
?>
</head>
<body class="wp-admin wp-core-ui">
<div id="wizard"></div>
<div role="contentinfo" class="yoast-wizard-return-link-container">
<a class="button yoast-wizard-return-link" href="<?php echo esc_url( $dashboard_url ); ?>">
<span aria-hidden="true" class="dashicons dashicons-no"></span>
<?php
esc_html_e( 'Close the Wizard', 'wordpress-seo' );
?>
</a>
</div>
<?php
wp_print_media_templates();
wp_print_footer_scripts();
/**
* Is called before the closing </body> tag in the Yoast Configuration wizard.
*
* Allows users to add their own scripts.
*
* @since 4.0
*/
do_action( 'wpseo_configuration_wizard_footer' );
wp_print_scripts( 'yoast-seo-configuration-wizard' );
?>
</body>
</html>
<?php
}
/**
* Get the API config for the wizard.
*
* @return array The API endpoint config.
*/
public function get_config() {
$config = [
'namespace' => WPSEO_Configuration_Endpoint::REST_NAMESPACE,
'endpoint_retrieve' => WPSEO_Configuration_Endpoint::ENDPOINT_RETRIEVE,
'endpoint_store' => WPSEO_Configuration_Endpoint::ENDPOINT_STORE,
'nonce' => wp_create_nonce( 'wp_rest' ),
'root' => esc_url_raw( rest_url() ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'finishUrl' => admin_url( 'admin.php?page=wpseo_dashboard&configuration=finished' ),
];
return $config;
}
/**
* Checks if the current page is the configuration page.
*
* @return bool
*/
protected function is_config_page() {
return ( filter_input( INPUT_GET, 'page' ) === self::PAGE_IDENTIFIER );
}
/**
* Adds a notification to the notification center.
*/
private function add_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->add_notification( self::get_notification() );
}
/**
* Removes the notification from the notification center.
*/
private function remove_notification() {
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification( self::get_notification() );
}
/**
* Gets the notification.
*
* @return Yoast_Notification
*/
private static function get_notification() {
$message = __( 'The configuration wizard helps you to easily configure your site to have the optimal SEO settings.', 'wordpress-seo' );
$message .= '<br/>';
$message .= sprintf(
/* translators: %1$s resolves to Yoast SEO, %2$s resolves to the starting tag of the link to the wizard, %3$s resolves to the closing link tag */
__( 'We have detected that you have not finished this wizard yet, so we recommend you to %2$sstart the configuration wizard to configure %1$s%3$s.', 'wordpress-seo' ),
'Yoast SEO',
'<a href="' . admin_url( '?page=' . self::PAGE_IDENTIFIER ) . '">',
'</a>'
);
$notification = new Yoast_Notification(
$message,
[
'type' => Yoast_Notification::WARNING,
'id' => 'wpseo-dismiss-onboarding-notice',
'capabilities' => 'wpseo_manage_options',
'priority' => 0.8,
]
);
return $notification;
}
/**
* When the notice should be shown.
*
* @return bool
*/
private function should_add_notification() {
return ( WPSEO_Options::get( 'show_onboarding_notice' ) === true );
}
/**
* Remove the options that triggers the notice for the configuration wizard.
*/
private function remove_notification_option() {
WPSEO_Options::set( 'show_onboarding_notice', false );
}
}

View File

@@ -1,182 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Configuration_Service.
*/
class WPSEO_Configuration_Service {
/**
* Class holding the onboarding wizard configuration.
*
* @var WPSEO_Configuration_Structure
*/
protected $structure;
/**
* Class holding the onboarding wizard components.
*
* @var WPSEO_Configuration_Components
*/
protected $components;
/**
* Class handling the onboarding wizard persistence.
*
* @var WPSEO_Configuration_Storage
*/
protected $storage;
/**
* Class handling the onboarding wizard endpoint.
*
* @var WPSEO_Configuration_Endpoint
*/
protected $endpoint;
/**
* Adapter that converts onboarding wizard configuration to WordPress options.
*
* @var WPSEO_Configuration_Options_Adapter
*/
protected $adapter;
/**
* Class handling the onboarding wizard endpoint.
*
* @var WPSEO_Configuration_Translations
*/
protected $translations;
/**
* Hook into the REST API and switch language.
*/
public function initialize() {
$this->set_default_providers();
$this->endpoint->register();
}
/**
* Set default handlers.
*/
public function set_default_providers() {
$this->set_storage( new WPSEO_Configuration_Storage() );
$this->set_options_adapter( new WPSEO_Configuration_Options_Adapter() );
$this->set_components( new WPSEO_Configuration_Components() );
$this->set_endpoint( new WPSEO_Configuration_Endpoint() );
$this->set_structure( new WPSEO_Configuration_Structure() );
$this->set_translations( new WPSEO_Configuration_Translations( \get_user_locale() ) );
}
/**
* Set storage handler.
*
* @param WPSEO_Configuration_Storage $storage Storage handler to use.
*/
public function set_storage( WPSEO_Configuration_Storage $storage ) {
$this->storage = $storage;
}
/**
* Set endpoint handler.
*
* @param WPSEO_Configuration_Endpoint $endpoint Endpoint implementation to use.
*/
public function set_endpoint( WPSEO_Configuration_Endpoint $endpoint ) {
$this->endpoint = $endpoint;
$this->endpoint->set_service( $this );
}
/**
* Set the options adapter.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to use.
*/
public function set_options_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$this->adapter = $adapter;
}
/**
* Set components provider.
*
* @param WPSEO_Configuration_Components $components Component provider to use.
*/
public function set_components( WPSEO_Configuration_Components $components ) {
$this->components = $components;
}
/**
* Set structure provider.
*
* @param WPSEO_Configuration_Structure $structure Structure provider to use.
*/
public function set_structure( WPSEO_Configuration_Structure $structure ) {
$this->structure = $structure;
}
/**
* Sets the translations object.
*
* @param WPSEO_Configuration_Translations $translations The translations object.
*/
public function set_translations( WPSEO_Configuration_Translations $translations ) {
$this->translations = $translations;
}
/**
* Populate the configuration.
*/
protected function populate_configuration() {
// Switch to the user locale with fallback to the site locale.
switch_to_locale( \get_user_locale() );
// Make sure we have our translations available.
wpseo_load_textdomain();
$this->structure->initialize();
$this->storage->set_adapter( $this->adapter );
$this->storage->add_default_fields();
$this->components->initialize();
$this->components->set_storage( $this->storage );
// @todo: check if this is really needed, since the switch happens only in the API.
restore_current_locale();
}
/**
* Used by endpoint to retrieve configuration.
*
* @return array List of settings.
*/
public function get_configuration() {
$this->populate_configuration();
$fields = $this->storage->retrieve();
$steps = $this->structure->retrieve();
$translations = $this->translations->retrieve();
return [
'fields' => $fields,
'steps' => $steps,
'translations' => $translations,
];
}
/**
* Used by endpoint to store changes.
*
* @param WP_REST_Request $request Request from the REST API.
*
* @return array List of feedback per option if saving succeeded.
*/
public function set_configuration( WP_REST_Request $request ) {
$this->populate_configuration();
return $this->storage->store( $request->get_json_params() );
}
}

View File

@@ -1,205 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Configuration_Storage.
*/
class WPSEO_Configuration_Storage {
/**
* Holds the configuration options adapter.
*
* @var \WPSEO_Configuration_Options_Adapter
*/
protected $adapter;
/**
* Holds the configuration fields.
*
* @var \WPSEO_Config_Field[]
*/
protected $fields = [];
/**
* Add default fields.
*/
public function add_default_fields() {
$fields = [
new WPSEO_Config_Field_Success_Message(),
new WPSEO_Config_Field_Mailchimp_Signup(),
new WPSEO_Config_Field_Environment(),
new WPSEO_Config_Field_Site_Type(),
new WPSEO_Config_Field_Multiple_Authors(),
new WPSEO_Config_Field_Title_Intro(),
new WPSEO_Config_Field_Site_Name(),
new WPSEO_Config_Field_Separator(),
new WPSEO_Config_Field_Profile_URL_Facebook(),
new WPSEO_Config_Field_Profile_URL_Twitter(),
new WPSEO_Config_Field_Profile_URL_Instagram(),
new WPSEO_Config_Field_Profile_URL_LinkedIn(),
new WPSEO_Config_Field_Profile_URL_MySpace(),
new WPSEO_Config_Field_Profile_URL_Pinterest(),
new WPSEO_Config_Field_Profile_URL_YouTube(),
new WPSEO_Config_Field_Profile_URL_Wikipedia(),
new WPSEO_Config_Field_Company_Or_Person(),
new WPSEO_Config_Field_Company_Info_Missing(),
new WPSEO_Config_Field_Company_Name(),
new WPSEO_Config_Field_Company_Logo(),
new WPSEO_Config_Field_Person(),
new WPSEO_Config_Field_Post_Type_Visibility(),
new WPSEO_Config_Field_Tracking_Intro(),
new WPSEO_Config_Field_Tracking(),
];
$post_type_factory = new WPSEO_Config_Factory_Post_Type();
$fields = array_merge( $fields, $post_type_factory->get_fields() );
foreach ( $fields as $field ) {
$this->add_field( $field );
}
}
/**
* Allow for field injections.
*
* @param WPSEO_Config_Field $field Field to add to the stack.
*/
public function add_field( WPSEO_Config_Field $field ) {
$this->fields[] = $field;
if ( isset( $this->adapter ) ) {
$field->set_adapter( $this->adapter );
}
}
/**
* Set the adapter to use.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to use.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$this->adapter = $adapter;
foreach ( $this->fields as $field ) {
$field->set_adapter( $this->adapter );
}
}
/**
* Retrieve the current adapter.
*
* @return WPSEO_Configuration_Options_Adapter
*/
public function get_adapter() {
return $this->adapter;
}
/**
* Retrieve the registered fields.
*
* @return array List of settings.
*/
public function retrieve() {
$output = [];
foreach ( $this->fields as $field ) {
$build = $field->to_array();
$data = $this->get_field_data( $field );
if ( ! is_null( $data ) ) {
$build['data'] = $data;
}
$output[ $field->get_identifier() ] = $build;
}
return $output;
}
/**
* Save the data.
*
* @param array $data_to_store Data provided by the API which needs to be processed for saving.
*
* @return string Results
*/
public function store( $data_to_store ) {
$output = [];
foreach ( $this->fields as $field ) {
$field_identifier = $field->get_identifier();
if ( ! array_key_exists( $field_identifier, $data_to_store ) ) {
continue;
}
$field_data = [];
if ( isset( $data_to_store[ $field_identifier ] ) ) {
$field_data = $data_to_store[ $field_identifier ];
}
$result = $this->adapter->set( $field, $field_data );
$build = [
'result' => $result,
];
// Set current data to object to be displayed.
$data = $this->get_field_data( $field );
if ( ! is_null( $data ) ) {
$build['data'] = $data;
}
$output[ $field_identifier ] = $build;
}
return $output;
}
/**
* Filter out null input values.
*
* @param mixed $input Input to test against.
*
* @return bool
*/
protected function is_not_null( $input ) {
return ! is_null( $input );
}
/**
* Get data from a specific field.
*
* @param WPSEO_Config_Field $field Field to get data for.
*
* @return array|mixed
*/
protected function get_field_data( WPSEO_Config_Field $field ) {
$data = $this->adapter->get( $field );
if ( is_array( $data ) ) {
$defaults = $field->get_data();
// Remove 'null' values from input.
$data = array_filter( $data, [ $this, 'is_not_null' ] );
// Merge defaults with data.
$data = array_merge( $defaults, $data );
}
if ( is_null( $data ) ) {
// Get default if no data was set.
$data = $field->get_data();
return $data;
}
return $data;
}
}

View File

@@ -1,123 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Configuration_Structure
*/
class WPSEO_Configuration_Structure {
/**
* Registered steps.
*
* @var array
*/
protected $steps = [];
/**
* List of fields for each configuration step.
*
* This list does not include the fields for the 'postTypeVisibility'
* step as that list will be generated on the fly.
*
* @var array
*/
private $fields = [
'environment_type' => [ 'environment_type' ],
'siteType' => [ 'siteType' ],
'publishingEntity' => [
'publishingEntity',
'publishingEntityType',
'publishingEntityCompanyInfo',
'publishingEntityCompanyName',
'publishingEntityCompanyLogo',
'publishingEntityPersonId',
'profileUrlFacebook',
'profileUrlTwitter',
'profileUrlInstagram',
'profileUrlLinkedIn',
'profileUrlMySpace',
'profileUrlPinterest',
'profileUrlYouTube',
'profileUrlWikipedia',
],
'multipleAuthors' => [ 'multipleAuthors' ],
'titleTemplate' => [
'titleIntro',
'siteName',
'separator',
],
'tracking' => [
'trackingIntro',
'tracking',
],
'newsletter' => [
'mailchimpSignup',
'suggestions',
],
'success' => [ 'successMessage' ],
];
/**
* WPSEO_Configuration_Structure constructor.
*/
public function initialize() {
$this->add_step( 'environment-type', __( 'Environment', 'wordpress-seo' ), $this->fields['environment_type'] );
$this->add_step( 'site-type', __( 'Site type', 'wordpress-seo' ), $this->fields['siteType'] );
$this->add_step(
'publishing-entity',
__( 'Organization or person', 'wordpress-seo' ),
$this->fields['publishingEntity']
);
$fields = [ 'postTypeVisibility' ];
$post_type_factory = new WPSEO_Config_Factory_Post_Type();
foreach ( $post_type_factory->get_fields() as $post_type_field ) {
$fields[] = $post_type_field->get_identifier();
}
$this->add_step( 'post-type-visibility', __( 'Search engine visibility', 'wordpress-seo' ), $fields );
$this->add_step(
'multiple-authors',
__( 'Multiple authors', 'wordpress-seo' ),
$this->fields['multipleAuthors']
);
$this->add_step( 'title-template', __( 'Title settings', 'wordpress-seo' ), $this->fields['titleTemplate'] );
/* translators: %s expands to Yoast SEO */
$this->add_step( 'tracking', sprintf( __( 'Help us improve %s', 'wordpress-seo' ), 'Yoast SEO' ), $this->fields['tracking'] );
$this->add_step( 'newsletter', __( 'Continue learning', 'wordpress-seo' ), $this->fields['newsletter'], true, true );
$this->add_step( 'success', __( 'Success!', 'wordpress-seo' ), $this->fields['success'], true, true );
}
/**
* Add a step to the structure
*
* @param string $identifier Identifier for this step.
* @param string $title Title to display for this step.
* @param array $fields Fields to use on the step.
* @param bool $navigation Show navigation buttons.
* @param bool $full_width Wheter the step content is full width or not.
*/
protected function add_step( $identifier, $title, $fields, $navigation = true, $full_width = false ) {
$this->steps[ $identifier ] = [
'title' => $title,
'fields' => $fields,
'hideNavigation' => ! (bool) $navigation,
'fullWidth' => $full_width,
];
}
/**
* Retrieve the registered steps.
*
* @return array
*/
public function retrieve() {
return $this->steps;
}
}

View File

@@ -1,64 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Configuration_Structure.
*/
class WPSEO_Configuration_Translations {
/**
* Registered steps.
*
* @var array
*/
protected $translations = [];
/**
* The locale.
*
* @var string
*/
protected $locale;
/**
* Sets the translations based on the file.
*
* @param string $locale The locale to retrieve the translations for.
*/
public function __construct( $locale ) {
$this->locale = $locale;
$this->translations = $this->get_translations_from_file();
}
/**
* Retrieve the translations.
*
* @return array
*/
public function retrieve() {
return $this->translations;
}
/**
* Retrieves the translations from the JSON-file.
*
* @return array Array with the translations.
*/
protected function get_translations_from_file() {
$file = WPSEO_PATH . 'languages/yoast-components-' . $this->locale . '.json';
if ( file_exists( $file ) ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Retrieving a local file.
$file = file_get_contents( $file );
if ( is_string( $file ) && $file !== '' ) {
return json_decode( $file, true );
}
}
return [];
}
}

View File

@@ -1,86 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Represents the mailchimp signup components.
*/
class WPSEO_Config_Component_Mailchimp_Signup implements WPSEO_Config_Component {
/**
* The name of the mailchimp signup meta key.
*
* @var string
*/
const META_NAME = 'wpseo-has-mailchimp-signup';
/**
* Gets the component identifier.
*
* @return string
*/
public function get_identifier() {
return 'MailchimpSignup';
}
/**
* Gets the field.
*
* @return WPSEO_Config_Field_Mailchimp_Signup
*/
public function get_field() {
return new WPSEO_Config_Field_Mailchimp_Signup();
}
/**
* Get the data for the field.
*
* @return mixed
*/
public function get_data() {
$data = [
'hasSignup' => $this->has_mailchimp_signup(),
];
return $data;
}
/**
* Save data.
*
* @param array $data Data containing changes.
*
* @return mixed
*/
public function set_data( $data ) {
$has_saved = false;
if ( ! empty( $data['hasSignup'] ) ) {
// Saves the user meta.
update_user_meta( get_current_user_id(), self::META_NAME, true );
$has_saved = ( $data['hasSignup'] === $this->has_mailchimp_signup() );
}
// Collect results to return to the configurator.
$results = [
'hasSignup' => $has_saved,
];
return $results;
}
/**
* Checks if the user has entered their email for mailchimp already.
*
* @return bool
*/
protected function has_mailchimp_signup() {
$user_meta = get_user_meta( get_current_user_id(), self::META_NAME, true );
return ( ! empty( $user_meta ) );
}
}

View File

@@ -1,119 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Represents the configuration suggestions component.
*/
class WPSEO_Config_Component_Suggestions implements WPSEO_Config_Component {
/**
* Gets the component identifier.
*
* @return string
*/
public function get_identifier() {
return 'Suggestions';
}
/**
* Gets the field.
*
* @return WPSEO_Config_Field
*/
public function get_field() {
$field = new WPSEO_Config_Field_Suggestions();
// Only show Premium upsell when we are not inside a Premium install.
if ( ! YoastSEO()->helpers->product->is_premium() ) {
$field->add_suggestion(
/* translators: %s resolves to Yoast SEO Premium */
sprintf( __( 'Outrank the competition with %s', 'wordpress-seo' ), 'Yoast SEO Premium' ),
/* translators: %1$s resolves to Yoast SEO Premium */
sprintf( __( 'Do you want to outrank your competition? %1$s gives you awesome additional features that\'ll help you to set up your SEO strategy like a professional. Add synonyms and related keywords, use our Premium SEO analysis, the redirect manager and our internal linking tool. %1$s will also give you access to premium support.', 'wordpress-seo' ), 'Yoast SEO Premium' ),
[
'label' => __( 'Upgrade to Premium', 'wordpress-seo' ),
'type' => 'primary',
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/wizard-suggestion-premium' ),
],
[
'url' => WPSEO_Shortlinker::get( 'https://yoa.st/video-yoast-seo-premium' ),
'title' => sprintf(
/* translators: %1$s expands to Yoast SEO Premium. */
__( '%1$s video', 'wordpress-seo' ),
'Yoast SEO Premium'
),
]
);
}
$field->add_suggestion(
__( 'Find out what words your audience uses to find you', 'wordpress-seo' ),
sprintf(
/* translators: %1$s resolves to Keyword research training */
__( 'Keyword research is essential in any SEO strategy. You decide the search terms you want to be found for, and figure out what words your audience uses to find you. Great keyword research tells you what content you need to start ranking for the terms you want to rank for. Make sure your efforts go into the keywords you actually have a chance at ranking for! The %1$s walks you through this process, step by step.', 'wordpress-seo' ),
'Keyword research training'
),
[
'label' => 'Keyword research training',
'type' => 'link',
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/3lg' ),
],
[
'url' => WPSEO_Shortlinker::get( 'https://yoa.st/3lf' ),
'title' => sprintf(
/* translators: %1$s expands to Keyword research training. */
__( '%1$s video', 'wordpress-seo' ),
'Keyword research training'
),
]
);
// When we are running in Yoast SEO Premium and don't have Local SEO installed, show Local SEO as suggestion.
if ( YoastSEO()->helpers->product->is_premium() && ! defined( 'WPSEO_LOCAL_FILE' ) ) {
$field->add_suggestion(
__( 'Attract more customers near you', 'wordpress-seo' ),
/* translators: %1$s resolves to Local SEO */
sprintf( __( 'If you want to outrank the competition in a specific town or region, check out our %1$s plugin! Youll be able to easily insert Google maps, opening hours, contact information and a store locator. Besides that %1$s helps you to improve the usability of your contact page.', 'wordpress-seo' ), 'Local SEO' ),
[
'label' => 'Local SEO',
'type' => 'link',
'href' => WPSEO_Shortlinker::get( 'https://yoa.st/wizard-suggestion-local-seo' ),
],
[
'url' => WPSEO_Shortlinker::get( 'https://yoa.st/video-localseo' ),
'title' => sprintf(
/* translators: %1$s expands to Local SEO. */
__( '%1$s video', 'wordpress-seo' ),
'Local SEO'
),
]
);
}
return $field;
}
/**
* Get the data for the field.
*
* @return array
*/
public function get_data() {
return [];
}
/**
* Save data.
*
* @param array $data Data containing changes.
*
* @return bool
*/
public function set_data( $data ) {
return true;
}
}

View File

@@ -1,42 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Config Component interface.
*/
interface WPSEO_Config_Component {
/**
* Get onboarding wizard component identifier.
*
* @return string
*/
public function get_identifier();
/**
* Get onboarding wizard component data.
*
* @return mixed
*/
public function get_data();
/**
* Save changes.
*
* @param array $data Data provided by the API.
*
* @return mixed
*/
public function set_data( $data );
/**
* Get onboarding wizard component field.
*
* @return WPSEO_Config_Field
*/
public function get_field();
}

View File

@@ -1,76 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Configurator
*/
/**
* Class WPSEO_Config_Factory_Post_Type.
*/
class WPSEO_Config_Factory_Post_Type {
/**
* List of fields.
*
* @var WPSEO_Config_Field_Choice_Post_Type[]
*/
protected static $fields = [];
/**
* Retrieves a list of fields.
*
* @return WPSEO_Config_Field_Choice_Post_Type[] List of fields.
*/
public function get_fields() {
if ( empty( self::$fields ) ) {
$fields = [];
// WPSEO_Post_type::get_accessible_post_types() should *not* be used to get a similar experience from the settings.
$post_types = get_post_types( [ 'public' => true ], 'objects' );
$post_types = WPSEO_Post_Type::filter_attachment_post_type( $post_types );
if ( ! empty( $post_types ) ) {
foreach ( $post_types as $post_type => $post_type_object ) {
$label = $this->decode_html_entities( $post_type_object->label );
$field = new WPSEO_Config_Field_Choice_Post_Type( $post_type, $label );
$this->add_custom_properties( $post_type, $field );
$fields[] = $field;
}
}
self::$fields = $fields;
}
return self::$fields;
}
/**
* Add custom properties for specific post types.
*
* @param string $post_type Post type of field that is being added.
* @param WPSEO_Config_Field $field Field that corresponds to the post type.
*/
private function add_custom_properties( $post_type, $field ) {
if ( $post_type === 'attachment' ) {
$field->set_property( 'explanation', __( 'WordPress automatically generates an URL for each media item in the library. Enabling this will allow for google to index the generated URL.', 'wordpress-seo' ) );
}
}
/**
* Replaces the HTML entity with it's actual symbol.
*
* Because we do not not know what consequences it will have if we convert every HTML entity,
* we will only replace the characters that we have known problems with in text's.
*
* @param string $text The text to decode.
*
* @return string String with decoded HTML entities.
*/
private function decode_html_entities( $text ) {
return str_replace( '&#39;', '', $text );
}
}

View File

@@ -1,87 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Config_Field_Choice_Post_Type.
*/
class WPSEO_Config_Field_Choice_Post_Type extends WPSEO_Config_Field_Choice {
/**
* Post type.
*
* @var string
*/
protected $post_type;
/**
* WPSEO_Config_Field_Choice_Post_Type constructor.
*
* @param string $post_type The post type to add.
* @param string $label Label to show (translated post type).
*/
public function __construct( $post_type, $label ) {
parent::__construct( 'postType' . ucfirst( $post_type ) );
$this->post_type = $post_type;
/* Translators: %1$s expands to the name of the post type. The options given to the user are "visible" and "hidden" */
$this->set_property( 'label', sprintf( __( 'Search engines should show "%1$s" in search results:', 'wordpress-seo' ), $label ) );
$this->add_choice( 'true', __( 'Yes', 'wordpress-seo' ) );
$this->add_choice( 'false', __( 'No', 'wordpress-seo' ) );
}
/**
* Set adapter.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$adapter->add_custom_lookup(
$this->get_identifier(),
[ $this, 'get_data' ],
[ $this, 'set_data' ]
);
}
/**
* Get the post type of this field.
*
* @return string Post type.
*/
public function get_post_type() {
return $this->post_type;
}
/**
* Retrieves the data.
*
* @return bool
*/
public function get_data() {
$key = 'noindex-' . $this->get_post_type();
if ( WPSEO_Options::get( $key, false ) === false ) {
return 'true';
}
return 'false';
}
/**
* Set new data.
*
* @param string $visible Visible (true) or hidden (false).
*
* @return bool
*/
public function set_data( $visible ) {
$post_type = $this->get_post_type();
return WPSEO_Options::set( 'noindex-' . $post_type, ( $visible === 'false' ) );
}
}

View File

@@ -1,42 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Config_Field_Choice.
*/
class WPSEO_Config_Field_Choice extends WPSEO_Config_Field {
/**
* WPSEO_Config_Field_Choice constructor.
*
* @param string $field Field name to use.
*/
public function __construct( $field ) {
parent::__construct( $field, 'Choice' );
$this->properties['choices'] = [];
}
/**
* Add a choice to the properties.
*
* @param string $value Value op the option.
* @param string $label Label to display for the value.
* @param string $aria_label Optional. Aria label text to use.
*/
public function add_choice( $value, $label, $aria_label = '' ) {
$choice = [
'label' => $label,
];
if ( $aria_label ) {
$choice['screenReaderText'] = $aria_label;
}
$this->properties['choices'][ $value ] = $choice;
}
}

View File

@@ -1,28 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Configurator
*/
/**
* Class WPSEO_Config_Field_Company_Info_Missing.
*/
class WPSEO_Config_Field_Company_Info_Missing extends WPSEO_Config_Field {
/**
* WPSEO_Config_Field_Company_Info_Missing constructor.
*
* @codeCoverageIgnore This is only using WPSEO_Config_Field and WPSEO_Utils functionality.
*/
public function __construct() {
parent::__construct( 'publishingEntityCompanyInfo', 'CompanyInfoMissing' );
$l10n_data = WPSEO_Language_Utils::get_knowledge_graph_company_info_missing_l10n();
$this->set_property( 'message', $l10n_data['message'] );
$this->set_property( 'link', $l10n_data['URL'] );
$this->set_requires( 'publishingEntityType', 'company' );
}
}

View File

@@ -1,32 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Configurator
*/
/**
* Class WPSEO_Config_Field_Company_Logo.
*/
class WPSEO_Config_Field_Company_Logo extends WPSEO_Config_Field {
/**
* WPSEO_Config_Field_Company_Logo constructor.
*/
public function __construct() {
parent::__construct( 'publishingEntityCompanyLogo', 'MediaUpload' );
$this->set_property( 'label', __( 'Provide an image of the organization logo', 'wordpress-seo' ) );
$this->set_requires( 'publishingEntityType', 'company' );
}
/**
* Sets the adapter.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$adapter->add_option_lookup( $this->get_identifier(), 'company_logo' );
}
}

View File

@@ -1,33 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Configurator
*/
/**
* Class WPSEO_Config_Field_Company_Name.
*/
class WPSEO_Config_Field_Company_Name extends WPSEO_Config_Field {
/**
* WPSEO_Config_Field_Company_Name constructor.
*/
public function __construct() {
parent::__construct( 'publishingEntityCompanyName', 'Input' );
$this->set_property( 'label', __( 'The name of the organization', 'wordpress-seo' ) );
$this->set_property( 'autoComplete', 'organization' );
$this->set_requires( 'publishingEntityType', 'company' );
}
/**
* Sets the adapter.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$adapter->add_option_lookup( $this->get_identifier(), 'company_name' );
}
}

View File

@@ -1,35 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Configurator
*/
/**
* Class WPSEO_Config_Field_Company_Or_Person.
*/
class WPSEO_Config_Field_Company_Or_Person extends WPSEO_Config_Field_Choice {
/**
* WPSEO_Config_Field_Company_Or_Person constructor.
*/
public function __construct() {
parent::__construct( 'publishingEntityType' );
$this->set_property( 'label', __( 'Does your site represent a person or an organization?', 'wordpress-seo' ) );
$this->set_property( 'description', __( 'This information will be used in Google\'s Knowledge Graph Card, the big block of information you see on the right side of the search results.', 'wordpress-seo' ) );
$this->add_choice( 'company', __( 'Organization', 'wordpress-seo' ) );
$this->add_choice( 'person', __( 'Person', 'wordpress-seo' ) );
}
/**
* Sets the adapter.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$adapter->add_option_lookup( $this->get_identifier(), 'company_or_person' );
}
}

View File

@@ -1,91 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Config_Field_Environment.
*/
class WPSEO_Config_Field_Environment extends WPSEO_Config_Field_Choice {
/**
* WPSEO_Config_Field_Environment constructor.
*/
public function __construct() {
parent::__construct( 'environment_type' );
$this->set_property( 'label', __( 'Please specify if your site is under construction or already active.', 'wordpress-seo' ) );
$this->set_property( 'description', __( 'Choose under construction if you want to keep the site out of the index of search engines. Don\'t forget to activate it once you\'re ready to publish your site.', 'wordpress-seo' ) );
$this->add_choice( 'production', __( 'Option A: My site is live and ready to be indexed', 'wordpress-seo' ) );
$this->add_choice( 'staging', __( 'Option B: My site is under construction and should not be indexed', 'wordpress-seo' ) );
}
/**
* Set adapter.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$adapter->add_custom_lookup(
$this->get_identifier(),
[ $this, 'get_data' ],
[ $this, 'set_data' ]
);
}
/**
* Gets the option that is set for this field.
*
* @return string The value for the environment_type wpseo option.
*/
public function get_data() {
return WPSEO_Options::get( 'environment_type' );
}
/**
* Set new data.
*
* @param string $environment_type The site's environment type.
*
* @return bool Returns whether the value is successfully set.
*/
public function set_data( $environment_type ) {
$return = true;
if ( $this->get_data() !== $environment_type ) {
$return = WPSEO_Options::set( 'environment_type', $environment_type );
if ( ! $this->set_indexation( $environment_type ) ) {
return false;
}
}
return $return;
}
/**
* Set the WordPress Search Engine Visibility option based on the environment type.
*
* @param string $environment_type The environment the site is running in.
*
* @return bool Returns if the options is set successfully.
*/
protected function set_indexation( $environment_type ) {
$new_blog_public_value = 0;
$current_blog_public_value = get_option( 'blog_public' );
if ( $environment_type === 'production' ) {
$new_blog_public_value = 1;
}
if ( $current_blog_public_value !== $new_blog_public_value ) {
update_option( 'blog_public', $new_blog_public_value );
return true;
}
return ( get_option( 'blog_public' ) === $new_blog_public_value );
}
}

View File

@@ -1,65 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Config_Field_Mailchimp_Signup.
*/
class WPSEO_Config_Field_Mailchimp_Signup extends WPSEO_Config_Field {
/**
* WPSEO_Config_Field_Mailchimp_Signup constructor.
*/
public function __construct() {
parent::__construct( 'mailchimpSignup', 'MailchimpSignup' );
$current_user = wp_get_current_user();
$user_email = ( $current_user->ID > 0 ) ? $current_user->user_email : '';
$signup_text = sprintf(
/* translators: %1$s expands to Yoast SEO for WordPress, %2$s expands to Yoast */
__( 'Sign up for our newsletter if you would like to keep up-to-date about %1$s, other cool plugins by %2$s, and interesting news and tips from the world of SEO.', 'wordpress-seo' ),
'Yoast SEO for WordPress',
'Yoast'
);
$gdpr_notice = sprintf(
/* translators: %1$s expands Yoast, %2$s expands to an opening anchor tag, %3$s expands to a closing anchor tag. */
__( '%1$s respects your privacy. Read our %2$sprivacy policy%3$s on how we handle your personal information.', 'wordpress-seo' ),
'Yoast',
'<a target="_blank" rel="noopener noreferrer" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/gdpr-config-wizard' ) . '">',
'</a>'
);
$this->set_property( 'label', $signup_text );
$this->set_property( 'decoration', plugin_dir_url( WPSEO_FILE ) . 'images/newsletter-collage.png' );
$this->set_property( 'mailchimpActionUrl', 'https://yoast.us1.list-manage.com/subscribe/post-json?u=ffa93edfe21752c921f860358&id=972f1c9122' );
$this->set_property( 'currentUserEmail', $user_email );
$this->set_property( 'freeAccountNotice', __( 'Includes a free MyYoast account which gives you access to our free SEO for Beginners course!', 'wordpress-seo' ) );
$this->set_property( 'GDPRNotice', sprintf( '<small>%s</small>', $gdpr_notice ) );
}
/**
* Get the data.
*
* @return array
*/
public function get_data() {
return [
'hasSignup' => $this->has_mailchimp_signup(),
];
}
/**
* Checks if the user has entered their email for mailchimp already.
*
* @return bool
*/
protected function has_mailchimp_signup() {
$user_meta = get_user_meta( get_current_user_id(), WPSEO_Config_Component_Mailchimp_Signup::META_NAME, true );
return ( ! empty( $user_meta ) );
}
}

View File

@@ -1,86 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Config_Field_Multiple_Authors.
*/
class WPSEO_Config_Field_Multiple_Authors extends WPSEO_Config_Field_Choice {
/**
* WPSEO_Config_Field_Multiple_Authors constructor.
*/
public function __construct() {
parent::__construct( 'multipleAuthors' );
$this->set_property( 'label', __( 'Does, or will, your site have multiple authors?', 'wordpress-seo' ) );
$this->set_property( 'description', __( 'If you choose no, your author archives will be deactivated to prevent duplicate content issues.', 'wordpress-seo' ) );
$this->add_choice( 'yes', __( 'Yes', 'wordpress-seo' ) );
$this->add_choice( 'no', __( 'No', 'wordpress-seo' ) );
}
/**
* Set adapter.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$adapter->add_custom_lookup(
$this->get_identifier(),
[ $this, 'get_data' ],
[ $this, 'set_data' ]
);
}
/**
* Get the data from the stored options.
*
* @return string|null
*/
public function get_data() {
if ( WPSEO_Options::get( 'has_multiple_authors', false ) ) {
$value = WPSEO_Options::get( 'has_multiple_authors' );
}
if ( ! isset( $value ) || is_null( $value ) ) {
// If there are more than one users with level > 1 default to multiple authors.
$user_criteria = [
'fields' => 'IDs',
'who' => 'authors',
];
$users = get_users( $user_criteria );
$value = count( $users ) > 1;
}
return ( $value ) ? 'yes' : 'no';
}
/**
* Set the data in the options.
*
* @param string $data The data to set for the field.
*
* @return bool Returns true or false for successful storing the data.
*/
public function set_data( $data ) {
$value = ( $data === 'yes' );
// Set multiple authors option.
$result_multiple_authors = WPSEO_Options::set( 'has_multiple_authors', $value );
/*
* Set disable author archives option. When multiple authors is set to true,
* the disable author option has to be false. Because of this the $value is inversed.
*/
$result_author_archives = WPSEO_Options::set( 'disable-author', ! $value );
return ( $result_multiple_authors === true && $result_author_archives === true );
}
}

View File

@@ -1,32 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\Configurator
*/
/**
* Class WPSEO_Config_Field_Person_Name.
*/
class WPSEO_Config_Field_Person extends WPSEO_Config_Field {
/**
* WPSEO_Config_Field_Company_Or_Person constructor.
*/
public function __construct() {
parent::__construct( 'publishingEntityPersonId', 'WordPressUserSelector' );
$this->set_property( 'label', __( 'The person', 'wordpress-seo' ) );
$this->set_requires( 'publishingEntityType', 'person' );
}
/**
* Sets the adapter.
*
* @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
*/
public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
$adapter->add_option_lookup( $this->get_identifier(), 'company_or_person_user_id' );
}
}

View File

@@ -1,25 +0,0 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin\ConfigurationUI
*/
/**
* Class WPSEO_Config_Field_Post_Type_Visibility.
*/
class WPSEO_Config_Field_Post_Type_Visibility extends WPSEO_Config_Field {
/**
* WPSEO_Config_Field_Post_Type_Visibility constructor.
*/
public function __construct() {
parent::__construct( 'postTypeVisibility', 'HTML' );
$copy = __( 'Please specify what content types you would like to appear in search engines. If you do not know the differences between these, it\'s best to choose the default settings.', 'wordpress-seo' );
$html = '<p>' . esc_html( $copy ) . '</p><br/>';
$this->set_property( 'html', $html );
}
}

Some files were not shown because too many files have changed in this diff Show More