/** * Load the frontend scripts and styles * * @since 1.0 * @return void */ function affwp_frontend_scripts_and_styles() { global $post; if (!is_object($post)) { return; } if (has_shortcode($post->post_content, 'affiliate_area') || has_shortcode($post->post_content, 'affiliate_area') || apply_filters('affwp_force_frontend_scripts', false)) { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('affwp-frontend', AFFILIATEWP_PLUGIN_URL . 'assets/js/frontend' . $suffix . '.js', array('jquery'), AFFILIATEWP_VERSION); wp_localize_script('affwp-frontend', 'affwp_vars', array('affwp_version' => AFFILIATEWP_VERSION, 'permalinks' => get_option('permalink_structure'), 'pretty_affiliate_urls' => affwp_is_pretty_referral_urls(), 'currency_sign' => affwp_currency_filter(''), 'currency_pos' => affiliate_wp()->settings->get('currency_position', 'before'))); wp_enqueue_style('affwp-forms', AFFILIATEWP_PLUGIN_URL . 'assets/css/forms' . $suffix . '.css', AFFILIATEWP_VERSION); wp_enqueue_style('dashicons'); if (affwp_is_recaptcha_enabled()) { wp_enqueue_script('affwp-recaptcha', 'https://www.google.com/recaptcha/api.js', array(), AFFILIATEWP_VERSION); } } }
if (!empty($terms_of_use)) { ?> <p> <label class="affwp-tos" for="affwp-tos"> <input id="affwp-tos" class="required" type="checkbox" name="affwp_tos" /> <?php printf(__('Agree to our <a href="%s" target="_blank">Terms of Use</a>', 'affiliate-wp'), esc_url(get_permalink(affiliate_wp()->settings->get('terms_of_use')))); ?> </label> </p> <?php } ?> <?php if (affwp_is_recaptcha_enabled()) { ?> <div class="g-recaptcha" data-sitekey="<?php echo esc_attr(affiliate_wp()->settings->get('recaptcha_site_key')); ?> "></div> <p> <input type="hidden" name="g-recaptcha-remoteip" value=<?php echo esc_attr(affiliate_wp()->tracking->get_ip()); ?> /> </p> <?php } ?>
/** * Verify reCAPTCHA response is valid using a POST request to the Google API * * @access private * @since 1.7 * @param array $data * @return boolean */ private function recaptcha_response_is_valid($data) { if (!affwp_is_recaptcha_enabled() || empty($data['g-recaptcha-response']) || empty($data['g-recaptcha-remoteip'])) { return false; } $verify = wp_safe_remote_post('https://www.google.com/recaptcha/api/siteverify', array('body' => array('secret' => affiliate_wp()->settings->get('recaptcha_secret_key'), 'response' => $data['g-recaptcha-response'], 'remoteip' => $data['g-recaptcha-remoteip']))); $verify = json_decode(wp_remote_retrieve_body($verify)); return !empty($verify->success) && true === $verify->success; }