mailoptin.php
151 lines
| 1 | <?php |
| 2 | |
| 3 | // Exit if accessed directly. |
| 4 | if ( !defined( 'ABSPATH' ) ) exit; |
| 5 | |
| 6 | if ( ! class_exists( 'MO_Admin_Notice' ) ) { |
| 7 | class MO_Admin_Notice { |
| 8 | public function __construct() { |
| 9 | add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
| 10 | add_action( 'network_admin_notices', array( $this, 'admin_notice' ) ); |
| 11 | add_action( 'admin_init', array( $this, 'dismiss_admin_notice' ) ); |
| 12 | } |
| 13 | public function dismiss_admin_notice() { |
| 14 | if ( ! isset( $_GET['mo-adaction'] ) || $_GET['mo-adaction'] != 'mo_dismiss_adnotice' ) { |
| 15 | return; |
| 16 | } |
| 17 | $url = admin_url(); |
| 18 | update_option( 'mo_dismiss_adnotice', 'true' ); |
| 19 | wp_redirect( $url ); |
| 20 | exit; |
| 21 | } |
| 22 | public function admin_notice() { |
| 23 | global $pagenow; |
| 24 | if($pagenow == 'index.php' || (isset($_GET['page']) && strpos($_GET['page'], 'email-encoder-bundle-option-page') !== false)) { |
| 25 | if (get_option('mo_dismiss_adnotice', 'false') == 'true') { |
| 26 | return; |
| 27 | } |
| 28 | if ($this->is_plugin_installed() && $this->is_plugin_active()) { |
| 29 | return; |
| 30 | } |
| 31 | $dismiss_url = esc_url_raw( |
| 32 | add_query_arg( |
| 33 | array( |
| 34 | 'mo-adaction' => 'mo_dismiss_adnotice' |
| 35 | ), |
| 36 | admin_url() |
| 37 | ) |
| 38 | ); |
| 39 | $this->notice_css(); |
| 40 | $install_url = wp_nonce_url( |
| 41 | admin_url('update.php?action=install-plugin&plugin=mailoptin'), |
| 42 | 'install-plugin_mailoptin' |
| 43 | ); |
| 44 | $activate_url = wp_nonce_url(admin_url('plugins.php?action=activate&plugin=mailoptin%2Fmailoptin.php'), 'activate-plugin_mailoptin/mailoptin.php'); |
| 45 | ?> |
| 46 | <div class="mo-admin-notice notice notice-success"> |
| 47 | <div class="mo-notice-first-half"> |
| 48 | <p> |
| 49 | <?php |
| 50 | printf( |
| 51 | __('Free optin form plugin that will %1$sincrease your email list subscribers%2$s and keep them engaged with %1$sautomated and schedule newsletters%2$s.'), |
| 52 | '<span class="mo-stylize"><strong>', '</strong></span>'); |
| 53 | ?> |
| 54 | </p> |
| 55 | <p style="text-decoration: underline;font-size: 12px;">Recommended by Email Encoder plugin</p> |
| 56 | </div> |
| 57 | <div class="mo-notice-other-half"> |
| 58 | <?php if ( ! $this->is_plugin_installed()) : ?> |
| 59 | <a class="button button-primary button-hero" id="mo-install-mailoptin-plugin" href="<?php echo $install_url; ?>"> |
| 60 | <?php _e('Install MailOptin Now for Free!'); ?> |
| 61 | </a> |
| 62 | <?php endif; ?> |
| 63 | <?php if ($this->is_plugin_installed() && ! $this->is_plugin_active()) : ?> |
| 64 | <a class="button button-primary button-hero" id="mo-activate-mailoptin-plugin" href="<?php echo $activate_url; ?>"> |
| 65 | <?php _e('Activate MailOptin Now!'); ?> |
| 66 | </a> |
| 67 | <?php endif; ?> |
| 68 | <div class="mo-notice-learn-more"> |
| 69 | <a target="_blank" href="https://mailoptin.io">Learn more</a> |
| 70 | </div> |
| 71 | </div> |
| 72 | <a href="<?php echo $dismiss_url; ?>"> |
| 73 | <button type="button" class="notice-dismiss"> |
| 74 | <span class="screen-reader-text"><?php _e('Dismiss this notice'); ?>.</span> |
| 75 | </button> |
| 76 | </a> |
| 77 | </div> |
| 78 | <?php |
| 79 | } |
| 80 | } |
| 81 | public function current_admin_url() { |
| 82 | $parts = parse_url( home_url() ); |
| 83 | $uri = $parts['scheme'] . '://' . $parts['host']; |
| 84 | if ( array_key_exists( 'port', $parts ) ) { |
| 85 | $uri .= ':' . $parts['port']; |
| 86 | } |
| 87 | $uri .= add_query_arg( array() ); |
| 88 | return $uri; |
| 89 | } |
| 90 | public function is_plugin_installed() { |
| 91 | $installed_plugins = get_plugins(); |
| 92 | return isset( $installed_plugins['mailoptin/mailoptin.php'] ); |
| 93 | } |
| 94 | public function is_plugin_active() { |
| 95 | return is_plugin_active( 'mailoptin/mailoptin.php' ); |
| 96 | } |
| 97 | public function notice_css() { |
| 98 | ?> |
| 99 | <style type="text/css"> |
| 100 | .mo-admin-notice { |
| 101 | background: #fff; |
| 102 | color: #000; |
| 103 | border-left-color: #46b450; |
| 104 | position: relative; |
| 105 | } |
| 106 | .mo-admin-notice .notice-dismiss:before { |
| 107 | color: #72777c; |
| 108 | } |
| 109 | .mo-admin-notice .mo-stylize { |
| 110 | line-height: 2; |
| 111 | } |
| 112 | .mo-admin-notice .button-primary { |
| 113 | background: #006799; |
| 114 | text-shadow: none; |
| 115 | border: 0; |
| 116 | box-shadow: none; |
| 117 | } |
| 118 | .mo-notice-first-half { |
| 119 | width: 66%; |
| 120 | display: inline-block; |
| 121 | margin: 10px 0; |
| 122 | } |
| 123 | .mo-notice-other-half { |
| 124 | width: 33%; |
| 125 | display: inline-block; |
| 126 | padding: 20px 0; |
| 127 | position: absolute; |
| 128 | text-align: center; |
| 129 | } |
| 130 | .mo-notice-first-half p { |
| 131 | font-size: 14px; |
| 132 | } |
| 133 | .mo-notice-learn-more a { |
| 134 | margin: 10px; |
| 135 | } |
| 136 | .mo-notice-learn-more { |
| 137 | margin-top: 10px; |
| 138 | } |
| 139 | </style> |
| 140 | <?php |
| 141 | } |
| 142 | public static function instance() { |
| 143 | static $instance = null; |
| 144 | if ( is_null( $instance ) ) { |
| 145 | $instance = new self(); |
| 146 | } |
| 147 | return $instance; |
| 148 | } |
| 149 | } |
| 150 | MO_Admin_Notice::instance(); |
| 151 | } |