芝麻web文件管理V1.00
';
}
/**
* Outputs the simplified footer used for the Onboarding Wizard.
*
* @since 4.0.0
*
* @return void
*/
public function connectFooter( $pro = '' ) {
?>
esc_html__( 'You are not allowed to install plugins.', 'all-in-one-seo-pack' )
];
}
if ( empty( $key ) ) {
return [
'error' => esc_html__( 'Please enter your license key to connect.', 'all-in-one-seo-pack' ),
];
}
// Verify pro version is not installed.
$active = activate_plugin( 'all-in-one-seo-pack-pro/all_in_one_seo_pack_pro', false, false, true );
if ( ! is_wp_error( $active ) ) {
// Deactivate plugin.
deactivate_plugins( plugin_basename( AIOSEO_FILE ), false, false );
return [
'error' => esc_html__( 'Pro version is already installed.', 'all-in-one-seo-pack' )
];
}
// Just check if network is set.
$network = isset( $_POST['network'] ) ? (bool) wp_unslash( $_POST['network'] ) : false; // phpcs:ignore HM.Security.ValidatedSanitizedInput.InputNotSanitized, HM.Security.NonceVerification.Missing, Generic.Files.LineLength.MaxExceeded
$network = ! empty( $network );
// Redirect.
$token = hash( 'sha512', wp_rand() );
// Save the options.
aioseo()->internalOptions->internal->connect->key = $key;
aioseo()->internalOptions->internal->connect->time = time();
aioseo()->internalOptions->internal->connect->network = $network;
aioseo()->internalOptions->internal->connect->token = $token;
$url = add_query_arg( [
'key' => $key,
'network' => $network,
'token' => $token,
'version' => aioseo()->version,
'siteurl' => admin_url(),
'homeurl' => home_url(),
'endpoint' => admin_url( 'admin-ajax.php' ),
'php' => PHP_VERSION,
'wp' => get_bloginfo( 'version' ),
'redirect' => rawurldecode( base64_encode( $redirect ? $redirect : admin_url( 'admin.php?page=aioseo-settings' ) ) ),
'v' => 1,
], defined( 'AIOSEO_UPGRADE_URL' ) ? AIOSEO_UPGRADE_URL : 'https://upgrade.aioseo.com' );
return [
'url' => $url,
];
}
/**
* Process AIOSEO Connect.
*
* @since 1.0.0
*
* @param string $downloadUrl The download URL.
* @param string $postToken The token to validate.
* @return array An array containing a valid response or an error message.
*/
public function process() {
// Verify params present (oth & download link).
$postToken = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; // phpcs:ignore HM.Security.NonceVerification.Missing
$downloadUrl = ! empty( $_POST['file'] ) ? esc_url_raw( wp_unslash( $_POST['file'] ) ) : ''; // phpcs:ignore HM.Security.NonceVerification.Missing
// Translators: 1 - The marketing site anchor name ("aioseo.com").
$error = sprintf( esc_html__( 'Could not install upgrade. Please download from %1$s and install manually.', 'all-in-one-seo-pack' ), esc_html( AIOSEO_MARKETING_DOMAIN ) );
$success = esc_html__( 'Plugin installed & activated.', 'all-in-one-seo-pack' );
// verify params present (token & download link).
if ( empty( $downloadUrl ) || empty( $postToken ) ) {
wp_send_json_error( $error );
}
// Verify token.
$token = aioseo()->internalOptions->internal->connect->token;
if ( empty( $token ) ) {
wp_send_json_error( $error );
}
// This function has been included in WP Core since 3.9.2. @see: https://developer.wordpress.org/reference/functions/hash_equals/
if ( ! hash_equals( $token, $postToken ) ) { // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.hash_equalsFound
wp_send_json_error( $error );
}
// Delete connect token so we don't replay.
aioseo()->internalOptions->internal->connect->token = null;
// Verify pro not activated.
if ( aioseo()->pro ) {
wp_send_json_success( $success );
}
// Check license key.
$licenseKey = aioseo()->internalOptions->internal->connect->key;
if ( ! $licenseKey ) {
wp_send_json_error( esc_html__( 'You are not licensed.', 'all-in-one-seo-pack' ) );
}
// Set the license key in a new option so we can get it when Pro is activated.
aioseo()->internalOptions->internal->validLicenseKey = $licenseKey;
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-screen.php';
require_once ABSPATH . 'wp-admin/includes/screen.php';
// Set the current screen to avoid undefined notices.
set_current_screen( 'toplevel_page_aioseo' );
// Prepare variables.
$url = esc_url_raw(
add_query_arg(
[
'page' => 'aioseo-settings',
],
admin_url( 'admin.php' )
)
);
// Verify pro not installed.
$network = aioseo()->internalOptions->internal->connect->network;
$active = activate_plugin( 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php', $url, $network, true );
if ( ! is_wp_error( $active ) ) {
aioseo()->internalOptions->internal->connect->reset();
deactivate_plugins( plugin_basename( AIOSEO_FILE ), false, $network );
wp_send_json_success( $success );
}
$creds = request_filesystem_credentials( $url, '', false, false, null );
// Check for file system permissions.
if ( false === $creds ) {
wp_send_json_error( $error );
}
if ( ! aioseo()->helpers->wpfs( $creds ) ) {
wp_send_json_error( $error );
}
// Do not allow WordPress to search/download translations, as this will break JS output.
remove_action( 'upgrader_process_complete', [ 'Language_Pack_Upgrader', 'async_upgrade' ], 20 );
// Create the plugin upgrader with our custom skin.
$installer = new Utils\PluginUpgraderSilentAjax( new Utils\PluginUpgraderSkin() );
// Error check.
if ( ! method_exists( $installer, 'install' ) ) {
wp_send_json_error( $error );
}
$installer->install( $downloadUrl );
// Flush the cache and return the newly installed plugin basename.
wp_cache_flush();
$pluginBasename = $installer->plugin_info();
if ( ! $pluginBasename ) {
wp_send_json_error( $error );
}
// Activate the plugin silently.
$activated = activate_plugin( $pluginBasename, '', $network, true );
if ( is_wp_error( $activated ) ) {
wp_send_json_error( esc_html__( 'The Pro version installed correctly, but it needs to be activated from the Plugins page inside your WordPress admin.', 'all-in-one-seo-pack' ) );
}
aioseo()->internalOptions->internal->connect->reset();
deactivate_plugins( plugin_basename( AIOSEO_FILE ), false, $network );
wp_send_json_success( $success );
}
}