Affiliates reCAPTCHA and input the Site Key and the Secret Key. * Version: 2.0.0 * Author: itthinx * Author URI: http://www.itthinx.com */ if ( !defined( 'ABSPATH' ) ) { exit; } /** * Plugin reCAPTCHA handler for the API v2. * Renders admin and handles captcha. */ class Affiliates_Recaptcha { /** * Adds action and filter hooks. */ public static function init() { add_action( 'affiliates_admin_menu', array( __CLASS__, 'affiliates_admin_menu' ) ); add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'plugin_action_links' ) ); if ( !apply_filters( 'affiliates_recaptcha_legacy', false ) ) { add_filter( 'affiliates_captcha_get', array( __CLASS__, 'affiliates_captcha_get' ), 10, 2 ); add_filter( 'affiliates_captcha_validate', array( __CLASS__, 'affiliates_captcha_validate' ), 10, 2 ); } else { require_once 'includes/class-affiliates-recaptcha-legacy.php'; add_filter( 'affiliates_captcha_get', array( 'Affiliates_Recaptcha_Legacy', 'affiliates_captcha_get' ), 10, 2 ); add_filter( 'affiliates_captcha_validate', array( 'Affiliates_Recaptcha_Legacy', 'affiliates_captcha_validate' ), 10, 2 ); } } /** * Adds a submenu item to the Affiliates menu for integration options. */ public static function affiliates_admin_menu() { $page = add_submenu_page( 'affiliates-admin', __( 'Affiliates reCAPTCHA', 'affiliates-recaptcha' ), __( 'reCAPTCHA', 'affiliates-recaptcha' ), AFFILIATES_ADMINISTER_OPTIONS, 'affiliates-admin-recaptcha', array( __CLASS__, 'settings' ) ); $pages[] = $page; add_action( 'admin_print_styles-' . $page, 'affiliates_admin_print_styles' ); add_action( 'admin_print_scripts-' . $page, 'affiliates_admin_print_scripts' ); } /** * Adds a link to our settings on the plugin entry. * * @param array $links * @return array */ public static function plugin_action_links( $links ) { if ( current_user_can( 'manage_options' ) ) { $_links = array(); $_links[] = sprintf( '%s', esc_url( admin_url( 'admin.php?page=affiliates-admin-recaptcha' ) ), esc_html( __( 'Settings', 'affiliates-recaptcha' ) ) ); $links = $_links + $links; } return $links; } /** * Renders the settings page. */ public static function settings() { if ( !current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Access denied.', 'affiliates-recaptcha' ) ); } if ( isset( $_POST['action'] ) && ( $_POST['action'] == 'save' ) && wp_verify_nonce( $_POST['affiliates-recaptcha'], 'admin' ) ) { $public_key = !empty( $_POST['public_key'] ) ? trim( strip_tags( $_POST['public_key'] ) ) : ''; $private_key = !empty( $_POST['private_key'] ) ? trim( strip_tags( $_POST['private_key'] ) ) : ''; delete_option( 'affiliates-recaptcha-public-key' ); delete_option( 'affiliates-recaptcha-private-key' ); add_option( 'affiliates-recaptcha-public-key', $public_key, '', 'no' ); add_option( 'affiliates-recaptcha-private-key', $private_key, '', 'no' ); echo '