diff options
author | Yury German <blueknight@gentoo.org> | 2022-01-23 18:37:36 -0500 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2022-01-23 18:37:36 -0500 |
commit | f18b23a3a9378fb0a98856d436aa9ebf94e47429 (patch) | |
tree | e418433e22854ebd2d77eaa869d5d0470a973317 /plugins/jetpack/3rd-party/creative-mail.php | |
parent | Add classic-editor 1.5 (diff) | |
download | blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.gz blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.tar.bz2 blogs-gentoo-f18b23a3a9378fb0a98856d436aa9ebf94e47429.zip |
Updating Classic Editor, Google Authenticatior, Jetpack, Public Post Preview, Table of Contents, Wordpress Importer
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/3rd-party/creative-mail.php')
-rw-r--r-- | plugins/jetpack/3rd-party/creative-mail.php | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/plugins/jetpack/3rd-party/creative-mail.php b/plugins/jetpack/3rd-party/creative-mail.php new file mode 100644 index 00000000..957a8a2d --- /dev/null +++ b/plugins/jetpack/3rd-party/creative-mail.php @@ -0,0 +1,128 @@ +<?php +/** + * Compatibility functions for the Creative Mail plugin. + * https://wordpress.org/plugins/creative-mail-by-constant-contact/ + * + * @since 8.9.0 + * + * @package automattic/jetpack + */ + +namespace Automattic\Jetpack\Creative_Mail; + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +const PLUGIN_SLUG = 'creative-mail-by-constant-contact'; +const PLUGIN_FILE = 'creative-mail-by-constant-contact/creative-mail-plugin.php'; + +add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' ); +add_action( 'admin_init', __NAMESPACE__ . '\try_install' ); +add_action( 'jetpack_activated_plugin', __NAMESPACE__ . '\configure_plugin', 10, 2 ); + +/** + * Verify the intent to install Creative Mail, and kick off installation. + * + * This works in tandem with a JITM set up in the JITM package. + */ +function try_install() { + if ( ! isset( $_GET['creative-mail-action'] ) ) { + return; + } + + check_admin_referer( 'creative-mail-install' ); + + $result = false; + $redirect = admin_url( 'edit.php?post_type=feedback' ); + + // Attempt to install and activate the plugin. + if ( current_user_can( 'activate_plugins' ) ) { + switch ( $_GET['creative-mail-action'] ) { + case 'install': + $result = install_and_activate(); + break; + case 'activate': + $result = activate(); + break; + } + } + + if ( $result ) { + /** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */ + do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' ); + $redirect = admin_url( 'admin.php?page=creativemail' ); + } else { + $redirect = add_query_arg( 'creative-mail-install-error', true, $redirect ); + } + + wp_safe_redirect( $redirect ); + + exit; +} + +/** + * Install and activate the Creative Mail plugin. + * + * @return bool result of installation + */ +function install_and_activate() { + jetpack_require_lib( 'plugins' ); + $result = \Jetpack_Plugins::install_and_activate_plugin( PLUGIN_SLUG ); + + if ( is_wp_error( $result ) ) { + return false; + } else { + return true; + } +} + +/** + * Activate the Creative Mail plugin. + * + * @return bool result of activation + */ +function activate() { + $result = activate_plugin( PLUGIN_FILE ); + + // Activate_plugin() returns null on success. + return is_null( $result ); +} + +/** + * Notify the user that the installation of Creative Mail failed. + */ +function error_notice() { + if ( empty( $_GET['creative-mail-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return; + } + + ?> + <div class="notice notice-error is-dismissible"> + <p><?php esc_html_e( 'There was an error installing Creative Mail.', 'jetpack' ); ?></p> + </div> + <?php +} + +/** + * Set some options when first activating the plugin via Jetpack. + * + * @since 8.9.0 + * + * @param string $plugin_file Plugin file. + * @param string $source Where did the plugin installation originate. + */ +function configure_plugin( $plugin_file, $source ) { + if ( PLUGIN_FILE !== $plugin_file ) { + return; + } + + $plugin_info = array( + 'plugin' => 'jetpack', + 'version' => JETPACK__VERSION, + 'time' => time(), + 'source' => esc_attr( $source ), + ); + + update_option( 'ce4wp_referred_by', $plugin_info ); +} |