| 1 |
<?php |
| 2 |
/** |
| 3 |
* Email notice class. |
| 4 |
* |
| 5 |
* @since 2.0 |
| 6 |
* @author Incsub (Joel James) |
| 7 |
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
| 8 |
* @copyright Copyright (c) 2022, Incsub |
| 9 |
* @package WPMUDEV\Notices |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace WPMUDEV\Notices\Notices; |
| 13 |
|
| 14 |
// If this file is called directly, abort. |
| 15 |
defined( 'WPINC' ) || die; |
| 16 |
|
| 17 |
use WPMUDEV\Notices\Handler; |
| 18 |
|
| 19 |
if ( ! class_exists( __NAMESPACE__ . '\\Email' ) ) { |
| 20 |
/** |
| 21 |
* Class Email |
| 22 |
* |
| 23 |
* @since 2.0 |
| 24 |
* @package WPMUDEV\Notices |
| 25 |
*/ |
| 26 |
class Email extends Notice { |
| 27 |
|
| 28 |
/** |
| 29 |
* Current notice type. |
| 30 |
* |
| 31 |
* @since 2.0 |
| 32 |
* @var string $type |
| 33 |
*/ |
| 34 |
protected $type = 'email'; |
| 35 |
|
| 36 |
/** |
| 37 |
* User id /API Key for Mailchimp subscriber list |
| 38 |
* |
| 39 |
* @since 1.2 |
| 40 |
* @var string $mc_user_id |
| 41 |
*/ |
| 42 |
private $mc_user_id = '53a1e972a043d1264ed082a5b'; |
| 43 |
|
| 44 |
/** |
| 45 |
* Render a notice type content. |
| 46 |
* |
| 47 |
* @since 2.0 |
| 48 |
* |
| 49 |
* @param string $plugin Plugin ID. |
| 50 |
* |
| 51 |
* @return void |
| 52 |
*/ |
| 53 |
public function render( $plugin ) { |
| 54 |
$this->enqueue_assets( $plugin ); |
| 55 |
|
| 56 |
$admin_email = get_site_option( 'admin_email' ); |
| 57 |
|
| 58 |
/* translators: %s - plugin name */ |
| 59 |
$title = __( "We're happy that you've chosen to install %s!", 'wdev_frash' ); |
| 60 |
$title = apply_filters( 'wdev_email_title_' . $plugin, $title ); |
| 61 |
|
| 62 |
/* translators: %s - plugin name */ |
| 63 |
$message = __( 'Are you interested in how to make the most of this plugin? How would you like a quick 5 day email crash course with actionable advice on building your membership site? Only the info you want, no subscription!', 'wdev_frash' ); |
| 64 |
$message = apply_filters( 'wdev_email_message_' . $plugin, $message ); |
| 65 |
|
| 66 |
// Plugin title. |
| 67 |
$plugin_title = $this->get_option( 'title', __( 'Plugin', 'wdev_frash' ) ); |
| 68 |
|
| 69 |
?> |
| 70 |
<div class="notice notice-info frash-notice frash-notice-<?php echo esc_attr( $this->type ); ?> hidden"> |
| 71 |
<?php $this->render_hidden_fields( $plugin ); ?> |
| 72 |
|
| 73 |
<div class="frash-notice-logo <?php echo esc_attr( $plugin ); ?>"><span></span></div> |
| 74 |
<div class="frash-notice-message"> |
| 75 |
<p class="notice-title"><?php printf( esc_html( $title ), esc_html( $plugin_title ) ); ?></p> |
| 76 |
<p><?php printf( esc_html( $message ), esc_html( $plugin_title ) ); ?></p> |
| 77 |
<div class="frash-notice-cta"> |
| 78 |
<?php |
| 79 |
/** |
| 80 |
* Fires before subscribe form renders. |
| 81 |
* |
| 82 |
* @since 1.3 |
| 83 |
* @since 2.0.4 Mailchimp ID deprecated. |
| 84 |
* |
| 85 |
* @param int $mc_list_id Mailchimp list ID (deprecated). |
| 86 |
*/ |
| 87 |
do_action( 'frash_before_subscribe_form_render', '' ); |
| 88 |
?> |
| 89 |
<form action="<?php echo esc_url( $this->api_url( 'mailjet/v1/plugin' ) ); ?>" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank"> |
| 90 |
<label for="wpmudev-email" class="hidden"><?php esc_html_e( 'Email', 'wdev_frash' ); ?></label> |
| 91 |
<input type="email" name="email" class="email" id="wpmudev-email" value="<?php echo esc_attr( $admin_email ); ?>" required="required"/> |
| 92 |
<input type="hidden" name="source" id="wpmudev-source" value="<?php echo esc_attr( $plugin ); ?>"/> |
| 93 |
<button class="frash-notice-act button-primary" data-msg="<?php esc_attr_e( 'Thanks :)', 'wdev_frash' ); ?>" type="submit"> |
| 94 |
<?php echo esc_html( $this->get_option( 'cta_email', __( 'Get Fast!', 'wdev_frash' ) ) ); ?> |
| 95 |
</button> |
| 96 |
<span class="frash-notice-cta-divider">|</span> |
| 97 |
<a href="#" class="frash-notice-dismiss" data-msg="<?php esc_attr_e( 'Saving', 'wdev_frash' ); ?>"> |
| 98 |
<?php esc_html_e( 'No thanks', 'wdev_frash' ); ?> |
| 99 |
</a> |
| 100 |
<?php |
| 101 |
/** |
| 102 |
* Fires after subscribe form fields are rendered. |
| 103 |
* Use this hook to add additional fields for on the sub form. |
| 104 |
* |
| 105 |
* Make sure that the additional field has is also present on the |
| 106 |
* actual MC subscribe form. |
| 107 |
* |
| 108 |
* @since 1.3 |
| 109 |
* @since 2.0.4 Mailchimp ID deprecated. |
| 110 |
* |
| 111 |
* @param int $mc_list_id Mailchimp list ID (deprecated). |
| 112 |
*/ |
| 113 |
do_action( 'frash_subscribe_form_fields', '' ); |
| 114 |
?> |
| 115 |
</form> |
| 116 |
<?php |
| 117 |
/** |
| 118 |
* Fires after subscribe form is rendered |
| 119 |
* |
| 120 |
* @since 1.3 |
| 121 |
* @since 2.0.4 Mailchimp ID deprecated. |
| 122 |
* |
| 123 |
* @param int $mc_list_id Mailchimp list ID (deprecated). |
| 124 |
*/ |
| 125 |
do_action( 'frash_before_subscribe_form_render', '' ); |
| 126 |
?> |
| 127 |
</div> |
| 128 |
</div> |
| 129 |
</div> |
| 130 |
<?php |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Render a notice type content. |
| 135 |
* |
| 136 |
* @since 2.0 |
| 137 |
* |
| 138 |
* @param string $plugin Plugin ID. |
| 139 |
* |
| 140 |
* @return void |
| 141 |
*/ |
| 142 |
protected function render_hidden_fields( $plugin ) { |
| 143 |
$wp_url = $this->get_option( 'wp_slug' ); |
| 144 |
if ( false === strpos( $wp_url, '://' ) ) { |
| 145 |
$wp_url = 'https://wordpress.org/plugins/' . trim( $wp_url, '/' ); |
| 146 |
} |
| 147 |
|
| 148 |
?> |
| 149 |
<input type="hidden" name="type" value="<?php echo esc_attr( $this->type ); ?>"/> |
| 150 |
<input type="hidden" name="plugin_id" value="<?php echo esc_attr( $plugin ); ?>"/> |
| 151 |
<input type="hidden" name="url_wp" value="<?php echo esc_attr( $wp_url ); ?>"/> |
| 152 |
<?php wp_nonce_field( 'wpmudev_notices_action', 'notice_nonce' ); ?> |
| 153 |
<?php |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Enqueue assets for a notice if required. |
| 158 |
* |
| 159 |
* @since 2.0 |
| 160 |
* |
| 161 |
* @param string $plugin Plugin ID. |
| 162 |
* |
| 163 |
* @return void |
| 164 |
*/ |
| 165 |
protected function enqueue_assets( $plugin ) { |
| 166 |
$handle = 'wpmudev-notices-dashboard'; |
| 167 |
|
| 168 |
wp_enqueue_style( |
| 169 |
$handle, |
| 170 |
$this->assets_url( 'css/dashboard-notices.min.css' ), |
| 171 |
array(), |
| 172 |
Handler::instance()->version |
| 173 |
); |
| 174 |
|
| 175 |
wp_enqueue_script( |
| 176 |
$handle, |
| 177 |
$this->assets_url( 'js/dashboard-notices.min.js' ), |
| 178 |
array(), |
| 179 |
Handler::instance()->version, |
| 180 |
true |
| 181 |
); |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Check if current notice is allowed for the plugin. |
| 186 |
* |
| 187 |
* @since 2.0 |
| 188 |
* |
| 189 |
* @param string $plugin Plugin ID. |
| 190 |
* |
| 191 |
* @return bool |
| 192 |
*/ |
| 193 |
public function can_show( $plugin ) { |
| 194 |
// Show only on dashboard. |
| 195 |
return 'dashboard' === $this->screen_id(); |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Parse options for the notice. |
| 200 |
* |
| 201 |
* @since 2.0 |
| 202 |
* |
| 203 |
* @param array $options Plugin options. |
| 204 |
* |
| 205 |
* @return array |
| 206 |
*/ |
| 207 |
protected function parse_options( array $options ) { |
| 208 |
return wp_parse_args( |
| 209 |
$options, |
| 210 |
array( |
| 211 |
'title' => __( 'Plugin', 'wdev_frash' ), |
| 212 |
'wp_slug' => '', |
| 213 |
'cta_email' => __( 'Get Fast!', 'wdev_frash' ), |
| 214 |
) |
| 215 |
); |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
|