Skip to content

Commit

Permalink
Apply coding standards to MO Notice class
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyrob committed Oct 19, 2019
1 parent fab6591 commit d99abd9
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 181 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fix some Coding Standards Issues
* Correct maximum execution time limit to 5 minutes
* Fix some new Coding Standards errors and warnings
* Applied coding standards to MO Notice class
* Clean unused global variables
* Implemented compatibility with Fusion Builder
* Fix error caused by menu registration in WordPress 5.3
Expand Down
183 changes: 183 additions & 0 deletions classes/class-mo-admin-notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php

if ( ! class_exists( 'MO_Admin_Notice' ) ) {

class MO_Admin_Notice {
public function __construct() {
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
add_action( 'network_admin_notices', array( $this, 'admin_notice' ) );

add_action( 'admin_init', array( $this, 'dismiss_admin_notice' ) );
}

public function dismiss_admin_notice() {
if ( ! isset( $_GET['mo-adaction'] ) || 'mo_dismiss_adnotice' !== $_GET['mo-adaction'] ) {
return;
}

$url = admin_url();
update_option( 'mo_dismiss_adnotice', 'true' );

wp_safe_redirect( $url );
exit;
}

public function admin_notice() {

global $pagenow;

if ( 'index.php' === $pagenow || ( isset( $_GET['page'] ) && false !== strpos( $_GET['page'], 's2_' ) ) ) {

if ( get_option( 'mo_dismiss_adnotice', 'false' ) === 'true' ) {
return;
}

if ( $this->is_plugin_installed() && $this->is_plugin_active() ) {
return;
}

$dismiss_url = esc_url_raw(
add_query_arg(
array(
'mo-adaction' => 'mo_dismiss_adnotice',
),
admin_url()
)
);
$this->notice_css();
$install_url = wp_nonce_url(
admin_url( 'update.php?action=install-plugin&plugin=mailoptin' ),
'install-plugin_mailoptin'
);

$activate_url = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=mailoptin%2Fmailoptin.php' ), 'activate-plugin_mailoptin/mailoptin.php' );
?>
<div class="mo-admin-notice notice notice-success">
<div class="mo-notice-first-half">
<p>
<?php
printf(
// Translators: Mail Optin admin notice
__( '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.', 'subscribe2' ),
'<span class="mo-stylize"><strong>',
'</strong></span>'
);
?>
</p>
<p style="text-decoration: underline;font-size: 12px;">Recommended by Subscribe2 plugin</p>
</div>
<div class="mo-notice-other-half">
<?php if ( ! $this->is_plugin_installed() ) : ?>
<a class="button button-primary button-hero" id="mo-install-mailoptin-plugin" href="<?php echo $install_url; ?>">
<?php _e( 'Install MailOptin Now for Free!', 'subscribe2' ); ?>
</a>
<?php endif; ?>
<?php if ( $this->is_plugin_installed() && ! $this->is_plugin_active() ) : ?>
<a class="button button-primary button-hero" id="mo-activate-mailoptin-plugin" href="<?php echo $activate_url; ?>">
<?php _e( 'Activate MailOptin Now!', 'subscribe2' ); ?>
</a>
<?php endif; ?>
<div class="mo-notice-learn-more">
<a target="_blank" href="https://mailoptin.io">Learn more</a>
</div>
</div>
<a href="<?php echo $dismiss_url; ?>">
<button type="button" class="notice-dismiss">
<span class="screen-reader-text"><?php _e( 'Dismiss this notice', 'subscribe2' ); ?>.</span>
</button>
</a>
</div>
<?php
}
}

public function current_admin_url() {
$parts = wp_parse_url( home_url() );
$uri = $parts['scheme'] . '://' . $parts['host'];

if ( array_key_exists( 'port', $parts ) ) {
$uri .= ':' . $parts['port'];
}

$uri .= add_query_arg( array() );

return $uri;
}

public function is_plugin_installed() {
$installed_plugins = get_plugins();

return isset( $installed_plugins['mailoptin/mailoptin.php'] );
}

public function is_plugin_active() {
return is_plugin_active( 'mailoptin/mailoptin.php' );
}

public function notice_css() {
?>
<style type="text/css">
.mo-admin-notice {
background: #fff;
color: #000;
border-left-color: #46b450;
position: relative;
}

.mo-admin-notice .notice-dismiss:before {
color: #72777c;
}

.mo-admin-notice .mo-stylize {
line-height: 2;
}

.mo-admin-notice .button-primary {
background: #006799;
text-shadow: none;
border: 0;
box-shadow: none;
}

.mo-notice-first-half {
width: 66%;
display: inline-block;
margin: 10px 0;
}

.mo-notice-other-half {
width: 33%;
display: inline-block;
padding: 20px 0;
position: absolute;
text-align: center;
}

.mo-notice-first-half p {
font-size: 14px;
}

.mo-notice-learn-more a {
margin: 10px;
}

.mo-notice-learn-more {
margin-top: 10px;
}
</style>
<?php
}

public static function instance() {
static $instance = null;

if ( is_null( $instance ) ) {
$instance = new self();
}

return $instance;
}
}

MO_Admin_Notice::instance();
}
2 changes: 1 addition & 1 deletion classes/class-s2-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ public function s2init() {
add_filter( 'set-screen-option', array( &$this, 'subscribers_set_screen_option' ), 10, 3 );

// MailOptin admin notices
require_once S2PATH . 'classes/mo-notice.php';
require_once S2PATH . 'classes/class-mo-admin-notice.php';

// capture CSV export
if ( isset( $_POST['s2_admin'] ) && isset( $_POST['csv'] ) ) {
Expand Down
180 changes: 0 additions & 180 deletions classes/mo-notice.php

This file was deleted.

0 comments on commit d99abd9

Please sign in to comment.