| 1 |
<?php |
| 2 |
defined('ABSPATH') or exit('Restricted access!'); |
| 3 |
?> |
| 4 |
<div class="wrap"> |
| 5 |
<h1>Connect Nudgify to your website</h1> |
| 6 |
|
| 7 |
<hr /> |
| 8 |
|
| 9 |
<h2>Settings</h2> |
| 10 |
|
| 11 |
<form id="nudgify-form-options" name="dofollow" action="options.php" method="post"> |
| 12 |
<?php settings_errors(); ?> |
| 13 |
<?php echo wp_kses_post(nudgify_feedback_message('connect')); ?> |
| 14 |
|
| 15 |
<?php settings_fields(NudgifyOptions::OPTIONS_GROUP); ?> |
| 16 |
<?php do_settings_sections(NudgifyOptions::OPTIONS_GROUP); ?> |
| 17 |
<input type="hidden" name="<?php echo esc_attr(NudgifyOptions::SAVED); ?>" id="<?php echo esc_attr(NudgifyOptions::SAVED); ?>" data-initial="<?php echo esc_attr(get_option(NudgifyOptions::SAVED, time())); ?>" value="<?php echo esc_attr(get_option(NudgifyOptions::SAVED, time())); ?>" /> |
| 18 |
|
| 19 |
<?php if (get_option(NudgifyOptions::CONNECTED)) { ?> |
| 20 |
<div class="notice notice-success"> |
| 21 |
<p><strong>Your site is connected to Nudgify.</strong></p> |
| 22 |
</div> |
| 23 |
<?php } ?> |
| 24 |
|
| 25 |
|
| 26 |
<table class="form-table"> |
| 27 |
<tr> |
| 28 |
<th> |
| 29 |
<label for="<?php echo esc_attr(NudgifyOptions::ENABLED); ?>">Enable Nudgify</label> |
| 30 |
</th> |
| 31 |
<td> |
| 32 |
<select id="<?php echo esc_attr(NudgifyOptions::ENABLED); ?>" name="<?php echo esc_attr(NudgifyOptions::ENABLED); ?>" data-initial="<?php echo esc_attr(get_option(NudgifyOptions::ENABLED)); ?>" style="width: 10em;"> |
| 33 |
<option value="1" <?php echo (get_option(NudgifyOptions::ENABLED) == 1) ? 'selected' : ''; ?>>Yes</option> |
| 34 |
<option value="0" <?php echo (get_option(NudgifyOptions::ENABLED) == 0) ? 'selected' : ''; ?>>No</option> |
| 35 |
</select> |
| 36 |
</td> |
| 37 |
</tr> |
| 38 |
<tr class="depends-on-enabled <?php echo get_option(NudgifyOptions::ENABLED) ? '' : 'hidden'; ?>"> |
| 39 |
<th> |
| 40 |
<label for="<?php echo esc_attr(NudgifyOptions::SITE_KEY); ?>">Site Key</label> |
| 41 |
</th> |
| 42 |
<td> |
| 43 |
<input id="<?php echo esc_attr(NudgifyOptions::SITE_KEY); ?>" class="regular-text code" name="<?php echo esc_attr(NudgifyOptions::SITE_KEY); ?>" type="text" value="<?php echo esc_attr(get_option(NudgifyOptions::SITE_KEY)); ?>" /> |
| 44 |
|
| 45 |
<p class="description"> |
| 46 |
Go to your the <a href="https://app.nudgify.com/integrations/wordpress" target="_blank" rel="noopener">Wordpress Integration page</a> for your current site to find your Site Key. |
| 47 |
</p> |
| 48 |
</td> |
| 49 |
</tr> |
| 50 |
<tr class="depends-on-enabled <?php echo get_option(NudgifyOptions::ENABLED) ? '' : 'hidden'; ?>"> |
| 51 |
<th> |
| 52 |
<label for="<?php echo esc_attr(NudgifyOptions::API_TOKEN); ?>">API Key</label> |
| 53 |
</th> |
| 54 |
<td> |
| 55 |
<input id="<?php echo esc_attr(NudgifyOptions::API_TOKEN); ?>" class="regular-text code" name="<?php echo esc_attr(NudgifyOptions::API_TOKEN); ?>" type="text" value="<?php echo esc_attr(get_option(NudgifyOptions::API_TOKEN)); ?>" /> |
| 56 |
|
| 57 |
<p class="description"> |
| 58 |
Go to your <a href="https://app.nudgify.com/settings" target="_blank" rel="noopener">Profile Details</a> to find your API Key. |
| 59 |
</p> |
| 60 |
</td> |
| 61 |
</tr> |
| 62 |
<tr class="depends-on-enabled <?php echo get_option(NudgifyOptions::ENABLED) ? '' : 'hidden'; ?>"> |
| 63 |
<th> |
| 64 |
<label for="<?php echo esc_attr(NudgifyOptions::AUTOSYNC); ?>">Sync new orders to Nudgify</label> |
| 65 |
</th> |
| 66 |
<td> |
| 67 |
<select id="<?php echo esc_attr(NudgifyOptions::AUTOSYNC); ?>" name="<?php echo esc_attr(NudgifyOptions::AUTOSYNC); ?>" style="width: 10em;"> |
| 68 |
<option value="1" <?php echo (get_option(NudgifyOptions::AUTOSYNC) == 1) ? 'selected' : ''; ?>>Yes</option> |
| 69 |
<option value="0" <?php echo (get_option(NudgifyOptions::AUTOSYNC) == 0) ? 'selected' : ''; ?>>No</option> |
| 70 |
</select> |
| 71 |
<p class="description"> |
| 72 |
Enable this option to automatically sync new WooCommerce orders with Nudgify |
| 73 |
</p> |
| 74 |
</td> |
| 75 |
</tr> |
| 76 |
<tr> |
| 77 |
<th></th> |
| 78 |
<td> |
| 79 |
<p class="depends-on-enabled submit <?php echo get_option(NudgifyOptions::ENABLED) ? '' : 'hidden'; ?>"> |
| 80 |
<input type="submit" name="submit" id="nudgify-setup" class="button button-primary" value="Set up connection"> |
| 81 |
</p> |
| 82 |
<p class="depends-on-enabled submit <?php echo get_option(NudgifyOptions::ENABLED) ? 'hidden' : ''; ?>"> |
| 83 |
<input type="submit" name="submit" id="nudgify-submit" class="button button-primary" value="Save settings"> |
| 84 |
</p> |
| 85 |
</td> |
| 86 |
</tr> |
| 87 |
</table> |
| 88 |
</form> |
| 89 |
|
| 90 |
<?php if (nudgify_woocommerce_enabled()) { ?> |
| 91 |
<div class="depends-on-enabled <?php echo get_option(NudgifyOptions::ENABLED) ? '' : 'hidden'; ?>"> |
| 92 |
<hr> |
| 93 |
<h2>Sync orders</h2> |
| 94 |
<?php echo wp_kses_post(nudgify_feedback_message('manualsync')); ?> |
| 95 |
<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post" id="nudgify-form-manualsync"> |
| 96 |
<input type="hidden" name="action" value="<?php echo esc_attr(NudgifyOptions::DO_MANUAL_SYNC); ?>" /> |
| 97 |
<input type="hidden" name="nudgify_manual_sync_nonce" value="<?php echo esc_attr(wp_create_nonce('nudgify_manual_sync_nonce')); ?>" /> |
| 98 |
<table class="form-table"> |
| 99 |
<tr> |
| 100 |
<th></th> |
| 101 |
<td> |
| 102 |
<?php submit_button('Manually sync orders'); ?> |
| 103 |
<p class="description"> |
| 104 |
This will send the last 30 orders to Nudgify |
| 105 |
</p> |
| 106 |
</td> |
| 107 |
</tr> |
| 108 |
<tr> |
| 109 |
<td colspan="2"> |
| 110 |
<p style="background: #f0f0f1; padding: 10px; border-left: 4px solid #2271b1;"> |
| 111 |
<strong>Debug Info:</strong><br> |
| 112 |
Action: <code><?php echo esc_html(NudgifyOptions::DO_MANUAL_SYNC); ?></code><br> |
| 113 |
Form submits to: <code><?php echo esc_html(admin_url('admin-post.php')); ?></code><br> |
| 114 |
Expected URL: <code><?php echo esc_html(admin_url('admin-post.php?action='.NudgifyOptions::DO_MANUAL_SYNC)); ?></code> |
| 115 |
</p> |
| 116 |
</td> |
| 117 |
</tr> |
| 118 |
<tr> |
| 119 |
<td></td> |
| 120 |
<td class="nudgify-feedback"></td> |
| 121 |
</tr> |
| 122 |
</table> |
| 123 |
</form> |
| 124 |
</div> |
| 125 |
<?php } ?> |
| 126 |
<div class="nudgify-rating-wrapper" style="background: #fff; border: 1px solid #c3c4c7; border-left-width: 4px; box-shadow: 0 1px 1px rgb(0 0 0 / 4%); padding: 1px 12px; border-left-color: #f4c056;"> |
| 127 |
<div class="nudgify-rating-inner-container" style="display: flex;"> |
| 128 |
<div class="nudgify-rating-icon" style="padding: 20px;"> |
| 129 |
<svg fill="#F4C056" height="40" width="40" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 511.987 511.987" xml:space="preserve"> |
| 130 |
<g> |
| 131 |
<g> |
| 132 |
<path |
| 133 |
d="M510.991,185.097c-2.475-7.893-9.301-13.632-17.515-14.72l-148.843-19.84L275.087,11.316 |
| 134 |
c-7.211-14.464-30.976-14.464-38.187,0l-69.547,139.221l-148.843,19.84c-8.213,1.088-15.04,6.827-17.515,14.72 |
| 135 |
c-2.496,7.872-0.213,16.512,5.867,22.101l107.392,98.923L85.604,486.857c-1.365,8.469,2.517,16.96,9.835,21.483 |
| 136 |
c7.339,4.501,16.661,4.203,23.616-0.811l136.939-97.792l136.939,97.792c3.691,2.667,8.043,3.989,12.395,3.989 |
| 137 |
c3.883,0,7.765-1.067,11.221-3.179c7.317-4.523,11.2-13.013,9.835-21.483l-28.651-180.736l107.392-98.923 |
| 138 |
C511.204,201.609,513.487,192.969,510.991,185.097z" |
| 139 |
></path> |
| 140 |
</g> |
| 141 |
</g> |
| 142 |
</svg> |
| 143 |
</div> |
| 144 |
<div class="nudgify-rating-info" style="margin-left:20px;"> |
| 145 |
<h3 style="margin-bottom: 10px !important;">Your site is connected to Nudgify.</h3> |
| 146 |
<span> |
| 147 |
If you like the Nudgify plugin, we'd love to hear from you! Please consider leaving a review to help more people discover Nudgify. We really appreciate it! |
| 148 |
</span> |
| 149 |
</div> |
| 150 |
<div class="nudgify-rating-btn" style="margin:auto; margin-left:40px;"> |
| 151 |
<a href="https://wordpress.org/plugins/nudgify/#reviews" target="_blank" class="button button-primary">Rate Nudgify</a> |
| 152 |
</div> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
</div> |
| 156 |
<script> |
| 157 |
jQuery('#nudgify-form-manualsync').on('submit', function(event) { |
| 158 |
event.preventDefault(); |
| 159 |
var form = jQuery('#nudgify-form-manualsync'); |
| 160 |
var button = form.find('input[type=submit]'); |
| 161 |
var buttonText = button.val(); |
| 162 |
var feedback = form.find('.nudgify-feedback'); |
| 163 |
|
| 164 |
// Get the action value from hidden input |
| 165 |
var actionValue = form.find('input[name="action"]').val(); |
| 166 |
var ajaxEndpoint = window.ajaxurl || '<?php echo esc_js(admin_url('admin-ajax.php')); ?>'; |
| 167 |
var ajaxUrl = ajaxEndpoint + '?action=' + actionValue; |
| 168 |
|
| 169 |
console.log('[Nudgify AJAX] Submitting to:', ajaxUrl); |
| 170 |
console.log('[Nudgify AJAX] Form data:', form.serialize()); |
| 171 |
|
| 172 |
jQuery.ajax({ |
| 173 |
type: "POST", |
| 174 |
url: ajaxUrl, |
| 175 |
data: form.serialize(), |
| 176 |
beforeSend: function() { |
| 177 |
button.prop('disabled', true); |
| 178 |
button.val('Syncing orders ...'); |
| 179 |
feedback.html(''); |
| 180 |
}, |
| 181 |
success: function(data) { |
| 182 |
console.log('[Nudgify AJAX] Success response:', data); |
| 183 |
button.prop('disabled', false); |
| 184 |
button.val(buttonText); |
| 185 |
feedback.html(data); |
| 186 |
}, |
| 187 |
error: function(xhr, status, error) { |
| 188 |
console.error('[Nudgify AJAX] Error:', status, error); |
| 189 |
console.error('[Nudgify AJAX] Response:', xhr.responseText); |
| 190 |
button.prop('disabled', false); |
| 191 |
button.val(buttonText); |
| 192 |
feedback.html('<div class="notice notice-error"><p>Error: ' + error + '</p></div>'); |
| 193 |
} |
| 194 |
}); |
| 195 |
}); |
| 196 |
|
| 197 |
jQuery('#nudgify-form-options').on('submit', function() { |
| 198 |
var button = jQuery('#nudgify-form-options').find('#nudgify-setup'); |
| 199 |
button.prop('disabled', true); |
| 200 |
button.val('Connecting ...'); |
| 201 |
}); |
| 202 |
|
| 203 |
jQuery('#<?php echo esc_js(NudgifyOptions::SITE_KEY); ?>,#<?php echo esc_js(NudgifyOptions::API_TOKEN); ?>').on('change', function(event) { |
| 204 |
jQuery('#<?php echo esc_js(NudgifyOptions::SAVED); ?>').val(Date.now()); |
| 205 |
}); |
| 206 |
|
| 207 |
jQuery('#<?php echo esc_js(NudgifyOptions::ENABLED); ?>').on('change', function(event) { |
| 208 |
if (event.target.value) { |
| 209 |
jQuery('#<?php echo esc_js(NudgifyOptions::SAVED); ?>').val(Date.now()); |
| 210 |
} |
| 211 |
jQuery('.depends-on-enabled').toggleClass('hidden'); |
| 212 |
}); |
| 213 |
</script> |
| 214 |
|