Initial commit: Atomaste website
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,186 @@
|
||||
<?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 {
|
||||
/**
|
||||
* A list of conflicting plugin slugs.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $conflictingPluginSlugs = [
|
||||
// Note: We should NOT add Jetpack here since they automatically disable their SEO module when ours is active.
|
||||
'wordpress-seo',
|
||||
'seo-by-rank-math',
|
||||
'wp-seopress',
|
||||
'autodescription',
|
||||
'slim-seo',
|
||||
'squirrly-seo',
|
||||
'google-sitemap-generator',
|
||||
'xml-sitemap-feed',
|
||||
'www-xml-sitemap-generator-org',
|
||||
'google-sitemap-plugin',
|
||||
];
|
||||
|
||||
/**
|
||||
* 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' ], 20 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public 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 = wp_get_active_and_valid_plugins();
|
||||
if ( is_multisite() ) {
|
||||
$activePlugins = array_merge( $activePlugins, wp_get_active_network_plugins() );
|
||||
}
|
||||
|
||||
$conflictingPlugins = [];
|
||||
switch ( $type ) {
|
||||
// Note: We should NOT add Jetpack here since they automatically disable their SEO module when ours is active.
|
||||
case 'seo':
|
||||
$conflictingPlugins = [
|
||||
'Rank Math SEO' => 'seo-by-rank-math/rank-math.php',
|
||||
'Rank Math SEO Pro' => 'seo-by-rank-math-pro/rank-math-pro.php',
|
||||
'SEOPress' => 'wp-seopress/seopress.php',
|
||||
'The SEO Framework' => 'autodescription/autodescription.php',
|
||||
'Yoast SEO' => 'wordpress-seo/wp-seo.php',
|
||||
'Yoast SEO Premium' => 'wordpress-seo-premium/wp-seo-premium.php'
|
||||
];
|
||||
break;
|
||||
case 'sitemap':
|
||||
$conflictingPlugins = [
|
||||
'Google XML Sitemaps' => 'google-sitemap-generator/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',
|
||||
'XML Sitemap & Google News' => 'xml-sitemap-feed/xml-sitemap.php'
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
$activeConflictingPlugins = [];
|
||||
foreach ( $activePlugins as $pluginFilePath ) {
|
||||
foreach ( $conflictingPlugins as $index => $pluginPath ) {
|
||||
if ( false !== strpos( $pluginFilePath, $pluginPath ) ) {
|
||||
$activeConflictingPlugins[ $index ] = $pluginPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $activeConflictingPlugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate conflicting plugins.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @param array $types An array of types to look for.
|
||||
* @return void
|
||||
*/
|
||||
public function deactivateConflictingPlugins( $types ) {
|
||||
$seo = in_array( 'seo', $types, true ) ? $this->getConflictingPlugins( 'seo' ) : [];
|
||||
$sitemap = in_array( 'sitemap', $types, true ) ? $this->getConflictingPlugins( 'sitemap' ) : [];
|
||||
$plugins = array_merge(
|
||||
$seo,
|
||||
$sitemap
|
||||
);
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
|
||||
foreach ( $plugins as $pluginPath ) {
|
||||
if ( is_plugin_active( $pluginPath ) ) {
|
||||
deactivate_plugins( $pluginPath );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of conflicting plugin slugs.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @return array An array of conflicting plugin slugs.
|
||||
*/
|
||||
public function getConflictingPluginSlugs() {
|
||||
return $this->conflictingPluginSlugs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?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' ) ) &&
|
||||
aioseo()->options->advanced->truSeo
|
||||
) {
|
||||
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 = aioseo()->helpers->getCurrentScreen();
|
||||
if ( empty( $currentScreen->id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$rssItems = aioseo()->helpers->fetchAioseoArticles();
|
||||
if ( ! $rssItems ) {
|
||||
esc_html_e( 'Temporarily unable to load feed.', 'all-in-one-seo-pack' );
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<ul>
|
||||
<?php
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
<?php
|
||||
namespace AIOSEO\Plugin\Common\Admin;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivation survey.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*/
|
||||
class DeactivationSurvey {
|
||||
/**
|
||||
* The API URL we are calling.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $apiUrl = 'https://plugin.aioseo.com/wp-json/am-deactivate-survey/v1/deactivation-data';
|
||||
|
||||
/**
|
||||
* Name for this plugin.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Unique slug for this plugin.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plugin;
|
||||
|
||||
/**
|
||||
* Primary class constructor.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @param string $name Plugin name.
|
||||
* @param string $plugin Plugin slug.
|
||||
*/
|
||||
public function __construct( $name = '', $plugin = '' ) {
|
||||
$this->name = $name;
|
||||
$this->plugin = $plugin;
|
||||
|
||||
// Don't run deactivation survey on dev sites.
|
||||
if ( aioseo()->helpers->isDev() ) {
|
||||
// return;
|
||||
}
|
||||
|
||||
add_action( 'admin_print_scripts', [ $this, 'js' ], 20 );
|
||||
add_action( 'admin_print_scripts', [ $this, 'css' ] );
|
||||
add_action( 'admin_footer', [ $this, 'modal' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL of the remote endpoint.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @return string The URL.
|
||||
*/
|
||||
public function getApiUrl() {
|
||||
if ( defined( 'AIOSEO_DEACTIVATION_SURVEY_URL' ) ) {
|
||||
return AIOSEO_DEACTIVATION_SURVEY_URL;
|
||||
}
|
||||
|
||||
return $this->apiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current admin screen is the plugins page.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @return bool True if it is, false if not.
|
||||
*/
|
||||
public function isPluginPage() {
|
||||
$screen = aioseo()->helpers->getCurrentScreen();
|
||||
if ( empty( $screen->id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array( $screen->id, [ 'plugins', 'plugins-network' ], true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Survey javascript.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function js() {
|
||||
if ( ! $this->isPluginPage() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
window.addEventListener("load", function() {
|
||||
var deactivateLink = document.querySelector('#the-list [data-slug="<?php echo esc_html( $this->plugin ); ?>"] span.deactivate a') ||
|
||||
document.querySelector('#deactivate-<?php echo esc_html( $this->plugin ); ?>'),
|
||||
overlay = document.querySelector('#am-deactivate-survey-<?php echo esc_html( $this->plugin ); ?>'),
|
||||
form = overlay.querySelector('form'),
|
||||
formOpen = false;
|
||||
|
||||
deactivateLink.addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
overlay.style.display = 'table';
|
||||
formOpen = true;
|
||||
form.querySelector('.am-deactivate-survey-option:first-of-type input[type=radio]').focus();
|
||||
});
|
||||
|
||||
form.addEventListener('change', function(event) {
|
||||
if (event.target.matches('input[type=radio]')) {
|
||||
event.preventDefault();
|
||||
Array.from(form.querySelectorAll('input[type=text], .error')).forEach(function(el) { el.style.display = 'none'; });
|
||||
Array.from(form.querySelectorAll('.am-deactivate-survey-option')).forEach(function(el) { el.classList.remove('selected'); });
|
||||
var option = event.target.closest('.am-deactivate-survey-option');
|
||||
option.classList.add('selected');
|
||||
|
||||
var otherField = option.querySelector('input[type=text]');
|
||||
if (otherField) {
|
||||
otherField.style.display = 'block';
|
||||
otherField.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener('click', function(event) {
|
||||
if (event.target.matches('.am-deactivate-survey-deactivate')) {
|
||||
event.preventDefault();
|
||||
window.location.href = deactivateLink.getAttribute('href');
|
||||
}
|
||||
});
|
||||
|
||||
form.addEventListener('submit', function(event) {
|
||||
event.preventDefault();
|
||||
if (!form.querySelector('input[type=radio]:checked')) {
|
||||
if(!form.querySelector('span[class="error"]')) {
|
||||
form.querySelector('.am-deactivate-survey-footer')
|
||||
.insertAdjacentHTML('afterbegin', '<span class="error"><?php echo esc_js( __( 'Please select an option', 'all-in-one-seo-pack' ) ); ?></span>');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var selected = form.querySelector('.selected');
|
||||
var otherField = selected.querySelector('input[type=text]');
|
||||
var data = {
|
||||
code: selected.querySelector('input[type=radio]').value,
|
||||
reason: selected.querySelector('.am-deactivate-survey-option-reason').textContent,
|
||||
details: otherField ? otherField.value : '',
|
||||
site: '<?php echo esc_url( home_url() ); ?>',
|
||||
plugin: '<?php echo esc_html( $this->plugin ); ?>'
|
||||
}
|
||||
|
||||
var submitSurvey = fetch('<?php echo esc_url( $this->getApiUrl() ); ?>', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
|
||||
submitSurvey.finally(function() {
|
||||
window.location.href = deactivateLink.getAttribute('href');
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('keyup', function(event) {
|
||||
if (27 === event.keyCode && formOpen) {
|
||||
overlay.style.display = 'none';
|
||||
formOpen = false;
|
||||
deactivateLink.focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Survey CSS.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function css() {
|
||||
if ( ! $this->isPluginPage() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
||||
<style type="text/css">
|
||||
.am-deactivate-survey-modal {
|
||||
display: none;
|
||||
table-layout: fixed;
|
||||
position: fixed;
|
||||
z-index: 9999;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background: rgba(0,0,0,0.8);
|
||||
}
|
||||
.am-deactivate-survey-wrap {
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.am-deactivate-survey {
|
||||
background-color: #fff;
|
||||
max-width: 550px;
|
||||
margin: 0 auto;
|
||||
padding: 30px;
|
||||
text-align: left;
|
||||
}
|
||||
.am-deactivate-survey .error {
|
||||
display: block;
|
||||
color: red;
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
.am-deactivate-survey-title {
|
||||
display: block;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding: 0 0 18px 0;
|
||||
margin: 0 0 18px 0;
|
||||
}
|
||||
.am-deactivate-survey-title span {
|
||||
color: #999;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.am-deactivate-survey-desc {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
margin: 0 0 18px 0;
|
||||
}
|
||||
.am-deactivate-survey-option {
|
||||
margin: 0 0 10px 0;
|
||||
}
|
||||
.am-deactivate-survey-option-input {
|
||||
margin-right: 10px !important;
|
||||
}
|
||||
.am-deactivate-survey-option-details {
|
||||
display: none;
|
||||
width: 90%;
|
||||
margin: 10px 0 0 30px;
|
||||
}
|
||||
.am-deactivate-survey-footer {
|
||||
margin-top: 18px;
|
||||
}
|
||||
.am-deactivate-survey-deactivate {
|
||||
float: right;
|
||||
font-size: 13px;
|
||||
color: #ccc;
|
||||
text-decoration: none;
|
||||
padding-top: 7px;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Survey modal.
|
||||
*
|
||||
* @since 4.5.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function modal() {
|
||||
if ( ! $this->isPluginPage() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$options = [
|
||||
1 => [
|
||||
'title' => esc_html__( 'I no longer need the plugin', 'all-in-one-seo-pack' ),
|
||||
],
|
||||
2 => [
|
||||
'title' => esc_html__( 'I\'m switching to a different plugin', 'all-in-one-seo-pack' ),
|
||||
'details' => esc_html__( 'Please share which plugin', 'all-in-one-seo-pack' ),
|
||||
],
|
||||
3 => [
|
||||
'title' => esc_html__( 'I couldn\'t get the plugin to work', 'all-in-one-seo-pack' ),
|
||||
],
|
||||
4 => [
|
||||
'title' => esc_html__( 'It\'s a temporary deactivation', 'all-in-one-seo-pack' ),
|
||||
],
|
||||
5 => [
|
||||
'title' => esc_html__( 'Other', 'all-in-one-seo-pack' ),
|
||||
'details' => esc_html__( 'Please share the reason', 'all-in-one-seo-pack' ),
|
||||
],
|
||||
];
|
||||
?>
|
||||
|
||||
<div class="am-deactivate-survey-modal" id="am-deactivate-survey-<?php echo esc_html( $this->plugin ); ?>">
|
||||
<div class="am-deactivate-survey-wrap">
|
||||
<form class="am-deactivate-survey" method="post">
|
||||
<span class="am-deactivate-survey-title"><span class="dashicons dashicons-testimonial"></span><?php echo ' ' . esc_html__( 'Quick Feedback', 'all-in-one-seo-pack' ); ?></span>
|
||||
<span class="am-deactivate-survey-desc">
|
||||
<?php
|
||||
echo esc_html(
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin name.
|
||||
__( 'If you have a moment, please share why you are deactivating %1$s:', 'all-in-one-seo-pack' ),
|
||||
$this->name
|
||||
)
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
<div class="am-deactivate-survey-options">
|
||||
<?php foreach ( $options as $id => $option ) : ?>
|
||||
<div class="am-deactivate-survey-option">
|
||||
<label for="am-deactivate-survey-option-<?php echo esc_html( $this->plugin ); ?>-<?php echo intval( $id ); ?>" class="am-deactivate-survey-option-label">
|
||||
<input
|
||||
id="am-deactivate-survey-option-<?php echo esc_html( $this->plugin ); ?>-<?php echo intval( $id ); ?>"
|
||||
class="am-deactivate-survey-option-input"
|
||||
type="radio"
|
||||
name="code"
|
||||
value="<?php echo intval( $id ); ?>"
|
||||
/>
|
||||
<span class="am-deactivate-survey-option-reason"><?php echo esc_html( $option['title'] ); ?></span>
|
||||
</label>
|
||||
<?php if ( ! empty( $option['details'] ) ) : ?>
|
||||
<input class="am-deactivate-survey-option-details" type="text" placeholder="<?php echo esc_html( $option['details'] ); ?>" />
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="am-deactivate-survey-footer">
|
||||
<button type="submit" class="am-deactivate-survey-submit button button-primary button-large">
|
||||
<?php
|
||||
echo sprintf(
|
||||
// Translators: 1 - & symbol.
|
||||
esc_html__( 'Submit %1$s Deactivate', 'all-in-one-seo-pack' ),
|
||||
'&'
|
||||
);
|
||||
?>
|
||||
</button>
|
||||
<a href="#" class="am-deactivate-survey-deactivate">
|
||||
<?php
|
||||
echo sprintf(
|
||||
// Translators: 1 - & symbol.
|
||||
esc_html__( 'Skip %1$s Deactivate', 'all-in-one-seo-pack' ),
|
||||
'&'
|
||||
);
|
||||
?>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?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' ] );
|
||||
|
||||
add_action( 'init', [ $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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
namespace AIOSEO\Plugin\Common\Admin\Notices;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the Conflicting Plugins notice..
|
||||
*
|
||||
* @since 4.5.1
|
||||
*/
|
||||
class ConflictingPlugins {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_aioseo-dismiss-conflicting-plugins-notice', [ $this, 'dismissNotice' ] );
|
||||
add_action( 'wp_ajax_aioseo-deactivate-conflicting-plugins-notice', [ $this, 'deactivateConflictingPlugins' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Go through all the checks to see if we should show the notice.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybeShowNotice() {
|
||||
$dismissed = get_option( '_aioseo_conflicting_plugins_dismissed', true );
|
||||
if ( '1' === $dismissed ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'activate_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only show if there are conflicting plugins.
|
||||
$conflictingPlugins = aioseo()->conflictingPlugins->getAllConflictingPlugins();
|
||||
if ( empty( $conflictingPlugins ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->showNotice();
|
||||
|
||||
// Print the script to the footer.
|
||||
add_action( 'admin_footer', [ $this, 'printScript' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the notice.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function showNotice() {
|
||||
$type = ! empty( aioseo()->conflictingPlugins->getConflictingPlugins( 'seo' ) ) ? 'SEO' : 'sitemap';
|
||||
?>
|
||||
<div class="notice notice-error aioseo-conflicting-plugin-notice is-dismissible">
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses(
|
||||
sprintf(
|
||||
// phpcs:ignore Generic.Files.LineLength.MaxExceeded
|
||||
// Translators: 1 - Type of conflicting plugin (i.e. SEO or Sitemap), 2 - Opening HTML link tag, 3 - Closing HTML link tag.
|
||||
__( 'Please keep only one %1$s plugin active, otherwise, you might lose your rankings and traffic. %2$sClick here to Deactivate.%3$s', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
|
||||
$type,
|
||||
'<a href="#" rel="noopener noreferrer" class="deactivate-conflicting-plugins">',
|
||||
'</a>'
|
||||
),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'class' => []
|
||||
],
|
||||
'strong' => [],
|
||||
]
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#conflicting_seo_plugins.rank-math-notice {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the script for dismissing the notice.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printScript() {
|
||||
// Create a nonce.
|
||||
$nonce1 = wp_create_nonce( 'aioseo-dismiss-conflicting-plugins' );
|
||||
$nonce2 = wp_create_nonce( 'aioseo-deactivate-conflicting-plugins' );
|
||||
?>
|
||||
<script>
|
||||
window.addEventListener('load', function () {
|
||||
var dismissBtn,
|
||||
deactivateBtn
|
||||
|
||||
// Add an event listener to the dismiss button.
|
||||
dismissBtn = document.querySelector('.aioseo-conflicting-plugin-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-conflicting-plugins-notice'
|
||||
postData += '&nonce=<?php echo esc_html( $nonce1 ); ?>'
|
||||
|
||||
httpRequest.open('POST', '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>')
|
||||
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
|
||||
httpRequest.send(postData)
|
||||
})
|
||||
|
||||
deactivateBtn = document.querySelector('.aioseo-conflicting-plugin-notice .deactivate-conflicting-plugins')
|
||||
deactivateBtn.addEventListener('click', function (event) {
|
||||
event.preventDefault()
|
||||
|
||||
var httpRequest = new XMLHttpRequest(),
|
||||
postData = ''
|
||||
|
||||
// Build the data to send in our request.
|
||||
postData += '&action=aioseo-deactivate-conflicting-plugins-notice'
|
||||
postData += '&nonce=<?php echo esc_html( $nonce2 ); ?>'
|
||||
|
||||
httpRequest.open('POST', '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>')
|
||||
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
|
||||
httpRequest.onerror = function () {
|
||||
window.location.reload()
|
||||
}
|
||||
httpRequest.onload = function () {
|
||||
window.location.reload()
|
||||
}
|
||||
httpRequest.send(postData)
|
||||
})
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss the notice.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @return string The successful response.
|
||||
*/
|
||||
public function dismissNotice() {
|
||||
// Early exit if we're not on a aioseo-dismiss-conflicting-plugins-notice action.
|
||||
if ( ! isset( $_POST['action'] ) || 'aioseo-dismiss-conflicting-plugins-notice' !== $_POST['action'] ) {
|
||||
return wp_send_json_error( 'invalid-action' );
|
||||
}
|
||||
|
||||
check_ajax_referer( 'aioseo-dismiss-conflicting-plugins', 'nonce' );
|
||||
|
||||
update_option( '_aioseo_conflicting_plugins_dismissed', true );
|
||||
|
||||
return wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivates the conflicting plugins.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @return string The successful response.
|
||||
*/
|
||||
public function deactivateConflictingPlugins() {
|
||||
// Early exit if we're not on a aioseo-dismiss-conflicting-plugins-notice action.
|
||||
if ( ! isset( $_POST['action'] ) || 'aioseo-deactivate-conflicting-plugins-notice' !== $_POST['action'] ) {
|
||||
return wp_send_json_error( 'invalid-action' );
|
||||
}
|
||||
|
||||
check_ajax_referer( 'aioseo-deactivate-conflicting-plugins', 'nonce' );
|
||||
|
||||
aioseo()->conflictingPlugins->deactivateConflictingPlugins( [ 'seo', 'sitemap' ] );
|
||||
|
||||
return wp_send_json_success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?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; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
|
||||
|
||||
$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', '>=' ) ) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName
|
||||
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(
|
||||
// phpcs:ignore Generic.Files.LineLength.MaxExceeded
|
||||
// Translators: 1 - Opening HTML bold tag, 2 - Closing HTML bold tag, 3 - The short plugin name ("AIOSEO"), 4 - The current year, 5 - Opening HTML link tag, 6 - 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',
|
||||
gmdate( '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'] ) ) { // phpcs:ignore HM.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Recommended
|
||||
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 string 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
$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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,607 @@
|
||||
<?php
|
||||
namespace AIOSEO\Plugin\Common\Admin\Notices;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use AIOSEO\Plugin\Common\Models;
|
||||
|
||||
/**
|
||||
* Abstract class that Pro and Lite both extend.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Notices {
|
||||
/**
|
||||
* Source of notifications content.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $url = 'https://plugin-cdn.aioseo.com/wp-content/notifications.json';
|
||||
|
||||
/**
|
||||
* Review class instance.
|
||||
*
|
||||
* @since 4.2.7
|
||||
*
|
||||
* @var Review
|
||||
*/
|
||||
private $review = null;
|
||||
|
||||
/**
|
||||
* Migration class instance.
|
||||
*
|
||||
* @since 4.2.7
|
||||
*
|
||||
* @var Migration
|
||||
*/
|
||||
private $migration = null;
|
||||
|
||||
/**
|
||||
* Import class instance.
|
||||
*
|
||||
* @since 4.2.7
|
||||
*
|
||||
* @var Import
|
||||
*/
|
||||
private $import = null;
|
||||
|
||||
/**
|
||||
* DeprecatedWordPress class instance.
|
||||
*
|
||||
* @since 4.2.7
|
||||
*
|
||||
* @var DeprecatedWordPress
|
||||
*/
|
||||
private $deprecatedWordPress = null;
|
||||
|
||||
/**
|
||||
* ConflictingPlugins class instance.
|
||||
*
|
||||
* @since 4.5.1
|
||||
*
|
||||
* @var ConflictingPlugins
|
||||
*/
|
||||
private $conflictingPlugins = null;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'aioseo_admin_notifications_update', [ $this, 'update' ] );
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'updated_option', [ $this, 'maybeResetBlogVisibility' ], 10, 3 );
|
||||
add_action( 'init', [ $this, 'init' ], 2 );
|
||||
|
||||
$this->review = new Review();
|
||||
$this->migration = new Migration();
|
||||
$this->import = new Import();
|
||||
$this->deprecatedWordPress = new DeprecatedWordPress();
|
||||
$this->conflictingPlugins = new ConflictingPlugins();
|
||||
|
||||
add_action( 'admin_notices', [ $this, 'notices' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize notifications.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
// If our tables do not exist, create them now.
|
||||
if ( ! aioseo()->core->db->tableExists( 'aioseo_notifications' ) ) {
|
||||
aioseo()->updates->addInitialCustomTablesForV4();
|
||||
}
|
||||
|
||||
$this->maybeUpdate();
|
||||
$this->initInternalNotices();
|
||||
$this->deleteInternalNotices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we should update our notifications.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function maybeUpdate() {
|
||||
$nextRun = aioseo()->core->networkCache->get( 'admin_notifications_update' );
|
||||
if ( null !== $nextRun && time() < $nextRun ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Schedule the action.
|
||||
aioseo()->actionScheduler->scheduleAsync( 'aioseo_admin_notifications_update' );
|
||||
|
||||
// Update the cache.
|
||||
aioseo()->core->networkCache->update( 'admin_notifications_update', time() + DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Notifications from the server.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update() {
|
||||
$notifications = $this->fetch();
|
||||
foreach ( $notifications as $notification ) {
|
||||
// First, let's check to see if this notification already exists. If so, we want to override it.
|
||||
$n = aioseo()->core->db
|
||||
->start( 'aioseo_notifications' )
|
||||
->where( 'notification_id', $notification->id )
|
||||
->run()
|
||||
->model( 'AIOSEO\\Plugin\\Common\\Models\\Notification' );
|
||||
|
||||
$buttons = [
|
||||
'button1' => [
|
||||
'label' => ! empty( $notification->btns->main->text ) ? $notification->btns->main->text : null,
|
||||
'url' => ! empty( $notification->btns->main->url ) ? $notification->btns->main->url : null
|
||||
],
|
||||
'button2' => [
|
||||
'label' => ! empty( $notification->btns->alt->text ) ? $notification->btns->alt->text : null,
|
||||
'url' => ! empty( $notification->btns->alt->url ) ? $notification->btns->alt->url : null
|
||||
]
|
||||
];
|
||||
|
||||
if ( $n->exists() ) {
|
||||
$n->title = $notification->title;
|
||||
$n->content = $notification->content;
|
||||
$n->type = ! empty( $notification->notification_type ) ? $notification->notification_type : 'info';
|
||||
$n->level = $notification->type;
|
||||
$n->notification_id = $notification->id;
|
||||
$n->start = ! empty( $notification->start ) ? $notification->start : null;
|
||||
$n->end = ! empty( $notification->end ) ? $notification->end : null;
|
||||
$n->button1_label = $buttons['button1']['label'];
|
||||
$n->button1_action = $buttons['button1']['url'];
|
||||
$n->button2_label = $buttons['button2']['label'];
|
||||
$n->button2_action = $buttons['button2']['url'];
|
||||
$n->save();
|
||||
continue;
|
||||
}
|
||||
|
||||
$n = new Models\Notification();
|
||||
$n->slug = uniqid();
|
||||
$n->title = $notification->title;
|
||||
$n->content = $notification->content;
|
||||
$n->type = ! empty( $notification->notification_type ) ? $notification->notification_type : 'info';
|
||||
$n->level = $notification->type;
|
||||
$n->notification_id = $notification->id;
|
||||
$n->start = ! empty( $notification->start ) ? $notification->start : null;
|
||||
$n->end = ! empty( $notification->end ) ? $notification->end : null;
|
||||
$n->button1_label = $buttons['button1']['label'];
|
||||
$n->button1_action = $buttons['button1']['url'];
|
||||
$n->button2_label = $buttons['button2']['label'];
|
||||
$n->button2_action = $buttons['button2']['url'];
|
||||
$n->dismissed = 0;
|
||||
$n->save();
|
||||
|
||||
// Since we've added a new remote notification, let's show the notification drawer.
|
||||
aioseo()->core->cache->update( 'show_notifications_drawer', true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the feed of notifications.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return array An array of notifications.
|
||||
*/
|
||||
private function fetch() {
|
||||
$response = aioseo()->helpers->wpRemoteGet( $this->getUrl() );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
|
||||
if ( empty( $body ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->verify( json_decode( $body ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify notification data before it is saved.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $notifications Array of notifications items to verify.
|
||||
* @return array An array of verified notifications.
|
||||
*/
|
||||
private function verify( $notifications ) {
|
||||
$data = [];
|
||||
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
foreach ( $notifications as $notification ) {
|
||||
// The message and license should never be empty, if they are, ignore.
|
||||
if ( empty( $notification->content ) || empty( $notification->type ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! is_array( $notification->type ) ) {
|
||||
$notification->type = [ $notification->type ];
|
||||
}
|
||||
foreach ( $notification->type as $type ) {
|
||||
// Ignore if type does not match.
|
||||
if ( ! $this->validateType( $type ) ) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore if expired.
|
||||
if ( ! empty( $notification->end ) && time() > strtotime( $notification->end ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if notification existed before installing AIOSEO.
|
||||
// Prevents bombarding the user with notifications after activation.
|
||||
$activated = aioseo()->internalOptions->internal->firstActivated( time() );
|
||||
if (
|
||||
! empty( $notification->start ) &&
|
||||
$activated > strtotime( $notification->start )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = $notification;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the notification type.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $type The notification type we are targeting.
|
||||
* @return boolean True if yes, false if no.
|
||||
*/
|
||||
public function validateType( $type ) {
|
||||
$validated = false;
|
||||
|
||||
if ( 'all' === $type ) {
|
||||
$validated = true;
|
||||
}
|
||||
|
||||
// Store notice if version matches.
|
||||
if ( $this->versionMatch( aioseo()->version, $type ) ) {
|
||||
$validated = true;
|
||||
}
|
||||
|
||||
return $validated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Version Compare.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $currentVersion The current version being used.
|
||||
* @param string|array $compareVersion The version to compare with.
|
||||
* @return bool True if we match, false if not.
|
||||
*/
|
||||
public function versionMatch( $currentVersion, $compareVersion ) {
|
||||
if ( is_array( $compareVersion ) ) {
|
||||
foreach ( $compareVersion as $compare_single ) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName
|
||||
$recursiveResult = $this->versionMatch( $currentVersion, $compare_single ); // phpcs:ignore Squiz.NamingConventions.ValidVariableName
|
||||
if ( $recursiveResult ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentParse = explode( '.', $currentVersion );
|
||||
if ( strpos( $compareVersion, '-' ) ) {
|
||||
$compareParse = explode( '-', $compareVersion );
|
||||
} elseif ( strpos( $compareVersion, '.' ) ) {
|
||||
$compareParse = explode( '.', $compareVersion );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentCount = count( $currentParse );
|
||||
$compareCount = count( $compareParse );
|
||||
for ( $i = 0; $i < $currentCount || $i < $compareCount; $i++ ) {
|
||||
if ( isset( $compareParse[ $i ] ) && 'x' === strtolower( $compareParse[ $i ] ) ) {
|
||||
unset( $compareParse[ $i ] );
|
||||
}
|
||||
|
||||
if ( ! isset( $currentParse[ $i ] ) ) {
|
||||
unset( $compareParse[ $i ] );
|
||||
} elseif ( ! isset( $compareParse[ $i ] ) ) {
|
||||
unset( $currentParse[ $i ] );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $compareParse as $index => $subNumber ) {
|
||||
if ( $currentParse[ $index ] !== $subNumber ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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_NOTIFICATIONS_URL' ) ) {
|
||||
return AIOSEO_NOTIFICATIONS_URL;
|
||||
}
|
||||
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add notices.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function notices() {
|
||||
// Double check we're actually in the admin before outputting anything.
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->review->maybeShowNotice();
|
||||
$this->migration->maybeShowNotice();
|
||||
$this->import->maybeShowNotice();
|
||||
$this->deprecatedWordPress->maybeShowNotice();
|
||||
$this->conflictingPlugins->maybeShowNotice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the internal notices.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initInternalNotices() {
|
||||
$this->blogVisibility();
|
||||
$this->descriptionFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes internal notices we no longer need.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function deleteInternalNotices() {
|
||||
$pluginData = aioseo()->helpers->getPluginData();
|
||||
if ( $pluginData['miPro']['installed'] || $pluginData['miLite']['installed'] ) {
|
||||
$notification = Models\Notification::getNotificationByName( 'install-mi' );
|
||||
if ( ! $notification->exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Models\Notification::deleteNotificationByName( 'install-mi' );
|
||||
}
|
||||
|
||||
if ( $pluginData['optinMonster']['installed'] ) {
|
||||
$notification = Models\Notification::getNotificationByName( 'install-om' );
|
||||
if ( ! $notification->exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Models\Notification::deleteNotificationByName( 'install-om' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends a notice by a (default) 1 week start date.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $notice The notice to extend.
|
||||
* @param string $start How long to extend.
|
||||
* @return void
|
||||
*/
|
||||
public function remindMeLater( $notice, $start = '+1 week' ) {
|
||||
$notification = Models\Notification::getNotificationByName( $notice );
|
||||
if ( ! $notification->exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification->start = gmdate( 'Y-m-d H:i:s', strtotime( $start ) );
|
||||
$notification->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a notice if the blog is set to hidden.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function blogVisibility() {
|
||||
$notification = Models\Notification::getNotificationByName( 'blog-visibility' );
|
||||
if ( get_option( 'blog_public' ) ) {
|
||||
if ( $notification->exists() ) {
|
||||
Models\Notification::deleteNotificationByName( 'blog-visibility' );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $notification->exists() || ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Models\Notification::addNotification( [
|
||||
'slug' => uniqid(),
|
||||
'notification_name' => 'blog-visibility',
|
||||
'title' => __( 'Search Engines Blocked', 'all-in-one-seo-pack' ),
|
||||
'content' => sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Warning: %1$s has detected that you are blocking access to search engines. You can change this in Settings > Reading if this was unintended.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
),
|
||||
'type' => 'error',
|
||||
'level' => [ 'all' ],
|
||||
'button1_label' => __( 'Fix Now', 'all-in-one-seo-pack' ),
|
||||
'button1_action' => admin_url( 'options-reading.php' ),
|
||||
'button2_label' => __( 'Remind Me Later', 'all-in-one-seo-pack' ),
|
||||
'button2_action' => 'http://action#notification/blog-visibility-reminder',
|
||||
'start' => gmdate( 'Y-m-d H:i:s' )
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a notice if the description format is missing the Description tag.
|
||||
*
|
||||
* @since 4.0.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function descriptionFormat() {
|
||||
$notification = Models\Notification::getNotificationByName( 'description-format' );
|
||||
if ( ! in_array( 'descriptionFormat', aioseo()->internalOptions->deprecatedOptions, true ) ) {
|
||||
if ( $notification->exists() ) {
|
||||
Models\Notification::deleteNotificationByName( 'description-format' );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$descriptionFormat = aioseo()->options->deprecated->searchAppearance->global->descriptionFormat;
|
||||
if ( false !== strpos( $descriptionFormat, '#description' ) ) {
|
||||
if ( $notification->exists() ) {
|
||||
Models\Notification::deleteNotificationByName( 'description-format' );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $notification->exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Models\Notification::addNotification( [
|
||||
'slug' => uniqid(),
|
||||
'notification_name' => 'description-format',
|
||||
'title' => __( 'Invalid Description Format', 'all-in-one-seo-pack' ),
|
||||
'content' => sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Warning: %1$s has detected that you may have an invalid description format. This could lead to descriptions not being properly applied to your content.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
) . ' ' . __( 'A Description tag is required in order to properly display your meta descriptions on your site.', 'all-in-one-seo-pack' ),
|
||||
'type' => 'error',
|
||||
'level' => [ 'all' ],
|
||||
'button1_label' => __( 'Fix Now', 'all-in-one-seo-pack' ),
|
||||
'button1_action' => 'http://route#aioseo-search-appearance&aioseo-scroll=description-format&aioseo-highlight=description-format:advanced',
|
||||
'button2_label' => __( 'Remind Me Later', 'all-in-one-seo-pack' ),
|
||||
'button2_action' => 'http://action#notification/description-format-reminder',
|
||||
'start' => gmdate( 'Y-m-d H:i:s' )
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if blog visibility is changing and add/delete the appropriate notification.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $optionName The name of the option we are checking.
|
||||
* @param mixed $oldValue The old value.
|
||||
* @param mixed $newValue The new value.
|
||||
* @return void
|
||||
*/
|
||||
public function maybeResetBlogVisibility( $optionName, $oldValue = '', $newValue = '' ) {
|
||||
if ( 'blog_public' === $optionName ) {
|
||||
if ( 1 === intval( $newValue ) ) {
|
||||
$notification = Models\Notification::getNotificationByName( 'blog-visibility' );
|
||||
if ( ! $notification->exists() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Models\Notification::deleteNotificationByName( 'blog-visibility' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->blogVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a notice if the blog is set to hidden.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function conflictingPlugins( $plugins = [] ) {
|
||||
if ( empty( $plugins ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Warning: %1$s has detected other active SEO or sitemap plugins. We recommend that you deactivate the following plugins to prevent any conflicts:', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
) . '<ul>';
|
||||
|
||||
foreach ( $plugins as $pluginName => $pluginPath ) {
|
||||
$content .= '<li><strong>' . $pluginName . '</strong></li>';
|
||||
}
|
||||
|
||||
$content .= '</ul>';
|
||||
|
||||
// Update an existing notice.
|
||||
$notification = Models\Notification::getNotificationByName( 'conflicting-plugins' );
|
||||
if ( $notification->exists() ) {
|
||||
$notification->content = $content;
|
||||
$notification->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new one if it doesn't exist.
|
||||
Models\Notification::addNotification( [
|
||||
'slug' => uniqid(),
|
||||
'notification_name' => 'conflicting-plugins',
|
||||
'title' => __( 'Conflicting Plugins Detected', 'all-in-one-seo-pack' ),
|
||||
'content' => $content,
|
||||
'type' => 'error',
|
||||
'level' => [ 'all' ],
|
||||
'button1_label' => __( 'Fix Now', 'all-in-one-seo-pack' ),
|
||||
'button1_action' => 'http://action#sitemap/deactivate-conflicting-plugins?refresh',
|
||||
'button2_label' => __( 'Remind Me Later', 'all-in-one-seo-pack' ),
|
||||
'button2_action' => 'http://action#notification/conflicting-plugins-reminder',
|
||||
'start' => gmdate( 'Y-m-d H:i:s' )
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
namespace AIOSEO\Plugin\Common\Admin\Notices;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Review Plugin Notice.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Review {
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_aioseo-dismiss-review-plugin-cta', [ $this, 'dismissNotice' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Go through all the checks to see if we should show the notice.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybeShowNotice() {
|
||||
$dismissed = get_user_meta( get_current_user_id(), '_aioseo_plugin_review_dismissed', true );
|
||||
if ( '3' === $dismissed || '4' === $dismissed ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $dismissed ) && $dismissed > time() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only show to users that interact with our pluign.
|
||||
if ( ! current_user_can( 'publish_posts' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only show if plugin has been active for over 10 days.
|
||||
if ( ! aioseo()->internalOptions->internal->firstActivated ) {
|
||||
aioseo()->internalOptions->internal->firstActivated = time();
|
||||
}
|
||||
|
||||
$activated = aioseo()->internalOptions->internal->firstActivated( time() );
|
||||
if ( $activated > strtotime( '-10 days' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( get_option( 'aioseop_options' ) || get_option( 'aioseo_options_v3' ) ) {
|
||||
$this->showNotice();
|
||||
} else {
|
||||
$this->showNotice2();
|
||||
}
|
||||
|
||||
// Print the script to the footer.
|
||||
add_action( 'admin_footer', [ $this, 'printScript' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually show the review plugin.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function showNotice() {
|
||||
$feedbackUrl = add_query_arg(
|
||||
[
|
||||
'wpf7528_24' => untrailingslashit( home_url() ),
|
||||
'wpf7528_26' => aioseo()->options->has( 'general' ) && aioseo()->options->general->has( 'licenseKey' )
|
||||
? aioseo()->options->general->licenseKey
|
||||
: '',
|
||||
'wpf7528_27' => aioseo()->pro ? 'pro' : 'lite',
|
||||
'wpf7528_28' => AIOSEO_VERSION,
|
||||
'utm_source' => aioseo()->pro ? 'proplugin' : 'liteplugin',
|
||||
'utm_medium' => 'review-notice',
|
||||
'utm_campaign' => 'feedback',
|
||||
'utm_content' => AIOSEO_VERSION,
|
||||
],
|
||||
'https://aioseo.com/plugin-feedback/'
|
||||
);
|
||||
|
||||
$string1 = sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Are you enjoying %1$s?', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_NAME
|
||||
);
|
||||
$string2 = __( 'Yes I love it', 'all-in-one-seo-pack' );
|
||||
$string3 = __( 'Not Really...', 'all-in-one-seo-pack' );
|
||||
$string4 = sprintf(
|
||||
// Translators: 1 - The plugin name ("All in One SEO").
|
||||
__( 'We\'re sorry to hear you aren\'t enjoying %1$s. We would love a chance to improve. Could you take a minute and let us know what we can do better?', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_NAME
|
||||
); // phpcs:ignore Generic.Files.LineLength.MaxExceeded
|
||||
$string5 = __( 'Give feedback', 'all-in-one-seo-pack' );
|
||||
$string6 = __( 'No thanks', 'all-in-one-seo-pack' );
|
||||
$string7 = __( 'That\'s awesome! Could you please do us a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', 'all-in-one-seo-pack' );
|
||||
// Translators: 1 - The plugin name ("All in One SEO").
|
||||
$string9 = __( 'Ok, you deserve it', 'all-in-one-seo-pack' );
|
||||
$string10 = __( 'Nope, maybe later', 'all-in-one-seo-pack' );
|
||||
$string11 = __( 'I already did', 'all-in-one-seo-pack' );
|
||||
|
||||
?>
|
||||
<div class="notice notice-info aioseo-review-plugin-cta is-dismissible">
|
||||
<div class="step-1">
|
||||
<p><?php echo esc_html( $string1 ); ?></p>
|
||||
<p>
|
||||
<a href="#" class="aioseo-review-switch-step-3" data-step="3"><?php echo esc_html( $string2 ); ?></a> 🙂 |
|
||||
<a href="#" class="aioseo-review-switch-step-2" data-step="2"><?php echo esc_html( $string3 ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="step-2" style="display:none;">
|
||||
<p><?php echo esc_html( $string4 ); ?></p>
|
||||
<p>
|
||||
<a href="<?php echo esc_url( $feedbackUrl ); ?>" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $string5 ); ?></a>
|
||||
<a href="#" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $string6 ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="step-3" style="display:none;">
|
||||
<p><?php echo esc_html( $string7 ); ?></p>
|
||||
<p>
|
||||
<a href="https://wordpress.org/support/plugin/all-in-one-seo-pack/reviews/?filter=5#new-post" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer">
|
||||
<?php echo esc_html( $string9 ); ?>
|
||||
</a> •
|
||||
<a href="#" class="aioseo-dismiss-review-notice-delay" target="_blank" rel="noopener noreferrer">
|
||||
<?php echo esc_html( $string10 ); ?>
|
||||
</a> •
|
||||
<a href="#" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer">
|
||||
<?php echo esc_html( $string11 ); ?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually show the review plugin 2.0.
|
||||
*
|
||||
* @since 4.2.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function showNotice2() {
|
||||
$string1 = sprintf(
|
||||
// Translators: 1 - The plugin name ("All in One SEO").
|
||||
__( 'Hey, we noticed you have been using %1$s for some time - that’s awesome! Could you please do us a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
|
||||
'<strong>' . esc_html( AIOSEO_PLUGIN_NAME ) . '</strong>'
|
||||
);
|
||||
|
||||
// Translators: 1 - The plugin name ("All in One SEO").
|
||||
$string9 = __( 'Ok, you deserve it', 'all-in-one-seo-pack' );
|
||||
$string10 = __( 'Nope, maybe later', 'all-in-one-seo-pack' );
|
||||
$string11 = __( 'I already did', 'all-in-one-seo-pack' );
|
||||
|
||||
?>
|
||||
<div class="notice notice-info aioseo-review-plugin-cta is-dismissible">
|
||||
<div class="step-3">
|
||||
<p><?php echo $string1; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
||||
<p>
|
||||
<a href="https://wordpress.org/support/plugin/all-in-one-seo-pack/reviews/?filter=5#new-post" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer">
|
||||
<?php echo esc_html( $string9 ); ?>
|
||||
</a> •
|
||||
<a href="#" class="aioseo-dismiss-review-notice-delay" target="_blank" rel="noopener noreferrer">
|
||||
<?php echo esc_html( $string10 ); ?>
|
||||
</a> •
|
||||
<a href="#" class="aioseo-dismiss-review-notice" target="_blank" rel="noopener noreferrer">
|
||||
<?php echo esc_html( $string11 ); ?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the script for dismissing the notice.
|
||||
*
|
||||
* @since 4.0.13
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printScript() {
|
||||
// Create a nonce.
|
||||
$nonce = wp_create_nonce( 'aioseo-dismiss-review' );
|
||||
?>
|
||||
<style>
|
||||
.aioseop-notice-review_plugin_cta .aioseo-action-buttons {
|
||||
display: none;
|
||||
}
|
||||
@keyframes dismissBtnVisible {
|
||||
from { opacity: 0.99; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
.aioseo-review-plugin-cta button.notice-dismiss {
|
||||
animation-duration: 0.001s;
|
||||
animation-name: dismissBtnVisible;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.addEventListener('load', function () {
|
||||
var aioseoSetupButton,
|
||||
dismissBtn
|
||||
|
||||
aioseoSetupButton = function (dismissBtn) {
|
||||
var notice = document.querySelector('.notice.aioseo-review-plugin-cta'),
|
||||
delay = false,
|
||||
relay = true,
|
||||
stepOne = notice.querySelector('.step-1'),
|
||||
stepTwo = notice.querySelector('.step-2'),
|
||||
stepThree = notice.querySelector('.step-3')
|
||||
|
||||
// Add an event listener to the dismiss button.
|
||||
dismissBtn.addEventListener('click', function (event) {
|
||||
var httpRequest = new XMLHttpRequest(),
|
||||
postData = ''
|
||||
|
||||
// Build the data to send in our request.
|
||||
postData += '&delay=' + delay
|
||||
postData += '&relay=' + relay
|
||||
postData += '&action=aioseo-dismiss-review-plugin-cta'
|
||||
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)
|
||||
})
|
||||
|
||||
notice.addEventListener('click', function (event) {
|
||||
if (event.target.matches('.aioseo-review-switch-step-3')) {
|
||||
event.preventDefault()
|
||||
stepOne.style.display = 'none'
|
||||
stepTwo.style.display = 'none'
|
||||
stepThree.style.display = 'block'
|
||||
}
|
||||
if (event.target.matches('.aioseo-review-switch-step-2')) {
|
||||
event.preventDefault()
|
||||
stepOne.style.display = 'none'
|
||||
stepThree.style.display = 'none'
|
||||
stepTwo.style.display = 'block'
|
||||
}
|
||||
if (event.target.matches('.aioseo-dismiss-review-notice-delay')) {
|
||||
event.preventDefault()
|
||||
delay = true
|
||||
relay = false
|
||||
dismissBtn.click()
|
||||
}
|
||||
if (event.target.matches('.aioseo-dismiss-review-notice')) {
|
||||
if ('#' === event.target.getAttribute('href')) {
|
||||
event.preventDefault()
|
||||
}
|
||||
relay = false
|
||||
dismissBtn.click()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
dismissBtn = document.querySelector('.aioseo-review-plugin-cta .notice-dismiss')
|
||||
if (!dismissBtn) {
|
||||
document.addEventListener('animationstart', function (event) {
|
||||
if (event.animationName == 'dismissBtnVisible') {
|
||||
dismissBtn = document.querySelector('.aioseo-review-plugin-cta .notice-dismiss')
|
||||
if (dismissBtn) {
|
||||
aioseoSetupButton(dismissBtn)
|
||||
}
|
||||
}
|
||||
}, false)
|
||||
|
||||
} else {
|
||||
aioseoSetupButton(dismissBtn)
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss the review plugin CTA.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return string The successful response.
|
||||
*/
|
||||
public function dismissNotice() {
|
||||
// Early exit if we're not on a aioseo-dismiss-review-plugin-cta action.
|
||||
if ( ! isset( $_POST['action'] ) || 'aioseo-dismiss-review-plugin-cta' !== $_POST['action'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
check_ajax_referer( 'aioseo-dismiss-review', 'nonce' );
|
||||
$delay = isset( $_POST['delay'] ) ? 'true' === sanitize_text_field( wp_unslash( $_POST['delay'] ) ) : false;
|
||||
$relay = isset( $_POST['relay'] ) ? 'true' === sanitize_text_field( wp_unslash( $_POST['relay'] ) ) : false;
|
||||
|
||||
if ( ! $delay ) {
|
||||
update_user_meta( get_current_user_id(), '_aioseo_plugin_review_dismissed', $relay ? '4' : '3' );
|
||||
|
||||
return wp_send_json_success();
|
||||
}
|
||||
|
||||
update_user_meta( get_current_user_id(), '_aioseo_plugin_review_dismissed', strtotime( '+1 week' ) );
|
||||
|
||||
return wp_send_json_success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
<?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 = (array) 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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
<?php
|
||||
namespace AIOSEO\Plugin\Common\Admin;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use AIOSEO\Plugin\Common\Models;
|
||||
|
||||
/**
|
||||
* Abstract class that Pro and Lite both extend.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class PostSettings {
|
||||
/**
|
||||
* The integrations instance.
|
||||
*
|
||||
* @since 4.4.3
|
||||
*
|
||||
* @var array[object]
|
||||
*/
|
||||
public $integrations;
|
||||
|
||||
/**
|
||||
* Initialize the admin.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the Post Type Overview cache.
|
||||
add_action( 'save_post', [ $this, 'clearPostTypeOverviewCache' ], 100 );
|
||||
add_action( 'delete_post', [ $this, 'clearPostTypeOverviewCache' ], 100 );
|
||||
add_action( 'wp_trash_post', [ $this, 'clearPostTypeOverviewCache' ], 100 );
|
||||
|
||||
if ( wp_doing_ajax() || wp_doing_cron() || ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load Vue APP.
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueuePostSettingsAssets' ] );
|
||||
|
||||
// Add metabox.
|
||||
add_action( 'add_meta_boxes', [ $this, 'addPostSettingsMetabox' ] );
|
||||
|
||||
// Add metabox (upsell) to terms on init hook.
|
||||
add_action( 'init', [ $this, 'init' ], 1000 );
|
||||
|
||||
// Save metabox.
|
||||
add_action( 'save_post', [ $this, 'saveSettingsMetabox' ] );
|
||||
add_action( 'edit_attachment', [ $this, 'saveSettingsMetabox' ] );
|
||||
add_action( 'add_attachment', [ $this, 'saveSettingsMetabox' ] );
|
||||
|
||||
// Filter the sql clauses to show posts filtered by our params.
|
||||
add_filter( 'posts_clauses', [ $this, 'changeClausesToFilterPosts' ], 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues the JS/CSS for the on page/posts settings.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueuePostSettingsAssets() {
|
||||
if (
|
||||
aioseo()->helpers->isScreenBase( 'event-espresso' ) ||
|
||||
aioseo()->helpers->isScreenBase( 'post' ) ||
|
||||
aioseo()->helpers->isScreenBase( 'term' ) ||
|
||||
aioseo()->helpers->isScreenBase( 'edit-tags' ) ||
|
||||
aioseo()->helpers->isScreenBase( 'site-editor' )
|
||||
) {
|
||||
$page = null;
|
||||
if (
|
||||
aioseo()->helpers->isScreenBase( 'event-espresso' ) ||
|
||||
aioseo()->helpers->isScreenBase( 'post' )
|
||||
) {
|
||||
$page = 'post';
|
||||
}
|
||||
|
||||
aioseo()->core->assets->load( 'src/vue/standalone/post-settings/main.js', [], aioseo()->helpers->getVueData( $page ) );
|
||||
aioseo()->core->assets->load( 'src/vue/standalone/link-format/main.js', [], aioseo()->helpers->getVueData( $page ) );
|
||||
}
|
||||
|
||||
$screen = aioseo()->helpers->getCurrentScreen();
|
||||
if ( empty( $screen->id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'attachment' === $screen->id ) {
|
||||
wp_enqueue_media();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not we can add the metabox.
|
||||
*
|
||||
* @since 4.1.7
|
||||
*
|
||||
* @param string $postType The post type to check.
|
||||
* @return boolean Whether or not can add the Metabox.
|
||||
*/
|
||||
public function canAddPostSettingsMetabox( $postType ) {
|
||||
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
|
||||
|
||||
$pageAnalysisSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_analysis' );
|
||||
$generalSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_general_settings' );
|
||||
$socialSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_social_settings' );
|
||||
$schemaSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_schema_settings' );
|
||||
$linkAssistantCapability = aioseo()->access->hasCapability( 'aioseo_page_link_assistant_settings' );
|
||||
$redirectsCapability = aioseo()->access->hasCapability( 'aioseo_page_redirects_manage' );
|
||||
$advancedSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_advanced_settings' );
|
||||
$seoRevisionsSettingsCapability = aioseo()->access->hasCapability( 'aioseo_page_seo_revisions_settings' );
|
||||
|
||||
if (
|
||||
$dynamicOptions->searchAppearance->postTypes->has( $postType ) &&
|
||||
$dynamicOptions->searchAppearance->postTypes->$postType->advanced->showMetaBox &&
|
||||
! (
|
||||
empty( $pageAnalysisSettingsCapability ) &&
|
||||
empty( $generalSettingsCapability ) &&
|
||||
empty( $socialSettingsCapability ) &&
|
||||
empty( $schemaSettingsCapability ) &&
|
||||
empty( $linkAssistantCapability ) &&
|
||||
empty( $redirectsCapability ) &&
|
||||
empty( $advancedSettingsCapability ) &&
|
||||
empty( $seoRevisionsSettingsCapability )
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a meta box to page/posts screens.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPostSettingsMetabox() {
|
||||
$screen = aioseo()->helpers->getCurrentScreen();
|
||||
if ( empty( $screen->post_type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$postType = $screen->post_type;
|
||||
if ( $this->canAddPostSettingsMetabox( $postType ) ) {
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
$aioseoMetaboxTitle = sprintf( esc_html__( '%1$s Settings', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME );
|
||||
|
||||
add_meta_box(
|
||||
'aioseo-settings',
|
||||
$aioseoMetaboxTitle,
|
||||
[ $this, 'postSettingsMetabox' ],
|
||||
[ $postType ],
|
||||
'normal',
|
||||
apply_filters( 'aioseo_post_metabox_priority', 'high' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the on page/posts settings metabox with Vue App wrapper.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postSettingsMetabox() {
|
||||
$this->postSettingsHiddenField();
|
||||
?>
|
||||
<div id="aioseo-post-settings-metabox">
|
||||
<?php aioseo()->templates->getTemplate( 'parts/loader.php' ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the hidden field where all the metabox data goes.
|
||||
*
|
||||
* @since 4.0.17
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postSettingsHiddenField() {
|
||||
static $fieldExists = false;
|
||||
if ( $fieldExists ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fieldExists = true;
|
||||
|
||||
?>
|
||||
<div id="aioseo-post-settings-field">
|
||||
<input type="hidden" name="aioseo-post-settings" id="aioseo-post-settings" value=""/>
|
||||
<?php wp_nonce_field( 'aioseoPostSettingsNonce', 'PostSettingsNonce' ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles metabox saving.
|
||||
*
|
||||
* @since 4.0.3
|
||||
*
|
||||
* @param int $postId Post ID.
|
||||
* @return void
|
||||
*/
|
||||
public function saveSettingsMetabox( $postId ) {
|
||||
if ( ! aioseo()->helpers->isValidPost( $postId, [ 'all' ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Security check.
|
||||
if ( ! isset( $_POST['PostSettingsNonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['PostSettingsNonce'] ) ), 'aioseoPostSettingsNonce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we don't have our post settings input, we can safely skip.
|
||||
if ( ! isset( $_POST['aioseo-post-settings'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check user permissions.
|
||||
if ( ! current_user_can( 'edit_post', $postId ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$currentPost = json_decode( sanitize_text_field( wp_unslash( ( $_POST['aioseo-post-settings'] ) ) ), true );
|
||||
|
||||
// If there is no data, there likely was an error, e.g. if the hidden field wasn't populated on load and the user saved the post without making changes in the metabox.
|
||||
// In that case we should return to prevent a complete reset of the data.
|
||||
// https://github.com/awesomemotive/aioseo/issues/2254
|
||||
if ( empty( $currentPost ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Models\Post::savePost( $postId, $currentPost );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the Post Type Overview cache from our cache table.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param int $postId The Post ID being updated/deleted.
|
||||
* @return void
|
||||
*/
|
||||
public function clearPostTypeOverviewCache( $postId ) {
|
||||
$postType = get_post_type( $postId );
|
||||
if ( empty( $postType ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
aioseo()->core->cache->delete( $postType . '_overview_data' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of post types with an overview showing how many posts are good, okay and so on.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @return array The list of post types with the overview.
|
||||
*/
|
||||
public function getPostTypesOverview() {
|
||||
$overviewData = [];
|
||||
$eligiblePostTypes = aioseo()->helpers->getTruSeoEligiblePostTypes();
|
||||
foreach ( aioseo()->helpers->getPublicPostTypes( true ) as $postType ) {
|
||||
if ( ! in_array( $postType, $eligiblePostTypes, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$overviewData[ $postType ] = $this->getPostTypeOverview( $postType );
|
||||
}
|
||||
|
||||
return $overviewData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how many posts are good, okay, needs improvement or are missing the focus keyphrase for the given post type.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param string $postType The post type name.
|
||||
* @return array The overview data for the given post type.
|
||||
*/
|
||||
public function getPostTypeOverview( $postType ) {
|
||||
$overviewData = aioseo()->core->cache->get( $postType . '_overview_data' );
|
||||
if ( null !== $overviewData ) {
|
||||
return $overviewData;
|
||||
}
|
||||
|
||||
$eligiblePostTypes = aioseo()->helpers->getTruSeoEligiblePostTypes();
|
||||
if ( ! in_array( $postType, $eligiblePostTypes, true ) ) {
|
||||
return [
|
||||
'total' => 0,
|
||||
'withoutFocusKeyphrase' => 0,
|
||||
'needsImprovement' => 0,
|
||||
'okay' => 0,
|
||||
'good' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$specialPageIds = aioseo()->helpers->getSpecialPageIds();
|
||||
$implodedPageIdPlaceholders = array_fill( 0, count( $specialPageIds ), '%d' );
|
||||
$implodedPageIdPlaceholders = implode( ', ', $implodedPageIdPlaceholders );
|
||||
|
||||
global $wpdb;
|
||||
$overviewData = $wpdb->get_row(
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
|
||||
$wpdb->prepare(
|
||||
"SELECT
|
||||
COUNT(*) as total,
|
||||
COALESCE( SUM(CASE WHEN ap.keyphrases = '' OR ap.keyphrases IS NULL OR ap.keyphrases LIKE %s THEN 1 ELSE 0 END), 0) as withoutFocusKeyphrase,
|
||||
COALESCE( SUM(CASE WHEN ap.seo_score < 50 AND NOT (ap.keyphrases = '' OR ap.keyphrases IS NULL OR ap.keyphrases LIKE %s) THEN 1 ELSE 0 END), 0) as needsImprovement,
|
||||
COALESCE( SUM(CASE WHEN ap.seo_score BETWEEN 50 AND 79 AND NOT (ap.keyphrases = '' OR ap.keyphrases IS NULL OR ap.keyphrases LIKE %s) THEN 1 ELSE 0 END), 0) as okay,
|
||||
COALESCE( SUM(CASE WHEN ap.seo_score >= 80 AND NOT (ap.keyphrases = '' OR ap.keyphrases IS NULL OR ap.keyphrases LIKE %s) THEN 1 ELSE 0 END), 0) as good
|
||||
FROM {$wpdb->posts} as p
|
||||
LEFT JOIN {$wpdb->prefix}aioseo_posts as ap ON ap.post_id = p.ID
|
||||
WHERE p.post_status = 'publish'
|
||||
AND p.post_type = %s
|
||||
AND p.ID NOT IN ( $implodedPageIdPlaceholders )",
|
||||
// phpcs:enable
|
||||
'{"focus":{"keyphrase":""%',
|
||||
'{"focus":{"keyphrase":""%',
|
||||
'{"focus":{"keyphrase":""%',
|
||||
'{"focus":{"keyphrase":""%',
|
||||
$postType,
|
||||
...array_values( $specialPageIds )
|
||||
),
|
||||
ARRAY_A
|
||||
);
|
||||
|
||||
// Ensure sure all the values are integers.
|
||||
foreach ( $overviewData as $key => $value ) {
|
||||
$overviewData[ $key ] = (int) $value;
|
||||
}
|
||||
|
||||
// Give me the raw SQL of the query.
|
||||
aioseo()->core->cache->update( $postType . '_overview_data', $overviewData, HOUR_IN_SECONDS );
|
||||
|
||||
return $overviewData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the JOIN and WHERE clause to filter just the posts we need to show depending on the query string.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param array $clauses Associative array of the clauses for the query.
|
||||
* @param \WP_Query $query The WP_Query instance (passed by reference).
|
||||
* @return array The clauses array updated.
|
||||
*/
|
||||
public function changeClausesToFilterPosts( $clauses, $query = null ) {
|
||||
if ( ! is_admin() || ! $query->is_main_query() ) {
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
$filter = filter_input( INPUT_GET, 'aioseo-filter' );
|
||||
if ( empty( $filter ) ) {
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
$whereClause = '';
|
||||
$noKeyphrasesClause = "(aioseo_p.keyphrases = '' OR aioseo_p.keyphrases IS NULL OR aioseo_p.keyphrases LIKE '{\"focus\":{\"keyphrase\":\"\"%')";
|
||||
switch ( $filter ) {
|
||||
case 'withoutFocusKeyphrase':
|
||||
$whereClause = " AND $noKeyphrasesClause ";
|
||||
break;
|
||||
case 'needsImprovement':
|
||||
$whereClause = " AND aioseo_p.seo_score < 50 AND NOT $noKeyphrasesClause ";
|
||||
break;
|
||||
case 'okay':
|
||||
$whereClause = " AND aioseo_p.seo_score BETWEEN 50 AND 80 AND NOT $noKeyphrasesClause ";
|
||||
break;
|
||||
case 'good':
|
||||
$whereClause = " AND aioseo_p.seo_score > 80 AND NOT $noKeyphrasesClause ";
|
||||
break;
|
||||
}
|
||||
|
||||
$prefix = aioseo()->core->db->prefix;
|
||||
$postsTable = aioseo()->core->db->db->posts;
|
||||
$clauses['join'] .= " LEFT JOIN {$prefix}aioseo_posts AS aioseo_p ON ({$postsTable}.ID = aioseo_p.post_id) ";
|
||||
$clauses['where'] .= $whereClause;
|
||||
|
||||
add_action( 'wp', [ $this, 'filterPostsAfterChangingClauses' ] );
|
||||
|
||||
return $clauses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the posts array to remove the ones that are not eligible for page analysis.
|
||||
* Hooked into `wp` action hook.
|
||||
*
|
||||
* @since 4.7.1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function filterPostsAfterChangingClauses() {
|
||||
remove_action( 'wp', [ $this, 'filterPostsAfterChangingClauses' ] );
|
||||
// phpcs:disable Squiz.NamingConventions.ValidVariableName
|
||||
global $wp_query;
|
||||
if ( ! empty( $wp_query->posts ) && is_array( $wp_query->posts ) ) {
|
||||
$wp_query->posts = array_filter( $wp_query->posts, function ( $post ) {
|
||||
return aioseo()->helpers->isTruSeoEligible( $post->ID );
|
||||
} );
|
||||
|
||||
// Update `post_count` for pagination.
|
||||
if ( isset( $wp_query->post_count ) ) {
|
||||
$wp_query->post_count = count( $wp_query->posts );
|
||||
}
|
||||
}
|
||||
// phpcs:enable Squiz.NamingConventions.ValidVariableName
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,543 @@
|
||||
<?php
|
||||
namespace AIOSEO\Plugin\Common\Admin;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* WP Site Health class.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class SiteHealth {
|
||||
/**
|
||||
* Class Constructor.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'site_status_tests', [ $this, 'registerTests' ], 0 );
|
||||
add_filter( 'debug_information', [ $this, 'addDebugInfo' ], 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add AIOSEO WP Site Health tests.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $tests The current filters array.
|
||||
* @return array
|
||||
*/
|
||||
public function registerTests( $tests ) {
|
||||
$tests['direct']['aioseo_site_public'] = [
|
||||
'label' => 'AIOSEO Site Public',
|
||||
'test' => [ $this, 'testCheckSitePublic' ],
|
||||
];
|
||||
$tests['direct']['aioseo_site_info'] = [
|
||||
'label' => 'AIOSEO Site Info',
|
||||
'test' => [ $this, 'testCheckSiteInfo' ],
|
||||
];
|
||||
$tests['direct']['aioseo_google_search_console'] = [
|
||||
'label' => 'AIOSEO Google Search Console',
|
||||
'test' => [ $this, 'testCheckGoogleSearchConsole' ],
|
||||
];
|
||||
$tests['direct']['aioseo_plugin_update'] = [
|
||||
'label' => 'AIOSEO Plugin Update',
|
||||
'test' => [ $this, 'testCheckPluginUpdate' ],
|
||||
];
|
||||
|
||||
$tests['direct']['aioseo_schema_markup'] = [
|
||||
'label' => 'AIOSEO Schema Markup',
|
||||
'test' => [ $this, 'testCheckSchemaMarkup' ],
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds our site health debug info.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param array $debugInfo The debug info.
|
||||
* @return array $debugInfo The debug info.
|
||||
*/
|
||||
public function addDebugInfo( $debugInfo ) {
|
||||
$fields = [];
|
||||
|
||||
$noindexed = $this->noindexed();
|
||||
if ( $noindexed ) {
|
||||
$fields['noindexed'] = $this->field(
|
||||
__( 'Noindexed content', 'all-in-one-seo-pack' ),
|
||||
implode( ', ', $noindexed )
|
||||
);
|
||||
}
|
||||
|
||||
$nofollowed = $this->nofollowed();
|
||||
if ( $nofollowed ) {
|
||||
$fields['nofollowed'] = $this->field(
|
||||
__( 'Nofollowed content', 'all-in-one-seo-pack' ),
|
||||
implode( ', ', $nofollowed )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! count( $fields ) ) {
|
||||
return $debugInfo;
|
||||
}
|
||||
|
||||
$debugInfo['aioseo'] = [
|
||||
'label' => __( 'SEO', 'all-in-one-seo-pack' ),
|
||||
'description' => sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'The fields below contain important SEO information from %1$s that may effect your site.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
),
|
||||
'private' => false,
|
||||
'show_count' => true,
|
||||
'fields' => $fields,
|
||||
];
|
||||
|
||||
return $debugInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the site is public.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return array The test result.
|
||||
*/
|
||||
public function testCheckSitePublic() {
|
||||
$test = 'aioseo_site_public';
|
||||
|
||||
if ( ! get_option( 'blog_public' ) ) {
|
||||
return $this->result(
|
||||
$test,
|
||||
'critical',
|
||||
__( 'Your site does not appear in search results', 'all-in-one-seo-pack' ),
|
||||
__( 'Your site is set to private. This means WordPress asks search engines to exclude your website from search results.', 'all-in-one-seo-pack' ),
|
||||
$this->actionLink( admin_url( 'options-reading.php' ), __( 'Go to Settings > Reading', 'all-in-one-seo-pack' ) )
|
||||
);
|
||||
}
|
||||
|
||||
return $this->result(
|
||||
$test,
|
||||
'good',
|
||||
__( 'Your site appears in search results', 'all-in-one-seo-pack' ),
|
||||
__( 'Your site is set to public. Search engines will index your website and it will appear in search results.', 'all-in-one-seo-pack' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the site title and tagline are set.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return array The test result.
|
||||
*/
|
||||
public function testCheckSiteInfo() {
|
||||
$siteTitle = get_bloginfo( 'name' );
|
||||
$siteTagline = get_bloginfo( 'description' );
|
||||
|
||||
if ( ! $siteTitle || ! $siteTagline ) {
|
||||
return $this->result(
|
||||
'aioseo_site_info',
|
||||
'recommended',
|
||||
__( 'Your Site Title and/or Tagline are blank', 'all-in-one-seo-pack' ),
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__(
|
||||
'Your Site Title and/or Tagline are blank. We recommend setting both of these values as %1$s requires these for various features, including our schema markup',
|
||||
'all-in-one-seo-pack'
|
||||
),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
),
|
||||
$this->actionLink( admin_url( 'options-general.php' ), __( 'Go to Settings > General', 'all-in-one-seo-pack' ) )
|
||||
);
|
||||
}
|
||||
|
||||
return $this->result(
|
||||
'aioseo_site_info',
|
||||
'good',
|
||||
__( 'Your Site Title and Tagline are set', 'all-in-one-seo-pack' ),
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Great! These are required for %1$s\'s schema markup and are often used as fallback values for various other features.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether Google Search Console is connected.
|
||||
*
|
||||
* @since 4.6.2
|
||||
*
|
||||
* @return array The test result.
|
||||
*/
|
||||
public function testCheckGoogleSearchConsole() {
|
||||
$googleSearchConsole = aioseo()->searchStatistics->api->auth->isConnected();
|
||||
|
||||
if ( ! $googleSearchConsole ) {
|
||||
return $this->result(
|
||||
'aioseo_google_search_console',
|
||||
'recommended',
|
||||
__( 'Connect Your Site with Google Search Console', 'all-in-one-seo-pack' ),
|
||||
__( 'Sync your site with Google Search Console and get valuable insights right inside your WordPress dashboard. Track keyword rankings and search performance for individual posts with actionable insights to help you rank higher in search results!', 'all-in-one-seo-pack' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded
|
||||
$this->actionLink( admin_url( 'admin.php?page=aioseo-settings&aioseo-scroll=google-search-console-settings&aioseo-highlight=google-search-console-settings#/webmaster-tools?activetool=googleSearchConsole' ), __( 'Connect to Google Search Console', 'all-in-one-seo-pack' ) ) // phpcs:ignore Generic.Files.LineLength.MaxExceeded
|
||||
);
|
||||
}
|
||||
|
||||
return $this->result(
|
||||
'aioseo_google_search_console',
|
||||
'good',
|
||||
__( 'Google Search Console is Connected', 'all-in-one-seo-pack' ),
|
||||
__( 'Awesome! Google Search Console is connected to your site. This will help you monitor and maintain your site\'s presence in Google Search results.', 'all-in-one-seo-pack' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the required settings for our schema markup are set.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return array The test result.
|
||||
*/
|
||||
public function testCheckSchemaMarkup() {
|
||||
$menuPath = admin_url( 'admin.php?page=aioseo-search-appearance' );
|
||||
|
||||
if ( 'organization' === aioseo()->options->searchAppearance->global->schema->siteRepresents ) {
|
||||
if (
|
||||
! aioseo()->options->searchAppearance->global->schema->organizationName ||
|
||||
(
|
||||
! aioseo()->options->searchAppearance->global->schema->organizationLogo &&
|
||||
! aioseo()->helpers->getSiteLogoUrl()
|
||||
)
|
||||
) {
|
||||
return $this->result(
|
||||
'aioseo_schema_markup',
|
||||
'recommended',
|
||||
__( 'Your Organization Name and/or Logo are blank', 'all-in-one-seo-pack' ),
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Your Organization Name and/or Logo are blank. These values are required for %1$s\'s Organization schema markup.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
),
|
||||
$this->actionLink( $menuPath, __( 'Go to Schema Settings', 'all-in-one-seo-pack' ) )
|
||||
);
|
||||
}
|
||||
|
||||
return $this->result(
|
||||
'aioseo_schema_markup',
|
||||
'good',
|
||||
__( 'Your Organization Name and Logo are set', 'all-in-one-seo-pack' ),
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Awesome! These are required for %1$s\'s Organization schema markup.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
! aioseo()->options->searchAppearance->global->schema->person ||
|
||||
(
|
||||
'manual' === aioseo()->options->searchAppearance->global->schema->person &&
|
||||
(
|
||||
! aioseo()->options->searchAppearance->global->schema->personName ||
|
||||
! aioseo()->options->searchAppearance->global->schema->personLogo
|
||||
)
|
||||
)
|
||||
) {
|
||||
return $this->result(
|
||||
'aioseo_schema_markup',
|
||||
'recommended',
|
||||
__( 'Your Person Name and/or Image are blank', 'all-in-one-seo-pack' ),
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Your Person Name and/or Image are blank. These values are required for %1$s\'s Person schema markup.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
),
|
||||
$this->actionLink( $menuPath, __( 'Go to Schema Settings', 'all-in-one-seo-pack' ) )
|
||||
);
|
||||
}
|
||||
|
||||
return $this->result(
|
||||
'aioseo_schema_markup',
|
||||
'good',
|
||||
__( 'Your Person Name and Image are set', 'all-in-one-seo-pack' ),
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'Awesome! These are required for %1$s\'s Person schema markup.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the plugin should be updated.
|
||||
*
|
||||
* @since 4.7.2
|
||||
*
|
||||
* @return bool Whether the plugin should be updated.
|
||||
*/
|
||||
public function shouldUpdate() {
|
||||
$response = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/all-in-one-seo-pack.json' );
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
if ( ! $body ) {
|
||||
// Something went wrong.
|
||||
return false;
|
||||
}
|
||||
|
||||
$pluginData = json_decode( $body );
|
||||
|
||||
return version_compare( AIOSEO_VERSION, $pluginData->version, '<' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the required settings for our schema markup are set.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return array The test result.
|
||||
*/
|
||||
public function testCheckPluginUpdate() {
|
||||
if ( $this->shouldUpdate() ) {
|
||||
return $this->result(
|
||||
'aioseo_plugin_update',
|
||||
'critical',
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( '%1$s needs to be updated', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
),
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( 'An update is available for %1$s. Upgrade to the latest version to receive all the latest features, bug fixes and security improvements.', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
),
|
||||
$this->actionLink( admin_url( 'plugins.php' ), __( 'Go to Plugins', 'all-in-one-seo-pack' ) )
|
||||
);
|
||||
}
|
||||
|
||||
return $this->result(
|
||||
'aioseo_plugin_update',
|
||||
'good',
|
||||
sprintf(
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
__( '%1$s is updated to the latest version', 'all-in-one-seo-pack' ),
|
||||
AIOSEO_PLUGIN_SHORT_NAME
|
||||
),
|
||||
__( 'Fantastic! By updating to the latest version, you have access to all the latest features, bug fixes and security improvements.', 'all-in-one-seo-pack' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of noindexed content.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return array $noindexed A list of noindexed content.
|
||||
*/
|
||||
protected function noindexed() {
|
||||
$globalDefault = aioseo()->options->searchAppearance->advanced->globalRobotsMeta->default;
|
||||
if (
|
||||
! $globalDefault &&
|
||||
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->noindex
|
||||
) {
|
||||
return [
|
||||
__( 'Your entire site is set to globally noindex content.', 'all-in-one-seo-pack' )
|
||||
];
|
||||
}
|
||||
|
||||
$noindexed = [];
|
||||
|
||||
if (
|
||||
! $globalDefault &&
|
||||
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->noindexPaginated
|
||||
) {
|
||||
$noindexed[] = __( 'Paginated Content', 'all-in-one-seo-pack' );
|
||||
}
|
||||
|
||||
$archives = [
|
||||
'author' => __( 'Author Archives', 'all-in-one-seo-pack' ),
|
||||
'date' => __( 'Date Archives', 'all-in-one-seo-pack' ),
|
||||
'search' => __( 'Search Page', 'all-in-one-seo-pack' )
|
||||
];
|
||||
|
||||
// Archives.
|
||||
foreach ( $archives as $name => $type ) {
|
||||
if (
|
||||
! aioseo()->options->searchAppearance->archives->{ $name }->advanced->robotsMeta->default &&
|
||||
aioseo()->options->searchAppearance->archives->{ $name }->advanced->robotsMeta->noindex
|
||||
) {
|
||||
$noindexed[] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( aioseo()->helpers->getPublicPostTypes() as $postType ) {
|
||||
if (
|
||||
aioseo()->dynamicOptions->searchAppearance->postTypes->has( $postType['name'] ) &&
|
||||
! aioseo()->dynamicOptions->searchAppearance->postTypes->{ $postType['name'] }->advanced->robotsMeta->default &&
|
||||
aioseo()->dynamicOptions->searchAppearance->postTypes->{ $postType['name'] }->advanced->robotsMeta->noindex
|
||||
) {
|
||||
$noindexed[] = $postType['label'] . ' (' . $postType['name'] . ')';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( aioseo()->helpers->getPublicTaxonomies() as $taxonomy ) {
|
||||
if (
|
||||
aioseo()->dynamicOptions->searchAppearance->taxonomies->has( $taxonomy['name'] ) &&
|
||||
! aioseo()->dynamicOptions->searchAppearance->taxonomies->{ $taxonomy['name'] }->advanced->robotsMeta->default &&
|
||||
aioseo()->dynamicOptions->searchAppearance->taxonomies->{ $taxonomy['name'] }->advanced->robotsMeta->noindex
|
||||
) {
|
||||
$noindexed[] = $taxonomy['label'] . ' (' . $taxonomy['name'] . ')';
|
||||
}
|
||||
}
|
||||
|
||||
return $noindexed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of nofollowed content.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return array $nofollowed A list of nofollowed content.
|
||||
*/
|
||||
protected function nofollowed() {
|
||||
$globalDefault = aioseo()->options->searchAppearance->advanced->globalRobotsMeta->default;
|
||||
if (
|
||||
! $globalDefault &&
|
||||
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->nofollow
|
||||
) {
|
||||
return [
|
||||
__( 'Your entire site is set to globally nofollow content.', 'all-in-one-seo-pack' )
|
||||
];
|
||||
}
|
||||
|
||||
$nofollowed = [];
|
||||
|
||||
if (
|
||||
! $globalDefault &&
|
||||
aioseo()->options->searchAppearance->advanced->globalRobotsMeta->nofollowPaginated
|
||||
) {
|
||||
$nofollowed[] = __( 'Paginated Content', 'all-in-one-seo-pack' );
|
||||
}
|
||||
|
||||
$archives = [
|
||||
'author' => __( 'Author Archives', 'all-in-one-seo-pack' ),
|
||||
'date' => __( 'Date Archives', 'all-in-one-seo-pack' ),
|
||||
'search' => __( 'Search Page', 'all-in-one-seo-pack' )
|
||||
];
|
||||
|
||||
// Archives.
|
||||
foreach ( $archives as $name => $type ) {
|
||||
if (
|
||||
! aioseo()->options->searchAppearance->archives->{ $name }->advanced->robotsMeta->default &&
|
||||
aioseo()->options->searchAppearance->archives->{ $name }->advanced->robotsMeta->nofollow
|
||||
) {
|
||||
$nofollowed[] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( aioseo()->helpers->getPublicPostTypes() as $postType ) {
|
||||
if (
|
||||
aioseo()->dynamicOptions->searchAppearance->postTypes->has( $postType['name'] ) &&
|
||||
! aioseo()->dynamicOptions->searchAppearance->postTypes->{ $postType['name'] }->advanced->robotsMeta->default &&
|
||||
aioseo()->dynamicOptions->searchAppearance->postTypes->{ $postType['name'] }->advanced->robotsMeta->nofollow
|
||||
) {
|
||||
$nofollowed[] = $postType['label'] . ' (' . $postType['name'] . ')';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( aioseo()->helpers->getPublicTaxonomies() as $taxonomy ) {
|
||||
if (
|
||||
aioseo()->dynamicOptions->searchAppearance->taxonomies->has( $taxonomy['name'] ) &&
|
||||
! aioseo()->dynamicOptions->searchAppearance->taxonomies->{ $taxonomy['name'] }->advanced->robotsMeta->default &&
|
||||
aioseo()->dynamicOptions->searchAppearance->taxonomies->{ $taxonomy['name'] }->advanced->robotsMeta->nofollow
|
||||
) {
|
||||
$nofollowed[] = $taxonomy['label'] . ' (' . $taxonomy['name'] . ')';
|
||||
}
|
||||
}
|
||||
|
||||
return $nofollowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debug info data field.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $label The field label.
|
||||
* @param string $value The field value.
|
||||
* @param boolean $private Whether the field shouldn't be included if the debug info is copied.
|
||||
* @return array The debug info data field.
|
||||
*/
|
||||
private function field( $label, $value, $private = false ) {
|
||||
return [
|
||||
'label' => $label,
|
||||
'value' => $value,
|
||||
'private' => $private,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test result.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param string $status The result status.
|
||||
* @param string $header The test header.
|
||||
* @param string $description The result description.
|
||||
* @param string $actions The result actions.
|
||||
* @return array The test result.
|
||||
*/
|
||||
protected function result( $name, $status, $header, $description, $actions = '' ) {
|
||||
$color = 'blue';
|
||||
switch ( $status ) {
|
||||
case 'good':
|
||||
break;
|
||||
case 'recommended':
|
||||
$color = 'orange';
|
||||
break;
|
||||
case 'critical':
|
||||
$color = 'red';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'test' => $name,
|
||||
'status' => $status,
|
||||
'label' => $header,
|
||||
'description' => $description,
|
||||
'actions' => $actions,
|
||||
'badge' => [
|
||||
'label' => AIOSEO_PLUGIN_SHORT_NAME,
|
||||
'color' => $color,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an action link.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @param string $path The path.
|
||||
* @param string $anchor The anchor text.
|
||||
* @return string The action link.
|
||||
*/
|
||||
protected function actionLink( $path, $anchor ) {
|
||||
return sprintf(
|
||||
'<p><a href="%1$s">%2$s</a></p>',
|
||||
$path,
|
||||
$anchor
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
<?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 = null, $update = false, $postBefore = null ) {
|
||||
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 = null, $postBefore = null ) {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
<?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' => wp_timezone_string(),
|
||||
'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, '"' ) !== false ) {
|
||||
$v = str_replace( '"', '\"', $v );
|
||||
}
|
||||
});
|
||||
|
||||
$settings = $this->filterPrivateSettings( $settings );
|
||||
|
||||
$internal = aioseo()->internalOptions->all();
|
||||
array_walk_recursive( $internal, function( &$v ) {
|
||||
if ( is_string( $v ) && strpos( $v, '"' ) !== false ) {
|
||||
$v = str_replace( '"', '\"', $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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
namespace AIOSEO\Plugin\Common\Admin;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use AIOSEO\Plugin\Common\Models;
|
||||
|
||||
/**
|
||||
* The Admin class.
|
||||
*
|
||||
* @since 4.7.4
|
||||
*/
|
||||
class WritingAssistant {
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @since 4.7.4
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'add_meta_boxes', [ $this, 'addMetabox' ] );
|
||||
add_action( 'delete_post', [ $this, 'deletePost' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the writing assistant post.
|
||||
*
|
||||
* @since 4.7.4
|
||||
*
|
||||
* @param int $postId The post id.
|
||||
* @return void
|
||||
*/
|
||||
public function deletePost( $postId ) {
|
||||
Models\WritingAssistantPost::getPost( $postId )->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a meta box to the page/posts screens.
|
||||
*
|
||||
* @since 4.7.4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addMetabox() {
|
||||
if ( ! aioseo()->access->hasCapability( 'aioseo_page_writing_assistant_settings' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$postType = get_post_type();
|
||||
if (
|
||||
(
|
||||
! aioseo()->options->writingAssistant->postTypes->all &&
|
||||
! in_array( $postType, aioseo()->options->writingAssistant->postTypes->included, true )
|
||||
) ||
|
||||
! in_array( $postType, aioseo()->helpers->getPublicPostTypes( true ), true )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip post types that do not support an editor.
|
||||
if ( ! post_type_supports( $postType, 'editor' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore certain plugins.
|
||||
if (
|
||||
aioseo()->thirdParty->webStories->isPluginActive() &&
|
||||
'web-story' === $postType
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueueAssets' ] );
|
||||
|
||||
// Translators: 1 - The plugin short name ("AIOSEO").
|
||||
$aioseoMetaboxTitle = sprintf( esc_html__( '%1$s Writing Assistant', 'all-in-one-seo-pack' ), AIOSEO_PLUGIN_SHORT_NAME );
|
||||
|
||||
add_meta_box(
|
||||
'aioseo-writing-assistant-metabox',
|
||||
$aioseoMetaboxTitle,
|
||||
[ $this, 'renderMetabox' ],
|
||||
null,
|
||||
'normal',
|
||||
'low'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the on-page settings metabox with the Vue App wrapper.
|
||||
*
|
||||
* @since 4.7.4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function renderMetabox() {
|
||||
?>
|
||||
<div id="aioseo-writing-assistant-metabox-app">
|
||||
<?php aioseo()->templates->getTemplate( 'parts/loader.php' ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues the JS/CSS for the standalone.
|
||||
*
|
||||
* @since 4.7.4
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enqueueAssets() {
|
||||
if ( ! aioseo()->helpers->isScreenBase( 'post' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
aioseo()->core->assets->load(
|
||||
'src/vue/standalone/writing-assistant/main.js',
|
||||
[],
|
||||
aioseo()->writingAssistant->helpers->getStandaloneVueData(),
|
||||
'aioseoWritingAssistant'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user