name = 'recaptcha'; /** * label (string) Multiple words, can include spaces, visible when selecting a field type */ $this->label = __('reCAPTCHA', 'acf-recaptcha'); /** * category (string) basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME */ $this->category = 'Custom'; /** * defaults (array) Array of default settings which are merged into the field object. These are used later in settings */ $this->defaults = array( 'site_key' => '', 'secret_key' => '', 're_theme' => 'light', 're_type' => 'image', 're_size' => 'normal', ); $this->l10n = array( 'error' => __('Please click the checkbox.', 'acf-recaptcha'), ); parent::__construct(); } /* * render_field_settings() * * Create extra settings for your field. These are visible when editing a field * * @type action * @since 3.6 * @date 23/01/13 * * @param $field (array) the $field being edited * @return n/a */ function render_field_settings($field) { /* * acf_render_field_setting * * This function will create a setting for your field. Simply pass the $field parameter and an array of field settings. * The array of settings does not require a `value` or `prefix`; These settings are found from the $field array. * * More than one setting can be added by copy/paste the above code. * Please note that you must also have a matching $defaults value for the field name (font_size) */ acf_render_field_setting($field, array( 'label' => __('Site Key', 'acf-recaptcha'), 'instructions' => __('Enter your site key from Google reCAPTCHA.', 'acf-recaptcha'), 'name' => 'site_key', 'required' => true, )); acf_render_field_setting($field, array( 'label' => __('Secret Key', 'acf-recaptcha'), 'instructions' => __('Enter your secret key from Google reCAPTCHA.', 'acf-recaptcha'), 'name' => 'secret_key', 'required' => true, )); acf_render_field_setting($field, array( 'label' => __('Theme', 'acf-recaptcha'), 'type' => 'radio', 'name' => 're_theme', 'layout' => 'horizontal', 'choices' => array( 'light' => __('light'), 'dark' => __('dark'), ), )); acf_render_field_setting($field, array( 'label' => __('Type', 'acf-recaptcha'), 'type' => 'radio', 'name' => 're_type', 'layout' => 'horizontal', 'choices' => array( 'image' => __('image'), 'audio' => __('audio'), ), )); acf_render_field_setting($field, array( 'label' => __('Size', 'acf-recaptcha'), 'type' => 'radio', 'name' => 're_size', 'layout' => 'horizontal', 'choices' => array( 'normal' => __('normal'), 'compact' => __('compact'), ), )); } /* * render_field() * * Create the HTML interface for your field * * @param $field (array) the $field being rendered * * @type action * @since 3.6 * @date 23/01/13 * * @param $field (array) the $field being edited * @return n/a */ function render_field($field) { if (is_admin()) { return; } if ($field['site_key'] && $field['secret_key']): ?>
verify($value, $_SERVER['REMOTE_ADDR']); if ($response->isSuccess()) { return $valid; } $errors = $response->getErrorCodes(); if (empty($errors)) { return $valid; } $valid = 'Invalid reCaptcha value ' . $value . ' response isSuccess(): ' . ($response->isSuccess() ? 'true' : 'false') . ' errors: ' . json_encode($errors); return $valid; } } new acf_field_recaptcha();