1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254:
<?php
class Inbound_Notifications {
public function __construct() {
self::load_hooks();
}
public static function load_hooks() {
if (!defined('INBOUND_PRO_PATH')) {
add_filter( 'plugin_row_meta', array( __CLASS__ , 'filter_quick_links' ), 10, 2 );
add_action('admin_notices', array(__CLASS__, 'help_us_translate'));
add_action('admin_notices', array(__CLASS__, 'download_leads'));
add_action('admin_notices', array( __CLASS__, 'upgrade_to_pro' ));
}
add_action( 'wp_ajax_inbound_dismiss_ajax', array(__CLASS__, 'dismiss_notice'));
}
public static function filter_quick_links( $links, $file ) {
$plugins = array(
'landing-pages/landing-pages.php',
'cta/calls-to-action.php',
'leads/leads.php',
);
if ( in_array( $file , $plugins ) ) {
return array_merge(
$links,
array( '<a href="http://www.inboundnow.com/upgrade">'.__( 'UPGRADE TO PRO (FREE)' , 'inbound-pro' ) .'</a>' )
);
}
return $links;
}
public static function help_us_translate() {
global $pagenow;
global $current_user;
$message_id = 'translate';
if( !current_user_can('activate_plugins') ) {
return;
}
$post_types = array('landing-page', 'wp-call-to-action', 'wp-lead');
$type = get_post_type(get_the_ID());
if ( !in_array($type, $post_types)) {
return;
}
if (self::check_if_viewed($message_id)) {
return;
}
echo '<div class="updated" id="inbound_notice_'.$message_id.'">
<h2>' . __('Help Translate Inbound Now Marketing Plugins', 'inbound-pro') . '</h2>
<p style="width:80%;">' . sprintf(__('Help translate Inbound Now\'s marketing plugins to your %s native langauge %s!', 'inbound-pro'), '<a href="http://docs.inboundnow.com/guide/inbound-translations-project/" target="_blank">', '</a>') . '</p>
<a class="button button-primary button-large" href="http://www.inboundnow.com/translate-inbound-now/" target="_blank">' . __('Help Translate the plugins', 'inbound-pro') . '</a>
<a class="button button-large inbound_dismiss" href="#" id="'.$message_id.'" data-notification-id="'.$message_id.'" >' . __('No Thanks', 'inbound-pro') . '</a>
<br><br>
</div>';
self::javascript_dismiss_notice();
}
public static function upgrade_to_pro() {
$message_id = 'upgrade_to_pro';
if( !current_user_can('activate_plugins') ) {
return;
}
$post_types = array('landing-page', 'wp-call-to-action', 'wp-lead');
$type = get_post_type(get_the_ID());
if ( !in_array($type, $post_types)) {
return;
}
if (self::check_if_viewed($message_id)) {
return;
}
echo '<div class="updated" id="inbound_notice_'.$message_id.'">
<h1>A friendly message from Inbound Now</h1>
<p style="width:80%;">
'.__('Hello there!' , 'inbound-pro' ) .'
</p>
<p style="width:80%;">
' . __('We noticed you are using a stand alone version of an Inbound Now plugin. Did you know we provide a more powerful free plugin that includes this one and offers a lot more? ' , 'inbound-pro' ) .'
</p>
<p style="width:80%;">
' . __('It\'s free, and we invite you to try it.' , 'inbound-pro' ) .'
</p>
<br>
<a class="button button-primary button-large" href="http://www.inboundnow.com/upgrade/" target="_blank">' . __('Upgrade', 'inbound-pro') . '</a>
<a class="button button-default button-large inbound_dismiss" href="#" id="'.$message_id.'" data-notification-id="'.$message_id.'" >' . __('Dismiss this message', 'inbound-pro') . '</a>
<br>
<br>
</div>';
self::javascript_dismiss_notice();
}
public static function download_leads() {
$screen = get_current_screen();
if (!isset($screen) || $screen->id !='edit-inbound-forms' || class_exists('Inbound_Leads_Plugin') ) {
return;
}
if( !current_user_can('activate_plugins') ) {
return;
}
$message_id = 'download_leads';
if (self::check_if_viewed($message_id)) {
return;
}
echo '<div class="updated" id="inbound_notice_'.$message_id.'">
<h1>'.__('Want to view collected data?' , 'inbound-pro' ) .'</h1>
<p style="width:80%;">
' . __('You are collecting data, why not review it? Our Leads plugin helps you mange the data you collect with these forms. Leads plugin is available via the WordPress plugin\'s directory as well as included in our free Inbound Pro plugin. We recommend Inbound Pro because it provides better settings management and additional free features. ' , 'inbound-pro' ) .'
</p>
<p style="width:80%;">
' . __('Both are free, and we invite you to try them!' , 'inbound-pro' ) .'
</p>
<br>
<a class="button button-primary button-large" href="'.admin_url('plugin-install.php?tab=search&s=leads').'" >' . __('Download Leads Plugin', 'inbound-pro') . '</a>
<a class="button button-primary button-large" href="http://www.inboundnow.com/upgrade/" target="_blank">' . __('Download Inbound Pro (recommended)', 'inbound-pro') . '</a>
<a class="button button-default button-large inbound_dismiss" href="#" id="'.$message_id.'" data-notification-id="'.$message_id.'" >' . __('Dismiss this message', 'inbound-pro') . '</a>
<br>
<br>
</div>';
self::javascript_dismiss_notice();
}
public static function check_if_viewed( $notificaiton_id ) {
global $current_user;
$user_id = $current_user->ID;
return get_user_meta($user_id, 'inbound_notification_' . $notificaiton_id ) ;
}
public static function javascript_dismiss_notice() {
global $current_user;
$user_id = $current_user->ID;
?>
<script type="text/javascript">
jQuery( document ).ready(function() {
jQuery('body').on('click' , '.inbound_dismiss' , function() {
var notification_id = jQuery( this ).data('notification-id');
jQuery('#inbound_notice_' + notification_id).hide();
jQuery.ajax({
type: 'POST',
url: ajaxurl,
context: this,
data: {
action: 'inbound_dismiss_ajax',
notification_id: notification_id,
user_id: '<?php echo $user_id; ?>'
},
success: function (data) {
},
error: function (MLHttpRequest, textStatus, errorThrown) {
alert("Ajax not enabled");
}
});
})
});
</script>
<?php
}
public static function dismiss_notice() {
update_user_meta( intval($_REQUEST['user_id']), 'inbound_notification_' . sanitize_text_field($_REQUEST['notification_id']) , 'viewed' ) ;
exit;
}
}
new Inbound_Notifications;