notices.php (4220B)
1 <?php 2 /** 3 * Adds a notice to the plugins page 4 */ 5 6 $extendifySdkNoticesKey = 'extendify_subscribe_to_extendify'; 7 $extendifySdkUrl = add_query_arg( 8 [ 9 'utm_source' => rawurlencode(sanitize_text_field(wp_unslash($GLOBALS['extendifySdkSourcePlugin']))), 10 'utm_medium' => 'admin', 11 'utm_campaign' => 'notice', 12 'utm_content' => 'launch60', 13 ], 14 'https://extendify.com/pricing' 15 ); 16 $extendifySdkNoticesNonce = wp_create_nonce($extendifySdkNoticesKey); 17 18 add_action( 19 'admin_notices', 20 function () use ($extendifySdkNoticesKey, $extendifySdkNoticesNonce, $extendifySdkUrl) { 21 $currentPage = get_current_screen(); 22 if (!$currentPage || !in_array($currentPage->base, ['plugins'], true)) { 23 return; 24 } 25 26 // In short, the notice will always show until they press dismiss. 27 if (!get_user_option($extendifySdkNoticesKey)) { ?> 28 <div id="<?php echo esc_attr($extendifySdkNoticesKey); ?>" class="notice notice-info" 29 style="display:flex;align-items:stretch;justify-content:space-between;position:relative"> 30 <div style="display:flex;align-items:center;position:relative"> 31 <div style="margin-right:1.5rem;"> 32 <svg width="60" height="60" viewBox="0 0 103 103" fill="none" xmlns="http://www.w3.org/2000/svg"> 33 <title>Extendify Logo</title> 34 <rect y="25.75" width="70.8125" height="77.25" fill="black" /> 35 <rect x="45.0625" width="57.9375" height="57.9375" fill="#37C2A2" /> 36 </svg> 37 </div> 38 <div> 39 <h3 style="margin-bottom:0.25rem;"> 40 <?php esc_html_e('Special offer: Save 60% off Extendify Pro', 'extendify-sdk'); ?></h3> 41 <div style="max-width:850px;"> 42 <p> 43 <?php esc_html_e('Thank you for using Editor Plus by Extendify. For a limited time, sign up for Extendify Pro and save 60% using coupon code launch60. Extendify Pro gives full access to thousands of templates and patterns designed for the Gutenberg block editor.', 'extendify-sdk'); ?> 44 </p> 45 <p style="max-width:850px;"> 46 <?php 47 // translators: %s surrounding the word 'here' and is wrapped with <a>. 48 printf(esc_html__('Click %1$shere%2$s to sign up today!', 'extendify-sdk'), '<a target="_blank" href="' . esc_url($extendifySdkUrl) . '">', '</a>'); ?> 49 </p> 50 </div> 51 </div> 52 </div> 53 <div style="margin:5px -5px 0 0;"> 54 <button 55 style="max-width:15px;border:0;background:0;color: #7b7b7b;white-space:nowrap;cursor: pointer;padding: 0" 56 type="button" 57 title="<?php esc_attr_e('Dismiss notice', 'extendify-sdk'); ?>" 58 aria-label="<?php esc_attr_e('Dismiss Extendify notice', 'extendify-sdk'); ?>" 59 onclick="jQuery('#<?php echo esc_attr($extendifySdkNoticesKey); ?>').remove();jQuery.post(window.ajaxurl, {action: 'handle_<?php echo esc_attr($extendifySdkNoticesKey); ?>', _wpnonce: '<?php echo esc_attr($extendifySdkNoticesNonce); ?>' });"> 60 <svg width="15" height="15" style="width:100%" xmlns="http://www.w3.org/2000/svg" fill="none" 61 viewBox="0 0 24 24" stroke="currentColor"> 62 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" /> 63 </svg> 64 </button> 65 </div> 66 </div> 67 <?php 68 }//end if 69 } 70 ); 71 72 add_action( 73 'wp_ajax_handle_' . $extendifySdkNoticesKey, 74 function () use ($extendifySdkNoticesKey) { 75 if (!isset($_POST['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'])), $extendifySdkNoticesKey)) { 76 wp_send_json_error( 77 ['message' => esc_html__('The security check failed. Please refresh the page and try again.', 'extendify-sdk')], 78 401 79 ); 80 } 81 82 update_user_option(get_current_user_id(), $extendifySdkNoticesKey, time()); 83 wp_send_json_success(); 84 } 85 );