412e4539 by Jeff Balicki

dod

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent ee775142
Showing 1000 changed files with 4994 additions and 0 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

<?php
/**
* Plugin Name: All in One SEO
* Plugin URI: https://aioseo.com/
* Description: SEO for WordPress. Features like XML Sitemaps, SEO for custom post types, SEO for blogs, business sites, ecommerce sites, and much more. More than 100 million downloads since 2007.
* Author: All in One SEO Team
* Author URI: https://aioseo.com/
* Version: 4.3.3
* Text Domain: all-in-one-seo-pack
* Domain Path: /languages
*
* All in One SEO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* All in One SEO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AIOSEO. If not, see <https://www.gnu.org/licenses/>.
*
* @since 4.0.0
* @author All in One SEO Team
* @package AIOSEO\Plugin
* @license GPL-2.0+
* @copyright Copyright (c) 2020, All in One SEO
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! defined( 'AIOSEO_PHP_VERSION_DIR' ) ) {
define( 'AIOSEO_PHP_VERSION_DIR', basename( dirname( __FILE__ ) ) );
}
require_once dirname( __FILE__ ) . '/app/init/init.php';
// Check if this plugin should be disabled.
if ( aioseoPluginIsDisabled() ) {
return;
}
require_once dirname( __FILE__ ) . '/app/init/notices.php';
require_once dirname( __FILE__ ) . '/app/init/activation.php';
// We require PHP 5.4+ for the whole plugin to work.
if ( version_compare( PHP_VERSION, '5.6', '<' ) ) {
add_action( 'admin_notices', 'aioseo_php_notice' );
// Do not process the plugin code further.
return;
}
// We require WP 4.9+ for the whole plugin to work.
global $wp_version;
if ( version_compare( $wp_version, '4.9', '<' ) ) {
add_action( 'admin_notices', 'aioseo_wordpress_notice' );
// Do not process the plugin code further.
return;
}
if ( ! defined( 'AIOSEO_DIR' ) ) {
define( 'AIOSEO_DIR', __DIR__ );
}
if ( ! defined( 'AIOSEO_FILE' ) ) {
define( 'AIOSEO_FILE', __FILE__ );
}
// Don't allow multiple versions to be active.
if ( function_exists( 'aioseo' ) ) {
add_action( 'activate_all-in-one-seo-pack/all_in_one_seo_pack.php', 'aioseo_lite_just_activated' );
add_action( 'deactivate_all-in-one-seo-pack/all_in_one_seo_pack.php', 'aioseo_lite_just_deactivated' );
add_action( 'activate_all-in-one-seo-pack-pro/all_in_one_seo_pack.php', 'aioseo_pro_just_activated' );
add_action( 'admin_notices', 'aioseo_lite_notice' );
// Do not process the plugin code further.
return;
}
// We will be deprecating these versions of PHP in the future, so let's let the user know.
if ( version_compare( PHP_VERSION, '7.0', '<' ) ) {
add_action( 'admin_notices', 'aioseo_php_notice_deprecated' );
}
// Define the class and the function.
// The AIOSEOAbstract class is required here because it can't be autoloaded.
require_once dirname( __FILE__ ) . '/app/AIOSEOAbstract.php';
require_once dirname( __FILE__ ) . '/app/AIOSEO.php';
aioseo();
\ No newline at end of file
<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Abstract class holding the class properties of our main AIOSEO class.
*
* @since 4.2.7
*/
abstract class AIOSEOAbstract {
/**
* Core class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Core\Core
*/
public $core = null;
/**
* Helpers class instance.
*
* @since 4.2.7
*
* @var Object
*/
public $helpers = null;
/**
* InternalNetworkOptions class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Options\InternalNetworkOptions|\AIOSEO\Plugin\Pro\Options\InternalNetworkOptions
*/
public $internalNetworkOptions = null;
/**
* InternalOptions class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Lite\Options\InternalOptions|\AIOSEO\Plugin\Pro\Options\InternalOptions
*/
public $internalOptions = null;
/**
* PreUpdates class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Main\PreUpdates|\AIOSEO\Plugin\Pro\Main\PreUpdates
*/
public $preUpdates = null;
/**
* Db class instance.
* This prop is set for backwards compatibility.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Core\Db
*/
public $db = null;
/**
* Transients class instance.
* This prop is set for backwards compatibility.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Core\Cache
*/
public $transients = null;
/**
* OptionsCache class instance.
* This prop is set for backwards compatibility.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Options\Cache
*/
public $optionsCache = null;
/**
* PostSettings class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Lite\Admin\PostSettings|\AIOSEO\Plugin\Pro\Admin\PostSettings
*/
public $postSettings = null;
/**
* Standalone class instance.
*
* @since 4.2.7
*
* @var AIOSEO\Plugin\Common\Standalone
*/
public $standalone = null;
/**
* Search Statistics class instance.
*
* @since 4.3.0
*
* @var \AIOSEO\Plugin\Common\SearchStatistics\SearchStatistics|\AIOSEO\Plugin\Pro\SearchStatistics\SearchStatistics
*/
public $searchStatistics = null;
/**
* ThirdParty class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\ThirdParty\ThirdParty
*/
public $thirdParty = null;
/**
* Tags class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Utils\Addons|\AIOSEO\Plugin\Pro\Utils\Addons
*/
public $tags = null;
/**
* Addons class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Utils\Blocks
*/
public $blocks = null;
/**
* BadBotBlocker class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Tools\BadBotBlocker
*/
public $badBotBlocker = null;
/**
* Breadcrumbs class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Breadcrumbs\Breadcrumbs|\AIOSEO\Plugin\Pro\Breadcrumbs\Breadcrumbs
*/
public $breadcrumbs = null;
/**
* DynamicBackup class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Options\DynamicBackup|\AIOSEO\Plugin\Pro\Options\DynamicBackup
*/
public $dynamicBackup = null;
/**
* NetworkOptions class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Options\NetworkOptions|\AIOSEO\Plugin\Pro\Options\NetworkOptions
*/
public $networkOptions = null;
/**
* Backup class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Utils\Backup
*/
public $backup = null;
/**
* Access class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Utils\Access|\AIOSEO\Plugin\Pro\Utils\Access
*/
public $access = null;
/**
* NetworkLicense class instance.
*
* @since 4.2.7
*
* @var null|\AIOSEO\Plugin\Pro\Admin\NetworkLicense
*/
public $networkLicense = null;
/**
* License class instance.
*
* @since 4.2.7
*
* @var null|\AIOSEO\Plugin\Pro\Admin\License
*/
public $license = null;
/**
* Updates class isntance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Main\Updates|\AIOSEO\Plugin\Pro\Main\Updates
*/
public $updates = null;
/**
* Meta class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Meta\Meta|\AIOSEO\Plugin\Pro\Meta\Meta
*/
public $meta = null;
/**
* Social class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Social\Social|\AIOSEO\Plugin\Pro\Social\Social
*/
public $social = null;
/**
* RobotsTxt class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Tools\RobotsTxt
*/
public $robotsTxt = null;
/**
* Htaccess class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Tools\Htaccess
*/
public $htaccess = null;
/**
* Term class instance.
*
* @since 4.2.7
*
* @var null|\AIOSEO\Plugin\Pro\Admin\Term
*/
public $term = null;
/**
* Notices class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Lite\Admin\Notices\Notices|\AIOSEO\Plugin\Pro\Admin\Notices\Notices
*/
public $notices = null;
/**
* WpNotices class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Admin\Notices\WpNotices
*/
public $wpNotices = null;
/**
* Admin class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Lite\Admin\Admin|\AIOSEO\Plugin\Pro\Admin\Admin
*/
public $admin = null;
/**
* NetworkAdmin class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Admin\NetworkAdmin|\AIOSEO\Plugin\Pro\Admin\NetworkAdmin
*/
public $networkAdmin = null;
/**
* Activate class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Main|Activate|\AIOSEO\Plugin\Pro\Main\Activate
*/
public $activate = null;
/**
* ConflictingPlugins class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Admin\ConflictingPlugins|\AIOSEO\Plugin\Pro\Admin\ConflictingPlugins
*/
public $conflictingPlugins = null;
/**
* Migration class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Migration\Migration|\AIOSEO\Plugin\Pro\Migration\Migration
*/
public $migration = null;
/**
* ImportExport class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\ImportExport\ImportExport
*/
public $importExport = null;
/**
* Sitemap class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Sitemap\Sitemap|\AIOSEO\Plugin\Pro\Sitemap\Sitemap
*/
public $sitemap = null;
/**
* HtmlSitemap class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Sitemap\Html\Sitemap
*/
public $htmlSitemap = null;
/**
* CategoryBase class instance.
*
* @since 4.2.7
*
* @var null|\AIOSEO\Plugin\Pro\Main\CategoryBase
*/
public $categoryBase = null;
/**
* SlugMonitor class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Admin\SlugMonitor
*/
public $slugMonitor = null;
/**
* Schema class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Schema\Schema|\AIOSEO\Plugin\Pro\Schema\Schema
*/
public $schema = null;
/**
* Rss class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Rss
*/
public $rss = null;
/**
* Main class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Main\Main|\AIOSEO\Plugin\Pro\Main\Main
*/
public $main = null;
/**
* Head class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Main\Head|\AIOSEO\Plugin\Pro\Main\Head
*/
public $head = null;
/**
* Dashboard class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Admin\Dashboard|\AIOSEO\Plugin\Pro\Admin\Dashboard
*/
public $dashboard = null;
/**
* API class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Lite\Api\Api|\AIOSEO\Plugin\Pro\Api\Api
*/
public $api = null;
/**
* Help class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Help\Help
*/
public $help = null;
/**
* Settings class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Utils\VueSettings
*/
public $settings = null;
/**
* Cache class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Core\Cache
*/
public $cache = null;
/**
* CachePrune class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Core\CachePrune
*/
public $cachePrune = null;
/**
* Addons class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Utils\Addons|\AIOSEO\Plugin\Pro\Utils\Addons
*/
public $addons = null;
/**
* Addons class instance.
*
* @since 4.3.0
*
* @var \AIOSEO\Plugin\Common\Utils\Features|\AIOSEO\Plugin\Pro\Utils\Features
*/
public $features = null;
/**
* Options class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Lite\Options\Options|\AIOSEO\Plugin\Pro\Options\Options
*/
public $options = null;
/**
* DynamicOptions class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Options\DynamicOptions|\AIOSEO\Plugin\Pro\Options\DynamicOptions
*/
public $dynamicOptions = null;
/**
* Usage class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Lite\Admin\Usage|\Admin\Plugin\Pro\Admin\Usage
*/
public $usage = null;
/**
* SiteHealth class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Admin\SiteHealth|\AIOSEO\Plugin\Pro\Admin\SiteHealth
*/
public $siteHealth = null;
/**
* AutoUpdates class instance.
*
* @since 4.2.7
*
* @var null|\AIOSEO\Plugin\Admin\AutoUpdates
*/
public $autoUpdates = null;
/**
* Templates class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Utils\Templates|\AIOSEO\Plugin\Pro\Utils\Templates
*/
public $templates = null;
/**
* Filters class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Lite\Main\Filters|\AIOSEO\Plugin\Pro\Main\Filters
*/
public $filters = null;
/**
* ActionScheduler class instance.
*
* @since 4.2.7
*
* @var \AIOSEO\Plugin\Common\Utils\ActionScheduler
*/
public $actionScheduler = null;
/**
* AI class instance.
*
* @since 4.3.3
*
* @var null|\AIOSEO\Plugin\Pro\Ai\Ai
*/
public $ai = null;
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
/**
* Checks for conflicting plugins.
*
* @since 4.0.0
*/
class ConflictingPlugins {
/**
* Class Constructor.
*
* @since 4.0.0
*/
public function __construct() {
// We don't want to trigger our notices when not in the admin.
if ( ! is_admin() ) {
return;
}
add_action( 'init', [ $this, 'init' ] );
}
/**
* Initialize the conflicting plugins check.
*
* @since 4.0.0
*
* @return void
*/
public function init() {
// Only do this for users who can install/deactivate plugins.
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
$conflictingPlugins = $this->getAllConflictingPlugins();
$notification = Models\Notification::getNotificationByName( 'conflicting-plugins' );
if ( empty( $conflictingPlugins ) ) {
if ( ! $notification->exists() ) {
return;
}
Models\Notification::deleteNotificationByName( 'conflicting-plugins' );
return;
}
aioseo()->notices->conflictingPlugins( $conflictingPlugins );
}
/**
* Get a list of all conflicting plugins.
*
* @since 4.0.0
*
* @return array An array of conflicting plugins.
*/
protected function getAllConflictingPlugins() {
$conflictingSeoPlugins = $this->getConflictingPlugins( 'seo' );
$conflictingSitemapPlugins = [];
if (
aioseo()->options->sitemap->general->enable ||
aioseo()->options->sitemap->rss->enable
) {
$conflictingSitemapPlugins = $this->getConflictingPlugins( 'sitemap' );
}
return array_merge( $conflictingSeoPlugins, $conflictingSitemapPlugins );
}
/**
* Get a list of conflicting plugins for AIOSEO.
*
* @since 4.0.0
*
* @param string $type A type to look for.
* @return array An array of conflicting plugins.
*/
public function getConflictingPlugins( $type ) {
$activePlugins = get_option( 'active_plugins' );
$conflictingPlugins = [];
switch ( $type ) {
case 'seo':
$conflictingPlugins = [
'Yoast SEO' => 'wordpress-seo/wp-seo.php',
'Yoast SEO Premium' => 'wordpress-seo-premium/wp-seo-premium.php',
'Rank Math SEO' => 'seo-by-rank-math/rank-math.php',
'SEOPress' => 'wp-seopress/seopress.php',
'The SEO Framework' => 'autodescription/autodescription.php',
];
break;
case 'sitemap':
$conflictingPlugins = [
'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php',
'XML Sitemap & Google News' => 'xml-sitemap-feed/xml-sitemap.php',
'Google XML Sitemap Generator' => 'www-xml-sitemap-generator-org/www-xml-sitemap-generator-org.php',
'Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php',
];
break;
}
return array_intersect( $conflictingPlugins, $activePlugins );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class that holds our dashboard widget.
*
* @since 4.0.0
*/
class Dashboard {
/**
* Class Constructor.
*
* @since 4.0.0
*/
public function __construct() {
add_action( 'wp_dashboard_setup', [ $this, 'addDashboardWidgets' ] );
}
/**
* Registers our dashboard widgets.
*
* @since 4.2.0
*
* @return void
*/
public function addDashboardWidgets() {
// Add the SEO Setup widget.
if (
$this->canShowWidget( 'seoSetup' ) &&
apply_filters( 'aioseo_show_seo_setup', true ) &&
( aioseo()->access->isAdmin() || aioseo()->access->hasCapability( 'aioseo_setup_wizard' ) ) &&
! aioseo()->standalone->setupWizard->isCompleted()
) {
wp_add_dashboard_widget(
'aioseo-seo-setup',
// Translators: 1 - The plugin short name ("AIOSEO").
sprintf( esc_html__( '%s Setup', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME ),
[
$this,
'outputSeoSetup',
],
null,
null,
'normal',
'high'
);
}
// Add the Overview widget.
if (
$this->canShowWidget( 'seoOverview' ) &&
apply_filters( 'aioseo_show_seo_overview', true ) &&
( aioseo()->access->isAdmin() || aioseo()->access->hasCapability( 'aioseo_page_analysis' ) )
) {
wp_add_dashboard_widget(
'aioseo-overview',
// Translators: 1 - The plugin short name ("AIOSEO").
sprintf( esc_html__( '%s Overview', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME ),
[
$this,
'outputSeoOverview',
]
);
}
// Add the News widget.
if (
$this->canShowWidget( 'seoNews' ) &&
apply_filters( 'aioseo_show_seo_news', true ) &&
aioseo()->access->isAdmin()
) {
wp_add_dashboard_widget(
'aioseo-rss-feed',
esc_html__( 'SEO News', 'all-in-one-seo-pack' ),
[
$this,
'displayRssDashboardWidget',
]
);
}
}
/**
* Whether or not to show the widget.
*
* @since 4.0.0
* @version 4.2.8
*
* @param string $widget The widget to check if can show.
* @return boolean True if yes, false otherwise.
*/
protected function canShowWidget( $widget ) { // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
return true;
}
/**
* Output the SEO Setup widget.
*
* @since 4.2.0
*
* @return void
*/
public function outputSeoSetup() {
$this->output( 'aioseo-seo-setup-app' );
}
/**
* Output the SEO Overview widget.
*
* @since 4.2.0
*
* @return void
*/
public function outputSeoOverview() {
$this->output( 'aioseo-overview-app' );
}
/**
* Output the widget wrapper for the Vue App.
*
* @since 4.2.0
*
* @param string $appId The App ID to print out.
* @return void
*/
private function output( $appId ) {
// Enqueue the scripts for the widget.
$this->enqueue();
// Opening tag.
echo '<div id="' . esc_attr( $appId ) . '">';
// Loader element.
require AIOSEO_DIR . '/app/Common/Views/parts/loader.php';
// Closing tag.
echo '</div>';
}
/**
* Enqueue the scripts and styles.
*
* @since 4.2.0
*
* @return void
*/
private function enqueue() {
aioseo()->core->assets->load( 'src/vue/standalone/dashboard-widgets/main.js', [], aioseo()->helpers->getVueData( 'dashboard' ) );
}
/**
* Display RSS Dashboard Widget
*
* @since 4.0.0
*
* @return void
*/
public function displayRssDashboardWidget() {
// Check if the user has chosen not to display this widget through screen options.
$currentScreen = get_current_screen();
$hiddenWidgets = get_user_meta( get_current_user_id(), 'metaboxhidden_' . $currentScreen->id );
if ( $hiddenWidgets && count( $hiddenWidgets ) > 0 && is_array( $hiddenWidgets[0] ) && in_array( 'aioseo-rss-feed', $hiddenWidgets[0], true ) ) {
return;
}
include_once ABSPATH . WPINC . '/feed.php';
$rssItems = aioseo()->core->networkCache->get( 'rss_feed' );
if ( null === $rssItems ) {
$rss = fetch_feed( 'https://aioseo.com/feed/' );
if ( is_wp_error( $rss ) ) {
esc_html_e( 'Temporarily unable to load feed.', 'all-in-one-seo-pack' );
return;
}
$rssItems = $rss->get_items( 0, 4 ); // Show four items.
$cached = [];
foreach ( $rssItems as $item ) {
$cached[] = [
'url' => $item->get_permalink(),
'title' => aioseo()->helpers->decodeHtmlEntities( $item->get_title() ),
'date' => $item->get_date( get_option( 'date_format' ) ),
'content' => substr( wp_strip_all_tags( $item->get_content() ), 0, 128 ) . '...',
];
}
$rssItems = $cached;
aioseo()->core->networkCache->update( 'rss_feed', $cached, 12 * HOUR_IN_SECONDS );
}
?>
<ul>
<?php
if ( false === $rssItems ) {
echo '<li>' . esc_html( __( 'No articles were found.', 'all-in-one-seo-pack' ) ) . '</li>';
return;
}
foreach ( $rssItems as $item ) {
?>
<li>
<a target="_blank" href="<?php echo esc_url( $item['url'] ); ?>" rel="noopener noreferrer">
<?php echo esc_html( $item['title'] ); ?>
</a>
<span><?php echo esc_html( $item['date'] ); ?></span>
<div>
<?php echo esc_html( wp_strip_all_tags( $item['content'] ) ) . '...'; ?>
</div>
</li>
<?php
}
?>
</ul>
<?php
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Abstract class that Pro and Lite both extend.
*
* @since 4.2.5
*/
class NetworkAdmin extends Admin {
/**
* Construct method.
*
* @since 4.2.5
*/
public function __construct() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if (
is_network_admin() &&
! is_plugin_active_for_network( plugin_basename( AIOSEO_FILE ) )
) {
return;
}
if ( wp_doing_ajax() || wp_doing_cron() ) {
return;
}
add_action( 'sanitize_comment_cookies', [ $this, 'init' ], 21 );
}
/**
* Initialize the admin.
*
* @since 4.2.5
*
* @return void
*/
public function init() {
add_action( 'network_admin_menu', [ $this, 'addNetworkMenu' ] );
$this->setPages();
}
/**
* Add the network menu inside of WordPress.
*
* @since 4.2.5
*
* @return void
*/
public function addNetworkMenu() {
$this->addMainMenu( 'aioseo' );
foreach ( $this->pages as $slug => $page ) {
if (
'aioseo-settings' !== $slug &&
'aioseo-tools' !== $slug &&
'aioseo-about' !== $slug &&
'aioseo-feature-manager' !== $slug
) {
continue;
}
$hook = add_submenu_page(
$this->pageSlug,
! empty( $page['page_title'] ) ? $page['page_title'] : $page['menu_title'],
$page['menu_title'],
$this->getPageRequiredCapability( $slug ),
$slug,
[ $this, 'page' ]
);
add_action( "load-{$hook}", [ $this, 'hooks' ] );
}
// Remove the "dashboard" submenu page that is not needed in the network admin.
remove_submenu_page( $this->pageSlug, $this->pageSlug );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin\Notices;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WordPress Deprecated Notice.
*
* @since 4.1.2
*/
class DeprecatedWordPress {
/**
* Class Constructor.
*
* @since 4.1.2
*/
public function __construct() {
add_action( 'wp_ajax_aioseo-dismiss-deprecated-wordpress-notice', [ $this, 'dismissNotice' ] );
}
/**
* Go through all the checks to see if we should show the notice.
*
* @since 4.1.2
*
* @return void
*/
public function maybeShowNotice() {
global $wp_version;
$dismissed = get_option( '_aioseo_deprecated_wordpress_dismissed', true );
if ( '1' === $dismissed ) {
return;
}
// Only show to users that interact with our pluign.
if ( ! current_user_can( 'publish_posts' ) ) {
return;
}
// Only show if WordPress version is deprecated.
if ( version_compare( $wp_version, '5.3', '>=' ) ) {
return;
}
$this->showNotice();
// Print the script to the footer.
add_action( 'admin_footer', [ $this, 'printScript' ] );
}
/**
* Actually show the review plugin.
*
* @since 4.1.2
*
* @return void
*/
public function showNotice() {
$medium = false !== strpos( AIOSEO_PHP_VERSION_DIR, 'pro' ) ? 'proplugin' : 'liteplugin';
?>
<div class="notice notice-warning aioseo-deprecated-wordpress-notice is-dismissible">
<p>
<?php
echo wp_kses(
sprintf(
// Translators: 1 - Opening HTML bold tag, 2 - Closing HTML bold tag.
__( 'Your site is running an %1$soutdated version%2$s of WordPress. We recommend using the latest version of WordPress in order to keep your site secure.', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'<strong>',
'</strong>'
),
[
'strong' => [],
]
);
?>
<br><br>
<?php
echo wp_kses(
sprintf(
// Translators: 1 - Opening HTML bold tag, 2 - Closing HTML bold tag, 3 - The plugin name ("All in One SEO"), 4 - Opening HTML link tag, 5 - Closing HTML link tag.
__( '%1$sNote:%2$s %3$s will be discontinuing support for WordPress versions older than version 5.3 by the end of %4$s. %5$sRead more for additional information.%6$s', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'<strong>',
'</strong>',
'AIOSEO',
date( 'Y' ),
'<a href="https://aioseo.com/docs/update-wordpress/?utm_source=WordPress&utm_medium=' . $medium . '&utm_campaign=outdated-wordpress-notice" target="_blank" rel="noopener noreferrer">', // phpcs:ignore Generic.Files.LineLength.MaxExceeded
'</a>'
),
[
'a' => [
'href' => [],
'target' => [],
'rel' => [],
],
'strong' => [],
]
);
?>
</p>
</div>
<?php
// In case this is on plugin activation.
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
/**
* Print the script for dismissing the notice.
*
* @since 4.1.2
*
* @return void
*/
public function printScript() {
// Create a nonce.
$nonce = wp_create_nonce( 'aioseo-dismiss-deprecated-wordpress' );
?>
<script>
window.addEventListener('load', function () {
var dismissBtn
// Add an event listener to the dismiss button.
dismissBtn = document.querySelector('.aioseo-deprecated-wordpress-notice .notice-dismiss')
dismissBtn.addEventListener('click', function (event) {
var httpRequest = new XMLHttpRequest(),
postData = ''
// Build the data to send in our request.
postData += '&action=aioseo-dismiss-deprecated-wordpress-notice'
postData += '&nonce=<?php echo esc_html( $nonce ); ?>'
httpRequest.open('POST', '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>')
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
httpRequest.send(postData)
})
});
</script>
<?php
}
/**
* Dismiss the deprecated WordPress notice.
*
* @since 4.1.2
*
* @return WP_Response The successful response.
*/
public function dismissNotice() {
// Early exit if we're not on a aioseo-dismiss-deprecated-wordpress-notice action.
if ( ! isset( $_POST['action'] ) || 'aioseo-dismiss-deprecated-wordpress-notice' !== $_POST['action'] ) {
return;
}
check_ajax_referer( 'aioseo-dismiss-deprecated-wordpress', 'nonce' );
update_option( '_aioseo_deprecated_wordpress_dismissed', true );
return wp_send_json_success();
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin\Notices;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Plugin import notice.
*
* @since 4.0.0
*/
class Import {
/**
* Go through all the checks to see if we should show the notice.
*
* @since 4.0.0
*
* @return void
*/
public function maybeShowNotice() {
if ( ! aioseo()->importExport->isImportRunning() ) {
return;
}
$this->showNotice();
}
/**
* Register the notice so that it appears.
*
* @since 4.0.0
*
* @return void
*/
public function showNotice() {
$string1 = __( 'SEO Meta Import In Progress', 'all-in-one-seo-pack' );
// Translators: 1 - The plugin name ("All in One SEO").
$string2 = sprintf( __( '%1$s is importing your existing SEO data in the background.', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME );
$string3 = __( 'This notice will automatically disappear as soon as the import has completed. Meanwhile, everything should continue to work as expected.', 'all-in-one-seo-pack' );
?>
<div class="notice notice-info aioseo-migration">
<p><strong><?php echo esc_html( $string1 ); ?></strong></p>
<p><?php echo esc_html( $string2 ); ?></p>
<p><?php echo esc_html( $string3 ); ?></p>
</div>
<style>
</style>
<?php
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin\Notices;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* V3 to V4 migration notice.
*
* @since 4.0.0
*/
class Migration {
/**
* Go through all the checks to see if we should show the notice.
*
* @since 4.0.0
*
* @return void
*/
public function maybeShowNotice() {
$transientPosts = aioseo()->core->cache->get( 'v3_migration_in_progress_posts' );
$transientTerms = aioseo()->core->cache->get( 'v3_migration_in_progress_terms' );
if ( ! $transientPosts && ! $transientTerms ) {
return;
}
// Disable the notice for now since it is almost unnecessary. We can come back and revisit this in the future.
// $this->showNotice();
}
/**
* Register the notice so that it appears.
*
* @since 4.0.0
*
* @return void
*/
public function showNotice() {
// Translators: 1 - The plugin name ("AIOSEO).
$string1 = sprintf( __( '%1$s V3->V4 Migration In Progress', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME );
// Translators: 1 - The plugin name ("All in One SEO").
$string2 = sprintf( __( '%1$s is currently upgrading your database and migrating your SEO data in the background.', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME );
$string3 = __( 'This notice will automatically disappear as soon as the migration has completed. Meanwhile, everything should continue to work as expected.', 'all-in-one-seo-pack' );
?>
<div class="notice notice-info aioseo-migration">
<p><strong><?php echo esc_html( $string1 ); ?></strong></p>
<p><?php echo esc_html( $string2 ); ?></p>
<p><?php echo esc_html( $string3 ); ?></p>
</div>
<style>
</style>
<?php
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin\Notices;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WpNotices class.
*
* @since 4.2.3
*/
class WpNotices {
/**
* Notices array
*
* @since 4.2.3
*
* @var array
*/
private $notices;
/**
* The cache key.
*
* @since 4.2.3
*
* @var string
*/
private $cacheKey = 'wp_notices';
/**
* Class Constructor.
*
* @since 4.2.3
*/
public function __construct() {
add_action( 'rest_api_init', [ $this, 'registerApiField' ] );
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueueScripts' ] );
add_action( 'admin_notices', [ $this, 'adminNotices' ] );
}
/**
* Enqueue notices scripts.
*
* @since 4.2.3
*
* @return void
*/
public function enqueueScripts() {
aioseo()->core->assets->load( 'src/vue/standalone/wp-notices/main.js' );
}
/**
* Registers an API field with notices.
*
* @since 4.2.3
*
* @return void
*/
public function registerApiField() {
foreach ( aioseo()->helpers->getPublicPostTypes( true ) as $postType ) {
register_rest_field( $postType, 'aioseo_notices', [
'get_callback' => [ $this, 'apiGetNotices' ]
] );
}
}
/**
* API field callback.
*
* @since 4.2.3
*
* @return array Notices array
*/
public function apiGetNotices() {
$notices = $this->getNoticesInContext();
// Notices show only one time.
$this->removeNotices( $notices );
return $notices;
}
/**
* Get all notices.
*
* @since 4.2.3
*
* @return array Notices array
*/
public function getNotices() {
if ( empty( $this->notices ) ) {
$this->notices = aioseo()->core->cache->get( $this->cacheKey );
}
return ! empty( $this->notices ) ? $this->notices : [];
}
/**
* Get all notices in the current context.
*
* @since 4.2.6
*
* @return array Notices array
*/
public function getNoticesInContext() {
$contextNotices = $this->getNotices();
foreach ( $contextNotices as $key => $notice ) {
if ( empty( $notice['allowedContexts'] ) ) {
continue;
}
$allowed = false;
foreach ( $notice['allowedContexts'] as $allowedContext ) {
if ( $this->isAllowedContext( $allowedContext ) ) {
$allowed = true;
break;
}
}
if ( ! $allowed ) {
unset( $contextNotices[ $key ] );
}
}
return $contextNotices;
}
/**
* Test if we are in the current context.
*
* @since 4.2.6
*
* @param string $context The context to test. (posts)
* @return bool Is the required context.
*/
private function isAllowedContext( $context ) {
switch ( $context ) {
case 'posts':
return aioseo()->helpers->isScreenPostList() ||
aioseo()->helpers->isScreenPostEdit() ||
aioseo()->helpers->isAjaxCronRestRequest();
}
return false;
}
/**
* Finds a notice by message.
*
* @since 4.2.3
*
* @param string $message The message string.
* @param string $type The message type.
* @return void|array The found notice.
*/
public function getNotice( $message, $type = '' ) {
$notices = $this->getNotices();
foreach ( $notices as $notice ) {
if ( $notice['options']['id'] === $this->getNoticeId( $message, $type ) ) {
return $notice;
}
}
}
/**
* Generates a notice id.
*
* @since 4.2.3
*
* @param string $message The message string.
* @param string $type The message type.
* @return string The notice id.
*/
public function getNoticeId( $message, $type = '' ) {
return md5( $message . $type );
}
/**
* Clear notices.
*
* @since 4.2.3
*
* @return void
*/
public function clearNotices() {
$this->notices = [];
$this->updateCache();
}
/**
* Remove certain notices.
*
* @since 4.2.6
*
* @param array $notices A list of notices to remove.
* @return void
*/
public function removeNotices( $notices ) {
foreach ( array_keys( $notices ) as $noticeKey ) {
unset( $this->notices[ $noticeKey ] );
}
$this->updateCache();
}
/**
* Adds a notice.
*
* @since 4.2.3
*
* @param string $message The message.
* @param string $status The message status [success, info, warning, error]
* @param array $options Options for the message. https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createnotice
* @param array $allowedContexts The contexts where this notice will show.
* @return void
*/
public function addNotice( $message, $status = 'warning', $options = [], $allowedContexts = [] ) {
$type = ! empty( $options['type'] ) ? $options['type'] : '';
$foundNotice = $this->getNotice( $message, $type );
if ( empty( $message ) || ! empty( $foundNotice ) ) {
return;
}
$notice = [
'message' => $message,
'status' => $status,
'options' => wp_parse_args( $options, [
'id' => $this->getNoticeId( $message, $type ),
'isDismissible' => true
] ),
'allowedContexts' => $allowedContexts
];
$this->notices[] = $notice;
$this->updateCache();
}
/**
* Show notices on classic editor.
*
* @since 4.2.3
*
* @return void
*/
public function adminNotices() {
// Double check we're actually in the admin before outputting anything.
if ( ! is_admin() ) {
return;
}
$notices = $this->getNoticesInContext();
foreach ( $notices as $notice ) {
// Hide snackbar notices on classic editor.
if ( ! empty( $notice['options']['type'] ) && 'snackbar' === $notice['options']['type'] ) {
continue;
}
$status = ! empty( $notice['status'] ) ? $notice['status'] : 'warning';
$class = ! empty( $notice['options']['class'] ) ? $notice['options']['class'] : '';
?>
<div
class="notice notice-<?php echo esc_attr( $status ) ?> <?php echo esc_attr( $class ) ?>">
<?php echo '<p>' . $notice['message'] . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php
if ( ! empty( $notice['options']['actions'] ) ) {
foreach ( $notice['options']['actions'] as $action ) {
echo '<p>';
if ( ! empty( $action['url'] ) ) {
$class = ! empty( $action['class'] ) ? $action['class'] : '';
$target = ! empty( $action['target'] ) ? $action['target'] : '';
echo '<a
href="' . esc_attr( $action['url'] ) . '"
class="' . esc_attr( $class ) . '"
target="' . esc_attr( $target ) . '"
>';
}
echo $action['label']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ( ! empty( $action['url'] ) ) {
echo '</a>';
}
echo '</p>';
}
?>
<?php } ?>
</div>
<?php
}
// Notices show only one time.
$this->removeNotices( $notices );
}
/**
* Helper to update the cache with the current notices array.
*
* @since 4.2.6
*
* @return void
*/
private function updateCache() {
aioseo()->core->cache->update( $this->cacheKey, $this->notices );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles all admin code for the SEO Analysis menu.
*
* @since 4.2.6
*/
class SeoAnalysis {
/**
* Class constructor.
*
* @since 4.2.6
*/
public function __construct() {
add_action( 'save_post', [ $this, 'bustStaticHomepageResults' ], 10, 1 );
}
/**
* Busts the SEO Analysis for the static homepage when it is updated.
*
* @since 4.2.6
*
* @param int $postId The post ID.
* @return void
*/
public function bustStaticHomepageResults( $postId ) {
if ( ! aioseo()->helpers->isStaticHomePage( $postId ) ) {
return;
}
aioseo()->internalOptions->internal->siteAnalysis->score = 0;
aioseo()->internalOptions->internal->siteAnalysis->results = null;
aioseo()->core->cache->delete( 'analyze_site_code' );
aioseo()->core->cache->delete( 'analyze_site_body' );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Monitors changes to post slugs.
*
* @since 4.2.3
*/
class SlugMonitor {
/**
* Holds posts that have been updated.
*
* @since 4.2.3
*
* @var array
*/
private $updatedPosts = [];
/**
* Class constructor.
*
* @since 4.2.3
*/
public function __construct() {
// We can't monitor changes without permalinks enabled.
if ( ! get_option( 'permalink_structure' ) ) {
return;
}
add_action( 'pre_post_update', [ $this, 'prePostUpdate' ] );
// WP 5.6+.
if ( function_exists( 'wp_after_insert_post' ) ) {
add_action( 'wp_after_insert_post', [ $this, 'afterInsertPost' ], 11, 4 );
} else {
add_action( 'post_updated', [ $this, 'postUpdated' ], 11, 3 );
}
}
/**
* Remember the previous post permalink.
*
* @since 4.2.3
*
* @param integer $postId The post ID.
* @return void
*/
public function prePostUpdate( $postId ) {
$this->updatedPosts[ $postId ] = get_permalink( $postId );
}
/**
* Called when a post has been completely inserted ( with categories and meta ).
*
* @since 4.2.3
*
* @param integer $postId The post ID.
* @param \WP_Post $post The post object.
* @param bool $update Whether this is an existing post being updated.
* @param null|\WP_Post $postBefore The post object before changes were made.
* @return void
*/
public function afterInsertPost( $postId, $post, $update, $postBefore ) {
if ( ! $update ) {
return;
}
$this->postUpdated( $postId, $post, $postBefore );
}
/**
* Called when a post has been updated - check if the slug has changed.
*
* @since 4.2.3
*
* @param integer $postId The post ID.
* @param \WP_Post $post The post object.
* @param \WP_Post $postBefore The post object before changes were made.
* @return void
*/
public function postUpdated( $postId, $post, $postBefore ) {
if ( ! isset( $this->updatedPosts[ $postId ] ) ) {
return;
}
$before = aioseo()->helpers->getPermalinkPath( $this->updatedPosts[ $postId ] );
$after = aioseo()->helpers->getPermalinkPath( get_permalink( $postId ) );
if ( ! aioseo()->helpers->hasPermalinkChanged( $before, $after ) ) {
return;
}
// Can we monitor this slug?
if ( ! $this->canMonitorPost( $post, $postBefore ) ) {
return;
}
// Ask aioseo-redirects if automatic redirects is monitoring it.
if ( $this->automaticRedirect( $post->post_type, $before, $after ) ) {
return;
}
// Filter to allow users to disable the slug monitor messages.
if ( apply_filters( 'aioseo_redirects_disable_slug_monitor', false ) ) {
return;
}
$redirectUrl = $this->manualRedirectUrl( [
'url' => $before,
'target' => $after,
'type' => 301
] );
$message = __( 'The permalink for this post just changed! This could result in 404 errors for your site visitors.', 'all-in-one-seo-pack' );
// Default notice redirecting to the Redirects screen.
$action = [
'url' => $redirectUrl,
'label' => __( 'Add Redirect to improve SEO', 'all-in-one-seo-pack' ),
'target' => '_blank',
'class' => 'aioseo-redirects-slug-changed'
];
// If redirects is active we'll show add-redirect in a modal.
if ( aioseo()->addons->getLoadedAddon( 'redirects' ) ) {
// We need to remove the target here so the action keeps the url used by the add-redirect modal.
unset( $action['target'] );
}
aioseo()->wpNotices->addNotice( $message, 'warning', [ 'actions' => [ $action ] ], [ 'posts' ] );
}
/**
* Checks if this is a post we can monitor.
*
* @since 4.2.3
*
* @param \WP_Post $post The post object.
* @param \WP_Post $postBefore The post object before changes were made.
* @return boolean True if we can monitor this post.
*/
private function canMonitorPost( $post, $postBefore ) {
// Check that this is for the expected post.
if ( ! isset( $post->ID ) || ! isset( $this->updatedPosts[ $post->ID ] ) ) {
return false;
}
// Don't do anything if we're not published.
if ( 'publish' !== $post->post_status || 'publish' !== $postBefore->post_status ) {
return false;
}
// Don't do anything is the post type is not public.
if ( ! is_post_type_viewable( $post->post_type ) ) {
return false;
}
return true;
}
/**
* Tries to add a automatic redirect.
*
* @since 4.2.3
*
* @param string $postType The post type.
* @param string $before The url before.
* @param string $after The url after.
* @return bool True if an automatic redirect was added.
*/
private function automaticRedirect( $postType, $before, $after ) {
if ( ! aioseo()->addons->getLoadedAddon( 'redirects' ) ) {
return false;
}
return aioseoRedirects()->monitor->automaticRedirect( $postType, $before, $after );
}
/**
* Generates a URL for adding manual redirects.
*
* @since 4.2.3
*
* @param array $urls An array of [url, target, type, slash, case, regex].
* @return string The redirect link.
*/
public function manualRedirectUrl( $urls ) {
if ( ! aioseo()->addons->getLoadedAddon( 'redirects' ) ) {
return admin_url( 'admin.php?page=aioseo-redirects' );
}
return aioseoRedirects()->helpers->manualRedirectUrl( $urls );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Admin;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Usage tracking class.
*
* @since 4.0.0
*/
abstract class Usage {
/**
* Returns the current plugin version type ("lite" or "pro").
*
* @since 4.1.3
*
* @return string The version type.
*/
abstract public function getType();
/**
* Source of notifications content.
*
* @since 4.0.0
*
* @var string
*/
private $url = 'https://aiousage.com/v1/track';
/**
* Whether or not usage tracking is enabled.
*
* @since 4.0.0
*
* @var bool
*/
protected $enabled = false;
/**
* Class Constructor.
*
* @since 4.0.0
*/
public function __construct() {
add_action( 'init', [ $this, 'init' ], 2 );
}
/**
* Runs on the init action.
*
* @since 4.0.0
*
* @return void
*/
public function init() {
try {
$action = 'aioseo_send_usage_data';
if ( ! $this->enabled ) {
aioseo()->actionScheduler->unschedule( $action );
return;
}
// Register the action handler.
add_action( $action, [ $this, 'process' ] );
if ( ! as_next_scheduled_action( $action ) ) {
as_schedule_recurring_action( $this->generateStartDate(), WEEK_IN_SECONDS, $action, [], 'aioseo' );
// Run the task immediately using an async action.
as_enqueue_async_action( $action, [], 'aioseo' );
}
} catch ( \Exception $e ) {
// Do nothing.
}
}
/**
* Processes the usage tracking.
*
* @since 4.0.0
*
* @return void
*/
public function process() {
if ( ! $this->enabled ) {
return;
}
wp_remote_post(
$this->getUrl(),
[
'timeout' => 10,
'headers' => array_merge( [
'Content-Type' => 'application/json; charset=utf-8'
], aioseo()->helpers->getApiHeaders() ),
'user-agent' => aioseo()->helpers->getApiUserAgent(),
'body' => wp_json_encode( $this->getData() )
]
);
}
/**
* Gets the URL for the notifications api.
*
* @since 4.0.0
*
* @return string The URL to use for the api requests.
*/
private function getUrl() {
if ( defined( 'AIOSEO_USAGE_TRACKING_URL' ) ) {
return AIOSEO_USAGE_TRACKING_URL;
}
return $this->url;
}
/**
* Retrieves the data to send in the usage tracking.
*
* @since 4.0.0
*
* @return array An array of data to send.
*/
protected function getData() {
$themeData = wp_get_theme();
$type = $this->getType();
return [
// Generic data (environment).
'url' => home_url(),
'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION,
'wp_version' => get_bloginfo( 'version' ),
'mysql_version' => aioseo()->core->db->db->db_version(),
'server_version' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '',
'is_ssl' => is_ssl(),
'is_multisite' => is_multisite(),
'sites_count' => function_exists( 'get_blog_count' ) ? (int) get_blog_count() : 1,
'active_plugins' => $this->getActivePlugins(),
'theme_name' => $themeData->name,
'theme_version' => $themeData->version,
'user_count' => function_exists( 'get_user_count' ) ? get_user_count() : null,
'locale' => get_locale(),
'timezone_offset' => aioseo()->helpers->getTimeZoneOffset(),
'email' => get_bloginfo( 'admin_email' ),
// AIOSEO specific data.
'aioseo_version' => AIOSEO_VERSION,
'aioseo_license_key' => null,
'aioseo_license_type' => null,
'aioseo_is_pro' => false,
"aioseo_${type}_installed_date" => aioseo()->internalOptions->internal->installed,
'aioseo_settings' => $this->getSettings()
];
}
/**
* Get the settings and escape the quotes so it can be JSON encoded.
*
* @since 4.0.0
*
* @return array An array of settings data.
*/
private function getSettings() {
$settings = aioseo()->options->all();
array_walk_recursive( $settings, function( &$v ) {
if ( is_string( $v ) && strpos( $v, '&quot' ) !== false ) {
$v = str_replace( '&quot', '&#x5c;&quot', $v );
}
});
$settings = $this->filterPrivateSettings( $settings );
$internal = aioseo()->internalOptions->all();
array_walk_recursive( $internal, function( &$v ) {
if ( is_string( $v ) && strpos( $v, '&quot' ) !== false ) {
$v = str_replace( '&quot', '&#x5c;&quot', $v );
}
});
return [
'options' => $settings,
'internal' => $internal
];
}
/**
* Return a list of active plugins.
*
* @since 4.0.0
*
* @return array An array of active plugin data.
*/
private function getActivePlugins() {
if ( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}
$active = get_option( 'active_plugins', [] );
$plugins = array_intersect_key( get_plugins(), array_flip( $active ) );
return array_map(
static function ( $plugin ) {
if ( isset( $plugin['Version'] ) ) {
return $plugin['Version'];
}
return 'Not Set';
},
$plugins
);
}
/**
* Generate a random start date for usage tracking.
*
* @since 4.0.0
*
* @return integer The randomized start date.
*/
private function generateStartDate() {
$tracking = [
'days' => wp_rand( 0, 6 ) * DAY_IN_SECONDS,
'hours' => wp_rand( 0, 23 ) * HOUR_IN_SECONDS,
'minutes' => wp_rand( 0, 23 ) * HOUR_IN_SECONDS,
'seconds' => wp_rand( 0, 59 )
];
return strtotime( 'next sunday' ) + array_sum( $tracking );
}
/**
* Anonimizes or obfuscates the value of certain settings.
*
* @since 4.3.2
*
* @param array $settings The settings.
* @return array The altered settings.
*/
private function filterPrivateSettings( $settings ) {
if ( ! empty( $settings['advanced']['openAiKey'] ) ) {
$settings['advanced']['openAiKey'] = true;
}
if ( ! empty( $settings['localBusiness']['maps']['apiKey'] ) ) {
$settings['localBusiness']['maps']['apiKey'] = true;
}
return $settings;
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Analyze {
/**
* Analyzes the site for SEO.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function analyzeSite( $request ) {
$body = $request->get_json_params();
$analyzeUrl = ! empty( $body['url'] ) ? esc_url_raw( urldecode( $body['url'] ) ) : null;
$refreshResults = ! empty( $body['refresh'] ) ? (bool) $body['refresh'] : false;
$analyzeOrHomeUrl = ! empty( $analyzeUrl ) ? $analyzeUrl : home_url();
$responseCode = null === aioseo()->core->cache->get( 'analyze_site_code' ) ? [] : aioseo()->core->cache->get( 'analyze_site_code' );
$responseBody = null === aioseo()->core->cache->get( 'analyze_site_body' ) ? [] : aioseo()->core->cache->get( 'analyze_site_body' );
if (
empty( $responseCode ) ||
empty( $responseCode[ $analyzeOrHomeUrl ] ) ||
empty( $responseBody ) ||
empty( $responseBody[ $analyzeOrHomeUrl ] ) ||
$refreshResults
) {
$token = aioseo()->internalOptions->internal->siteAnalysis->connectToken;
$url = defined( 'AIOSEO_ANALYZE_URL' ) ? AIOSEO_ANALYZE_URL : 'https://analyze.aioseo.com';
$response = aioseo()->helpers->wpRemotePost( $url . '/v1/analyze/', [
'timeout' => 60,
'headers' => [
'X-AIOSEO-Key' => $token,
'Content-Type' => 'application/json'
],
'body' => wp_json_encode( [
'url' => $analyzeOrHomeUrl
] ),
] );
$responseCode[ $analyzeOrHomeUrl ] = wp_remote_retrieve_response_code( $response );
$responseBody[ $analyzeOrHomeUrl ] = json_decode( wp_remote_retrieve_body( $response ) );
aioseo()->core->cache->update( 'analyze_site_code', $responseCode, 10 * MINUTE_IN_SECONDS );
aioseo()->core->cache->update( 'analyze_site_body', $responseBody, 10 * MINUTE_IN_SECONDS );
}
if ( 200 !== $responseCode[ $analyzeOrHomeUrl ] || empty( $responseBody[ $analyzeOrHomeUrl ]->success ) || ! empty( $responseBody[ $analyzeOrHomeUrl ]->error ) ) {
if ( ! empty( $responseBody[ $analyzeOrHomeUrl ]->error ) && 'invalid-token' === $responseBody[ $analyzeOrHomeUrl ]->error ) {
aioseo()->internalOptions->internal->siteAnalysis->reset();
}
return new \WP_REST_Response( [
'success' => false,
'response' => $responseBody[ $analyzeOrHomeUrl ]
], 400 );
}
if ( $analyzeUrl ) {
$competitors = aioseo()->internalOptions->internal->siteAnalysis->competitors;
$competitors = array_reverse( $competitors, true );
$competitors[ $analyzeUrl ] = wp_json_encode( $responseBody[ $analyzeOrHomeUrl ] );
$competitors = array_reverse( $competitors, true );
// Reset the competitors.
aioseo()->internalOptions->internal->siteAnalysis->competitors = $competitors;
return new \WP_REST_Response( $competitors, 200 );
}
$results = $responseBody[ $analyzeOrHomeUrl ]->results;
// Image alt attributes get stripped by sanitize_text_field, so we need to adjust the way they are stored to keep them intact.
if ( ! empty( $results->basic->noImgAltAtts->value ) ) {
$results->basic->noImgAltAtts->value = array_map( 'htmlentities', $results->basic->noImgAltAtts->value );
}
aioseo()->internalOptions->internal->siteAnalysis->results = wp_json_encode( $results );
aioseo()->internalOptions->internal->siteAnalysis->score = $responseBody[ $analyzeOrHomeUrl ]->score;
return new \WP_REST_Response( $responseBody[ $analyzeOrHomeUrl ], 200 );
}
/**
* Deletes the analyzed site for SEO.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function deleteSite( $request ) {
$body = $request->get_json_params();
$analyzeUrl = ! empty( $body['url'] ) ? esc_url_raw( urldecode( $body['url'] ) ) : null;
$competitors = aioseo()->internalOptions->internal->siteAnalysis->competitors;
unset( $competitors[ $analyzeUrl ] );
// Reset the competitors.
aioseo()->internalOptions->internal->siteAnalysis->competitors = $competitors;
return new \WP_REST_Response( $competitors, 200 );
}
/**
* Analyzes the title for SEO.
*
* @since 4.1.2
*
* @param \WP_REST_Request $request The REST Request.
* @return \WP_REST_Response The response.
*/
public static function analyzeHeadline( $request ) {
$body = $request->get_json_params();
$headline = ! empty( $body['headline'] ) ? sanitize_text_field( $body['headline'] ) : '';
$shouldStoreHeadline = ! empty( $body['shouldStoreHeadline'] ) ? rest_sanitize_boolean( $body['shouldStoreHeadline'] ) : false;
if ( empty( $headline ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => __( 'Please enter a valid headline.', 'all-in-one-seo-pack' )
], 400 );
}
$result = aioseo()->standalone->headlineAnalyzer->getResult( $headline );
$headlines = aioseo()->internalOptions->internal->headlineAnalysis->headlines;
$headlines = array_reverse( $headlines, true );
$headlines[ $headline ] = wp_json_encode( $result );
$headlines = array_reverse( $headlines, true );
// Store the headlines with the latest one.
if ( $shouldStoreHeadline ) {
aioseo()->internalOptions->internal->headlineAnalysis->headlines = $headlines;
}
return new \WP_REST_Response( $headlines, 200 );
}
/**
* Deletes the analyzed Headline for SEO.
*
* @since 4.1.6
*
* @param \WP_REST_Request $request The REST Request.
* @return \WP_REST_Response The response.
*/
public static function deleteHeadline( $request ) {
$body = $request->get_json_params();
$headline = sanitize_text_field( $body['headline'] );
$headlines = aioseo()->internalOptions->internal->headlineAnalysis->headlines;
unset( $headlines[ $headline ] );
// Reset the headlines.
aioseo()->internalOptions->internal->headlineAnalysis->headlines = $headlines;
return new \WP_REST_Response( $headlines, 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Connect {
/**
* Get the connect URL.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function getConnectUrl( $request ) {
$body = $request->get_json_params();
$key = ! empty( $body['licenseKey'] ) ? sanitize_text_field( $body['licenseKey'] ) : null;
$wizard = ! empty( $body['wizard'] ) ? (bool) $body['wizard'] : false;
$success = true;
$urlData = aioseo()->admin->connect->generateConnectUrl( $key, $wizard ? admin_url( 'index.php?page=aioseo-setup-wizard#/success' ) : null );
$url = '';
$message = '';
if ( ! empty( $urlData['error'] ) ) {
$success = false;
$message = $urlData['error'];
}
$url = $urlData['url'];
return new \WP_REST_Response( [
'success' => $success,
'url' => $url,
'message' => $message,
'popup' => ! isset( $urlData['popup'] ) ? true : $urlData['popup']
], 200 );
}
/**
* Process the connection.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function processConnect( $request ) {
$body = $request->get_json_params();
$downloadUrl = ! empty( $body['downloadUrl'] ) ? esc_url_raw( urldecode( $body['downloadUrl'] ) ) : null;
$token = ! empty( $body['token'] ) ? sanitize_text_field( $body['token'] ) : null;
$wizard = ! empty( $body['wizard'] ) ? sanitize_text_field( $body['wizard'] ) : null;
$success = true;
$message = '';
if ( $wizard ) {
aioseo()->internalOptions->internal->wizard = $wizard;
}
$response = aioseo()->admin->connect->process( $downloadUrl, $token );
if ( ! empty( $response['error'] ) ) {
$message = $response['error'];
} else {
$message = $response['success'];
}
return new \WP_REST_Response( [
'success' => $success,
'message' => $message
], 200 );
}
/**
* Saves the connect token.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function saveConnectToken( $request ) {
$body = $request->get_json_params();
$token = ! empty( $body['token'] ) ? sanitize_text_field( $body['token'] ) : null;
$success = true;
$message = 'token-saved';
aioseo()->internalOptions->internal->siteAnalysis->connectToken = $token;
return new \WP_REST_Response( [
'success' => $success,
'message' => $message
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Integrations\Semrush;
/**
* Route class for the API.
*
* @since 4.0.16
*/
class Integrations {
/**
* Fetches the additional keyphrases.
*
* @since 4.0.16
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function semrushGetKeyphrases( $request ) {
$body = $request->get_json_params();
$keyphrases = Semrush::getKeyphrases( $body['keyphrase'], $body['database'] );
if ( false === $keyphrases ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'Tokens expired and could not be refreshed.'
], 400 );
}
return new \WP_REST_Response( [
'success' => true,
'keyphrases' => $keyphrases
], 200 );
}
/**
* Authenticates with Semrush.
*
* @since 4.0.16
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function semrushAuthenticate( $request ) {
$body = $request->get_json_params();
if ( empty( $body['code'] ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'Missing authorization code.'
], 400 );
}
$success = Semrush::authenticate( $body['code'] );
if ( ! $success ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'Authentication failed.'
], 400 );
}
return new \WP_REST_Response( [
'success' => true,
'semrush' => aioseo()->internalOptions->integrations->semrush->all()
], 200 );
}
/**
* Refreshes the API tokens.
*
* @since 4.0.16
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function semrushRefresh() {
$success = Semrush::refreshTokens();
if ( ! $success ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'API tokens could not be refreshed.'
], 400 );
}
return new \WP_REST_Response( [
'success' => true,
'semrush' => aioseo()->internalOptions->integrations->semrush->all()
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Migration as CommonMigration;
use AIOSEO\Plugin\Common\Models;
/**
* Route class for the API.
*
* @since 4.0.6
*/
class Migration {
/**
* Resets blank title formats and retriggers the post/term meta migration.
*
* @since 4.0.6
*
* @return \WP_REST_Response The response.
*/
public static function fixBlankFormats() {
$oldOptions = ( new CommonMigration\OldOptions() )->oldOptions;
if ( ! $oldOptions ) {
return new \WP_REST_Response( [
'success' => true,
'message' => 'Could not load v3 options.'
], 400 );
}
$postTypes = aioseo()->helpers->getPublicPostTypes( true );
$taxonomies = aioseo()->helpers->getPublicTaxonomies( true );
foreach ( $oldOptions as $k => $v ) {
if ( ! preg_match( '/^aiosp_([a-zA-Z]*)_title_format$/', $k, $match ) || ! empty( $v ) ) {
continue;
}
$objectName = $match[1];
if ( in_array( $objectName, $postTypes, true ) && aioseo()->dynamicOptions->searchAppearance->postTypes->has( $objectName ) ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->$objectName->title = '#post_title #separator_sa #site_title';
continue;
}
if ( in_array( $objectName, $taxonomies, true ) && aioseo()->dynamicOptions->searchAppearance->taxonomies->has( $objectName ) ) {
aioseo()->dynamicOptions->searchAppearance->taxonomies->$objectName->title = '#taxonomy_title #separator_sa #site_title';
}
}
aioseo()->migration->redoMetaMigration();
Models\Notification::deleteNotificationByName( 'v3-migration-title-formats-blank' );
return new \WP_REST_Response( [
'success' => true,
'message' => 'Title formats have been reset; post/term migration has been scheduled.',
'notifications' => Models\Notification::getNotifications()
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Route class for the API.
*
* @since 4.2.5
*/
class Network {
/**
* Save network robots rules.
*
* @since 4.2.5
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function saveNetworkRobots( $request ) {
$isNetwork = 'network' === $request->get_param( 'siteId' );
$siteId = $isNetwork ? aioseo()->helpers->getNetworkId() : (int) $request->get_param( 'siteId' );
$body = $request->get_json_params();
$rules = ! empty( $body['rules'] ) ? array_map( 'sanitize_text_field', $body['rules'] ) : [];
$enabled = isset( $body['enabled'] ) ? boolval( $body['enabled'] ) : null;
aioseo()->helpers->switchToBlog( $siteId );
$options = $isNetwork ? aioseo()->networkOptions : aioseo()->options;
$enabled = null === $enabled ? $options->tools->robots->enable : $enabled;
$options->sanitizeAndSave( [
'tools' => [
'robots' => [
'enable' => $enabled,
'rules' => $rules
]
]
] );
return new \WP_REST_Response( [
'success' => true
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Notifications {
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function blogVisibilityReminder() {
return self::reminder( 'blog-visibility' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.5
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function descriptionFormatReminder() {
return self::reminder( 'description-format' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function installMiReminder() {
return self::reminder( 'install-mi' );
}
/**
* Extend the start date of a notice.
*
* @since 4.2.1
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function installOmReminder() {
return self::reminder( 'install-om' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function installAddonsReminder() {
return self::reminder( 'install-addons' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function installImageSeoReminder() {
return self::reminder( 'install-aioseo-image-seo' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function installLocalBusinessReminder() {
return self::reminder( 'install-aioseo-local-business' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function installNewsSitemapReminder() {
return self::reminder( 'install-aioseo-news-sitemap' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function installVideoSitemapReminder() {
return self::reminder( 'install-aioseo-video-sitemap' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function conflictingPluginsReminder() {
return self::reminder( 'conflicting-plugins' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function migrationCustomFieldReminder() {
return self::reminder( 'v3-migration-custom-field' );
}
/**
* Extend the start date of a notice.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function migrationSchemaNumberReminder() {
return self::reminder( 'v3-migration-schema-number' );
}
/**
* This allows us to not repeat code over and over.
*
* @since 4.0.0
*
* @param string $slug The slug of the reminder.
* @return @return \WP_REST_Response The response.
*/
protected static function reminder( $slug ) {
aioseo()->notices->remindMeLater( $slug );
return new \WP_REST_Response( [
'success' => true,
'notifications' => Models\Notification::getNotifications()
], 200 );
}
/**
* Dismiss notifications.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function dismissNotifications( $request ) {
$slugs = $request->get_json_params();
$notifications = aioseo()->core->db
->start( 'aioseo_notifications' )
->whereIn( 'slug', $slugs )
->run()
->models( 'AIOSEO\\Plugin\\Common\\Models\\Notification' );
foreach ( $notifications as $notification ) {
$notification->dismissed = 1;
$notification->save();
}
// Dismiss static notifications.
if ( in_array( 'notification-review', $slugs, true ) ) {
update_user_meta( get_current_user_id(), '_aioseo_notification_plugin_review_dismissed', '3' );
}
if ( in_array( 'notification-review-delay', $slugs, true ) ) {
update_user_meta( get_current_user_id(), '_aioseo_notification_plugin_review_dismissed', strtotime( '+1 week' ) );
}
return new \WP_REST_Response( [
'success' => true,
'notifications' => Models\Notification::getNotifications()
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Ping {
/**
* Returns a success if the API is alive.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function ping() {
return new \WP_REST_Response( [
'success' => true
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Plugins {
/**
* Installs plugins from vue.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function installPlugins( $request ) {
$error = esc_html__( 'Installation failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
$body = $request->get_json_params();
$plugins = ! empty( $body['plugins'] ) ? $body['plugins'] : [];
$network = ! empty( $body['network'] ) ? $body['network'] : false;
if ( ! is_array( $plugins ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
if ( ! aioseo()->addons->canInstall() ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
$failed = [];
$completed = [];
foreach ( $plugins as $plugin ) {
if ( empty( $plugin['plugin'] ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
$result = aioseo()->addons->installAddon( $plugin['plugin'], $network );
if ( ! $result ) {
$failed[] = $plugin['plugin'];
} else {
$completed[ $plugin['plugin'] ] = $result;
}
}
return new \WP_REST_Response( [
'success' => true,
'completed' => $completed,
'failed' => $failed
], 200 );
}
/**
* Upgrade plugins from vue.
*
* @since 4.1.6
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function upgradePlugins( $request ) {
$error = esc_html__( 'Plugin update failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
$body = $request->get_json_params();
$plugins = ! empty( $body['plugins'] ) ? $body['plugins'] : [];
$network = ! empty( $body['network'] ) ? $body['network'] : false;
if ( ! is_array( $plugins ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
if ( ! aioseo()->addons->canUpdate() ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
$failed = [];
$completed = [];
foreach ( $plugins as $plugin ) {
if ( empty( $plugin['plugin'] ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
$result = aioseo()->addons->upgradeAddon( $plugin['plugin'], $network );
if ( ! $result ) {
$failed[] = $plugin['plugin'];
} else {
$completed[ $plugin['plugin'] ] = aioseo()->addons->getAddon( $plugin['plugin'], true );
}
}
return new \WP_REST_Response( [
'success' => true,
'completed' => $completed,
'failed' => $failed
], 200 );
}
/**
* Deactivates plugins from vue.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function deactivatePlugins( $request ) {
$error = esc_html__( 'Deactivation failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
$body = $request->get_json_params();
$plugins = ! empty( $body['plugins'] ) ? $body['plugins'] : [];
$network = ! empty( $body['network'] ) ? $body['network'] : false;
if ( ! is_array( $plugins ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
if ( ! current_user_can( 'install_plugins' ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$failed = [];
$completed = [];
foreach ( $plugins as $plugin ) {
if ( empty( $plugin['plugin'] ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
// Activate the plugin silently.
$activated = deactivate_plugins( $plugin['plugin'], false, $network );
if ( is_wp_error( $activated ) ) {
$failed[] = $plugin['plugin'];
}
$completed[] = $plugin['plugin'];
}
return new \WP_REST_Response( [
'success' => true,
'completed' => $completed,
'failed' => $failed
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Sitemaps {
/**
* Delete all static sitemap files.
*
* @since 4.0.0
*
* @return \WP_REST_Response The response.
*/
public static function deleteStaticFiles() {
require_once ABSPATH . 'wp-admin/includes/file.php';
$files = list_files( get_home_path(), 1 );
if ( ! count( $files ) ) {
return;
}
$isGeneralSitemapStatic = aioseo()->options->sitemap->general->advancedSettings->enable &&
in_array( 'staticSitemap', aioseo()->internalOptions->internal->deprecatedOptions, true ) &&
! aioseo()->options->deprecated->sitemap->general->advancedSettings->dynamic;
$detectedFiles = [];
if ( ! $isGeneralSitemapStatic ) {
foreach ( $files as $filename ) {
if ( preg_match( '#.*sitemap.*#', $filename ) ) {
// We don't want to delete the video sitemap here at all.
$isVideoSitemap = preg_match( '#.*video.*#', $filename ) ? true : false;
if ( ! $isVideoSitemap ) {
$detectedFiles[] = $filename;
}
}
}
}
if ( ! count( $detectedFiles ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'No sitemap files found.'
], 400 );
}
$fs = aioseo()->core->fs;
if ( ! $fs->isWpfsValid() ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'No access to filesystem.'
], 400 );
}
foreach ( $detectedFiles as $file ) {
$fs->fs->delete( $file, false, 'f' );
}
Models\Notification::deleteNotificationByName( 'sitemap-static-files' );
return new \WP_REST_Response( [
'success' => true,
'notifications' => Models\Notification::getNotifications()
], 200 );
}
/**
* Deactivates conflicting plugins.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function deactivateConflictingPlugins() {
$error = esc_html__( 'Deactivation failed. Please check permissions and try again.', 'all-in-one-seo-pack' );
if ( ! current_user_can( 'install_plugins' ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $error
], 400 );
}
$plugins = array_merge(
aioseo()->conflictingPlugins->getConflictingPlugins( 'seo' ),
aioseo()->conflictingPlugins->getConflictingPlugins( 'sitemap' )
);
require_once ABSPATH . 'wp-admin/includes/plugin.php';
foreach ( $plugins as $pluginPath ) {
if ( is_plugin_active( $pluginPath ) ) {
deactivate_plugins( $pluginPath );
}
}
Models\Notification::deleteNotificationByName( 'conflicting-plugins' );
return new \WP_REST_Response( [
'success' => true,
'notifications' => Models\Notification::getNotifications()
], 200 );
}
/**
* Check whether the slug for the HTML sitemap is not in use.
*
* @since 4.1.3
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function validateHtmlSitemapSlug( $request ) {
$body = $request->get_json_params();
$pageUrl = ! empty( $body['pageUrl'] ) ? sanitize_text_field( $body['pageUrl'] ) : '';
if ( empty( $pageUrl ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'No path was provided.'
], 400 );
}
$parsedPageUrl = wp_parse_url( $pageUrl );
if ( empty( $parsedPageUrl['path'] ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'The given path is invalid.'
], 400 );
}
$isUrl = aioseo()->helpers->isUrl( $pageUrl );
$isInternalUrl = aioseo()->helpers->isInternalUrl( $pageUrl );
if ( $isUrl && ! $isInternalUrl ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'The given URL is not a valid internal URL.'
], 400 );
}
$pathExists = self::pathExists( $parsedPageUrl['path'], $isUrl );
return new \WP_REST_Response( [
'exists' => $pathExists
], 200 );
}
/**
* Checks whether the given path is unique or not.
*
* @since 4.1.4
* @version 4.2.6
*
* @param string $path The path.
* @param bool $path Whether the given path is a URL.
* @return boolean Whether the path exists.
*/
private static function pathExists( $path, $isUrl ) {
$path = trim( $path, '/' );
$url = $isUrl ? $path : trailingslashit( home_url() ) . $path;
// Let's do another check here, just to be sure that the domain matches.
if ( ! aioseo()->helpers->isInternalUrl( $url ) ) {
return false;
}
$response = wp_safe_remote_head( $url );
$status = wp_remote_retrieve_response_code( $response );
if ( ! $status ) {
// If there is no status code, we might be in a local environment with CURL misconfigured.
// In that case we can still check if a post exists for the path by quering the DB.
$post = aioseo()->helpers->getPostbyPath(
$path,
OBJECT,
aioseo()->helpers->getPublicPostTypes( true )
);
return is_object( $post );
}
return 200 === $status;
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Tags {
/**
* Get all Tags.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function getTags() {
return new \WP_REST_Response( [
'tags' => aioseo()->tags->all( true )
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
use AIOSEO\Plugin\Common\Tools as CommonTools;
/**
* Route class for the API.
*
* @since 4.0.0
*/
class Tools {
/**
* Import and delete the static robots.txt.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function importRobotsTxt( $request ) {
$body = $request->get_json_params();
$network = ! empty( $body['network'] ) ? (bool) $body['network'] : false;
if ( ! aioseo()->robotsTxt->importPhysicalRobotsTxt( $network ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => __( 'There was an error importing the physical robots.txt file.', 'all-in-one-seo-pack' )
], 400 );
}
aioseo()->options->tools->robots->enable = true;
if ( ! aioseo()->robotsTxt->deletePhysicalRobotsTxt() ) {
return new \WP_REST_Response( [
'success' => false,
'message' => __( 'There was an error deleting the physical robots.txt file.', 'all-in-one-seo-pack' )
], 400 );
}
Models\Notification::deleteNotificationByName( 'robots-physical-file' );
return new \WP_REST_Response( [
'success' => true,
'notifications' => Models\Notification::getNotifications()
], 200 );
}
/**
* Delete the static robots.txt.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function deleteRobotsTxt() {
if ( ! aioseo()->robotsTxt->deletePhysicalRobotsTxt() ) {
return new \WP_REST_Response( [
'success' => false,
'message' => __( 'There was an error deleting the physical robots.txt file.', 'all-in-one-seo-pack' )
], 400 );
}
Models\Notification::deleteNotificationByName( 'robots-physical-file' );
return new \WP_REST_Response( [
'success' => true,
'notifications' => Models\Notification::getNotifications()
], 200 );
}
/**
* Email debug info.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function emailDebugInfo( $request ) {
$body = $request->get_json_params();
$email = ! empty( $body['email'] ) ? $body['email'] : null;
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'invalid-email-address'
], 400 );
}
require_once ABSPATH . 'wp-admin/includes/update.php';
// Translators: 1 - The plugin name ("All in One SEO"), 2 - The Site URL.
$html = sprintf( __( '%1$s Debug Info from %2$s', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME, aioseo()->helpers->getSiteDomain() ) . "\r\n------------------\r\n\r\n";
$info = CommonTools\SystemStatus::getSystemStatusInfo();
foreach ( $info as $group ) {
if ( empty( $group['results'] ) ) {
continue;
}
$html .= "\r\n\r\n{$group['label']}\r\n";
foreach ( $group['results'] as $data ) {
$html .= "{$data['header']}: {$data['value']}\r\n";
}
}
if ( ! wp_mail(
$email,
// Translators: 1 - The plugin name ("All in One SEO).
sprintf( __( '%1$s Debug Info', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_NAME ),
$html
) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => __( 'Unable to send debug email, please check your email send settings and try again.', 'all-in-one-seo-pack' )
], 400 );
}
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Create a settings backup.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function createBackup( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
aioseo()->backup->create();
return new \WP_REST_Response( [
'success' => true,
'backups' => array_reverse( aioseo()->backup->all() )
], 200 );
}
/**
* Restore a settings backup.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function restoreBackup( $request ) {
$body = $request->get_json_params();
$backup = ! empty( $body['backup'] ) ? (int) $body['backup'] : null;
if ( empty( $backup ) ) {
return new \WP_REST_Response( [
'success' => false,
'backups' => array_reverse( aioseo()->backup->all() )
], 400 );
}
aioseo()->backup->restore( $backup );
return new \WP_REST_Response( [
'success' => true,
'backups' => array_reverse( aioseo()->backup->all() ),
'options' => aioseo()->options->all(),
'internalOptions' => aioseo()->internalOptions->all()
], 200 );
}
/**
* Delete a settings backup.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function deleteBackup( $request ) {
$body = $request->get_json_params();
$backup = ! empty( $body['backup'] ) ? (int) $body['backup'] : null;
if ( empty( $backup ) ) {
return new \WP_REST_Response( [
'success' => false,
'backups' => array_reverse( aioseo()->backup->all() )
], 400 );
}
aioseo()->backup->delete( $backup );
return new \WP_REST_Response( [
'success' => true,
'backups' => array_reverse( aioseo()->backup->all() )
], 200 );
}
/**
* Save the .htaccess file.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function saveHtaccess( $request ) {
$body = $request->get_json_params();
$htaccess = ! empty( $body['htaccess'] ) ? sanitize_textarea_field( $body['htaccess'] ) : '';
if ( empty( $htaccess ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => __( '.htaccess file is empty.', 'all-in-one-seo-pack' )
], 400 );
}
$htaccess = aioseo()->helpers->decodeHtmlEntities( $htaccess );
$saveHtaccess = (object) aioseo()->htaccess->saveContents( $htaccess );
if ( ! $saveHtaccess->success ) {
return new \WP_REST_Response( [
'success' => false,
'message' => $saveHtaccess->message ? $saveHtaccess->message : __( 'An error occurred while trying to write to the .htaccess file. Please try again later.', 'all-in-one-seo-pack' ),
'reason' => $saveHtaccess->reason
], 400 );
}
return new \WP_REST_Response( [
'success' => true
], 200 );
}
/**
* Clear the passed in log.
*
* @since 4.0.0
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function clearLog( $request ) {
$body = $request->get_json_params();
$log = ! empty( $body['log'] ) ? $body['log'] : null;
$logSize = 0;
switch ( $log ) {
case 'badBotBlockerLog':
aioseo()->badBotBlocker->clearLog();
$logSize = aioseo()->badBotBlocker->getLogSize();
break;
}
return new \WP_REST_Response( [
'success' => true,
'logSize' => aioseo()->helpers->convertFileSize( $logSize )
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles user related API routes.
*
* @since 4.2.8
*/
class User {
/**
* Get the user image.
*
* @since 4.2.8
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function getUserImage( $request ) {
$args = $request->get_params();
if ( empty( $args['userId'] ) ) {
return new \WP_REST_Response( [
'success' => false,
'message' => 'No user ID was provided.'
], 400 );
}
$url = get_avatar_url( $args['userId'] );
return new \WP_REST_Response( [
'success' => true,
'url' => is_array( $url ) ? $url[0] : $url,
], 200 );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Breadcrumbs;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Breadcrumb Block.
*
* @since 4.1.1
*/
class Block {
/**
* Class constructor.
*
* @since 4.1.1
*/
public function __construct() {
$this->register();
}
/**
* Registers the block.
*
* @since 4.1.1
*
* @return void
*/
public function register() {
aioseo()->blocks->registerBlock(
'aioseo/breadcrumbs', [
'render_callback' => [ $this, 'render' ]
]
);
}
/**
* Renders the block.
*
* @since 4.1.1
*
* @param array $blockAttributes The block attributes.
* @return string The output from the output buffering.
*/
public function render( $blockAttributes ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$postId = ! empty( $_GET['post_id'] ) ? wp_unslash( $_GET['post_id'] ) : false; // phpcs:ignore HM.Security.ValidatedSanitizedInput.InputNotSanitized
if ( aioseo()->blocks->isGBEditor() && ! empty( $postId ) ) {
return aioseo()->breadcrumbs->frontend->sideDisplay( false, 'post' === get_post_type( $postId ) ? 'post' : 'single', get_post( $postId ) );
}
return aioseo()->breadcrumbs->frontend->display( false );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Breadcrumbs;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Frontend.
*
* @since 4.1.1
*/
class Frontend {
/**
* A local 'cached' crumb array.
*
* @since 4.1.1
*
* @var array
*/
public $breadcrumbs = [];
/**
* Gets the current page's breadcrumbs.
*
* @since 4.1.1
*
* @return array
*/
public function getBreadcrumbs() {
if ( ! empty( $this->breadcrumbs ) ) {
return apply_filters( 'aioseo_breadcrumbs_trail', $this->breadcrumbs );
}
$type = '';
$reference = get_queried_object();
// These types need the queried object for reference.
if ( is_object( $reference ) ) {
if ( is_single() ) {
$type = 'single';
}
if ( is_singular( 'post' ) ) {
$type = 'post';
}
if ( is_page() && ! is_front_page() ) {
$type = 'page';
}
if ( is_category() || is_tag() ) {
$type = 'category';
}
if ( is_tax() ) {
$type = 'taxonomy';
}
if ( is_post_type_archive() ) {
$type = 'postTypeArchive';
}
if ( is_author() ) {
$type = 'author';
}
if ( is_home() ) {
$type = 'blog';
}
}
if ( is_date() ) {
$type = 'date';
$reference = [
'year' => get_query_var( 'year' ),
'month' => get_query_var( 'monthnum' ),
'day' => get_query_var( 'day' )
];
}
if ( is_search() ) {
$type = 'search';
$reference = htmlspecialchars( sanitize_text_field( get_search_query() ) );
}
if ( is_404() ) {
$type = 'notFound';
}
$paged = false;
if ( is_paged() || ( is_singular() && 1 < get_query_var( 'page' ) ) ) {
global $wp;
$paged = [
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' ),
'link' => home_url( $wp->request )
];
}
return apply_filters( 'aioseo_breadcrumbs_trail', aioseo()->breadcrumbs->buildBreadcrumbs( $type, $reference, $paged ) );
}
/**
* Helper function to display breadcrumbs for a specific page.
*
* @since 4.1.1
*
* @param bool $echo Print out the breadcrumb.
* @param string $type The type for the breadcrumb.
* @param string $reference A reference to be used for rendering the breadcrumb.
* @return string|void A html breadcrumb.
*/
public function sideDisplay( $echo = true, $type = '', $reference = '' ) {
// Save previously built breadcrumbs.
$previousCrumbs = $this->breadcrumbs;
// Build and run the sideDisplay.
$this->breadcrumbs = aioseo()->breadcrumbs->buildBreadcrumbs( $type, $reference );
$sideDisplay = $this->display( $echo );
// Restore previously built breadcrumbs.
$this->breadcrumbs = $previousCrumbs;
return $sideDisplay;
}
/**
* Display a generic breadcrumb preview.
*
* @since 4.1.5
*
* @param bool $echo Print out the breadcrumb.
* @param string $label The preview crumb label.
* @return string|void A html breadcrumb.
*/
public function preview( $echo = true, $label = '' ) {
// Translators: "Crumb" refers to a part of the breadcrumb trail.
$label = empty( $label ) ? __( 'Sample Crumb', 'all-in-one-seo-pack' ) : $label;
return $this->sideDisplay( $echo, 'preview', $label );
}
/**
* Display the breadcrumb in the frontend.
*
* @since 4.1.1
*
* @param bool $echo Print out the breadcrumb.
* @return string|void A html breadcrumb.
*/
public function display( $echo = true ) {
if ( ! aioseo()->options->breadcrumbs->enable || ! apply_filters( 'aioseo_breadcrumbs_output', true ) ) {
return;
}
// We can only run after this action because we need all post types loaded.
if ( ! did_action( 'init' ) ) {
return;
}
$breadcrumbs = $this->getBreadcrumbs();
if ( empty( $breadcrumbs ) ) {
return;
}
$breadcrumbsCount = count( $breadcrumbs );
$display = '<div class="aioseo-breadcrumbs">';
foreach ( $breadcrumbs as $breadcrumb ) {
--$breadcrumbsCount;
$breadcrumbDisplay = $this->breadcrumbToDisplay( $breadcrumb );
// Strip link from Last crumb.
if (
0 === $breadcrumbsCount &&
aioseo()->breadcrumbs->showCurrentItem() &&
! $this->linkCurrentItem() &&
'default' === $breadcrumbDisplay['templateType']
) {
$breadcrumbDisplay['template'] = $this->stripLink( $breadcrumbDisplay['template'] );
}
$display .= $breadcrumbDisplay['template'];
if ( 0 < $breadcrumbsCount ) {
$display .= $this->getSeparator();
}
}
$display .= '</div>';
$display = wp_kses_post( $display );
if ( $echo ) {
echo $display; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
return $display;
}
/**
* Turns a crumb array into a rendered html crumb.
*
* @since 4.1.1
*
* @param array $item The crumb array.
* @return string|void The crumb html.
*/
protected function breadcrumbToDisplay( $item ) {
$templateItem = $this->getCrumbTemplate( $item );
if ( empty( $templateItem['template'] ) ) {
return;
}
// Do tags.
$templateItem['template'] = aioseo()->breadcrumbs->tags->replaceTags( $templateItem['template'], $item );
// Restore html.
$templateItem['template'] = aioseo()->helpers->decodeHtmlEntities( $templateItem['template'] );
// Remove html link if it comes back from the template but we passed no links to it.
if ( empty( $item['link'] ) ) {
$templateItem['template'] = $this->stripLink( $templateItem['template'] );
}
// Allow shortcodes to run in the final html.
$templateItem['template'] = do_shortcode( $templateItem['template'] );
// Final security cleaning.
$templateItem['template'] = wp_kses_post( $templateItem['template'] );
return $templateItem;
}
/**
* Helper function to get a crumb's template.
*
* @since 4.1.1
*
* @param array $crumb The crumb array.
* @return string The html template.
*/
protected function getTemplate( $crumb ) {
return $this->getDefaultTemplate( $crumb );
}
/**
* Helper function to get a crumb's template.
*
* @since 4.1.1
*
* @param array $crumb The crumb array.
* @return array The template type and html.
*/
protected function getCrumbTemplate( $crumb ) {
return [
'templateType' => 'default',
'template' => $this->getTemplate( $crumb )
];
}
/**
* Default html template.
*
* @since 4.1.1
*
* @param string $type The crumb's type.
* @param mixed $reference The crumb's reference.
* @return string The default crumb template.
*/
public function getDefaultTemplate( $type = '', $reference = '' ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
return <<<TEMPLATE
<span class="aioseo-breadcrumb">
<a href="#breadcrumb_link" title="#breadcrumb_label">#breadcrumb_label</a>
</span>
TEMPLATE;
}
/**
* Helper function to strip a html link from the crumb.
*
* @since 4.1.1
*
* @param string $html The crumb's html.
* @return string A crumb html without links.
*/
public function stripLink( $html ) {
return preg_replace( '/<a\s.*?>|<\/a>/is', '', $html );
}
/**
* Get the breadcrumb configured separator.
*
* @since 4.1.1
*
* @return string The separator html.
*/
public function getSeparator() {
$separator = apply_filters( 'aioseo_breadcrumbs_separator_symbol', aioseo()->options->breadcrumbs->separator );
return apply_filters( 'aioseo_breadcrumbs_separator', '<span class="aioseo-breadcrumb-separator">' . esc_html( $separator ) . '</span>' );
}
/**
* Function to filter the linkCurrentItem option.
*
* @since 4.1.3
*
* @return bool Link current item.
*/
public function linkCurrentItem() {
return apply_filters( 'aioseo_breadcrumbs_link_current_item', aioseo()->options->breadcrumbs->linkCurrentItem );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Breadcrumbs;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Shortcode.
*
* @since 4.1.1
*/
class Shortcode {
/**
* Shortcode constructor.
*
* @since 4.1.1
*/
public function __construct() {
add_shortcode( 'aioseo_breadcrumbs', [ $this, 'display' ] );
}
/**
* Shortcode callback.
*
* @since 4.1.1
*
* @return string|void The breadcrumb html.
*/
public function display() {
return aioseo()->breadcrumbs->frontend->display( false );
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Breadcrumbs;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Widget.
*
* @since 4.1.1
*/
class Widget extends \WP_Widget {
/**
* The default attributes.
*
* @since 4.2.7
*
* @var array
*/
private $defaults = [];
/**
* Class constructor.
*
* @since 4.1.1
*/
public function __construct() {
// Widget defaults.
$this->defaults = [
'title' => ''
];
// Widget Slug.
$widgetSlug = 'aioseo-breadcrumb-widget';
// Widget basics.
$widgetOps = [
'classname' => $widgetSlug,
'description' => esc_html__( 'Display the current page breadcrumb.', 'all-in-one-seo-pack' ),
];
// Widget controls.
$controlOps = [
'id_base' => $widgetSlug,
];
// Load widget.
parent::__construct( $widgetSlug, esc_html__( 'AIOSEO - Breadcrumbs', 'all-in-one-seo-pack' ), $widgetOps, $controlOps );
}
/**
* Widget callback.
*
* @since 4.1.1
*
* @param array $args Widget args.
* @param array $instance The widget instance options.
* @return void
*/
public function widget( $args, $instance ) {
// Merge with defaults.
$instance = wp_parse_args( (array) $instance, $this->defaults );
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
// Title.
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'widget_title', $instance['title'], $instance, $this->id_base
) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
// Breadcrumb.
! empty( $_GET['legacy-widget-preview'] ) ? aioseo()->breadcrumbs->frontend->preview() : aioseo()->breadcrumbs->frontend->display();
// Workaround for a bug in the Gutenberg widget preview.
echo '<span style="display: none">a</span>'; // TODO: remove this when the preview bug is fixed.
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Widget option update.
*
* @since 4.1.1
*
* @param array $newInstance New instance options.
* @param array $oldInstance Old instance options.
* @return array Processed new instance options.
*/
public function update( $newInstance, $oldInstance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$newInstance['title'] = wp_strip_all_tags( $newInstance['title'] );
return $newInstance;
}
/**
* Widget options form.
*
* @since 4.1.1
*
* @param array $instance The widget instance options.
* @return void
*/
public function form( $instance ) {
// Merge with defaults.
$instance = wp_parse_args( (array) $instance, $this->defaults );
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
<?php echo esc_html( __( 'Title:', 'all-in-one-seo-pack' ) ); ?>
</label>
<input
type="text"
id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
value="<?php echo esc_attr( $instance['title'] ); ?>"
class="widefat"
/>
</p>
<?php
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Options;
use AIOSEO\Plugin\Common\Utils;
/**
* Loads core classes.
*
* @since 4.1.9
*/
class Core {
/**
* AIOSEO Tables.
*
* @since 4.2.5
*
* @var array
*/
private $aioseoTables = [
'aioseo_cache',
'aioseo_links',
'aioseo_links_suggestions',
'aioseo_notifications',
'aioseo_posts',
'aioseo_redirects',
'aioseo_redirects_404',
'aioseo_redirects_404_logs',
'aioseo_redirects_hits',
'aioseo_redirects_logs',
'aioseo_terms',
'aioseo_search_statistics_objects'
];
/**
* Filesystem class instance.
*
* @since 4.2.7
*
* @var Utils\Filesystem
*/
public $fs = null;
/**
* Filesystem class instance.
*
* @since 4.2.7
*
* @var Utils\Filesystem
*/
public $assets = null;
/**
* Assets class instance.
*
* @since 4.2.7
*
* @var Utils\Database
*/
public $db = null;
/**
* Cache class instance.
*
* @since 4.2.7
*
* @var Utils\Cache
*/
public $cache = null;
/**
* NetworkCache class instance.
*
* @since 4.2.7
*
* @var Utils\NetworkCache
*/
public $networkCache = null;
/**
* CachePrune class instance.
*
* @since 4.2.7
*
* @var Utils\CachePrune
*/
public $cachePrune = null;
/**
* Cache class instance.
*
* @since 4.2.7
*
* @var Options\Cache
*/
public $optionsCache = null;
/**
* Class constructor.
*
* @since 4.1.9
*/
public function __construct() {
$this->fs = new Utils\Filesystem( $this );
$this->assets = new Utils\Assets( $this );
$this->db = new Utils\Database();
$this->cache = new Utils\Cache();
$this->networkCache = new Utils\NetworkCache();
$this->cachePrune = new Utils\CachePrune();
$this->optionsCache = new Options\Cache();
}
/**
* Removes all our tables and options.
*
* @since 4.2.3
*
* @param bool $force Whether we should ignore the uninstall option or not. We ignore it when we reset all data via the Debug Panel.
* @return void
*/
public function uninstallDb( $force = false ) {
// Confirm that user has decided to remove all data, otherwise stop.
if ( ! $force && ! aioseo()->options->advanced->uninstall ) {
return;
}
// Delete all our custom tables.
global $wpdb;
foreach ( $this->getDbTables() as $tableName ) {
$wpdb->query( 'DROP TABLE IF EXISTS ' . $tableName ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
// Delete all AIOSEO Locations and Location Categories.
$wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type = 'aioseo-location'" );
$wpdb->query( "DELETE FROM {$wpdb->term_taxonomy} WHERE taxonomy = 'aioseo-location-category'" );
// Delete all the plugin settings.
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'aioseo\_%'" );
// Remove any transients we've left behind.
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '\_aioseo\_%'" );
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'aioseo\_%'" );
// Delete all entries from the action scheduler table.
$wpdb->query( "DELETE FROM {$wpdb->prefix}actionscheduler_actions WHERE hook LIKE 'aioseo\_%'" );
$wpdb->query( "DELETE FROM {$wpdb->prefix}actionscheduler_groups WHERE slug = 'aioseo'" );
}
/**
* Get all the DB tables with prefix.
*
* @since 4.2.5
*
* @return array An array of tables.
*/
public function getDbTables() {
global $wpdb;
$tables = [];
foreach ( $this->aioseoTables as $tableName ) {
$tables[] = $wpdb->prefix . $tableName;
}
return $tables;
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\Help;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Help {
/**
* Source of the documentation content.
*
* @since 4.0.0
*
* @var string
*/
private $url = 'https://cdn.aioseo.com/wp-content/docs.json';
/**
* Settings.
*
* @since 4.0.0
*
* @var array
*/
private $settings = [
'docsUrl' => 'https://aioseo.com/docs/',
'supportTicketUrl' => 'https://aioseo.com/account/support/',
'upgradeUrl' => 'https://aioseo.com/pricing/',
];
/**
* Gets the URL for the notifications api.
*
* @since 4.0.0
*
* @return string The URL to use for the api requests.
*/
private function getUrl() {
if ( defined( 'AIOSEO_DOCS_FEED_URL' ) ) {
return AIOSEO_DOCS_FEED_URL;
}
return $this->url;
}
/**
* Get docs from the network cache.
*
* @since 4.0.0
*
* @return array Docs data.
*/
public function getDocs() {
$aioseoAdminHelpDocs = aioseo()->core->networkCache->get( 'admin_help_docs' );
$aioseoAdminHelpDocsCacheTime = WEEK_IN_SECONDS;
if ( null === $aioseoAdminHelpDocs ) {
$request = aioseo()->helpers->wpRemoteGet( $this->getUrl() );
if ( is_wp_error( $request ) ) {
return [];
}
$response = $request['response'];
if ( ( $response['code'] <= 200 ) && ( $response['code'] > 299 ) ) {
$aioseoAdminHelpDocsCacheTime = 10 * MINUTE_IN_SECONDS;
}
$aioseoAdminHelpDocs = wp_remote_retrieve_body( $request );
aioseo()->core->networkCache->update( 'admin_help_docs', $aioseoAdminHelpDocs, $aioseoAdminHelpDocsCacheTime );
}
return $aioseoAdminHelpDocs ? json_decode( $aioseoAdminHelpDocs, true ) : [];
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\ImportExport;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Contains helper methods for the import from other plugins.
*
* @since 4.0.0
*/
abstract class Helpers {
/**
* Converts macros to smart tags.
*
* @since 4.1.3
*
* @param string $value The string with macros.
* @return string The string with macros converted.
*/
abstract public function macrosToSmartTags( $value );
/**
* Maps a list of old settings from V3 to their counterparts in V4.
*
* @since 4.0.0
*
* @param array $mappings The old settings, mapped to their new settings.
* @param array $group The old settings group.
* @param bool $convertMacros Whether to convert the old V3 macros to V4 smart tags.
* @return void
*/
public function mapOldToNew( $mappings, $group, $convertMacros = false ) {
if (
! is_array( $mappings ) ||
! is_array( $group ) ||
! count( $mappings ) ||
! count( $group )
) {
return;
}
$mainOptions = aioseo()->options->noConflict();
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
foreach ( $mappings as $name => $values ) {
if ( ! isset( $group[ $name ] ) ) {
continue;
}
$error = false;
$options = ! empty( $values['dynamic'] ) ? $dynamicOptions : $mainOptions;
$lastOption = '';
for ( $i = 0; $i < count( $values['newOption'] ); $i++ ) {
$lastOption = $values['newOption'][ $i ];
if ( ! $options->has( $lastOption, false ) ) {
$error = true;
break;
}
if ( count( $values['newOption'] ) - 1 !== $i ) {
$options = $options->$lastOption;
}
}
if ( $error ) {
continue;
}
switch ( $values['type'] ) {
case 'boolean':
if ( ! empty( $group[ $name ] ) ) {
$options->$lastOption = true;
break;
}
$options->$lastOption = false;
break;
case 'integer':
case 'float':
$value = aioseo()->helpers->sanitizeOption( $group[ $name ] );
if ( $value ) {
$options->$lastOption = $value;
}
break;
default:
$value = $group[ $name ];
if ( $convertMacros ) {
$value = $this->macrosToSmartTags( $value );
}
$options->$lastOption = aioseo()->helpers->sanitizeOption( $value );
break;
}
}
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\ImportExport;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Imports the settings and meta data from other plugins.
*
* @since 4.0.0
*/
abstract class Importer {
/**
* Imports the settings.
*
* @since 4.2.7
*
* @return void
*/
protected function importSettings() {}
/**
* Imports the post meta.
*
* @since 4.2.7
*
* @return void
*/
protected function importPostMeta() {}
/**
* Imports the term meta.
*
* @since 4.2.7
*
* @return void
*/
protected function importTermMeta() {}
/**
* PostMeta class instance.
*
* @since 4.2.7
*
* @var Object
*/
protected $postMeta = null;
/**
* TermMeta class instance.
*
* @since 4.2.7
*
* @var Object
*/
protected $termMeta = null;
/**
* Helpers class instance.
*
* @since 4.2.7
*
* @var Object
*/
public $helpers = null;
/**
* Starts the import.
*
* @since 4.0.0
*
* @param array $options What the user wants to import.
* @return void
*/
public function doImport( $options = [] ) {
if ( empty( $options ) ) {
$this->importSettings();
$this->importPostMeta();
$this->importTermMeta();
return;
}
foreach ( $options as $optionName ) {
switch ( $optionName ) {
case 'settings':
$this->importSettings();
break;
case 'postMeta':
$this->postMeta->scheduleImport();
break;
default:
break;
}
}
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Migrates the General Settings.
*
* @since 4.0.0
*/
class GeneralSettings {
/**
* List of options.
*
* @since 4.2.7
*
* @var array
*/
private $options = [];
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->options = get_option( 'rank-math-options-general' );
if ( empty( $this->options ) ) {
return;
}
$this->isTruSeoDisabled();
$this->migrateRedirectAttachments();
$this->migrateStripCategoryBase();
$this->migrateRssContentSettings();
$settings = [
'google_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'google' ] ],
'bing_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'bing' ] ],
'yandex_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'yandex' ] ],
'baidu_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'baidu' ] ],
'pinterest_verify' => [ 'type' => 'string', 'newOption' => [ 'webmasterTools', 'pinterest' ] ],
];
aioseo()->importExport->rankMath->helpers->mapOldToNew( $settings, $this->options );
}
/**
* Checks whether TruSEO should be disabled.
*
* @since 4.0.0
*
* @return void
*/
private function isTruSeoDisabled() {
if ( ! empty( $this->options['frontend_seo_score'] ) ) {
aioseo()->options->advanced->truSeo = 'on' === $this->options['frontend_seo_score'];
}
}
/**
* Migrates the Redirect Attachments setting.
*
* @since 4.0.0
*
* @return void
*/
private function migrateRedirectAttachments() {
if ( isset( $this->options['attachment_redirect_urls'] ) ) {
if ( 'on' === $this->options['attachment_redirect_urls'] ) {
aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'attachment_parent';
} else {
aioseo()->dynamicOptions->searchAppearance->postTypes->attachment->redirectAttachmentUrls = 'disabled';
}
}
}
/**
* Migrates the Strip Category Base setting.
*
* @since 4.2.0
*
* @return void
*/
private function migrateStripCategoryBase() {
if ( isset( $this->options['strip_category_base'] ) ) {
aioseo()->options->searchAppearance->advanced->removeCatBase = 'on' === $this->options['strip_category_base'] ? true : false;
}
}
/**
* Migrates the RSS content settings.
*
* @since 4.0.0
*
* @return void
*/
private function migrateRssContentSettings() {
if ( isset( $this->options['rss_before_content'] ) ) {
aioseo()->options->rssContent->before = esc_html( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['rss_before_content'] ) );
}
if ( isset( $this->options['rss_after_content'] ) ) {
aioseo()->options->rssContent->after = esc_html( aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $this->options['rss_after_content'] ) );
}
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\ImportExport;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Contains helper methods for the import from Rank Math.
*
* @since 4.0.0
*/
class Helpers extends ImportExport\Helpers {
/**
* Converts the macros from Rank Math to our own smart tags.
*
* @since 4.0.0
*
* @param string $string The string with macros.
* @param string $pageType The page type.
* @return string $string The string with smart tags.
*/
public function macrosToSmartTags( $string, $pageType = null ) {
$macros = $this->getMacros( $pageType );
if ( preg_match( '#%BLOGDESCLINK%#', $string ) ) {
$blogDescriptionLink = '<a href="' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'url' ) ) . '">' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'name' ) ) . ' - ' .
aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'description' ) ) . '</a>';
$string = str_replace( '%BLOGDESCLINK%', $blogDescriptionLink, $string );
}
if ( preg_match_all( '#%customfield\(([^%\s]*)\)%#', $string, $matches ) && ! empty( $matches[1] ) ) {
foreach ( $matches[1] as $name ) {
$string = aioseo()->helpers->pregReplace( "#%customfield\($name\)%#", "#custom_field-$name", $string );
}
}
if ( preg_match_all( '#%customterm\(([^%\s]*)\)%#', $string, $matches ) && ! empty( $matches[1] ) ) {
foreach ( $matches[1] as $name ) {
$string = aioseo()->helpers->pregReplace( "#%customterm\($name\)%#", "#tax_name-$name", $string );
}
}
foreach ( $macros as $macro => $tag ) {
$string = aioseo()->helpers->pregReplace( "#$macro(?![a-zA-Z0-9_])#im", $tag, $string );
}
// Strip out all remaining tags.
$string = aioseo()->helpers->pregReplace( '/%[^\%\s]*\([^\%]*\)%/i', '', aioseo()->helpers->pregReplace( '/%[^\%\s]*%/i', '', $string ) );
return trim( $string );
}
/**
* Returns the macro mappings.
*
* @since 4.1.1
*
* @param string $pageType The page type.
* @return array $macros The macros.
*/
protected function getMacros( $pageType = null ) {
$macros = [
'%sitename%' => '#site_title',
'%blog_title%' => '#site_title',
'%blog_description%' => '#tagline',
'%sitedesc%' => '#tagline',
'%sep%' => '#separator_sa',
'%post_title%' => '#post_title',
'%page_title%' => '#post_title',
'%postname%' => '#post_title',
'%title%' => '#post_title',
'%seo_title%' => '#post_title',
'%excerpt%' => '#post_excerpt',
'%wc_shortdesc%' => '#post_excerpt',
'%category%' => '#taxonomy_title',
'%term%' => '#taxonomy_title',
'%term_description%' => '#taxonomy_description',
'%currentdate%' => '#current_date',
'%currentday%' => '#current_day',
'%currentmonth%' => '#current_month',
'%name%' => '#author_first_name #author_last_name',
'%author%' => '#author_first_name #author_last_name',
'%date%' => '#post_date',
'%year%' => '#current_year',
'%search_query%' => '#search_term',
'%AUTHORLINK%' => '#author_link',
'%POSTLINK%' => '#post_link',
'%BLOGLINK%' => '#site_link',
/* '%seo_description%' => '',
'%user_description%' => '',
'%wc_price%' => '',
'%page%' => '',
'%FEATUREDIMAGE%' => '',
'%filename%' => '',*/
];
switch ( $pageType ) {
case 'archive':
$macros['%title%'] = '#archive_title';
break;
case 'term':
$macros['%title%'] = '#taxonomy_title';
break;
default:
$macros['%title%'] = '#post_title';
break;
}
// Strip all other tags.
$macros['%[^%]*%'] = '';
return $macros;
}
}
\ No newline at end of file
<?php
namespace AIOSEO\Plugin\Common\ImportExport\RankMath;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
// phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
/**
* Imports the post meta from Rank Math.
*
* @since 4.0.0
*/
class PostMeta {
/**
* Schedules the post meta import.
*
* @since 4.0.0
*
* @return void
*/
public function scheduleImport() {
try {
if ( as_next_scheduled_action( aioseo()->importExport->rankMath->postActionName ) ) {
return;
}
if ( ! aioseo()->core->cache->get( 'import_post_meta_rank_math' ) ) {
aioseo()->core->cache->update( 'import_post_meta_rank_math', time(), WEEK_IN_SECONDS );
}
as_schedule_single_action( time(), aioseo()->importExport->rankMath->postActionName, [], 'aioseo' );
} catch ( \Exception $e ) {
// Do nothing.
}
}
/**
* Imports the post meta.
*
* @since 4.0.0
*
* @return void
*/
public function importPostMeta() {
$postsPerAction = 100;
$publicPostTypes = implode( "', '", aioseo()->helpers->getPublicPostTypes( true ) );
$timeStarted = gmdate( 'Y-m-d H:i:s', aioseo()->core->cache->get( 'import_post_meta_rank_math' ) );
$posts = aioseo()->core->db
->start( 'posts' . ' as p' )
->select( 'p.ID, p.post_type' )
->join( 'postmeta as pm', '`p`.`ID` = `pm`.`post_id`' )
->leftJoin( 'aioseo_posts as ap', '`p`.`ID` = `ap`.`post_id`' )
->whereRaw( "pm.meta_key LIKE 'rank_math_%'" )
->whereRaw( "( p.post_type IN ( '$publicPostTypes' ) )" )
->whereRaw( "( ap.post_id IS NULL OR ap.updated < '$timeStarted' )" )
->orderBy( 'p.ID DESC' )
->groupBy( 'p.ID' )
->limit( $postsPerAction )
->run()
->result();
if ( ! $posts || ! count( $posts ) ) {
aioseo()->core->cache->delete( 'import_post_meta_rank_math' );
return;
}
$mappedMeta = [
'rank_math_title' => 'title',
'rank_math_description' => 'description',
'rank_math_canonical_url' => 'canonical_url',
'rank_math_focus_keyword' => 'keyphrases',
'rank_math_robots' => '',
'rank_math_advanced_robots' => '',
'rank_math_facebook_title' => 'og_title',
'rank_math_facebook_description' => 'og_description',
'rank_math_facebook_image' => 'og_image_custom_url',
'rank_math_twitter_use_facebook' => 'twitter_use_og',
'rank_math_twitter_title' => 'twitter_title',
'rank_math_twitter_description' => 'twitter_description',
'rank_math_twitter_image' => 'twitter_image_custom_url',
'rank_math_twitter_card_type' => 'twitter_card'
];
foreach ( $posts as $post ) {
$postMeta = aioseo()->core->db
->start( 'postmeta' . ' as pm' )
->select( 'pm.meta_key, pm.meta_value' )
->where( 'pm.post_id', $post->ID )
->whereRaw( "`pm`.`meta_key` LIKE 'rank_math_%'" )
->run()
->result();
$meta = [
'post_id' => $post->ID,
];
if ( ! $postMeta || ! count( $postMeta ) ) {
$aioseoPost = Models\Post::getPost( (int) $post->ID );
$aioseoPost->set( $meta );
$aioseoPost->save();
aioseo()->migration->meta->migrateAdditionalPostMeta( $post->ID );
continue;
}
foreach ( $postMeta as $record ) {
$name = $record->meta_key;
$value = $record->meta_value;
if (
! in_array( $post->post_type, [ 'page', 'attachment' ], true ) &&
preg_match( '#^rank_math_schema_([^\s]*)$#', $name, $match ) && ! empty( $match[1] )
) {
switch ( $match[1] ) {
case 'Article':
case 'NewsArticle':
case 'BlogPosting':
$meta['schema_type'] = 'Article';
$meta['schema_type_options'] = wp_json_encode(
[ 'article' => [ 'articleType' => $match[1] ] ]
);
break;
default:
break;
}
}
if ( ! in_array( $name, array_keys( $mappedMeta ), true ) ) {
continue;
}
switch ( $name ) {
case 'rank_math_focus_keyword':
$keyphrases = array_map( 'trim', explode( ',', $value ) );
$keyphraseArray = [
'focus' => [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $keyphrases[0] ) ],
'additional' => []
];
unset( $keyphrases[0] );
foreach ( $keyphrases as $keyphrase ) {
$keyphraseArray['additional'][] = [ 'keyphrase' => aioseo()->helpers->sanitizeOption( $keyphrase ) ];
}
$meta['keyphrases'] = wp_json_encode( $keyphraseArray );
break;
case 'rank_math_robots':
$value = aioseo()->helpers->maybeUnserialize( $value );
if ( ! empty( $value ) ) {
$meta['robots_default'] = false;
foreach ( $value as $robotsName ) {
$meta[ "robots_$robotsName" ] = true;
}
}
break;
case 'rank_math_advanced_robots':
$value = aioseo()->helpers->maybeUnserialize( $value );
if ( ! empty( $value['max-snippet'] ) && intval( $value['max-snippet'] ) ) {
$meta['robots_max_snippet'] = intval( $value['max-snippet'] );
}
if ( ! empty( $value['max-video-preview'] ) && intval( $value['max-video-preview'] ) ) {
$meta['robots_max_videopreview'] = intval( $value['max-video-preview'] );
}
if ( ! empty( $value['max-image-preview'] ) ) {
$meta['robots_max_imagepreview'] = aioseo()->helpers->sanitizeOption( lcfirst( $value['max-image-preview'] ) );
}
break;
case 'rank_math_facebook_image':
$meta['og_image_type'] = 'custom_image';
$meta[ $mappedMeta[ $name ] ] = esc_url( $value );
break;
case 'rank_math_twitter_image':
$meta['twitter_image_type'] = 'custom_image';
$meta[ $mappedMeta[ $name ] ] = esc_url( $value );
break;
case 'rank_math_twitter_card_type':
preg_match( '#large#', $value, $match );
$meta[ $mappedMeta[ $name ] ] = ! empty( $match ) ? 'summary_large_image' : 'summary';
break;
case 'rank_math_twitter_use_facebook':
$meta[ $mappedMeta[ $name ] ] = 'on' === $value;
break;
case 'rank_math_title':
case 'rank_math_description':
if ( 'page' === $post->post_type ) {
$value = aioseo()->helpers->pregReplace( '#%category%#', '', $value );
$value = aioseo()->helpers->pregReplace( '#%excerpt%#', '', $value );
}
$value = aioseo()->importExport->rankMath->helpers->macrosToSmartTags( $value );
default:
$meta[ $mappedMeta[ $name ] ] = esc_html( wp_strip_all_tags( strval( $value ) ) );
break;
}
}
$aioseoPost = Models\Post::getPost( $post->ID );
$aioseoPost->set( $meta );
$aioseoPost->save();
aioseo()->migration->meta->migrateAdditionalPostMeta( $post->ID );
}
if ( count( $posts ) === $postsPerAction ) {
try {
as_schedule_single_action( time() + 5, aioseo()->importExport->rankMath->postActionName, [], 'aioseo' );
} catch ( \Exception $e ) {
// Do nothing.
}
} else {
aioseo()->core->cache->delete( 'import_post_meta_rank_math' );
}
}
}
\ No newline at end of file
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.