DragDropBuilder
1 month ago
EmailSettings
1 year ago
Membership
1 month ago
AbstractSettingsPage.php
2 years ago
AddNewForm.php
1 year ago
AdminFooter.php
4 years ago
ExtensionsSettingsPage.php
1 year ago
FormList.php
4 months ago
Forms.php
1 year ago
FuseWP.php
3 years ago
GeneralSettings.php
9 months ago
IDUserColumn.php
5 years ago
LicenseUpgrader.php
3 years ago
MailOptin.php
3 years ago
MemberDirectories.php
1 year ago
MembersDirectoryList.php
4 years ago
ToolsSettingsPage.php
4 years ago
index.php
3 years ago
MailOptin.php
704 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages; |
| 4 | |
| 5 | use MailOptin\Core\Repositories\EmailCampaignRepository; |
| 6 | use MailOptin\Core\Repositories\OptinCampaignsRepository; |
| 7 | use ProfilePress\Core\Classes\Installer\PluginSilentUpgrader; |
| 8 | use ProfilePress\Core\Classes\Installer\PPress_Install_Skin; |
| 9 | |
| 10 | class MailOptin |
| 11 | { |
| 12 | const SLUG = 'ppress-mailoptin'; |
| 13 | |
| 14 | private $config = array( |
| 15 | 'lite_plugin' => 'mailoptin/mailoptin.php', |
| 16 | 'lite_download_url' => 'https://downloads.wordpress.org/plugin/mailoptin.latest-stable.zip', |
| 17 | 'mailoptin_settings' => 'admin.php?page=mailoptin-optin-campaigns', |
| 18 | ); |
| 19 | |
| 20 | private $output_data = array(); |
| 21 | |
| 22 | public function __construct() |
| 23 | { |
| 24 | if ( ! $this->is_activated()) { |
| 25 | add_action('ppress_admin_hooks', function () { |
| 26 | add_action('ppress_register_menu_page', array($this, 'register_settings_page')); |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | add_action('wp_ajax_ppress_activate_plugin', [$this, 'ppress_activate_plugin']); |
| 31 | add_action('wp_ajax_ppress_install_plugin', [$this, 'ppress_install_plugin']); |
| 32 | |
| 33 | if (wp_doing_ajax()) { |
| 34 | add_action('wp_ajax_ppress_mailoptin_page_check_plugin_status', array($this, 'ajax_check_plugin_status')); |
| 35 | } |
| 36 | |
| 37 | // Check what page we are on. |
| 38 | $page = isset($_GET['page']) ? \sanitize_key(\wp_unslash($_GET['page'])) : ''; |
| 39 | |
| 40 | if (self::SLUG !== $page) return; |
| 41 | |
| 42 | add_action('admin_init', array($this, 'redirect_to_mailoptin_settings')); |
| 43 | add_action('admin_enqueue_scripts', array($this, 'enqueue_assets')); |
| 44 | } |
| 45 | |
| 46 | public function ppress_install_plugin() |
| 47 | { |
| 48 | // Run a security check. |
| 49 | check_ajax_referer('ppress-admin-nonce', 'nonce'); |
| 50 | |
| 51 | $generic_error = esc_html__('There was an error while performing your request.', 'wp-user-avatar'); |
| 52 | $type = ! empty($_POST['type']) ? sanitize_key($_POST['type']) : 'plugin'; |
| 53 | |
| 54 | if ( ! current_user_can('install_plugins')) { |
| 55 | wp_send_json_error($generic_error); |
| 56 | } |
| 57 | |
| 58 | // Determine whether file modifications are allowed. |
| 59 | if ( ! wp_is_file_mod_allowed('ppress_can_install')) { |
| 60 | wp_send_json_error($generic_error); |
| 61 | } |
| 62 | |
| 63 | $error = $type === 'plugin' ? esc_html__('Could not install plugin. Please download and install manually.', 'wp-user-avatar') : esc_html__('Could not install addon. Please download from mailoptin.io and install manually.', 'wp-user-avatar'); |
| 64 | |
| 65 | if (empty($_POST['plugin'])) { |
| 66 | wp_send_json_error($error); |
| 67 | } |
| 68 | |
| 69 | // Set the current screen to avoid undefined notices. |
| 70 | set_current_screen('profilepress_page_ppress-mailoptin'); |
| 71 | |
| 72 | // Prepare variables. |
| 73 | $url = esc_url_raw( |
| 74 | add_query_arg( |
| 75 | [ |
| 76 | 'page' => 'ppress-extensions', |
| 77 | ], |
| 78 | admin_url('admin.php') |
| 79 | ) |
| 80 | ); |
| 81 | |
| 82 | ob_start(); |
| 83 | $creds = request_filesystem_credentials($url, '', false, false, null); |
| 84 | |
| 85 | // Hide the filesystem credentials form. |
| 86 | ob_end_clean(); |
| 87 | |
| 88 | // Check for file system permissions. |
| 89 | if ($creds === false) { |
| 90 | wp_send_json_error($error); |
| 91 | } |
| 92 | |
| 93 | if ( ! WP_Filesystem($creds)) { |
| 94 | wp_send_json_error($error); |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * We do not need any extra credentials if we have gotten this far, so let's install the plugin. |
| 99 | */ |
| 100 | |
| 101 | // Do not allow WordPress to search/download translations, as this will break JS output. |
| 102 | remove_action('upgrader_process_complete', ['Language_Pack_Upgrader', 'async_upgrade'], 20); |
| 103 | |
| 104 | // Create the plugin upgrader with our custom skin. |
| 105 | $installer = new PluginSilentUpgrader(new PPress_Install_Skin()); |
| 106 | |
| 107 | // Error check. |
| 108 | if ( ! method_exists($installer, 'install') || empty($_POST['plugin'])) { |
| 109 | wp_send_json_error($error); |
| 110 | } |
| 111 | |
| 112 | $installer->install($_POST['plugin']); // phpcs:ignore |
| 113 | |
| 114 | // Flush the cache and return the newly installed plugin basename. |
| 115 | wp_cache_flush(); |
| 116 | |
| 117 | $plugin_basename = $installer->plugin_info(); |
| 118 | |
| 119 | if (empty($plugin_basename)) { |
| 120 | wp_send_json_error($error); |
| 121 | } |
| 122 | |
| 123 | $result = [ |
| 124 | 'msg' => $generic_error, |
| 125 | 'is_activated' => false, |
| 126 | 'basename' => $plugin_basename, |
| 127 | ]; |
| 128 | |
| 129 | // Check for permissions. |
| 130 | if ( ! current_user_can('activate_plugins')) { |
| 131 | $result['msg'] = $type === 'plugin' ? esc_html__('Plugin installed.', 'wp-user-avatar') : esc_html__('Addon installed.', 'wp-user-avatar'); |
| 132 | |
| 133 | wp_send_json_success($result); |
| 134 | } |
| 135 | |
| 136 | // Activate the plugin silently. |
| 137 | $activated = activate_plugin($plugin_basename); |
| 138 | |
| 139 | if ( ! is_wp_error($activated)) { |
| 140 | $result['is_activated'] = true; |
| 141 | $result['msg'] = $type === 'plugin' ? esc_html__('Plugin installed & activated.', 'wp-user-avatar') : esc_html__('Addon installed & activated.', 'wp-user-avatar'); |
| 142 | |
| 143 | wp_send_json_success($result); |
| 144 | } |
| 145 | |
| 146 | // Fallback error just in case. |
| 147 | wp_send_json_error($result); |
| 148 | } |
| 149 | |
| 150 | public function ppress_activate_plugin() |
| 151 | { |
| 152 | // Run a security check. |
| 153 | check_ajax_referer('ppress-admin-nonce', 'nonce'); |
| 154 | |
| 155 | // Check for permissions. |
| 156 | if ( ! current_user_can('activate_plugins')) { |
| 157 | wp_send_json_error(esc_html__('Plugin activation is disabled for you on this site.', 'wp-user-avatar')); |
| 158 | } |
| 159 | |
| 160 | if (isset($_POST['plugin'])) { |
| 161 | |
| 162 | $plugin = sanitize_text_field(wp_unslash($_POST['plugin'])); |
| 163 | $activate = activate_plugins($plugin); |
| 164 | |
| 165 | if ( ! is_wp_error($activate)) { |
| 166 | wp_send_json_success(esc_html__('Plugin activated.', 'wp-user-avatar')); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | wp_send_json_error(esc_html__('Could not activate plugin. Please activate from the Plugins page.', 'wp-user-avatar')); |
| 171 | } |
| 172 | |
| 173 | public function register_settings_page() |
| 174 | { |
| 175 | add_submenu_page( |
| 176 | PPRESS_DASHBOARD_SETTINGS_SLUG, |
| 177 | 'Popups & Optin Forms', |
| 178 | esc_html__('Popups & Optins', 'wp-user-avatar'), |
| 179 | 'manage_options', |
| 180 | self::SLUG, |
| 181 | array($this, 'output') |
| 182 | ); |
| 183 | } |
| 184 | |
| 185 | public function enqueue_assets() |
| 186 | { |
| 187 | wp_enqueue_script( |
| 188 | 'ppress-admin-page-mailoptin', |
| 189 | PPRESS_ASSETS_URL . "/js/mailoptin.js", |
| 190 | array('jquery'), |
| 191 | PPRESS_VERSION_NUMBER, |
| 192 | true |
| 193 | ); |
| 194 | |
| 195 | \wp_localize_script( |
| 196 | 'ppress-admin-page-mailoptin', |
| 197 | 'ppress_pluginlanding', |
| 198 | $this->get_js_strings() |
| 199 | ); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * JS Strings. |
| 204 | */ |
| 205 | protected function get_js_strings() |
| 206 | { |
| 207 | $error_could_not_install = sprintf( |
| 208 | wp_kses( /* translators: %s - Lite plugin download URL. */ |
| 209 | __('Could not install plugin. Please <a href="%s">download</a> and install manually.', 'wp-user-avatar'), |
| 210 | array( |
| 211 | 'a' => array( |
| 212 | 'href' => true, |
| 213 | ), |
| 214 | ) |
| 215 | ), |
| 216 | esc_url_raw($this->config['lite_download_url']) |
| 217 | ); |
| 218 | |
| 219 | $error_could_not_activate = sprintf( |
| 220 | wp_kses( /* translators: %s - Lite plugin download URL. */ |
| 221 | __('Could not activate plugin. Please activate from the <a href="%s">Plugins page</a>.', 'wp-user-avatar'), |
| 222 | array( |
| 223 | 'a' => array( |
| 224 | 'href' => true, |
| 225 | ), |
| 226 | ) |
| 227 | ), |
| 228 | esc_url_raw(admin_url('plugins.php')) |
| 229 | ); |
| 230 | |
| 231 | return array( |
| 232 | 'installing' => esc_html__('Installing...', 'wp-user-avatar'), |
| 233 | 'activating' => esc_html__('Activating...', 'wp-user-avatar'), |
| 234 | 'activated' => esc_html__('MailOptin Installed & Activated', 'wp-user-avatar'), |
| 235 | 'install_now' => esc_html__('Install Now', 'wp-user-avatar'), |
| 236 | 'activate_now' => esc_html__('Activate Now', 'wp-user-avatar'), |
| 237 | 'download_now' => esc_html__('Download Now', 'wp-user-avatar'), |
| 238 | 'plugins_page' => esc_html__('Go to Plugins page', 'wp-user-avatar'), |
| 239 | 'error_could_not_install' => $error_could_not_install, |
| 240 | 'error_could_not_activate' => $error_could_not_activate, |
| 241 | 'manual_install_url' => $this->config['lite_download_url'], |
| 242 | 'manual_activate_url' => admin_url('plugins.php'), |
| 243 | 'mailoptin_settings_button' => esc_html__('Go to MailOptin Settings', 'wp-user-avatar'), |
| 244 | ); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Generate and output page HTML. |
| 249 | */ |
| 250 | public function output() |
| 251 | { |
| 252 | ?> |
| 253 | <style> |
| 254 | #ppress-admin-mailoptin { |
| 255 | width: 700px; |
| 256 | margin: 0 auto; |
| 257 | } |
| 258 | |
| 259 | #ppress-admin-mailoptin .notice { |
| 260 | display: none |
| 261 | } |
| 262 | |
| 263 | #ppress-admin-mailoptin *, #ppress-admin-mailoptin *::before, #ppress-admin-mailoptin *::after { |
| 264 | -webkit-box-sizing: border-box; |
| 265 | -moz-box-sizing: border-box; |
| 266 | box-sizing: border-box; |
| 267 | } |
| 268 | |
| 269 | #ppress-admin-mailoptin section { |
| 270 | margin: 50px 0; |
| 271 | text-align: left; |
| 272 | clear: both; |
| 273 | } |
| 274 | |
| 275 | #ppress-admin-mailoptin .top { |
| 276 | text-align: center; |
| 277 | } |
| 278 | |
| 279 | #ppress-admin-mailoptin .top img { |
| 280 | margin-bottom: 38px; |
| 281 | } |
| 282 | |
| 283 | #ppress-admin-mailoptin .top h1 { |
| 284 | font-size: 26px; |
| 285 | font-weight: 600; |
| 286 | margin-bottom: 0; |
| 287 | padding: 0; |
| 288 | } |
| 289 | |
| 290 | #ppress-admin-mailoptin .top p { |
| 291 | font-size: 17px; |
| 292 | color: #777777; |
| 293 | margin-top: .5em; |
| 294 | } |
| 295 | |
| 296 | #ppress-admin-mailoptin p { |
| 297 | font-size: 15px; |
| 298 | } |
| 299 | |
| 300 | #ppress-admin-mailoptin .cont { |
| 301 | display: inline-block; |
| 302 | position: relative; |
| 303 | width: 100%; |
| 304 | padding: 5px; |
| 305 | background-color: #ffffff; |
| 306 | -webkit-box-shadow: 0px 2px 5px 0px rgb(0 0 0 / 5%); |
| 307 | -moz-box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.05); |
| 308 | box-shadow: 0px 2px 5px 0px rgb(0 0 0 / 5%); |
| 309 | border-radius: 3px; |
| 310 | box-sizing: border-box; |
| 311 | } |
| 312 | |
| 313 | #ppress-admin-mailoptin .screenshot > * { |
| 314 | vertical-align: middle; |
| 315 | } |
| 316 | |
| 317 | #ppress-admin-mailoptin .screenshot .cont img { |
| 318 | max-width: 100%; |
| 319 | display: block; |
| 320 | } |
| 321 | |
| 322 | #ppress-admin-mailoptin .screenshot ul { |
| 323 | display: inline-block; |
| 324 | margin: 0 0 0 30px; |
| 325 | list-style-type: none; |
| 326 | max-width: 100%; |
| 327 | } |
| 328 | |
| 329 | #ppress-admin-mailoptin .screenshot li { |
| 330 | margin: 16px 0; |
| 331 | padding: 0 0 0 24px; |
| 332 | font-size: 15px; |
| 333 | color: #777777; |
| 334 | } |
| 335 | |
| 336 | #ppress-admin-mailoptin .step { |
| 337 | background-color: #F9F9F9; |
| 338 | -webkit-box-shadow: 0px 2px 5px 0px rgb(0 0 0 / 5%); |
| 339 | -moz-box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.05); |
| 340 | box-shadow: 0px 2px 5px 0px rgb(0 0 0 / 5%); |
| 341 | border: 1px solid #E5E5E5; |
| 342 | margin: 0 0 25px 0; |
| 343 | } |
| 344 | |
| 345 | #ppress-admin-mailoptin .step .num { |
| 346 | display: inline-block; |
| 347 | position: relative; |
| 348 | width: 100px; |
| 349 | height: 50px; |
| 350 | text-align: center; |
| 351 | } |
| 352 | |
| 353 | .ppress-admin-plugin-landing .loader { |
| 354 | margin: 0 auto; |
| 355 | position: relative; |
| 356 | text-indent: -9999em; |
| 357 | border-top: 4px solid #969696; |
| 358 | border-right: 4px solid #969696; |
| 359 | border-bottom: 4px solid #969696; |
| 360 | border-left: 4px solid #404040; |
| 361 | -webkit-transform: translateZ(0); |
| 362 | -ms-transform: translateZ(0); |
| 363 | transform: translateZ(0); |
| 364 | -webkit-animation: load8 1.1s infinite linear; |
| 365 | animation: load8 1.1s infinite linear; |
| 366 | background-color: transparent; |
| 367 | } |
| 368 | |
| 369 | .ppress-admin-plugin-landing .loader, .ppress-admin-plugin-landing .loader:after { |
| 370 | display: block; |
| 371 | border-radius: 50%; |
| 372 | width: 50px; |
| 373 | height: 50px |
| 374 | } |
| 375 | |
| 376 | @-webkit-keyframes load8 { |
| 377 | 0% { |
| 378 | -webkit-transform: rotate(0deg); |
| 379 | transform: rotate(0deg) |
| 380 | } |
| 381 | |
| 382 | 100% { |
| 383 | -webkit-transform: rotate(360deg); |
| 384 | transform: rotate(360deg) |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | @keyframes load8 { |
| 389 | 0% { |
| 390 | -webkit-transform: rotate(0deg); |
| 391 | transform: rotate(0deg) |
| 392 | } |
| 393 | |
| 394 | 100% { |
| 395 | -webkit-transform: rotate(360deg); |
| 396 | transform: rotate(360deg) |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | #ppress-admin-mailoptin .step .loader { |
| 401 | margin-top: -54px; |
| 402 | transition: all .3s; |
| 403 | opacity: 1; |
| 404 | } |
| 405 | |
| 406 | #ppress-admin-mailoptin .step .hidden { |
| 407 | opacity: 0; |
| 408 | transition: all .3s; |
| 409 | } |
| 410 | |
| 411 | #ppress-admin-mailoptin .step div { |
| 412 | display: inline-block; |
| 413 | width: calc(100% - 104px); |
| 414 | background-color: #ffffff; |
| 415 | padding: 30px; |
| 416 | border-left: 1px solid #eeeeee; |
| 417 | } |
| 418 | |
| 419 | #ppress-admin-mailoptin .step h2 { |
| 420 | font-size: 24px; |
| 421 | line-height: 22px; |
| 422 | margin-top: 0; |
| 423 | margin-bottom: 15px; |
| 424 | } |
| 425 | |
| 426 | #ppress-admin-mailoptin .step p { |
| 427 | font-size: 16px; |
| 428 | color: #777777; |
| 429 | } |
| 430 | |
| 431 | |
| 432 | #ppress-admin-mailoptin .step .button { |
| 433 | font-weight: 500; |
| 434 | box-shadow: none; |
| 435 | padding: 12px; |
| 436 | min-width: 200px; |
| 437 | height: auto; |
| 438 | line-height: 13px; |
| 439 | text-align: center; |
| 440 | font-size: 15px; |
| 441 | transition: all .3s; |
| 442 | } |
| 443 | |
| 444 | #ppress-admin-mailoptin .grey { |
| 445 | opacity: 0.5; |
| 446 | } |
| 447 | </style> |
| 448 | <?php |
| 449 | echo '<div id="ppress-admin-mailoptin" class="wrap ppress-admin-wrap ppress-admin-plugin-landing">'; |
| 450 | |
| 451 | $this->output_section_heading(); |
| 452 | $this->output_section_screenshot(); |
| 453 | $this->output_section_step_install(); |
| 454 | $this->output_section_step_setup(); |
| 455 | |
| 456 | echo '</div>'; |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Generate and output heading section HTML. |
| 461 | */ |
| 462 | protected function output_section_heading() |
| 463 | { |
| 464 | // Heading section. |
| 465 | printf( |
| 466 | '<section class="top"> |
| 467 | <img class="img-top" src="%1$s" alt="%2$s"/> |
| 468 | <h1>%3$s</h1> |
| 469 | <p>%4$s</p> |
| 470 | </section>', |
| 471 | esc_url(PPRESS_ASSETS_URL . '/images/profilepressxmailoptin.png'), |
| 472 | esc_attr__('ProfilePress ♥ MailOptin', 'wp-user-avatar'), |
| 473 | esc_html__('#1 Popup, Optin Forms & Marketing Automation Plugin', 'wp-user-avatar'), |
| 474 | esc_html__('MailOptin lets you display your registration and login forms as popups, create newsletter opt-in forms that integrates with Mailchimp, Aweber, Constant Contact, Active Campaign & more.', 'wp-user-avatar') |
| 475 | ); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Generate and output screenshot section HTML. |
| 480 | */ |
| 481 | protected function output_section_screenshot() |
| 482 | { |
| 483 | printf( |
| 484 | '<section class="screenshot"> |
| 485 | <div class="cont"> |
| 486 | <img src="%1$s" alt="%2$s"/> |
| 487 | </div> |
| 488 | <ul> |
| 489 | <li>%3$s</li> |
| 490 | <li>%4$s</li> |
| 491 | <li>%5$s</li> |
| 492 | <li>%6$s</li> |
| 493 | <li>%7$s</li> |
| 494 | </ul> |
| 495 | </section>', |
| 496 | 'https://mailoptin.io/wp-content/uploads/2018/10/lead-generation-customizer-demo.jpg', |
| 497 | esc_attr__('MailOptin screenshot', 'wp-user-avatar'), |
| 498 | esc_html__('Automatically notify your subscribers every time you publish a new post.', 'wp-user-avatar'), |
| 499 | esc_html__('Keep your subscribers engaged with daily, weekly and monthly email digest of published posts.', 'wp-user-avatar'), |
| 500 | esc_html__('Different types of opt-in form including Popup, notification bar, inline, scroll box, slide ins, sidebar forms.', 'wp-user-avatar'), |
| 501 | esc_html__('Page-level targeting and optin triggers to build hyper segmented email list.', 'wp-user-avatar'), |
| 502 | esc_html__('Analytics with actionable reporting & insights to improve your lead-generation strategy.', 'wp-user-avatar') |
| 503 | ); |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Generate and output step 'Install' section HTML. |
| 508 | */ |
| 509 | protected function output_section_step_install() |
| 510 | { |
| 511 | $step = $this->get_data_step_install(); |
| 512 | |
| 513 | if (empty($step)) { |
| 514 | return; |
| 515 | } |
| 516 | |
| 517 | printf( |
| 518 | '<section class="step step-install"> |
| 519 | <aside class="num"> |
| 520 | <img src="%1$s" alt="%2$s" /> |
| 521 | <i class="loader hidden"></i> |
| 522 | </aside> |
| 523 | <div> |
| 524 | <h2>%3$s</h2> |
| 525 | <p>%4$s</p> |
| 526 | <button class="button %5$s" data-plugin="%6$s" data-action="%7$s">%8$s</button> |
| 527 | </div> |
| 528 | </section>', |
| 529 | esc_url(PPRESS_ASSETS_URL . '/images/' . $step['icon']), |
| 530 | esc_attr__('Step 1', 'wp-user-avatar'), |
| 531 | esc_html__('Install and Activate MailOptin', 'wp-user-avatar'), |
| 532 | esc_html__('Install MailOptin from the WordPress.org plugin repository.', 'wp-user-avatar'), |
| 533 | esc_attr($step['button_class']), |
| 534 | esc_attr($step['plugin']), |
| 535 | esc_attr($step['button_action']), |
| 536 | esc_html($step['button_text']) |
| 537 | ); |
| 538 | } |
| 539 | |
| 540 | /** |
| 541 | * Generate and output step 'Setup' section HTML. |
| 542 | */ |
| 543 | protected function output_section_step_setup() |
| 544 | { |
| 545 | $step = $this->get_data_step_setup(); |
| 546 | |
| 547 | if (empty($step)) { |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | printf( |
| 552 | '<section class="step step-setup %1$s"> |
| 553 | <aside class="num"> |
| 554 | <img src="%2$s" alt="%3$s" /> |
| 555 | <i class="loader hidden"></i> |
| 556 | </aside> |
| 557 | <div> |
| 558 | <h2>%4$s</h2> |
| 559 | <p>%5$s</p> |
| 560 | <button class="button %6$s" data-url="%7$s">%8$s</button> |
| 561 | </div> |
| 562 | </section>', |
| 563 | esc_attr($step['section_class']), |
| 564 | esc_url(PPRESS_ASSETS_URL . '/images/' . $step['icon']), |
| 565 | esc_attr__('Step 2', 'wp-user-avatar'), |
| 566 | esc_html__('Set Up MailOptin', 'wp-user-avatar'), |
| 567 | esc_html__('Configure and create your first optin form.', 'wp-user-avatar'), |
| 568 | esc_attr($step['button_class']), |
| 569 | esc_url(admin_url($this->config['mailoptin_settings'])), |
| 570 | esc_html($step['button_text']) |
| 571 | ); |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Step 'Install' data. |
| 576 | */ |
| 577 | protected function get_data_step_install() |
| 578 | { |
| 579 | $step = array(); |
| 580 | |
| 581 | $this->output_data['all_plugins'] = get_plugins(); |
| 582 | $this->output_data['plugin_installed'] = array_key_exists($this->config['lite_plugin'], $this->output_data['all_plugins']); |
| 583 | $this->output_data['plugin_activated'] = false; |
| 584 | $this->output_data['plugin_setup'] = false; |
| 585 | |
| 586 | if ( ! $this->output_data['plugin_installed']) { |
| 587 | $step['icon'] = 'step-1.svg'; |
| 588 | $step['button_text'] = esc_html__('Install MailOptin', 'wp-user-avatar'); |
| 589 | $step['button_class'] = ''; |
| 590 | $step['button_action'] = 'install'; |
| 591 | $step['plugin'] = $this->config['lite_download_url']; |
| 592 | } else { |
| 593 | $this->output_data['plugin_activated'] = $this->is_activated(); |
| 594 | $this->output_data['plugin_setup'] = $this->is_configured(); |
| 595 | $step['icon'] = $this->output_data['plugin_activated'] ? 'step-complete.svg' : 'step-1.svg'; |
| 596 | $step['button_text'] = $this->output_data['plugin_activated'] ? esc_html__('MailOptin Installed & Activated', 'wp-user-avatar') : esc_html__('Activate MailOptin', 'wp-user-avatar'); |
| 597 | $step['button_class'] = $this->output_data['plugin_activated'] ? 'grey disabled' : ''; |
| 598 | $step['button_action'] = $this->output_data['plugin_activated'] ? '' : 'activate'; |
| 599 | $step['plugin'] = $this->config['lite_plugin']; |
| 600 | } |
| 601 | |
| 602 | return $step; |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Step 'Setup' data. |
| 607 | */ |
| 608 | protected function get_data_step_setup() |
| 609 | { |
| 610 | $step = array(); |
| 611 | |
| 612 | $step['icon'] = 'step-2.svg'; |
| 613 | $step['section_class'] = $this->output_data['plugin_activated'] ? '' : 'grey'; |
| 614 | $step['button_text'] = esc_html__('Start Setup', 'wp-user-avatar'); |
| 615 | $step['button_class'] = 'grey disabled'; |
| 616 | |
| 617 | if ($this->output_data['plugin_setup']) { |
| 618 | $step['icon'] = 'step-complete.svg'; |
| 619 | $step['section_class'] = ''; |
| 620 | $step['button_text'] = esc_html__('Go to MailOptin settings', 'wp-user-avatar'); |
| 621 | } else { |
| 622 | $step['button_class'] = $this->output_data['plugin_activated'] ? '' : 'grey disabled'; |
| 623 | } |
| 624 | |
| 625 | return $step; |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Ajax endpoint. Check plugin setup status. |
| 630 | * Used to properly init step 'Setup' section after completing step 'Install'. |
| 631 | */ |
| 632 | public function ajax_check_plugin_status() |
| 633 | { |
| 634 | // Security checks. |
| 635 | if ( |
| 636 | ! check_ajax_referer('ppress-admin-nonce', 'nonce', false) || |
| 637 | ! current_user_can('activate_plugins') |
| 638 | ) { |
| 639 | wp_send_json_error( |
| 640 | array( |
| 641 | 'error' => esc_html__('You do not have permission.', 'wp-user-avatar'), |
| 642 | ) |
| 643 | ); |
| 644 | } |
| 645 | |
| 646 | $result = array(); |
| 647 | |
| 648 | if ( ! $this->is_activated()) { |
| 649 | wp_send_json_error( |
| 650 | array( |
| 651 | 'error' => esc_html__('Plugin unavailable.', 'wp-user-avatar'), |
| 652 | ) |
| 653 | ); |
| 654 | } |
| 655 | |
| 656 | $result['setup_status'] = (int)$this->is_configured(); |
| 657 | |
| 658 | wp_send_json_success($result); |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Whether MailOptin plugin configured or not. |
| 663 | */ |
| 664 | protected function is_configured() |
| 665 | { |
| 666 | if ( ! $this->is_activated()) return false; |
| 667 | |
| 668 | $optins = OptinCampaignsRepository::get_optin_campaign_ids(); |
| 669 | |
| 670 | $emails = EmailCampaignRepository::get_email_campaign_ids(); |
| 671 | |
| 672 | return ! empty($optins) || ! empty($emails); |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * Whether MailOptin plugin active or not. |
| 677 | */ |
| 678 | protected function is_activated() |
| 679 | { |
| 680 | return class_exists('MailOptin\Core\Base'); |
| 681 | } |
| 682 | |
| 683 | public function redirect_to_mailoptin_settings() |
| 684 | { |
| 685 | if ($this->is_configured()) { |
| 686 | wp_safe_redirect(admin_url($this->config['mailoptin_settings'])); |
| 687 | exit; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * @return self |
| 693 | */ |
| 694 | public static function get_instance() |
| 695 | { |
| 696 | static $instance = null; |
| 697 | |
| 698 | if (is_null($instance)) { |
| 699 | $instance = new self(); |
| 700 | } |
| 701 | |
| 702 | return $instance; |
| 703 | } |
| 704 | } |