gglcptch_add_settings_page

The Google Captcha (reCAPTCHA) by BestWebSoft gglcptch add settings page function.

Description

gglcptch_add_settings_page(); 

Usage

  1. if ( !function_exists( 'gglcptch_add_settings_page' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-captcha-recaptcha-by-bestwebsoft/google-captcha.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gglcptch_add_settings_page(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/google-captcha.php  
  1. function gglcptch_add_settings_page() { 
  2. global $gglcptch_options, $gglcptch_plugin_info, $wp_version; 
  3. require_once( dirname( __FILE__ ) . '/includes/pro_banners.php' ); 
  4.  
  5. $plugin_basename = plugin_basename( __FILE__ ); 
  6. $message = $error = ''; 
  7.  
  8. $all_plugins = get_plugins(); 
  9. $is_network = is_multisite() && is_network_admin(); 
  10. $is_main_site = is_main_site( get_current_blog_id() ); 
  11. $admin_url = $is_network ? network_admin_url( '/' ) : admin_url( '/' ); 
  12. $bws_contact_form = gglcptch_plugin_status( array( 'contact-form-plugin/contact_form.php', 'contact-form-pro/contact_form_pro.php' ), $all_plugins, $is_network ); 
  13.  
  14. if ( isset( $_POST['bws_hide_premium_options'] ) && check_admin_referer( $plugin_basename, 'gglcptch_nonce_name' ) ) { 
  15. $result = bws_hide_premium_options( $gglcptch_options ); 
  16. $gglcptch_options = $result['options']; 
  17. update_option( 'gglcptch_options', $gglcptch_options ); 
  18. if ( ! isset( $_GET['action'] ) ) { 
  19.  
  20. $all_plugins = get_plugins(); 
  21.  
  22. /** Private and public keys */ 
  23. $gglcptch_keys = array( 
  24. 'public' => array( 
  25. 'display_name' => __( 'Site Key', 'google-captcha' ),  
  26. 'form_name' => 'gglcptch_public_key',  
  27. 'error_msg' => '',  
  28. ),  
  29. 'private' => array( 
  30. 'display_name' => __( 'Secret Key', 'google-captcha' ),  
  31. 'form_name' => 'gglcptch_private_key',  
  32. 'error_msg' => '',  
  33. ),  
  34. ); 
  35.  
  36. $versions = array( 
  37. 'v1' => sprintf( '%s 1', __( 'Version', 'google-captcha' ) ),  
  38. 'v2' => sprintf( '%s 2', __( 'Version', 'google-captcha' ) ),  
  39. 'invisible' => __( 'Invisible reCAPTCHA', 'google-captcha' ) 
  40. ); 
  41.  
  42. /** Checked forms */ 
  43. $gglcptch_forms = array( 
  44. array( 'login_form', __( 'Login form', 'google-captcha' ) ),  
  45. array( 'registration_form', __( 'Registration form', 'google-captcha' ) ),  
  46. array( 'reset_pwd_form', __( 'Reset password form', 'google-captcha' ) ),  
  47. array( 'comments_form', __( 'Comments form', 'google-captcha' ) ),  
  48. ); 
  49.  
  50. /** Google captcha themes */ 
  51. $gglcptch_themes = array( 
  52. array( 'red', 'Red' ),  
  53. array( 'white', 'White' ),  
  54. array( 'blackglass', 'Blackglass' ),  
  55. array( 'clean', 'Clean' ),  
  56. ); 
  57.  
  58. /** Save data for settings page */ 
  59. if ( isset( $_POST['gglcptch_form_submit'] ) && check_admin_referer( $plugin_basename, 'gglcptch_nonce_name' ) ) { 
  60. if ( isset( $_POST['bws_hide_premium_options'] ) ) { 
  61. $hide_result = bws_hide_premium_options( $gglcptch_options ); 
  62. $gglcptch_options = $hide_result['options']; 
  63.  
  64. if ( ! $_POST['gglcptch_public_key'] || '' == $_POST['gglcptch_public_key'] ) { 
  65. $gglcptch_keys['public']['error_msg'] = __( 'Enter site key', 'google-captcha' ); 
  66. $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google-captcha' ); 
  67. } else 
  68. $gglcptch_keys['public']['error_msg'] = ''; 
  69.  
  70. if ( ! $_POST['gglcptch_private_key'] || '' == $_POST['gglcptch_private_key'] ) { 
  71. $gglcptch_keys['private']['error_msg'] = __( 'Enter secret key', 'google-captcha' ); 
  72. $error = __( "WARNING: The captcha will not display while you don't fill key fields.", 'google-captcha' ); 
  73. } else 
  74. $gglcptch_keys['private']['error_msg'] = ''; 
  75.  
  76. if ( $_POST['gglcptch_public_key'] != $gglcptch_options['public_key'] || $_POST['gglcptch_private_key'] != $gglcptch_options['private_key'] ) 
  77. $gglcptch_options['keys_verified'] = false; 
  78.  
  79. $gglcptch_options['whitelist_message'] = stripslashes( esc_html( $_POST['gglcptch_whitelist_message'] ) ); 
  80. $gglcptch_options['public_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_public_key'] ) ) ); 
  81. $gglcptch_options['private_key'] = trim( stripslashes( esc_html( $_POST['gglcptch_private_key'] ) ) ); 
  82. $gglcptch_options['login_form'] = isset( $_POST['gglcptch_login_form'] ) ? 1 : 0; 
  83. $gglcptch_options['registration_form'] = isset( $_POST['gglcptch_registration_form'] ) ? 1 : 0; 
  84. $gglcptch_options['reset_pwd_form'] = isset( $_POST['gglcptch_reset_pwd_form'] ) ? 1 : 0; 
  85. $gglcptch_options['comments_form'] = isset( $_POST['gglcptch_comments_form'] ) ? 1 : 0; 
  86. $gglcptch_options['contact_form'] = isset( $_POST['gglcptch_contact_form'] ) ? 1 : 0; 
  87. $gglcptch_options['recaptcha_version'] = in_array( $_POST['gglcptch_recaptcha_version'], array( 'v1', 'v2', 'invisible' ) ) ? $_POST['gglcptch_recaptcha_version']: 'v2'; 
  88. $gglcptch_options['theme'] = stripslashes( esc_html( $_POST['gglcptch_theme'] ) ); 
  89. $gglcptch_options['theme_v2'] = stripslashes( esc_html( $_POST['gglcptch_theme_v2'] ) ); 
  90.  
  91. if ( function_exists( 'get_editable_roles' ) ) { 
  92. foreach ( get_editable_roles() as $role => $fields ) { 
  93. $gglcptch_options[ $role ] = isset( $_POST[ 'gglcptch_' . $role ] ) ? 1 : 0; 
  94.  
  95. update_option( 'gglcptch_options', $gglcptch_options ); 
  96. $message = __( 'Settings saved', 'google-captcha' ); 
  97.  
  98. if ( isset( $_REQUEST['bws_restore_confirm'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) { 
  99. $gglcptch_options = gglcptch_get_default_options(); 
  100. update_option( 'gglcptch_options', $gglcptch_options ); 
  101. $message = __( 'All plugin settings were restored', 'google-captcha' ); 
  102.  
  103. $bws_hide_premium_options_check = bws_hide_premium_options_check( $gglcptch_options ); 
  104.  
  105. /** GO PRO */ 
  106. if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) { 
  107. $go_pro_result = bws_go_pro_tab_check( $plugin_basename, 'gglcptch_options' ); 
  108. if ( ! empty( $go_pro_result[error] ) ) 
  109. $error = $go_pro_result[error]; 
  110. elseif ( ! empty( $go_pro_result['message'] ) ) 
  111. $message = $go_pro_result['message']; 
  112. } ?> 
  113. <div class="wrap gglcptch_settings_page"> 
  114. <h1 style="line-height: normal;"><?php _e( 'Google Captcha Settings', 'google-captcha' ); ?></h1> 
  115. <h2 class="nav-tab-wrapper"> 
  116. <a class="nav-tab<?php if ( ! isset( $_GET['action'] ) || ( isset( $_GET['action'] ) && ! in_array( $_GET['action'], array( 'whitelist', 'custom_code', 'go_pro' ) ) ) ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php"><?php _e( 'Settings', 'google-captcha' ); ?></a> 
  117. <a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'whitelist' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php&action=whitelist"><?php _e( 'Whitelist', 'google-captcha' ); ?></a> 
  118. <a class="nav-tab <?php if ( isset( $_GET['action'] ) && 'custom_code' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=google-captcha.php&action=custom_code"><?php _e( 'Custom code', 'google-captcha' ); ?></a> 
  119. <a class="nav-tab<?php if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) echo ' nav-tab-active'; ?> bws_go_pro_tab" href="admin.php?page=google-captcha.php&action=go_pro"><?php _e( 'Go PRO', 'google-captcha' ); ?></a> 
  120. </h2> 
  121. <?php if ( ! isset( $_GET['action'] ) && ! isset( $_REQUEST['bws_restore_default'] ) ) { 
  122. if ( $gglcptch_options['recaptcha_version'] == 'v1' ) { 
  123. printf( '<div id="gglcptch_v1_notice" class="updated inline"><p><strong>%s</strong></p></div>',  
  124. __( "Only one reCAPTCHA can be displayed on the page, it's related to reCAPTCHA version 1 features.", 'google-captcha' ) 
  125. ); 
  126. bws_show_settings_notice(); ?> 
  127. <div class="updated fade inline" <?php if ( "" == $message ) echo 'style="display:none"'; ?>><p><strong><?php echo $message; ?></strong></p></div> 
  128. <div class="error inline" <?php if ( "" == $error ) echo 'style="display:none"'; ?>><p><strong><?php echo $error; ?></strong></p></div> 
  129. <?php if ( ! empty( $hide_result['message'] ) ) { ?> 
  130. <div class="updated fade inline"><p><strong><?php echo $hide_result['message']; ?></strong></p></div> 
  131. <?php } 
  132. if ( ! isset( $_GET['action'] ) ) { 
  133. if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $plugin_basename, 'bws_settings_nonce_name' ) ) { 
  134. bws_form_restore_default_confirm( $plugin_basename ); 
  135. } else { ?> 
  136. <div style="margin: 20px 0;"> 
  137. <?php printf( __( "If you would like to add a Google Captcha (reCAPTCHA) to your page or post, please use %s button", 'google-captcha' ),  
  138. '<span class="bwsicons bwsicons-shortcode"></span>' 
  139. ); 
  140. echo bws_add_help_box( sprintf( 
  141. __( "You can add the Google Captcha (reCAPTCHA) to your page or post by clicking on %s button in the content edit block using the Visual mode. If the button isn't displayed or you would like to add the Google Captcha (reCAPTCHA) to your own form , please use the shortcode %s", 'google-captcha' ),  
  142. '<span class="bwsicons bwsicons-shortcode"></span>',  
  143. sprintf( '<span class="bws_code">[bws_google_captcha]</span><br/>' ) 
  144. ) ); ?> 
  145. </div> 
  146. <form id="gglcptch_admin_settings_page" class="bws_form" method="post" action="admin.php?page=google-captcha.php"> 
  147. <h3><?php _e( 'Authentication', 'google-captcha' ); ?></h3> 
  148. <p><?php printf( __( 'In order to use reCAPTCHA, please enter site and secret keys. You can manage your API keys %shere%s', 'google-captcha' ), '<a target="_blank" href="https://www.google.com/recaptcha/admin#list">', '</a>.' ); ?></p> 
  149. <table id="gglcptch-keys" class="form-table"> 
  150. <?php foreach ( $gglcptch_keys as $key => $fields ) { ?> 
  151. <tr valign="top"> 
  152. <th scope="row"><?php echo $fields['display_name']; ?></th> 
  153. <td> 
  154. <input type="text" name="<?php echo $fields['form_name']; ?>" value="<?php echo $gglcptch_options[ $key . '_key' ] ?>" maxlength="200" /> 
  155. <label class="gglcptch_error_msg error"><?php echo $fields['error_msg']; ?></label> 
  156. <span class="dashicons dashicons-yes gglcptch_verified <?php if ( ! isset( $gglcptch_options['keys_verified'] ) || true !== $gglcptch_options['keys_verified'] ) echo 'hidden'; ?>"></span> 
  157. </td> 
  158. </tr> 
  159. <?php } ?> 
  160. </table> 
  161. <?php if ( ! empty( $gglcptch_options['public_key'] ) && ! empty( $gglcptch_options['private_key'] ) ) { ?> 
  162. <p id="gglcptch-test-keys" class="submit hide-if-no-js"> 
  163. <a class="button button-secondary" href="<?php echo add_query_arg( array( '_wpnonce' => wp_create_nonce( 'gglcptch-test-keys' ) , 'action' => 'gglcptch-test-keys' ), admin_url( 'admin-ajax.php' ) ); ?>"><?php _e( 'Test Keys' , 'google-captcha' ); ?></a> 
  164. </p> 
  165. <?php } ?> 
  166. <h3><?php _e( 'Options', 'google-captcha' ); ?></h3> 
  167. <table class="form-table"> 
  168. <tr valign="top"> 
  169. <th scope="row"><?php _e( 'Enable reCAPTCHA for', 'google-captcha' ); ?></th> 
  170. <td> 
  171. <fieldset> 
  172. <p> 
  173. <i><?php _e( 'WordPress default', 'google-captcha' ); ?></i> 
  174. </p> 
  175. <?php foreach ( $gglcptch_forms as $form ) { 
  176. $gglcptch_form_type = $form[0]; 
  177. $gglcptch_form_name = $form[1]; 
  178. $gglcptch_form_attr = ( '1' == $gglcptch_options[ $gglcptch_form_type ] ) ? 'checked="checked"' : ''; 
  179. $gglcptch_form_notice = ''; 
  180.  
  181. if ( ( $gglcptch_form_type == 'registration_form' || $gglcptch_form_type == 'reset_pwd_form' ) && ! $is_main_site ) { 
  182. $gglcptch_form_notice .= sprintf( '<span class="bws_info">%s</span>', __( 'This option is available only for network or for main blog', 'google-captcha' ) ); 
  183. $gglcptch_form_attr = 'disabled="disabled" readonly="readonly"'; 
  184. } ?> 
  185. <label><input type="checkbox" name="<?php echo 'gglcptch_' . $gglcptch_form_type; ?>" value="<?php echo $gglcptch_form_type; ?>" <?php echo $gglcptch_form_attr; ?> /> <?php echo $gglcptch_form_name; ?></label> 
  186. <?php echo bws_add_help_box( '<img src="' . plugins_url( 'google-captcha/images/') . $gglcptch_form_type . '.jpg">', 'bws-auto-width' ); ?> 
  187. <span class="bws_info"><?php echo $gglcptch_form_notice; ?></span><br /> 
  188. <?php } ?> 
  189. <br /> 
  190. <p> 
  191. <i><?php _e( 'Plugins', 'google-captcha' ); ?></i> 
  192. </p> 
  193. <?php /** Check Contact Form by BestWebSoft */ 
  194. $gglcptch_plugin = $bws_contact_form; 
  195. $gglcptch_plugin_name = 'Contact Form by BestWebSoft'; 
  196. $gglcptch_attrs = $gglcptch_plugin_notice = ''; 
  197. if ( 'deactivated' == $gglcptch_plugin['status'] ) { 
  198. $gglcptch_attrs = 'disabled="disabled"'; 
  199. $gglcptch_plugin_notice = sprintf( __( 'You should %s to use this functionality', 'google-captcha' ),  
  200. sprintf( '<a href="%splugins.php">%s%s %s</a>', $admin_url, __( 'activate', 'google-captcha' ), ( is_network_admin() ? ' ' . __( 'for network', 'google-captcha' ) : '' ), $gglcptch_plugin_name ) 
  201. ); 
  202. } elseif ( 'not_installed' == $gglcptch_plugin['status'] ) { 
  203. $gglcptch_attrs = 'disabled="disabled"'; 
  204. $gglcptch_plugin_notice = sprintf( __( 'You should %s to use this functionality', 'google-captcha' ),  
  205. sprintf( '<a href="https://bestwebsoft.com/products/wordpress/plugins/contact-form/?k=0a750deb99a8e5296a5432f4c9cb9b55&pn=75&v=%s&wp_v=%s">%s %s</a>', $gglcptch_plugin_info["Version"], $wp_version, __( 'download', 'google-captcha' ), $gglcptch_plugin_name ) 
  206. ); 
  207. if ( $gglcptch_attrs == '' && ( is_plugin_active( 'contact-form-multi-pro/contact-form-multi-pro.php' ) || is_plugin_active( 'contact-form-multi/contact-form-multi.php' ) ) ) 
  208. $gglcptch_plugin_notice = ' (' . __( 'Check off for adding captcha to forms on their settings pages', 'google-captcha' ) . ')'; 
  209.  
  210. if ( '1' == $gglcptch_options['contact_form'] && $gglcptch_attrs == '' ) { 
  211. $gglcptch_attrs .= ' checked="checked"'; 
  212. } ?> 
  213. <label><input type="checkbox" <?php echo $gglcptch_attrs; ?> name="gglcptch_contact_form" value="contact_form" /> <?php echo $gglcptch_plugin_name; ?></label> 
  214. <?php echo bws_add_help_box( '<img src="' . plugins_url( 'google-captcha/images/contact_form.jpg') . '">', 'bws-auto-width' ); ?> 
  215. <span class="bws_info"><?php echo $gglcptch_plugin_notice; ?></span><br /> 
  216. <span class="bws_info"><?php printf( __( 'If you would like to add Google Captcha (reCAPTCHA) to a custom form see %s', 'google-captcha' ), sprintf( '<a href="https://support.bestwebsoft.com/hc/en-us/articles/202352499" target="_blank">%s</a>', __( 'FAQ', 'google-captcha' ) ) ); ?></span> 
  217. </fieldset> 
  218. </td> 
  219. </tr> 
  220. <tr valign="top"> 
  221. <th scope="row"><?php _e( 'Hide reCAPTCHA in Comments Form for', 'google-captcha' ); ?></th> 
  222. <td> 
  223. <fieldset> 
  224. <?php if ( function_exists( 'get_editable_roles' ) ) { 
  225. foreach ( get_editable_roles() as $role => $fields) : ?> 
  226. <label><input type="checkbox" name="<?php echo 'gglcptch_' . $role; ?>" value=<?php echo $role; if ( isset( $gglcptch_options[ $role ] ) && '1' == $gglcptch_options[ $role ] ) echo ' checked'; ?>> <?php echo $fields['name']; ?></label><br/> 
  227. <?php endforeach; 
  228. } ?> 
  229. </fieldset> 
  230. </td> 
  231. </tr> 
  232. <tr valign="top"> 
  233. <th scope="row"><?php _e( 'Whitelist Notification', 'google-captcha' ); ?></th> 
  234. <td> 
  235. <label> 
  236. <input type="text" id="gglcptch_whitelist_message" name="gglcptch_whitelist_message" value="<?php echo $gglcptch_options['whitelist_message']; ?>"> 
  237. <?php echo bws_add_help_box( __( 'This message will be displayed instead of the reCAPTCHA if the user IP is added to the whitelist', 'google-captcha' ) ); ?> 
  238. <div class="clear"></div> 
  239. </label> 
  240. </td> 
  241. </tr> 
  242. <tr valign="top"> 
  243. <th scope="row"><?php _e( 'reCAPTCHA Version', 'google-captcha' ); ?></th> 
  244. <td> 
  245. <fieldset> 
  246. <?php foreach ( $versions as $version => $version_name ) { ?> 
  247. <label> 
  248. <input type="radio" name="gglcptch_recaptcha_version" value="<?php echo $version; ?>" <?php checked( $version == $gglcptch_options['recaptcha_version'] ); ?>> <?php echo $version_name; ?> 
  249. </label> 
  250. <?php if ( 'invisible' != $version ) { 
  251. echo bws_add_help_box( '<img src="' . plugins_url( 'google-captcha/images/recaptcha_' . $version . '.png' ) . '">', 'bws-auto-width' ) . '<br/>'; 
  252. } else { 
  253. echo bws_add_help_box( __( "reCAPTCHA block won't be visible for non-suspicious users while suspicious ones will have to pass the captcha", 'google-captcha' ) ); 
  254. } ?> 
  255. </fieldset> 
  256. </td> 
  257. </tr> 
  258. <tr class="gglcptch_theme_v1" valign="top"> 
  259. <th scope="row"> 
  260. <?php _e( 'reCAPTCHA Theme', 'google-captcha' ); ?> 
  261. <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 1)</span> 
  262. </th> 
  263. <td> 
  264. <select name="gglcptch_theme"> 
  265. <?php foreach ( $gglcptch_themes as $theme ) : ?> 
  266. <option value=<?php echo $theme[0]; if ( $theme[0] == $gglcptch_options['theme'] ) echo ' selected'; ?>> <?php echo $theme[1]; ?></option> 
  267. <?php endforeach; ?> 
  268. </select> 
  269. </td> 
  270. </tr> 
  271. <tr class="gglcptch_theme_v2" valign="top"> 
  272. <th scope="row"> 
  273. <?php _e( 'reCAPTCHA Theme', 'google-captcha' ); ?> 
  274. <br/><span class="bws_info">(<?php _e( 'for version', 'google-captcha' ); ?> 2)</span> 
  275. </th> 
  276. <td> 
  277. <select name="gglcptch_theme_v2"> 
  278. <option value="light" <?php if ( 'light' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>Light</option> 
  279. <option value="dark" <?php if ( 'dark' == $gglcptch_options['theme_v2'] ) echo ' selected'; ?>>Dark</option> 
  280. </select> 
  281. </td> 
  282. </tr> 
  283. </table> 
  284. <p class="submit"> 
  285. <input id="bws-submit-button" type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'google-captcha' ); ?>" name="gglcptch_save_changes" /> 
  286. <input type="hidden" name="gglcptch_form_submit" value="submit" /> 
  287. <?php wp_nonce_field( $plugin_basename, 'gglcptch_nonce_name' ); ?> 
  288. </p> 
  289. </form> 
  290. <?php bws_form_restore_default_settings( $plugin_basename ); 
  291. } elseif ( 'whitelist' == $_GET['action'] ) { 
  292. require_once( dirname( __FILE__ ) . '/includes/whitelist.php' ); 
  293. $page = new Gglcptch_Whitelist( $plugin_basename ); 
  294. if ( is_object( $page ) ) 
  295. $page->display_content(); 
  296. } elseif ( 'custom_code' == $_GET['action'] ) { 
  297. } elseif ( 'go_pro' == $_GET['action'] ) { 
  298. bws_go_pro_tab_show( $bws_hide_premium_options_check, $gglcptch_plugin_info, $plugin_basename, 'google-captcha.php', 'google-captcha-pro.php', 'google-captcha-pro/google-captcha-pro.php', 'google-captcha', 'b850d949ccc1239cab0da315c3c822ab', '109', isset( $go_pro_result['pro_plugin_is_activated'] ) ); 
  299. bws_plugin_reviews_block( $gglcptch_plugin_info['Name'], 'google-captcha' ); ?> 
  300. </div> 
  301. <?php }