| 1 |
<?php |
| 2 |
namespace WPAdminify\Inc\Classes\Notifications; |
| 3 |
|
| 4 |
use WPAdminify\Inc\Classes\Notifications\Base\User_Data; |
| 5 |
use WPAdminify\Inc\Classes\Notifications\Model\Notice; |
| 6 |
|
| 7 |
if ( ! class_exists( 'Subscribe' ) ) { |
| 8 |
/** |
| 9 |
* Subscribe Class |
| 10 |
* |
| 11 |
* Jewel Theme <support@jeweltheme.com> |
| 12 |
*/ |
| 13 |
class Subscribe extends Notice { |
| 14 |
|
| 15 |
use User_Data; |
| 16 |
|
| 17 |
public $color = 'warning'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Construct method |
| 21 |
* |
| 22 |
* @author Jewel Theme <support@jeweltheme.com> |
| 23 |
*/ |
| 24 |
public function __construct() { |
| 25 |
parent::__construct(); |
| 26 |
add_action( 'wp_ajax_jltwp_adminify_subscribe', array( $this, 'jltwp_adminify_subscribe' ) ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Subscribe method |
| 31 |
* |
| 32 |
* @author Jewel Theme <support@jeweltheme.com> |
| 33 |
*/ |
| 34 |
public function jltwp_adminify_subscribe() { |
| 35 |
check_ajax_referer( 'jltwp_adminify_subscribe_nonce' ); |
| 36 |
|
| 37 |
$name = ! empty( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; |
| 38 |
$email = ! empty( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; |
| 39 |
|
| 40 |
if ( ! is_email( $email ) ) { |
| 41 |
$email = get_bloginfo( 'admin_email' ); |
| 42 |
} |
| 43 |
|
| 44 |
$author_obj = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
| 45 |
$user_id = $author_obj->ID; |
| 46 |
|
| 47 |
// First Name & Last name . |
| 48 |
if ( ! empty( $name ) ) { |
| 49 |
$full_name = $name; |
| 50 |
} else { |
| 51 |
$full_name = $author_obj->display_name; |
| 52 |
} |
| 53 |
|
| 54 |
$response = $this->get_collect_data( $user_id, array( |
| 55 |
'first_name' => $full_name, |
| 56 |
'email' => $email, |
| 57 |
) ); |
| 58 |
|
| 59 |
if ( ! is_wp_error( $response ) && 200 === $response['response']['code'] && 'OK' === $response['response']['message'] ) { |
| 60 |
wp_send_json_success( 'Thanks for Subscribe!' ); |
| 61 |
} else { |
| 62 |
wp_send_json_error( "Couldn't Subscribe" ); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Notice Header |
| 68 |
* |
| 69 |
* @author Jewel Theme <support@jeweltheme.com> |
| 70 |
*/ |
| 71 |
public function notice_header() { |
| 72 |
return ''; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Notice footer |
| 77 |
* |
| 78 |
* @author Jewel Theme <support@jeweltheme.com> |
| 79 |
*/ |
| 80 |
public function notice_footer() { |
| 81 |
return ''; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Set Title |
| 86 |
* |
| 87 |
* @author Jewel Theme <support@jeweltheme.com> |
| 88 |
*/ |
| 89 |
public function set_title() { |
| 90 |
printf( |
| 91 |
'<h4>Wanna get some discount for %1$s? No Worries!! We got you!! Enter your email, we will send you the discount code?</h4>', |
| 92 |
esc_html__( 'WP Adminify', 'adminify' ) |
| 93 |
); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Notice Content |
| 98 |
* |
| 99 |
* @author Jewel Theme <support@jeweltheme.com> |
| 100 |
*/ |
| 101 |
public function notice_content() { |
| 102 |
$userdata = \wp_get_current_user(); |
| 103 |
?> |
| 104 |
<div class="notice notice-wp-adminify is-dismissible notice-plugin-review notice-<?php echo esc_attr( $this->color ); ?> wp-adminify-notice-<?php echo esc_attr( $this->get_id() ); ?>"> |
| 105 |
<button type="button" class="notice-dismiss wp-adminify-notice-dismiss"></button> |
| 106 |
<img width="70" height="70" src="<?php echo esc_url( WP_ADMINIFY_ASSETS_IMAGE . 'logos/menu-icon.svg' ); ?>" alt="<?php esc_attr_e( 'Logo', 'adminify' ); ?>"> |
| 107 |
<div class="wp-adminify-subscribe-content"> |
| 108 |
<?php $this->set_title(); ?> |
| 109 |
<form style="display:flex"> |
| 110 |
<div class="wp-adminify-plugin-subscribe-input"> |
| 111 |
<input type="text" id="name" name="name" placeholder="Name" value="<?php echo esc_attr( $userdata->display_name ); ?>"> |
| 112 |
</div> |
| 113 |
<div class="wp-adminify-plugin-subscribe-input" style="padding-right:20px;padding-left:10px;"> |
| 114 |
<input type="text" id="email" name="email" placeholder="Email" value="<?php echo esc_attr( $userdata->user_email ); ?>"> |
| 115 |
</div> |
| 116 |
<button type="submit" class="button button-primary wp-adminify-subscribe-btn"><?php esc_html_e( 'Get Discount', 'adminify' ); ?></button> |
| 117 |
</form> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
<?php |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Rate URL |
| 125 |
* |
| 126 |
* @author Jewel Theme <support@jeweltheme.com> |
| 127 |
*/ |
| 128 |
public function plugin_rate_url() { |
| 129 |
return 'https://wordpress.org/plugins/' . WP_ADMINIFY_SLUG; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Footer content |
| 134 |
* |
| 135 |
* @author Jewel Theme <support@jeweltheme.com> |
| 136 |
*/ |
| 137 |
public function footer_content() { |
| 138 |
?> |
| 139 |
<a class="button button-primary rate-plugin-button" href="<?php echo esc_url( $this->plugin_rate_url() ); ?>" rel="nofollow" target="_blank"> |
| 140 |
<?php echo esc_html__( 'Rate Now', 'adminify' ); ?> |
| 141 |
</a> |
| 142 |
<a class="button notice-review-btn review-later wp-adminify-notice-dismiss" href="#" rel="nofollow"> |
| 143 |
<?php echo esc_html__( 'Later', 'adminify' ); ?> |
| 144 |
</a> |
| 145 |
<a class="button notice-review-btn review-done wp-adminify-notice-disable" href="#" rel="nofollow"> |
| 146 |
<?php echo esc_html__( 'I already did', 'adminify' ); ?> |
| 147 |
</a> |
| 148 |
<?php |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Intervals |
| 153 |
* |
| 154 |
* @author Jewel Theme <support@jeweltheme.com> |
| 155 |
*/ |
| 156 |
public function intervals() { |
| 157 |
return array( 5, 4, 10, 20, 15, 25, 30, 40, 60, 90, 150 ); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Core Script |
| 162 |
* |
| 163 |
* @param [type] $trigger_time . |
| 164 |
* |
| 165 |
* @return void |
| 166 |
* @author Jewel Theme <support@jeweltheme.com> |
| 167 |
*/ |
| 168 |
public function core_script( $trigger_time ) { |
| 169 |
parent::core_script( $trigger_time ); |
| 170 |
?> |
| 171 |
|
| 172 |
<script> |
| 173 |
jQuery(document).on('submit', '.wp-adminify-notice-subscribe .wp-adminify-subscribe-content form', function(e) { |
| 174 |
|
| 175 |
e.preventDefault(); |
| 176 |
|
| 177 |
let form = jQuery(this); |
| 178 |
let name = form.find('input[name=name]').val(); |
| 179 |
let email = form.find('input[name=email]').val(); |
| 180 |
let formWrapper = form.closest('.wp-adminify-subscribe-content'); |
| 181 |
|
| 182 |
formWrapper.css('opacity', '0.4').find('button').prop('disabled', true); |
| 183 |
|
| 184 |
jQuery.ajax({ |
| 185 |
url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', |
| 186 |
method: 'POST', |
| 187 |
crossDomain: true, |
| 188 |
data: { |
| 189 |
action: 'jltwp_adminify_subscribe', |
| 190 |
_wpnonce: '<?php echo esc_js( wp_create_nonce( 'jltwp_adminify_subscribe_nonce' ) ); ?>', |
| 191 |
name: name, |
| 192 |
email: email, |
| 193 |
} |
| 194 |
}) |
| 195 |
.done(function(response) { |
| 196 |
formWrapper.hide().after('<p class="wp-adminify--notice-message"><strong>' + response.data + '</strong><p>'); |
| 197 |
let subsTimeout = setTimeout(function() { |
| 198 |
jltwp_adminify_notice_action(null, form, 'disable'); |
| 199 |
clearTimeout(subsTimeout); |
| 200 |
}, 1500); |
| 201 |
}) |
| 202 |
.always(function() { |
| 203 |
formWrapper.css('opacity', '1').find('button').prop('disabled', false); |
| 204 |
}) |
| 205 |
|
| 206 |
}); |
| 207 |
</script> |
| 208 |
|
| 209 |
<?php |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
|