Core
5 days ago
Util
5 days ago
Check_Email_Encode_Tab.php
5 days ago
Check_Email_Notify_Tab.php
5 days ago
Check_Email_SMTP_Tab.php
5 days ago
class-check-email-header-parser.php
5 days ago
class-check-email-log-autoloader.php
5 days ago
class-check-email-newsletter.php
5 days ago
deactivate-feedback.php
5 days ago
helper-function.php
5 days ago
install.php
5 days ago
class-check-email-newsletter.php
125 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Check_Email_Newsletter class |
| 4 | * |
| 5 | * @author Magazine3 |
| 6 | * @category Admin |
| 7 | * @path includes/class-check-email-newsletter |
| 8 | * @Version 1.0.11 |
| 9 | */ |
| 10 | |
| 11 | |
| 12 | // Exit if accessed directly. |
| 13 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 14 | |
| 15 | class Check_Email_Newsletter { |
| 16 | |
| 17 | public function __construct () { |
| 18 | add_filter( 'ck_mail_localize_filter',array($this,'ck_mail_add_localize_footer_data'),10,2); |
| 19 | add_action( 'admin_enqueue_scripts', array($this, 'ck_mail_enqueue_newsletter_js') ); |
| 20 | add_action('wp_ajax_ck_mail_subscribe_to_news_letter', array($this, 'ck_mail_subscribe_to_news_letter')); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Load css and js files |
| 25 | * @since 2.4.6 |
| 26 | * */ |
| 27 | public function ck_mail_enqueue_newsletter_js(){ |
| 28 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 29 | |
| 30 | $script_data = array( |
| 31 | 'using_ck_mail' => esc_html__( 'Thanks for using Check & Log Email!', 'check-email' ), |
| 32 | 'do_you_want' => esc_html__( 'Do you want the latest updates on ', 'check-email' ), |
| 33 | 'ck_mail_update' => esc_html__( 'Check & Log Email update', 'check-email' ), |
| 34 | 'before_others' => esc_html__( ' before others and some best resources on monetization in a single email? - Free just for users of Check & Log Email!', 'check-email' ), |
| 35 | 'ck_mail_security_nonce' => wp_create_nonce( 'ck_mail_ajax_check_nonce' ), |
| 36 | 'ajax_url' => admin_url( 'admin-ajax.php' ) |
| 37 | ); |
| 38 | |
| 39 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound |
| 40 | $script_data = apply_filters('ck_mail_localize_filter',$script_data,'ck_mail_localize_data'); |
| 41 | |
| 42 | $check_email = wpchill_check_email(); |
| 43 | $plugin_dir_url = plugin_dir_url( $check_email->get_plugin_file() ); |
| 44 | |
| 45 | wp_register_script( 'ck_mail-newsletter-script', $plugin_dir_url . 'assets/js/admin/ck_mail-newsletter-script' . $suffix . '.js', array( 'jquery' ), CK_MAIL_VERSION,true); |
| 46 | wp_localize_script( 'ck_mail-newsletter-script', 'ck_mail_localize_data', $script_data ); |
| 47 | wp_enqueue_script( 'ck_mail-newsletter-script' ); |
| 48 | } |
| 49 | |
| 50 | public function ck_mail_add_localize_footer_data($object, $object_name){ |
| 51 | |
| 52 | $dismissed = explode (',', get_user_meta (wp_get_current_user()->ID, 'dismissed_wp_pointers', true)); |
| 53 | $do_tour = !in_array ('ck_mail_subscribe_pointer', $dismissed); |
| 54 | |
| 55 | if ($do_tour) { |
| 56 | wp_enqueue_style ('wp-pointer'); |
| 57 | wp_enqueue_script ('wp-pointer'); |
| 58 | } |
| 59 | |
| 60 | if($object_name == 'ck_mail_localize_data'){ |
| 61 | |
| 62 | global $current_user; |
| 63 | $tour = array (); |
| 64 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information. |
| 65 | $tab = isset($_GET['tab']) ? sanitize_text_field( wp_unslash($_GET['tab'])) : ''; |
| 66 | |
| 67 | if (!array_key_exists($tab, $tour)) { |
| 68 | $object['do_tour'] = $do_tour; |
| 69 | $object['get_home_url'] = get_home_url(); |
| 70 | $object['current_user_email'] = $current_user->user_email; |
| 71 | $object['current_user_name'] = $current_user->display_name; |
| 72 | $object['displayID'] = '#toplevel_page_check-email-status'; |
| 73 | $object['button1'] = esc_html__('No Thanks', 'check-email'); |
| 74 | $object['button2'] = false; |
| 75 | $object['function_name'] = ''; |
| 76 | } |
| 77 | } |
| 78 | return $object; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Process newsletter |
| 83 | * @since 1.0.11 |
| 84 | * */ |
| 85 | public function ck_mail_subscribe_to_news_letter() { |
| 86 | |
| 87 | if( ! current_user_can( 'manage_options' ) ) { |
| 88 | die( '-1' ); |
| 89 | } |
| 90 | if ( ! isset( $_POST['ck_mail_security_nonce'] ) ){ |
| 91 | die( '-1' ); |
| 92 | } |
| 93 | if ( !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ck_mail_security_nonce'] ) ), 'ck_mail_ajax_check_nonce' ) ){ |
| 94 | die( '-1' ); |
| 95 | } |
| 96 | |
| 97 | $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; |
| 98 | $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email']) ) : ''; |
| 99 | $website = isset( $_POST['website'] ) ? sanitize_text_field( wp_unslash( $_POST['website'] ) ):''; |
| 100 | |
| 101 | if ( $email ) { |
| 102 | |
| 103 | $api_url = 'http://magazine3.company/wp-json/api/central/email/subscribe'; |
| 104 | |
| 105 | $api_params = array( |
| 106 | 'name' => $name, |
| 107 | 'email' => $email, |
| 108 | 'website' => $website, |
| 109 | 'type' => 'checkmail', |
| 110 | ); |
| 111 | |
| 112 | $response = wp_remote_post( $api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
| 113 | $response = wp_remote_retrieve_body( $response ); |
| 114 | $response = json_decode( $response, true ); |
| 115 | echo wp_json_encode( array( 'response' => $response['response'] ) ); |
| 116 | |
| 117 | }else{ |
| 118 | echo wp_json_encode( array( 'response' => esc_html__( 'Email id required', 'check-email' ) ) ); |
| 119 | } |
| 120 | |
| 121 | wp_die(); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | new Check_Email_Newsletter(); |