wpcf7-recaptcha
Last commit date
assets
7 years ago
languages
7 years ago
changelog.txt
7 years ago
license.txt
7 years ago
readme.txt
7 years ago
recaptcha-v2.php
7 years ago
wpcf7-recaptcha.php
7 years ago
wpcf7-recaptcha.php
209 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: Contact Form 7 - reCaptcha v2 |
| 4 | * Description: ReCaptcha v2 Fix for Contact Form 7 5.1 and later. |
| 5 | * Version: 1.1.3 |
| 6 | * Author: IQComputing |
| 7 | * Author URI: http://www.iqcomputing.com/ |
| 8 | * License: GPL2 |
| 9 | * Text Domain: wpcf7-recaptcha |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | defined( 'ABSPATH' ) or die( 'You cannot be here.' ); |
| 14 | |
| 15 | |
| 16 | /** |
| 17 | * IQComputing Contact Form 7 reCaptcha Fix, Deity Class |
| 18 | */ |
| 19 | Class IQFix_WPCF7_Deity { |
| 20 | |
| 21 | public static $version = '1.1.3'; |
| 22 | |
| 23 | |
| 24 | /** |
| 25 | * Class Registration, set up necessities |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public static function register() { |
| 30 | |
| 31 | $class = new self(); |
| 32 | $class->include_files(); |
| 33 | $class->action_hooks(); |
| 34 | |
| 35 | } |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Include any necessary files |
| 40 | * |
| 41 | * @return void |
| 42 | */ |
| 43 | private function include_files() { |
| 44 | |
| 45 | $selection = WPCF7::get_option( 'iqfix_recaptcha' ); |
| 46 | |
| 47 | // Prevent update from v2 to v3 notice. |
| 48 | WPCF7::update_option( 'recaptcha_v2_v3_warning', false ); |
| 49 | |
| 50 | if( empty( $selection ) || version_compare( WPCF7_VERSION, '5.1', '<' ) ) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | include_once( plugin_dir_path( __FILE__ ) . 'recaptcha-v2.php' ); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | |
| 59 | /** |
| 60 | * Add any necessary action hooks |
| 61 | * |
| 62 | * @return void |
| 63 | */ |
| 64 | private function action_hooks() { |
| 65 | |
| 66 | add_action( 'admin_menu', array( $this, 'register_submenus' ) ); |
| 67 | |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * Register submenus for picking ReCaptcha versions |
| 73 | * |
| 74 | * @return void |
| 75 | */ |
| 76 | public function register_submenus() { |
| 77 | |
| 78 | add_submenu_page( |
| 79 | 'wpcf7', |
| 80 | esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ), |
| 81 | esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ), |
| 82 | WPCF7_ADMIN_READ_WRITE_CAPABILITY, |
| 83 | 'recaptcha-version', |
| 84 | array( $this, 'display_recaptcha_version_subpage' ) |
| 85 | ); |
| 86 | |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /** |
| 91 | * Display reCaptcha version subpage |
| 92 | * |
| 93 | * @return void |
| 94 | */ |
| 95 | public function display_recaptcha_version_subpage() { |
| 96 | |
| 97 | $updated = false; |
| 98 | $selection = WPCF7::get_option( 'iqfix_recaptcha' ); |
| 99 | |
| 100 | // Update Option |
| 101 | if( isset( $_POST, $_POST['iqfix_recaptcha_version'], $_POST['iqfix_wpcf7_submit'] ) ) { |
| 102 | |
| 103 | if( ! empty( $_POST['iqfix_wpcf7_nonce'] ) && wp_verify_nonce( $_POST['iqfix_wpcf7_nonce'], 'iqfix_wpcf7_vers_select' ) ) { |
| 104 | $selection = intval( $_POST['iqfix_recaptcha_version'] ); |
| 105 | WPCF7::update_option( 'iqfix_recaptcha', $selection ); |
| 106 | $updated = true; |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | |
| 111 | // Show simple message |
| 112 | if( version_compare( WPCF7_VERSION, '5.1', '<' ) ) { |
| 113 | printf( |
| 114 | '<div class="wrap"><h1>%1$s</h1><p>%2$s</p></div>', |
| 115 | esc_html__( 'Contact Form 7 - reCaptcha v2', 'wpcf7-recaptcha' ), |
| 116 | esc_html__( 'This version of Contact Form 7 already uses reCaptcha version 2, you do not need \'Contact Form 7 - reCaptcha v2\' installed at this time.', 'wpcf7-recaptcha' ) |
| 117 | ); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | ?> |
| 122 | |
| 123 | <div class="wrap"> |
| 124 | <style> |
| 125 | #iqFacebook {margin-top: 40px;} |
| 126 | #iqFacebook a {display: inline-block; margin-bottom: 12px;} |
| 127 | #iqFacebook img {display: block; max-width: 100%; height: auto;} |
| 128 | </style> |
| 129 | |
| 130 | <?php |
| 131 | |
| 132 | printf( '<h1>%1$s</h1>', esc_html__( 'Contact Form 7 - reCaptcha v2', 'wpcf7-recaptcha' ) ); |
| 133 | |
| 134 | if( $updated ) { |
| 135 | printf( |
| 136 | '<div class="notice updated"><p>%1$s</p></div>', |
| 137 | esc_html__( 'Your reCaptcha settings have been updated.', 'wpcf7-recaptcha' ) |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | /* translators: %s is a shortcode example wrapped in <code> tags. */ |
| 142 | printf( '<p>%1$s</p>', |
| 143 | sprintf( esc_html__( 'Select the version of reCaptcha you would like to use. You will still need to use the %s shortcode tag in your Contact Form 7 forms.', 'wpcf7-recaptcha' ), |
| 144 | '<code>[recaptcha]</code>' |
| 145 | ) |
| 146 | ); |
| 147 | ?> |
| 148 | |
| 149 | <form method="post"> |
| 150 | <?php wp_nonce_field( 'iqfix_wpcf7_vers_select', 'iqfix_wpcf7_nonce' ); ?> |
| 151 | <select name="iqfix_recaptcha_version"> |
| 152 | <option value="0"><?php esc_html_e( 'Default Usage', 'wpcf7-recaptcha' ); ?></option> |
| 153 | <option value="2" <?php selected( $selection, 2, true ); ?>><?php esc_html_e( 'reCaptcha Version 2', 'wpcf7-recaptcha' ); ?></option> |
| 154 | </select> |
| 155 | |
| 156 | <?php submit_button( esc_html__( 'Submit', 'wpcf7-recaptcha' ), 'submit', 'iqfix_wpcf7_submit' ); ?> |
| 157 | </form> |
| 158 | |
| 159 | <div id="iqFacebook"> |
| 160 | <?php |
| 161 | printf( '<a href="%1$s" target="_blank"><img src="%2$s" width="540" height="410" alt="%3$s" /></a>', |
| 162 | esc_url( 'https://www.facebook.com/iqcomputing' ), |
| 163 | esc_url( trailingslashit( plugin_dir_url( __FILE__ ) ) . 'assets/images/facebook-like.png' ), |
| 164 | /* translators: Image alternative tag. */ |
| 165 | esc_attr__( 'Like IQComputing on Facebook mascot', 'wpcf7-recaptcha' ) |
| 166 | ); |
| 167 | printf( '<p>%1$s</p>', |
| 168 | esc_html__( 'Click the image above and like us on Facebook! Facebook is where you will receive the latest news on both this plugin and all future IQComputing plugins.', 'wpcf7-recaptcha' ) |
| 169 | ); |
| 170 | ?> |
| 171 | </div> <!-- id="iqFacebook" --> |
| 172 | |
| 173 | </div> |
| 174 | |
| 175 | <?php |
| 176 | |
| 177 | } |
| 178 | |
| 179 | |
| 180 | } // END Class IQFix_WPCF7_Deity |
| 181 | |
| 182 | |
| 183 | /** |
| 184 | * Initialize Class |
| 185 | * |
| 186 | * @return void |
| 187 | */ |
| 188 | function iqfix_wpcf7_deity_init() { |
| 189 | |
| 190 | if( class_exists( 'WPCF7' ) ) { |
| 191 | IQFix_WPCF7_Deity::register(); |
| 192 | } |
| 193 | |
| 194 | } |
| 195 | add_action( 'plugins_loaded', 'iqfix_wpcf7_deity_init' ); |
| 196 | |
| 197 | |
| 198 | /** |
| 199 | * Remove upgrade notice from v2 to v3 |
| 200 | * Prevent api keys from being reset. |
| 201 | * |
| 202 | * @return void |
| 203 | */ |
| 204 | function iqfix_wpcf7_upgrade_recaptcha_v2_v3_removal() { |
| 205 | |
| 206 | remove_action( 'wpcf7_upgrade', 'wpcf7_upgrade_recaptcha_v2_v3', 10 ); |
| 207 | |
| 208 | } |
| 209 | add_action( 'admin_init', 'iqfix_wpcf7_upgrade_recaptcha_v2_v3_removal', 9 ); |