| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Plugin Name: Frontend Registration - Contact Form 7 |
|---|
| 4 | * Plugin URL: http://www.wpbuilderweb.com/frontend-registration-contact-form-7/ |
|---|
| 5 | * Description: This plugin will convert your Contact form 7 in to registration form for WordPress. PRO Plugin available now with New Features. <strong>PRO Version is also available with New Features.</strong>. |
|---|
| 6 | * Version: 5.1 |
|---|
| 7 | * Author: David Pokorny |
|---|
| 8 | * Author URI: http://www.wpbuilderweb.com |
|---|
| 9 | * Developer: Pokorny David |
|---|
| 10 | * Developer E-Mail: parmarcrish@gmail.com |
|---|
| 11 | * Text Domain: contact-form-7-freg |
|---|
| 12 | * Domain Path: /languages |
|---|
| 13 | * |
|---|
| 14 | * Copyright: © 2009-2015 izept.com. |
|---|
| 15 | * License: GNU General Public License v3.0 |
|---|
| 16 | * License URI: http://www.gnu.org/licenses/gpl-3.0.html |
|---|
| 17 | */ |
|---|
| 18 | /** |
|---|
| 19 | * |
|---|
| 20 | * @access public |
|---|
| 21 | * @since 1.1 |
|---|
| 22 | * @return $content |
|---|
| 23 | */ |
|---|
| 24 | if ( ! defined( 'ABSPATH' ) ) { |
|---|
| 25 | exit; // Exit if accessed directly |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | define( 'FRCF7_VERSION', '5.1' ); |
|---|
| 29 | |
|---|
| 30 | define( 'FRCF7_REQUIRED_WP_VERSION', '4.0' ); |
|---|
| 31 | |
|---|
| 32 | define( 'FRCF7_PLUGIN', __FILE__ ); |
|---|
| 33 | |
|---|
| 34 | define( 'FRCF7_PLUGIN_BASENAME', plugin_basename( FRCF7_PLUGIN ) ); |
|---|
| 35 | |
|---|
| 36 | define( 'FRCF7_PLUGIN_NAME', trim( dirname( FRCF7_PLUGIN_BASENAME ), '/' ) ); |
|---|
| 37 | |
|---|
| 38 | define( 'FRCF7_PLUGIN_DIR', untrailingslashit( dirname( FRCF7_PLUGIN ) ) ); |
|---|
| 39 | |
|---|
| 40 | define( 'FRCF7_PLUGIN_CSS_DIR', FRCF7_PLUGIN_DIR . '/css' ); |
|---|
| 41 | |
|---|
| 42 | add_action('plugins_loaded', function () { |
|---|
| 43 | require_once(ABSPATH . '/wp-admin/includes/plugin.php'); |
|---|
| 44 | if (!is_plugin_active('contact-form-7/wp-contact-form-7.php')) { |
|---|
| 45 | deactivate_plugins('frontend-registration-contact-form-7/frontend-registration-cf7.php'); |
|---|
| 46 | add_action('admin_notices', 'cf7fr_admin_notice'); |
|---|
| 47 | } else { |
|---|
| 48 | require_once (dirname(__FILE__) . '/frontend-registration-opt-cf7.php'); |
|---|
| 49 | } |
|---|
| 50 | }); |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * cf7fr_admin_notice |
|---|
| 54 | * |
|---|
| 55 | * @return void |
|---|
| 56 | */ |
|---|
| 57 | function cf7fr_admin_notice() |
|---|
| 58 | { |
|---|
| 59 | echo '<div class="error"><p>Plugin deactivated. Please activate contact form 7 plugin!</p></div>'; |
|---|
| 60 | return false; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | function cf7fr_editor_panels_reg ( $panels ) { |
|---|
| 64 | |
|---|
| 65 | $new_page = array( |
|---|
| 66 | 'Error' => array( |
|---|
| 67 | 'title' => __( 'Registration Settings', 'contact-form-7' ), |
|---|
| 68 | 'callback' => 'cf7fr_admin_reg_additional_settings' |
|---|
| 69 | ) |
|---|
| 70 | ); |
|---|
| 71 | |
|---|
| 72 | $panels = array_merge($panels, $new_page); |
|---|
| 73 | |
|---|
| 74 | return $panels; |
|---|
| 75 | |
|---|
| 76 | } |
|---|
| 77 | add_filter( 'wpcf7_editor_panels', 'cf7fr_editor_panels_reg' ); |
|---|
| 78 | |
|---|
| 79 | add_filter('plugin_row_meta', 'my_register_plugins_link', 10, 2); |
|---|
| 80 | function my_register_plugins_link ($links, $file) { |
|---|
| 81 | $base = plugin_basename(__FILE__); |
|---|
| 82 | if ($file == $base) { |
|---|
| 83 | $links[] = '<a href="http://www.wpbuilderweb.com/frontend-registration-contact-form-7/">' . __('PRO Version') . '</a>'; |
|---|
| 84 | $links[] = '<a href="http://www.wpbuilderweb.com/shop">' . __('More Plugins by David Pokorny') . '</a>'; |
|---|
| 85 | $links[] = '<a href="https://www.wpbuilderweb.com/donation-free-plugins/">' . __('Donate') . '</a>'; |
|---|
| 86 | } |
|---|
| 87 | return $links; |
|---|
| 88 | } |
|---|
| 89 | function cf7fr_admin_reg_additional_settings( $cf7 ) |
|---|
| 90 | { |
|---|
| 91 | |
|---|
| 92 | $post_id = sanitize_text_field($_GET['post']); |
|---|
| 93 | $tags = $cf7->scan_form_tags(); |
|---|
| 94 | $cf7frenable = get_post_meta($post_id, "_cf7fr_enable_registration", true); |
|---|
| 95 | $cf7fru = get_post_meta($post_id, "_cf7fru_", true); |
|---|
| 96 | $cf7fre = get_post_meta($post_id, "_cf7fre_", true); |
|---|
| 97 | $cf7frr = get_post_meta($post_id, "_cf7frr_", true); |
|---|
| 98 | $enablemail = get_post_meta($post_id, "_cf7fr_enablemail_registration", true); |
|---|
| 99 | $autologinfield = get_post_meta($post_id, "_cf7fr_autologinfield_reg", true); |
|---|
| 100 | $loginurlmail = get_post_meta($post_id, "_cf7fr_loginurlmail_reg", true); |
|---|
| 101 | $loginurlformail = get_post_meta($post_id, "_cf7fr_loginurlformail_reg", true); |
|---|
| 102 | $selectedrole = $cf7frr; |
|---|
| 103 | if(!$selectedrole) |
|---|
| 104 | { |
|---|
| 105 | $selectedrole = 'subscriber'; |
|---|
| 106 | } |
|---|
| 107 | if ($cf7frenable == "1") { $cf7frechecked = "CHECKED"; } else { $cf7frechecked = ""; } |
|---|
| 108 | if ($enablemail == "1") { $checkedmail = "CHECKED"; } else { $checkedmail = ""; } |
|---|
| 109 | if ($autologinfield == "1") { $autologinfield = "CHECKED"; } else { $autologinfield = ""; } |
|---|
| 110 | if ($loginurlmail == "1") { $loginurlmail = "CHECKED"; } else { $loginurlmail = ""; } |
|---|
| 111 | if ($loginurlformail != "") { $loginurlformail = $loginurlformail; } else { $loginurlformail = ""; } |
|---|
| 112 | |
|---|
| 113 | $selected = ""; |
|---|
| 114 | $admin_cm_output = ""; |
|---|
| 115 | |
|---|
| 116 | $admin_cm_output .= "<div id='additional_settings-sortables' class='meta-box'><div id='additionalsettingsdiv'>"; |
|---|
| 117 | $admin_cm_output .= "<h2 class='hndle ui-sortable-handle'><span>Frontend Registration Settings:</span></h2>"; |
|---|
| 118 | $admin_cm_output .= "<div class='inside'>"; |
|---|
| 119 | |
|---|
| 120 | $admin_cm_output .= "<div class='mail-field pretty p-switch p-fill'>"; |
|---|
| 121 | $admin_cm_output .= "<input name='cf7frenable' value='1' type='checkbox' $cf7frechecked>"; |
|---|
| 122 | $admin_cm_output .= "<div class='state'><label>Enable Registration on this form</label></div>"; |
|---|
| 123 | $admin_cm_output .= "</div>"; |
|---|
| 124 | |
|---|
| 125 | $admin_cm_output .= "<div class='mail-field pretty p-switch p-fill'>"; |
|---|
| 126 | $admin_cm_output .= "<input name='enablemail' value='' type='checkbox' $checkedmail>"; |
|---|
| 127 | $admin_cm_output .= "<div class='state'><label>Skip Contact Form 7 Mails ?</label></div>"; |
|---|
| 128 | $admin_cm_output .= "</div>"; |
|---|
| 129 | |
|---|
| 130 | $admin_cm_output .= "<div class='mail-field pretty p-switch p-fill'>"; |
|---|
| 131 | $admin_cm_output .= "<input name='autologinfield' value='' type='checkbox' $autologinfield>"; |
|---|
| 132 | $admin_cm_output .= "<div class='state'><label>Enable auto login after registration? </label></div>"; |
|---|
| 133 | $admin_cm_output .= "</div>"; |
|---|
| 134 | |
|---|
| 135 | $admin_cm_output .= "<div class='mail-field pretty p-switch p-fill'>"; |
|---|
| 136 | $admin_cm_output .= "<input name='loginurlmail' value='' type='checkbox' $loginurlmail>"; |
|---|
| 137 | $admin_cm_output .= "<div class='state'><label>Enable sent Login URL in Mail. </label></div>"; |
|---|
| 138 | $admin_cm_output .= "</div>"; |
|---|
| 139 | |
|---|
| 140 | $admin_cm_output .= "<div class='mail-field'>"; |
|---|
| 141 | $admin_cm_output .= "<br/><div class='state'><label>Set Custom Login URL for email :</label></div>"; |
|---|
| 142 | $admin_cm_output .= "<input name='loginurlformail' value='".$loginurlformail."' type='text' ><br/>"; |
|---|
| 143 | $admin_cm_output .= "</div>"; |
|---|
| 144 | |
|---|
| 145 | $admin_cm_output .= "<table>"; |
|---|
| 146 | |
|---|
| 147 | $admin_cm_output .= "<div class='handlediv' title='Click to toggle'><br></div><h2 class='hndle ui-sortable-handle'><span>Frontend Fields Settings:</span></h2>"; |
|---|
| 148 | |
|---|
| 149 | $admin_cm_output .= "<tr><td>Selected Field Name For User Name :</td></tr>"; |
|---|
| 150 | $admin_cm_output .= "<tr><td><select name='_cf7fru_'>"; |
|---|
| 151 | $admin_cm_output .= "<option value=''>Select Field</option>"; |
|---|
| 152 | foreach ($tags as $key => $value) { |
|---|
| 153 | if($cf7fru==$value['name']){$selected='selected=selected';}else{$selected = "";} |
|---|
| 154 | $admin_cm_output .= "<option ".$selected." value='".$value['name']."'>".$value['name']."</option>"; |
|---|
| 155 | } |
|---|
| 156 | $admin_cm_output .= "</select>"; |
|---|
| 157 | $admin_cm_output .= "</td></tr>"; |
|---|
| 158 | |
|---|
| 159 | $admin_cm_output .= "<tr><td>Selected Field Name For Email :</td></tr>"; |
|---|
| 160 | $admin_cm_output .= "<tr><td><select name='_cf7fre_'>"; |
|---|
| 161 | $admin_cm_output .= "<option value=''>Select Field</option>"; |
|---|
| 162 | foreach ($tags as $key => $value) { |
|---|
| 163 | if($cf7fre==$value['name']){$selected='selected=selected';}else{$selected = "";} |
|---|
| 164 | $admin_cm_output .= "<option ".$selected." value='".$value['name']."'>".$value['name']."</option>"; |
|---|
| 165 | } |
|---|
| 166 | $admin_cm_output .= "</select>"; |
|---|
| 167 | $admin_cm_output .= "</td></tr><tr><td>"; |
|---|
| 168 | $admin_cm_output .= "<input type='hidden' name='email' value='2'>"; |
|---|
| 169 | $admin_cm_output .= "<input type='hidden' name='post' value='$post_id'>"; |
|---|
| 170 | $admin_cm_output .= "</td></tr>"; |
|---|
| 171 | $admin_cm_output .= "<tr><td>Selected User Role:</td></tr>"; |
|---|
| 172 | $admin_cm_output .= "<tr><td>"; |
|---|
| 173 | $admin_cm_output .= "<select name='_cf7frr_'>"; |
|---|
| 174 | $editable_roles = get_editable_roles(); |
|---|
| 175 | foreach ( $editable_roles as $role => $details ) { |
|---|
| 176 | $name = translate_user_role($details['name'] ); |
|---|
| 177 | if ( $selectedrole == $role ) // preselect specified role |
|---|
| 178 | $admin_cm_output .= "<option selected='selected' value='" . esc_attr($role) . "'>$name</option>"; |
|---|
| 179 | else |
|---|
| 180 | $admin_cm_output .= "<option value='" . esc_attr($role) . "'>$name</option>"; |
|---|
| 181 | } |
|---|
| 182 | $admin_cm_output .="</select>"; |
|---|
| 183 | $admin_cm_output .= "</td></tr>"; |
|---|
| 184 | $admin_cm_output .="</table>"; |
|---|
| 185 | $admin_cm_output .= "</div>"; |
|---|
| 186 | $admin_cm_output .= "</div>"; |
|---|
| 187 | $admin_cm_output .= "</div>"; |
|---|
| 188 | |
|---|
| 189 | echo $admin_cm_output; |
|---|
| 190 | |
|---|
| 191 | } |
|---|
| 192 | // hook into contact form 7 admin form save |
|---|
| 193 | add_action('wpcf7_save_contact_form', 'cf7_save_reg_contact_form'); |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | function cf7_save_reg_contact_form( $cf7 ) |
|---|
| 197 | { |
|---|
| 198 | |
|---|
| 199 | $tags = $cf7->scan_form_tags(); |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | $post_id = sanitize_text_field($_POST['post_ID']); |
|---|
| 203 | |
|---|
| 204 | if (!empty($_POST['cf7frenable'])) { |
|---|
| 205 | $enable = sanitize_text_field($_POST['cf7frenable']); |
|---|
| 206 | update_post_meta($post_id, "_cf7fr_enable_registration", $enable); |
|---|
| 207 | } else { |
|---|
| 208 | update_post_meta($post_id, "_cf7fr_enable_registration", 0); |
|---|
| 209 | } |
|---|
| 210 | if (isset($_POST['enablemail'])) { |
|---|
| 211 | update_post_meta($post_id, "_cf7fr_enablemail_registration", 1); |
|---|
| 212 | } else { |
|---|
| 213 | update_post_meta($post_id, "_cf7fr_enablemail_registration", 0); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | if (isset($_POST['autologinfield'])) { |
|---|
| 217 | update_post_meta($post_id, "_cf7fr_autologinfield_reg", 1); |
|---|
| 218 | } else { |
|---|
| 219 | update_post_meta($post_id, "_cf7fr_autologinfield_reg", 0); |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | if (isset($_POST['loginurlmail'])) { |
|---|
| 223 | update_post_meta($post_id, "_cf7fr_loginurlmail_reg", 1); |
|---|
| 224 | } else { |
|---|
| 225 | update_post_meta($post_id, "_cf7fr_loginurlmail_reg", 0); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | if (isset($_POST['loginurlformail'])) { |
|---|
| 229 | update_post_meta($post_id, "_cf7fr_loginurlformail_reg", sanitize_text_field($_POST['loginurlformail'])); |
|---|
| 230 | } else { |
|---|
| 231 | update_post_meta($post_id, "_cf7fr_loginurlformail_reg", ""); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | $key = "_cf7fru_"; |
|---|
| 235 | $vals = sanitize_text_field($_POST[$key]); |
|---|
| 236 | update_post_meta($post_id, $key, $vals); |
|---|
| 237 | |
|---|
| 238 | $key = "_cf7fre_"; |
|---|
| 239 | $vals = sanitize_text_field($_POST[$key]); |
|---|
| 240 | update_post_meta($post_id, $key, $vals); |
|---|
| 241 | |
|---|
| 242 | $key = "_cf7frr_"; |
|---|
| 243 | $vals = sanitize_text_field($_POST[$key]); |
|---|
| 244 | update_post_meta($post_id, $key, $vals); |
|---|
| 245 | } |
|---|
| 246 | ?> |
|---|