Version Description
Download this release
Release Info
Developer | erdanish4 |
Plugin | Simple Registration for WooCommerce |
Version | 1.5.3 |
Comparing to | |
See all releases |
Code changes from version 1.5.1 to 1.5.3
- includes/wc-social-login.php +81 -81
- languages/woocommerce-simple-registration.pot +94 -94
- readme.txt +68 -58
- templates/registration-form.php +65 -65
- woocommerce-simple-registration.php +331 -331
includes/wc-social-login.php
CHANGED
@@ -1,81 +1,81 @@
|
|
1 |
-
<?php
|
2 |
-
/* Load Class */
|
3 |
-
WooCommerce_Simple_Registration_WC_Social_Login::get_instance();
|
4 |
-
|
5 |
-
/**
|
6 |
-
* WooCommerce Social Login Support
|
7 |
-
* @link http://www.woothemes.com/products/woocommerce-social-login/
|
8 |
-
* @since 1.3.0
|
9 |
-
**/
|
10 |
-
class WooCommerce_Simple_Registration_WC_Social_Login{
|
11 |
-
|
12 |
-
/**
|
13 |
-
* Returns the instance.
|
14 |
-
*/
|
15 |
-
public static function get_instance(){
|
16 |
-
static $instance = null;
|
17 |
-
if ( is_null( $instance ) ) $instance = new self;
|
18 |
-
return $instance;
|
19 |
-
}
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Constructor.
|
23 |
-
*/
|
24 |
-
public function __construct() {
|
25 |
-
|
26 |
-
/* Add Simple Registration Shortcode in "Display" Settings */
|
27 |
-
add_filter( 'woocommerce_social_login_settings', array( $this, 'settings' ) );
|
28 |
-
|
29 |
-
/* Render Buttons */
|
30 |
-
add_action( 'woocommerce_register_form_end', array( $this, 'render_social_login_buttons' ) );
|
31 |
-
}
|
32 |
-
|
33 |
-
/**
|
34 |
-
* Display Settings
|
35 |
-
*/
|
36 |
-
public function settings( $settings ){
|
37 |
-
|
38 |
-
/* Get the section */
|
39 |
-
$key = false;
|
40 |
-
foreach( $settings as $k => $v ){
|
41 |
-
if( isset( $v['id'] ) && 'wc_social_login_display' == $v['id'] ){
|
42 |
-
$key = $k;
|
43 |
-
break;
|
44 |
-
}
|
45 |
-
}
|
46 |
-
/* Bail, if section not found */
|
47 |
-
if( false === $key ){
|
48 |
-
return $settings;
|
49 |
-
}
|
50 |
-
|
51 |
-
/* Add "Simple Registration" in Display Option So User can enable/disable it. */
|
52 |
-
$settings[$key]['options']['woocommerce_simple_registration'] = __( 'Simple Registration', 'woocommerce-simple-registration' );
|
53 |
-
|
54 |
-
return $settings;
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Whether social login buttons are displayed on simple registration shortcode
|
59 |
-
*/
|
60 |
-
public function is_displayed_on( $handle = 'woocommerce_simple_registration' ) {
|
61 |
-
return in_array( 'woocommerce_simple_registration', apply_filters( 'wc_social_login_display', (array) get_option( 'wc_social_login_display', array() ) ) );
|
62 |
-
}
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Render social login buttons on frontend
|
66 |
-
*/
|
67 |
-
public function render_social_login_buttons() {
|
68 |
-
/* Bail if not enabled in simple registration output */
|
69 |
-
if( ! $this->is_displayed_on() ){
|
70 |
-
return;
|
71 |
-
}
|
72 |
-
/* Bail if in account page and this page already have login button. */
|
73 |
-
if ( is_account_page() && $this->is_displayed_on( 'my_account' ) ) {
|
74 |
-
return;
|
75 |
-
}
|
76 |
-
/* Render button. */
|
77 |
-
woocommerce_social_login_buttons( wc_get_page_permalink( 'myaccount' ) );
|
78 |
-
}
|
79 |
-
|
80 |
-
}
|
81 |
-
|
1 |
+
<?php
|
2 |
+
/* Load Class */
|
3 |
+
WooCommerce_Simple_Registration_WC_Social_Login::get_instance();
|
4 |
+
|
5 |
+
/**
|
6 |
+
* WooCommerce Social Login Support
|
7 |
+
* @link http://www.woothemes.com/products/woocommerce-social-login/
|
8 |
+
* @since 1.3.0
|
9 |
+
**/
|
10 |
+
class WooCommerce_Simple_Registration_WC_Social_Login{
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Returns the instance.
|
14 |
+
*/
|
15 |
+
public static function get_instance(){
|
16 |
+
static $instance = null;
|
17 |
+
if ( is_null( $instance ) ) $instance = new self;
|
18 |
+
return $instance;
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Constructor.
|
23 |
+
*/
|
24 |
+
public function __construct() {
|
25 |
+
|
26 |
+
/* Add Simple Registration Shortcode in "Display" Settings */
|
27 |
+
add_filter( 'woocommerce_social_login_settings', array( $this, 'settings' ) );
|
28 |
+
|
29 |
+
/* Render Buttons */
|
30 |
+
add_action( 'woocommerce_register_form_end', array( $this, 'render_social_login_buttons' ) );
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Display Settings
|
35 |
+
*/
|
36 |
+
public function settings( $settings ){
|
37 |
+
|
38 |
+
/* Get the section */
|
39 |
+
$key = false;
|
40 |
+
foreach( $settings as $k => $v ){
|
41 |
+
if( isset( $v['id'] ) && 'wc_social_login_display' == $v['id'] ){
|
42 |
+
$key = $k;
|
43 |
+
break;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
/* Bail, if section not found */
|
47 |
+
if( false === $key ){
|
48 |
+
return $settings;
|
49 |
+
}
|
50 |
+
|
51 |
+
/* Add "Simple Registration" in Display Option So User can enable/disable it. */
|
52 |
+
$settings[$key]['options']['woocommerce_simple_registration'] = __( 'Simple Registration', 'woocommerce-simple-registration' );
|
53 |
+
|
54 |
+
return $settings;
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Whether social login buttons are displayed on simple registration shortcode
|
59 |
+
*/
|
60 |
+
public function is_displayed_on( $handle = 'woocommerce_simple_registration' ) {
|
61 |
+
return in_array( 'woocommerce_simple_registration', apply_filters( 'wc_social_login_display', (array) get_option( 'wc_social_login_display', array() ) ) );
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Render social login buttons on frontend
|
66 |
+
*/
|
67 |
+
public function render_social_login_buttons() {
|
68 |
+
/* Bail if not enabled in simple registration output */
|
69 |
+
if( ! $this->is_displayed_on() ){
|
70 |
+
return;
|
71 |
+
}
|
72 |
+
/* Bail if in account page and this page already have login button. */
|
73 |
+
if ( is_account_page() && $this->is_displayed_on( 'my_account' ) ) {
|
74 |
+
return;
|
75 |
+
}
|
76 |
+
/* Render button. */
|
77 |
+
woocommerce_social_login_buttons( wc_get_page_permalink( 'myaccount' ) );
|
78 |
+
}
|
79 |
+
|
80 |
+
}
|
81 |
+
|
languages/woocommerce-simple-registration.pot
CHANGED
@@ -1,95 +1,95 @@
|
|
1 |
-
# Copyright (C) 2017 Astoundify
|
2 |
-
# This file is distributed under the same license as the Simple Registration for WooCommerce package.
|
3 |
-
msgid ""
|
4 |
-
msgstr ""
|
5 |
-
"Project-Id-Version: Simple Registration for WooCommerce 1.5.
|
6 |
-
"Report-Msgid-Bugs-To: "
|
7 |
-
"https://wordpress.org/support/plugin/woocommerce-simple-registration\n"
|
8 |
-
"POT-Creation-Date: 2017-
|
9 |
-
"MIME-Version: 1.0\n"
|
10 |
-
"Content-Type: text/plain; charset=utf-8\n"
|
11 |
-
"Content-Transfer-Encoding: 8bit\n"
|
12 |
-
"PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
|
13 |
-
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
-
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15 |
-
"X-Generator: grunt-wp-i18n1.0.0\n"
|
16 |
-
|
17 |
-
#: includes/wc-social-login.php:52
|
18 |
-
msgid "Simple Registration"
|
19 |
-
msgstr ""
|
20 |
-
|
21 |
-
#: templates/registration-form.php:17 templates/registration-form.php:54
|
22 |
-
msgid "Register"
|
23 |
-
msgstr ""
|
24 |
-
|
25 |
-
#: templates/registration-form.php:26
|
26 |
-
msgid "Username"
|
27 |
-
msgstr ""
|
28 |
-
|
29 |
-
#: templates/registration-form.php:33
|
30 |
-
msgid "Email address"
|
31 |
-
msgstr ""
|
32 |
-
|
33 |
-
#: templates/registration-form.php:40
|
34 |
-
msgid "Password"
|
35 |
-
msgstr ""
|
36 |
-
|
37 |
-
#: templates/registration-form.php:47
|
38 |
-
msgid "Anti-spam"
|
39 |
-
msgstr ""
|
40 |
-
|
41 |
-
#: templates/registration-form.php:58
|
42 |
-
msgid "Log in"
|
43 |
-
msgstr ""
|
44 |
-
|
45 |
-
#: woocommerce-simple-registration.php:203
|
46 |
-
msgid "First Name"
|
47 |
-
msgstr ""
|
48 |
-
|
49 |
-
#: woocommerce-simple-registration.php:208
|
50 |
-
msgid "Last Name"
|
51 |
-
msgstr ""
|
52 |
-
|
53 |
-
#: woocommerce-simple-registration.php:252
|
54 |
-
msgid "Registration page"
|
55 |
-
msgstr ""
|
56 |
-
|
57 |
-
#: woocommerce-simple-registration.php:253
|
58 |
-
msgid ""
|
59 |
-
"Use this page as WordPress registration URL. Page contents: "
|
60 |
-
"[woocommerce_simple_registration]"
|
61 |
-
msgstr ""
|
62 |
-
|
63 |
-
#: woocommerce-simple-registration.php:259
|
64 |
-
msgid "Select a page…"
|
65 |
-
msgstr ""
|
66 |
-
|
67 |
-
#: woocommerce-simple-registration.php:271
|
68 |
-
msgid "Enable first and last name fields."
|
69 |
-
msgstr ""
|
70 |
-
|
71 |
-
#: woocommerce-simple-registration.php:278
|
72 |
-
msgid "Require first and last name fields."
|
73 |
-
msgstr ""
|
74 |
-
|
75 |
-
#. Plugin Name of the plugin/theme
|
76 |
-
msgid "Simple Registration for WooCommerce"
|
77 |
-
msgstr ""
|
78 |
-
|
79 |
-
#. Plugin URI of the plugin/theme
|
80 |
-
msgid "https://astoundify.com/products/woocommerce-simple-registration/"
|
81 |
-
msgstr ""
|
82 |
-
|
83 |
-
#. Description of the plugin/theme
|
84 |
-
msgid ""
|
85 |
-
"A simple plugin to add a [woocommerce_simple_registration] shortcode to "
|
86 |
-
"display the registration form on a separate page."
|
87 |
-
msgstr ""
|
88 |
-
|
89 |
-
#. Author of the plugin/theme
|
90 |
-
msgid "Astoundify"
|
91 |
-
msgstr ""
|
92 |
-
|
93 |
-
#. Author URI of the plugin/theme
|
94 |
-
msgid "https://astoundify.com/"
|
95 |
Â
msgstr ""
|
1 |
+
# Copyright (C) 2017 Astoundify
|
2 |
+
# This file is distributed under the same license as the Simple Registration for WooCommerce package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: Simple Registration for WooCommerce 1.5.2\n"
|
6 |
+
"Report-Msgid-Bugs-To: "
|
7 |
+
"https://wordpress.org/support/plugin/woocommerce-simple-registration\n"
|
8 |
+
"POT-Creation-Date: 2017-10-02 14:09:27+00:00\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=utf-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
|
13 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15 |
+
"X-Generator: grunt-wp-i18n1.0.0\n"
|
16 |
+
|
17 |
+
#: includes/wc-social-login.php:52
|
18 |
+
msgid "Simple Registration"
|
19 |
+
msgstr ""
|
20 |
+
|
21 |
+
#: templates/registration-form.php:17 templates/registration-form.php:54
|
22 |
+
msgid "Register"
|
23 |
+
msgstr ""
|
24 |
+
|
25 |
+
#: templates/registration-form.php:26
|
26 |
+
msgid "Username"
|
27 |
+
msgstr ""
|
28 |
+
|
29 |
+
#: templates/registration-form.php:33
|
30 |
+
msgid "Email address"
|
31 |
+
msgstr ""
|
32 |
+
|
33 |
+
#: templates/registration-form.php:40
|
34 |
+
msgid "Password"
|
35 |
+
msgstr ""
|
36 |
+
|
37 |
+
#: templates/registration-form.php:47
|
38 |
+
msgid "Anti-spam"
|
39 |
+
msgstr ""
|
40 |
+
|
41 |
+
#: templates/registration-form.php:58
|
42 |
+
msgid "Log in"
|
43 |
+
msgstr ""
|
44 |
+
|
45 |
+
#: woocommerce-simple-registration.php:203
|
46 |
+
msgid "First Name"
|
47 |
+
msgstr ""
|
48 |
+
|
49 |
+
#: woocommerce-simple-registration.php:208
|
50 |
+
msgid "Last Name"
|
51 |
+
msgstr ""
|
52 |
+
|
53 |
+
#: woocommerce-simple-registration.php:252
|
54 |
+
msgid "Registration page"
|
55 |
+
msgstr ""
|
56 |
+
|
57 |
+
#: woocommerce-simple-registration.php:253
|
58 |
+
msgid ""
|
59 |
+
"Use this page as WordPress registration URL. Page contents: "
|
60 |
+
"[woocommerce_simple_registration]"
|
61 |
+
msgstr ""
|
62 |
+
|
63 |
+
#: woocommerce-simple-registration.php:259
|
64 |
+
msgid "Select a page…"
|
65 |
+
msgstr ""
|
66 |
+
|
67 |
+
#: woocommerce-simple-registration.php:271
|
68 |
+
msgid "Enable first and last name fields."
|
69 |
+
msgstr ""
|
70 |
+
|
71 |
+
#: woocommerce-simple-registration.php:278
|
72 |
+
msgid "Require first and last name fields."
|
73 |
+
msgstr ""
|
74 |
+
|
75 |
+
#. Plugin Name of the plugin/theme
|
76 |
+
msgid "Simple Registration for WooCommerce"
|
77 |
+
msgstr ""
|
78 |
+
|
79 |
+
#. Plugin URI of the plugin/theme
|
80 |
+
msgid "https://astoundify.com/products/woocommerce-simple-registration/"
|
81 |
+
msgstr ""
|
82 |
+
|
83 |
+
#. Description of the plugin/theme
|
84 |
+
msgid ""
|
85 |
+
"A simple plugin to add a [woocommerce_simple_registration] shortcode to "
|
86 |
+
"display the registration form on a separate page."
|
87 |
+
msgstr ""
|
88 |
+
|
89 |
+
#. Author of the plugin/theme
|
90 |
+
msgid "Astoundify"
|
91 |
+
msgstr ""
|
92 |
+
|
93 |
+
#. Author URI of the plugin/theme
|
94 |
+
msgid "https://astoundify.com/"
|
95 |
Â
msgstr ""
|
readme.txt
CHANGED
@@ -1,58 +1,68 @@
|
|
1 |
-
=== Simple Registration for WooCommerce ===
|
2 |
-
Contributors: Astoundify
|
3 |
-
Donate link: https://www.paypal.me/astoundify
|
4 |
-
Tags: woocommerce, woocommerce registration, woocommerce register, woocommerce registration form, woocommerce form
|
5 |
-
Requires at least: 4.7.0
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 1.5.
|
8 |
-
License: GPLv3 or later
|
9 |
-
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
-
|
11 |
-
A simple plugin to add a [woocommerce_simple_registration] shortcode to display the registration form on a separate page.
|
12 |
-
|
13 |
-
== Description ==
|
14 |
-
|
15 |
-
A simple plugin to add a [woocommerce_simple_registration] shortcode to display the registration form on a separate page.
|
16 |
-
|
17 |
-
== Installation ==
|
18 |
-
|
19 |
-
1. Upload the folder `woocommerce-simple-registration to the `/wp-content/plugins/` directory
|
20 |
-
2. Activate the plugin through the 'Plugins' menu in WordPress
|
21 |
-
3. Use the shortcode `woocommerce_simple_registration` on a self-created page to display the registration form.
|
22 |
-
|
23 |
-
== Changelog ==
|
24 |
-
|
25 |
-
= 1.5.
|
26 |
-
|
27 |
-
*
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
* Fix:
|
38 |
-
|
39 |
-
= 1.
|
40 |
-
|
41 |
-
* New:
|
42 |
-
* New:
|
43 |
-
|
44 |
-
= 1.
|
45 |
-
|
46 |
-
* Update
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
1 |
+
=== Simple Registration for WooCommerce ===
|
2 |
+
Contributors: Astoundify
|
3 |
+
Donate link: https://www.paypal.me/astoundify
|
4 |
+
Tags: woocommerce, woocommerce registration, woocommerce register, woocommerce registration form, woocommerce form
|
5 |
+
Requires at least: 4.7.0
|
6 |
+
Tested up to: 5.5.3
|
7 |
+
Stable tag: 1.5.3
|
8 |
+
License: GPLv3 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
+
|
11 |
+
A simple plugin to add a [woocommerce_simple_registration] shortcode to display the registration form on a separate page.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
A simple plugin to add a [woocommerce_simple_registration] shortcode to display the registration form on a separate page.
|
16 |
+
|
17 |
+
== Installation ==
|
18 |
+
|
19 |
+
1. Upload the folder `woocommerce-simple-registration to the `/wp-content/plugins/` directory
|
20 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
21 |
+
3. Use the shortcode `woocommerce_simple_registration` on a self-created page to display the registration form.
|
22 |
+
|
23 |
+
== Changelog ==
|
24 |
+
|
25 |
+
= 1.5.3: November 25, 2020 =
|
26 |
+
|
27 |
+
* Update: Compatibility check with latest WordPress v5.5.3.
|
28 |
+
* Update: Compatibility check with Latest WooCommerce v4.6.1 .
|
29 |
+
* Update: Compatibility check with the latest PHP v7.4.10.
|
30 |
+
|
31 |
+
= 1.5.2: October 2, 2017 =
|
32 |
+
|
33 |
+
* Fix: Do not allow spam honeypot to autofill.
|
34 |
+
|
35 |
+
= 1.5.1: August 31, 2017 =
|
36 |
+
|
37 |
+
* Fix: Remove duplicate `register_form` hook.
|
38 |
+
|
39 |
+
= 1.5.0: August 23, 2017 =
|
40 |
+
|
41 |
+
* New: Option to enable First/Last name fields and mark required. WooCommerce > Settings > Accounts.
|
42 |
+
* New: Option to define the page the Register form appears on. Updates all default registration links. WooCommerce > Settings > Accounts.
|
43 |
+
|
44 |
+
= 1.4.0: April 12, 2017 =
|
45 |
+
|
46 |
+
* New: Update README.
|
47 |
+
* Fix: Update strings.
|
48 |
+
|
49 |
+
= 1.3.0: November 17, 2016 =
|
50 |
+
|
51 |
+
* New: WooCommerce Social Login support. Add output in WooCommerce > Settings > Social Login.
|
52 |
+
* New: Collect first and last name on registration.
|
53 |
+
|
54 |
+
= 1.2.0 =
|
55 |
+
|
56 |
+
* Update register form with latest WC. Enable Password Meter.
|
57 |
+
|
58 |
+
= 1.1.0 =
|
59 |
+
|
60 |
+
* Fix: Include .pot file
|
61 |
+
|
62 |
+
= 1.0.1 =
|
63 |
+
|
64 |
+
* woocommerce-simple-registration.php author, version text changes.
|
65 |
+
|
66 |
+
= 1.0.0 =
|
67 |
+
|
68 |
+
* Initial release
|
templates/registration-form.php
CHANGED
@@ -1,65 +1,65 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Registration form.
|
4 |
-
*
|
5 |
-
* @author
|
6 |
-
* @package WooCommerce-Simple-Registration
|
7 |
-
* @version 1.0.0
|
8 |
-
*/
|
9 |
-
|
10 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
11 |
-
wp_enqueue_script( 'wc-password-strength-meter' );
|
12 |
-
|
13 |
-
?><div class="registration-form woocommerce">
|
14 |
-
|
15 |
-
<?php wc_print_notices(); ?>
|
16 |
-
|
17 |
-
<h2><?php _e( 'Register', 'woocommerce-simple-registration' ); ?></h2>
|
18 |
-
|
19 |
-
<form method="post" class="register">
|
20 |
-
|
21 |
-
<?php do_action( 'woocommerce_register_form_start' ); ?>
|
22 |
-
|
23 |
-
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) : ?>
|
24 |
-
|
25 |
-
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
|
26 |
-
<label for="reg_username"><?php _e( 'Username', 'woocommerce-simple-registration' ); ?> <span class="required">*</span></label>
|
27 |
-
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="reg_username" value="<?php if ( ! empty( $_POST['username'] ) ) echo esc_attr( $_POST['username'] ); ?>" />
|
28 |
-
</p>
|
29 |
-
|
30 |
-
<?php endif; ?>
|
31 |
-
|
32 |
-
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
|
33 |
-
<label for="reg_email"><?php _e( 'Email address', 'woocommerce-simple-registration' ); ?> <span class="required">*</span></label>
|
34 |
-
<input type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?>" />
|
35 |
-
</p>
|
36 |
-
|
37 |
-
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) : ?>
|
38 |
-
|
39 |
-
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
|
40 |
-
<label for="reg_password"><?php _e( 'Password', 'woocommerce-simple-registration' ); ?> <span class="required">*</span></label>
|
41 |
-
<input type="password" class="woocommerce-Input woocommerce-Input--text input-text" name="password" id="reg_password" />
|
42 |
-
</p>
|
43 |
-
|
44 |
-
<?php endif; ?>
|
45 |
-
|
46 |
-
<!-- Spam Trap -->
|
47 |
-
<div style="<?php echo ( ( is_rtl() ) ? 'right' : 'left' ); ?>: -999em; position: absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woocommerce-simple-registration' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div>
|
48 |
-
|
49 |
-
<?php do_action( 'woocommerce_register_form' ); ?>
|
50 |
-
<?php do_action( 'woocommerce_simple_registration_form' ); ?>
|
51 |
-
|
52 |
-
<p class="woocomerce-FormRow form-row">
|
53 |
-
<?php wp_nonce_field( 'woocommerce-register', 'woocommerce-register-nonce' ); ?>
|
54 |
-
<input type="submit" class="woocommerce-Button button" name="register" value="<?php esc_attr_e( 'Register', 'woocommerce-simple-registration' ); ?>" />
|
55 |
-
</p>
|
56 |
-
|
57 |
-
<p class="woocommerce-simple-registration-login-link">
|
58 |
-
<a href="<?php echo esc_url( wp_login_url( get_permalink() ) ); ?>"><?php esc_html_e( 'Log in', 'woocommerce-simple-registration' ); ?></a>
|
59 |
-
</p>
|
60 |
-
|
61 |
-
<?php do_action( 'woocommerce_register_form_end' ); ?>
|
62 |
-
|
63 |
-
</form>
|
64 |
-
|
65 |
-
</div>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Registration form.
|
4 |
+
*
|
5 |
+
* @author Astoundify
|
6 |
+
* @package WooCommerce-Simple-Registration
|
7 |
+
* @version 1.0.0
|
8 |
+
*/
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit;
|
11 |
+
wp_enqueue_script( 'wc-password-strength-meter' );
|
12 |
+
|
13 |
+
?><div class="registration-form woocommerce">
|
14 |
+
|
15 |
+
<?php wc_print_notices(); ?>
|
16 |
+
|
17 |
+
<h2><?php _e( 'Register', 'woocommerce-simple-registration' ); ?></h2>
|
18 |
+
|
19 |
+
<form method="post" class="register">
|
20 |
+
|
21 |
+
<?php do_action( 'woocommerce_register_form_start' ); ?>
|
22 |
+
|
23 |
+
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) : ?>
|
24 |
+
|
25 |
+
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
|
26 |
+
<label for="reg_username"><?php _e( 'Username', 'woocommerce-simple-registration' ); ?> <span class="required">*</span></label>
|
27 |
+
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="reg_username" value="<?php if ( ! empty( $_POST['username'] ) ) echo esc_attr( $_POST['username'] ); ?>" />
|
28 |
+
</p>
|
29 |
+
|
30 |
+
<?php endif; ?>
|
31 |
+
|
32 |
+
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
|
33 |
+
<label for="reg_email"><?php _e( 'Email address', 'woocommerce-simple-registration' ); ?> <span class="required">*</span></label>
|
34 |
+
<input type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?>" />
|
35 |
+
</p>
|
36 |
+
|
37 |
+
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) : ?>
|
38 |
+
|
39 |
+
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
|
40 |
+
<label for="reg_password"><?php _e( 'Password', 'woocommerce-simple-registration' ); ?> <span class="required">*</span></label>
|
41 |
+
<input type="password" class="woocommerce-Input woocommerce-Input--text input-text" name="password" id="reg_password" />
|
42 |
+
</p>
|
43 |
+
|
44 |
+
<?php endif; ?>
|
45 |
+
|
46 |
+
<!-- Spam Trap -->
|
47 |
+
<div style="<?php echo ( ( is_rtl() ) ? 'right' : 'left' ); ?>: -999em; position: absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woocommerce-simple-registration' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" autocomplete="off" /></div>
|
48 |
+
|
49 |
+
<?php do_action( 'woocommerce_register_form' ); ?>
|
50 |
+
<?php do_action( 'woocommerce_simple_registration_form' ); ?>
|
51 |
+
|
52 |
+
<p class="woocomerce-FormRow form-row">
|
53 |
+
<?php wp_nonce_field( 'woocommerce-register', 'woocommerce-register-nonce' ); ?>
|
54 |
+
<input type="submit" class="woocommerce-Button button" name="register" value="<?php esc_attr_e( 'Register', 'woocommerce-simple-registration' ); ?>" />
|
55 |
+
</p>
|
56 |
+
|
57 |
+
<p class="woocommerce-simple-registration-login-link">
|
58 |
+
<a href="<?php echo esc_url( wp_login_url( get_permalink() ) ); ?>"><?php esc_html_e( 'Log in', 'woocommerce-simple-registration' ); ?></a>
|
59 |
+
</p>
|
60 |
+
|
61 |
+
<?php do_action( 'woocommerce_register_form_end' ); ?>
|
62 |
+
|
63 |
+
</form>
|
64 |
+
|
65 |
+
</div>
|
woocommerce-simple-registration.php
CHANGED
@@ -1,331 +1,331 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Plugin Name: Simple Registration for WooCommerce
|
4 |
-
* Plugin URI: https://astoundify.com/products/woocommerce-simple-registration/
|
5 |
-
* Description: A simple plugin to add a [woocommerce_simple_registration] shortcode to display the registration form on a separate page.
|
6 |
-
* Version: 1.5.
|
7 |
-
* Author: Astoundify
|
8 |
-
* Author URI: https://astoundify.com/
|
9 |
-
* Text Domain: woocommerce-simple-registration
|
10 |
-
* Domain Path: /languages
|
11 |
-
*/
|
12 |
-
|
13 |
-
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Class WooCommerce_Simple_Registration.
|
17 |
-
*
|
18 |
-
* Main WooCommerce_Simple_Registration class initializes the plugin.
|
19 |
-
*
|
20 |
-
* @class WooCommerce_Simple_Registration
|
21 |
-
* @version 1.0.0
|
22 |
-
* @author
|
23 |
-
*/
|
24 |
-
class WooCommerce_Simple_Registration {
|
25 |
-
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Plugin version.
|
29 |
-
*
|
30 |
-
* @since 1.0.0
|
31 |
-
* @var string $version Plugin version number.
|
32 |
-
*/
|
33 |
-
public $version = '1.5.
|
34 |
-
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Plugin file.
|
38 |
-
*
|
39 |
-
* @since 1.0.0
|
40 |
-
* @var string $file Plugin file path.
|
41 |
-
*/
|
42 |
-
public $file = __FILE__;
|
43 |
-
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Instace of WooCommerce_Simple_Registration.
|
47 |
-
*
|
48 |
-
* @since 1.0.0
|
49 |
-
* @access private
|
50 |
-
* @var object $instance The instance of WooCommerce_Simple_Registration.
|
51 |
-
*/
|
52 |
-
private static $instance;
|
53 |
-
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Construct.
|
57 |
-
*
|
58 |
-
* Initialize the class and plugin.
|
59 |
-
*
|
60 |
-
* @since 1.0.0
|
61 |
-
*/
|
62 |
-
public function __construct() {
|
63 |
-
if ( ! class_exists( 'WooCommerce' ) ) {
|
64 |
-
return;
|
65 |
-
}
|
66 |
-
|
67 |
-
// Initialize plugin parts
|
68 |
-
$this->init();
|
69 |
-
|
70 |
-
// woocommerce_simple_registration shortcode
|
71 |
-
add_shortcode( 'woocommerce_simple_registration', array( $this, 'registration_template' ) );
|
72 |
-
|
73 |
-
// add a body class on this page
|
74 |
-
add_filter( 'body_class', array( $this, 'body_class' ) );
|
75 |
-
|
76 |
-
// add first name and last name to register form
|
77 |
-
add_action( 'woocommerce_register_form_start', array( $this, 'add_name_input' ) );
|
78 |
-
add_action( 'woocommerce_created_customer', array( $this, 'save_name_input' ) );
|
79 |
-
|
80 |
-
// Settings.
|
81 |
-
add_filter( 'woocommerce_account_settings', array( $this, 'account_settings' ) );
|
82 |
-
|
83 |
-
// Filter WP Register URL.
|
84 |
-
add_filter( 'register_url', array( $this, 'register_url' ) );
|
85 |
-
|
86 |
-
/**
|
87 |
-
* WooCommerce Social Login Support
|
88 |
-
* @link http://www.woothemes.com/products/woocommerce-social-login/
|
89 |
-
* @since 1.3.0
|
90 |
-
*/
|
91 |
-
if( function_exists( 'init_woocommerce_social_login' ) ){
|
92 |
-
require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'includes/wc-social-login.php' );
|
93 |
-
}
|
94 |
-
}
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Instance.
|
98 |
-
*
|
99 |
-
* An global instance of the class. Used to retrieve the instance
|
100 |
-
* to use on other files/plugins/themes.
|
101 |
-
*
|
102 |
-
* @since 1.0.0
|
103 |
-
* @return object Instance of the class.
|
104 |
-
*/
|
105 |
-
public static function instance() {
|
106 |
-
if ( is_null( self::$instance ) ) {
|
107 |
-
self::$instance = new self();
|
108 |
-
}
|
109 |
-
|
110 |
-
return self::$instance;
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* init.
|
115 |
-
*
|
116 |
-
* Initialize plugin parts.
|
117 |
-
*
|
118 |
-
* @since 1.0.0
|
119 |
-
*/
|
120 |
-
public function init() {
|
121 |
-
$this->load_textdomain();
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Textdomain.
|
126 |
-
*
|
127 |
-
* Load the textdomain based on WP language.
|
128 |
-
*
|
129 |
-
* @since 1.0.0
|
130 |
-
*/
|
131 |
-
public function load_textdomain() {
|
132 |
-
load_plugin_textdomain( 'woocommerce-simple-registration', false, basename( dirname( __FILE__ ) ) . '/languages' );
|
133 |
-
}
|
134 |
-
|
135 |
-
|
136 |
-
/**
|
137 |
-
* Registartion template.
|
138 |
-
*
|
139 |
-
* Return the registration template contents.
|
140 |
-
*
|
141 |
-
* @return string HTML registration form template.
|
142 |
-
*/
|
143 |
-
public function registration_template() {
|
144 |
-
|
145 |
-
ob_start();
|
146 |
-
|
147 |
-
if ( ! is_user_logged_in() ) :
|
148 |
-
|
149 |
-
$message = apply_filters( 'woocommerce_registration_message', '' );
|
150 |
-
|
151 |
-
if ( ! empty( $message ) ) :
|
152 |
-
wc_add_notice( $message );
|
153 |
-
endif;
|
154 |
-
|
155 |
-
wc_get_template( 'registration-form.php', array(), 'woocommerce-simple-registration/', plugin_dir_path( __FILE__ ) . 'templates/' );
|
156 |
-
|
157 |
-
else :
|
158 |
-
echo do_shortcode( '[woocommerce_my_account]' );
|
159 |
-
endif;
|
160 |
-
|
161 |
-
$return = ob_get_contents();
|
162 |
-
ob_end_clean();
|
163 |
-
|
164 |
-
return $return;
|
165 |
-
|
166 |
-
}
|
167 |
-
|
168 |
-
/**
|
169 |
-
* Add body classes for WC Simple Register page.
|
170 |
-
*
|
171 |
-
* @since 1.2.0
|
172 |
-
* @param array $classes
|
173 |
-
* @return array
|
174 |
-
*/
|
175 |
-
public function body_class( $classes ) {
|
176 |
-
if( is_singular() && $post_data = get_post( get_queried_object_id() ) ){
|
177 |
-
if ( isset( $post_data->post_content ) && has_shortcode( $post_data->post_content, 'woocommerce_simple_registration' ) ) {
|
178 |
-
$classes[] = 'woocommerce-register';
|
179 |
-
$classes[] = 'woocommerce-account';
|
180 |
-
$classes[] = 'woocommerce-page';
|
181 |
-
}
|
182 |
-
}
|
183 |
-
return $classes;
|
184 |
-
}
|
185 |
-
|
186 |
-
/**
|
187 |
-
* Add First Name & Last Name
|
188 |
-
* To disable this simply use this code:
|
189 |
-
* `add_filter( 'woocommerce_simple_registration_name_fields', '__return_false' );`
|
190 |
-
* @since 1.3.0
|
191 |
-
*/
|
192 |
-
public function add_name_input(){
|
193 |
-
// Name Field Option.
|
194 |
-
$enabled = 'yes' === WC_Admin_Settings::get_option( 'woocommerce_simple_registration_name_fields', 'yes' ) ? true : false;
|
195 |
-
$required = 'yes' === WC_Admin_Settings::get_option( 'woocommerce_simple_registration_name_fields_required', 'no' ) ? true : false;
|
196 |
-
|
197 |
-
/* Filter to disable this feature. */
|
198 |
-
if( ! apply_filters( 'woocommerce_simple_registration_name_fields', true ) || ! $enabled ){
|
199 |
-
return;
|
200 |
-
}
|
201 |
-
?>
|
202 |
-
<p class="woocommerce-FormRow woocommerce-FormRow--first form-row form-row-first">
|
203 |
-
<label for="reg_sr_firstname"><?php _e( 'First Name', 'woocommerce-simple-registration' ); ?><?php echo( $required ? ' <span class="required">*</span>' : '' ) ?></label>
|
204 |
-
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="sr_firstname" id="reg_sr_firstname" value="<?php if ( ! empty( $_POST['sr_firstname'] ) ) echo esc_attr( $_POST['sr_firstname'] ); ?>" <?php echo( $required ? ' required' : '' ) ?>/>
|
205 |
-
</p>
|
206 |
-
|
207 |
-
<p class="woocommerce-FormRow woocommerce-FormRow--last form-row form-row-last">
|
208 |
-
<label for="reg_sr_lastname"><?php _e( 'Last Name', 'woocommerce-simple-registration' ); ?><?php echo( $required ? ' <span class="required">*</span>' : '' ) ?></label>
|
209 |
-
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="sr_lastname" id="reg_sr_lastname" value="<?php if ( ! empty( $_POST['sr_lastname'] ) ) echo esc_attr( $_POST['sr_lastname'] ); ?>" <?php echo( $required ? ' required' : '' ) ?> />
|
210 |
-
</p>
|
211 |
-
<?php
|
212 |
-
}
|
213 |
-
|
214 |
-
/**
|
215 |
-
* Save First Name and Last Name
|
216 |
-
* @since 1.3.0
|
217 |
-
* @see WC/includes/wc-user-functions.php line 114
|
218 |
-
*/
|
219 |
-
public function save_name_input( $customer_id ){
|
220 |
-
// Name Field Option.
|
221 |
-
$enable = 'yes' === WC_Admin_Settings::get_option( 'woocommerce_simple_registration_name_fields', 'yes' ) ? true : false;
|
222 |
-
|
223 |
-
/* Filter to disable this feature. */
|
224 |
-
if( ! apply_filters( 'woocommerce_simple_registration_name_fields', true ) || ! $enable ){
|
225 |
-
return;
|
226 |
-
}
|
227 |
-
|
228 |
-
/* Strip slash everything */
|
229 |
-
$request = stripslashes_deep( $_POST );
|
230 |
-
|
231 |
-
/* Save First Name */
|
232 |
-
if ( isset( $request['sr_firstname'] ) && !empty( $request['sr_firstname'] ) ) {
|
233 |
-
update_user_meta( $customer_id, 'first_name', sanitize_text_field( $request['sr_firstname'] ) );
|
234 |
-
}
|
235 |
-
/* Save Last Name */
|
236 |
-
if ( isset( $request['sr_lastname'] ) && !empty( $request['sr_lastname'] ) ) {
|
237 |
-
update_user_meta( $customer_id, 'last_name', sanitize_text_field( $request['sr_lastname'] ) );
|
238 |
-
}
|
239 |
-
}
|
240 |
-
|
241 |
-
/**
|
242 |
-
* Settings
|
243 |
-
*
|
244 |
-
* @since 1.5.0
|
245 |
-
*
|
246 |
-
* @param array $settings WooCommerce Accounts Settings.
|
247 |
-
* @return array
|
248 |
-
*/
|
249 |
-
public function account_settings( $settings ) {
|
250 |
-
$page = array(
|
251 |
-
array(
|
252 |
-
'title' => __( 'Registration page', 'woocommerce-simple-registration' ),
|
253 |
-
'desc' => __( 'Use this page as WordPress registration URL. Page contents: [woocommerce_simple_registration]', 'woocommerce-simple-registration' ),
|
254 |
-
'id' => 'woocommerce_simple_registration_register_page',
|
255 |
-
'default' => 0,
|
256 |
-
'type' => 'single_select_page',
|
257 |
-
'args' => array(
|
258 |
-
'option_none_value' => 0,
|
259 |
-
'show_option_none' => esc_html__( 'Select a page…', 'woocommerce-simple-registration' ),
|
260 |
-
),
|
261 |
-
'class' => 'wc-enhanced-select',
|
262 |
-
'css' => 'min-width:300px;',
|
263 |
-
'desc_tip' => true,
|
264 |
-
),
|
265 |
-
);
|
266 |
-
|
267 |
-
array_splice( $settings, 2, 0, $page );
|
268 |
-
|
269 |
-
$name = array(
|
270 |
-
array(
|
271 |
-
'desc' => __( 'Enable first and last name fields.', 'woocommerce-simple-registration' ),
|
272 |
-
'id' => 'woocommerce_simple_registration_name_fields',
|
273 |
-
'default' => 'yes',
|
274 |
-
'checkboxgroup' => '',
|
275 |
-
'type' => 'checkbox',
|
276 |
-
),
|
277 |
-
array(
|
278 |
-
'desc' => __( 'Require first and last name fields.', 'woocommerce-simple-registration' ),
|
279 |
-
'id' => 'woocommerce_simple_registration_name_fields_required',
|
280 |
-
'default' => 'no',
|
281 |
-
'checkboxgroup' => '',
|
282 |
-
'type' => 'checkbox',
|
283 |
-
),
|
284 |
-
);
|
285 |
-
|
286 |
-
array_splice( $settings, 9, 0, $name );
|
287 |
-
|
288 |
-
return $settings;
|
289 |
-
}
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Register URL
|
293 |
-
*
|
294 |
-
* @since 1.5.0
|
295 |
-
*
|
296 |
-
* @param string $url Registration URL.
|
297 |
-
* @return string $url
|
298 |
-
*/
|
299 |
-
public function register_url( $url ) {
|
300 |
-
$register_page = WC_Admin_Settings::get_option( 'woocommerce_simple_registration_register_page', 0 );
|
301 |
-
|
302 |
-
if ( $register_page && get_permalink( $register_page ) ) {
|
303 |
-
$url = esc_url( get_permalink( $register_page ) );
|
304 |
-
}
|
305 |
-
|
306 |
-
return $url;
|
307 |
-
}
|
308 |
-
|
309 |
-
}
|
310 |
-
|
311 |
-
|
312 |
-
/**
|
313 |
-
* The main function responsible for returning the WooCommerce_Simple_Registration object.
|
314 |
-
*
|
315 |
-
* Use this function like you would a global variable, except without needing to declare the global.
|
316 |
-
*
|
317 |
-
* Example: <?php WooCommerce_Simple_Registration()->method_name(); ?>
|
318 |
-
*
|
319 |
-
* @since 1.0.0
|
320 |
-
*
|
321 |
-
* @return object WooCommerce_Simple_Registration class object.
|
322 |
-
*/
|
323 |
-
if ( ! function_exists( 'WooCommerce_Simple_Registration' ) ) :
|
324 |
-
|
325 |
-
function WooCommerce_Simple_Registration() {
|
326 |
-
return WooCommerce_Simple_Registration::instance();
|
327 |
-
}
|
328 |
-
|
329 |
-
endif;
|
330 |
-
|
331 |
-
add_action( 'plugins_loaded', 'WooCommerce_Simple_Registration' );
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: Simple Registration for WooCommerce
|
4 |
+
* Plugin URI: https://astoundify.com/products/woocommerce-simple-registration/
|
5 |
+
* Description: A simple plugin to add a [woocommerce_simple_registration] shortcode to display the registration form on a separate page.
|
6 |
+
* Version: 1.5.3
|
7 |
+
* Author: Astoundify
|
8 |
+
* Author URI: https://astoundify.com/
|
9 |
+
* Text Domain: woocommerce-simple-registration
|
10 |
+
* Domain Path: /languages
|
11 |
+
*/
|
12 |
+
|
13 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Class WooCommerce_Simple_Registration.
|
17 |
+
*
|
18 |
+
* Main WooCommerce_Simple_Registration class initializes the plugin.
|
19 |
+
*
|
20 |
+
* @class WooCommerce_Simple_Registration
|
21 |
+
* @version 1.0.0
|
22 |
+
* @author Astoundify
|
23 |
+
*/
|
24 |
+
class WooCommerce_Simple_Registration {
|
25 |
+
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Plugin version.
|
29 |
+
*
|
30 |
+
* @since 1.0.0
|
31 |
+
* @var string $version Plugin version number.
|
32 |
+
*/
|
33 |
+
public $version = '1.5.3';
|
34 |
+
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Plugin file.
|
38 |
+
*
|
39 |
+
* @since 1.0.0
|
40 |
+
* @var string $file Plugin file path.
|
41 |
+
*/
|
42 |
+
public $file = __FILE__;
|
43 |
+
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Instace of WooCommerce_Simple_Registration.
|
47 |
+
*
|
48 |
+
* @since 1.0.0
|
49 |
+
* @access private
|
50 |
+
* @var object $instance The instance of WooCommerce_Simple_Registration.
|
51 |
+
*/
|
52 |
+
private static $instance;
|
53 |
+
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Construct.
|
57 |
+
*
|
58 |
+
* Initialize the class and plugin.
|
59 |
+
*
|
60 |
+
* @since 1.0.0
|
61 |
+
*/
|
62 |
+
public function __construct() {
|
63 |
+
if ( ! class_exists( 'WooCommerce' ) ) {
|
64 |
+
return;
|
65 |
+
}
|
66 |
+
|
67 |
+
// Initialize plugin parts
|
68 |
+
$this->init();
|
69 |
+
|
70 |
+
// woocommerce_simple_registration shortcode
|
71 |
+
add_shortcode( 'woocommerce_simple_registration', array( $this, 'registration_template' ) );
|
72 |
+
|
73 |
+
// add a body class on this page
|
74 |
+
add_filter( 'body_class', array( $this, 'body_class' ) );
|
75 |
+
|
76 |
+
// add first name and last name to register form
|
77 |
+
add_action( 'woocommerce_register_form_start', array( $this, 'add_name_input' ) );
|
78 |
+
add_action( 'woocommerce_created_customer', array( $this, 'save_name_input' ) );
|
79 |
+
|
80 |
+
// Settings.
|
81 |
+
add_filter( 'woocommerce_account_settings', array( $this, 'account_settings' ) );
|
82 |
+
|
83 |
+
// Filter WP Register URL.
|
84 |
+
add_filter( 'register_url', array( $this, 'register_url' ) );
|
85 |
+
|
86 |
+
/**
|
87 |
+
* WooCommerce Social Login Support
|
88 |
+
* @link http://www.woothemes.com/products/woocommerce-social-login/
|
89 |
+
* @since 1.3.0
|
90 |
+
*/
|
91 |
+
if( function_exists( 'init_woocommerce_social_login' ) ){
|
92 |
+
require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'includes/wc-social-login.php' );
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Instance.
|
98 |
+
*
|
99 |
+
* An global instance of the class. Used to retrieve the instance
|
100 |
+
* to use on other files/plugins/themes.
|
101 |
+
*
|
102 |
+
* @since 1.0.0
|
103 |
+
* @return object Instance of the class.
|
104 |
+
*/
|
105 |
+
public static function instance() {
|
106 |
+
if ( is_null( self::$instance ) ) {
|
107 |
+
self::$instance = new self();
|
108 |
+
}
|
109 |
+
|
110 |
+
return self::$instance;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* init.
|
115 |
+
*
|
116 |
+
* Initialize plugin parts.
|
117 |
+
*
|
118 |
+
* @since 1.0.0
|
119 |
+
*/
|
120 |
+
public function init() {
|
121 |
+
$this->load_textdomain();
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Textdomain.
|
126 |
+
*
|
127 |
+
* Load the textdomain based on WP language.
|
128 |
+
*
|
129 |
+
* @since 1.0.0
|
130 |
+
*/
|
131 |
+
public function load_textdomain() {
|
132 |
+
load_plugin_textdomain( 'woocommerce-simple-registration', false, basename( dirname( __FILE__ ) ) . '/languages' );
|
133 |
+
}
|
134 |
+
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Registartion template.
|
138 |
+
*
|
139 |
+
* Return the registration template contents.
|
140 |
+
*
|
141 |
+
* @return string HTML registration form template.
|
142 |
+
*/
|
143 |
+
public function registration_template() {
|
144 |
+
|
145 |
+
ob_start();
|
146 |
+
|
147 |
+
if ( ! is_user_logged_in() ) :
|
148 |
+
|
149 |
+
$message = apply_filters( 'woocommerce_registration_message', '' );
|
150 |
+
|
151 |
+
if ( ! empty( $message ) ) :
|
152 |
+
wc_add_notice( $message );
|
153 |
+
endif;
|
154 |
+
|
155 |
+
wc_get_template( 'registration-form.php', array(), 'woocommerce-simple-registration/', plugin_dir_path( __FILE__ ) . 'templates/' );
|
156 |
+
|
157 |
+
else :
|
158 |
+
echo do_shortcode( '[woocommerce_my_account]' );
|
159 |
+
endif;
|
160 |
+
|
161 |
+
$return = ob_get_contents();
|
162 |
+
ob_end_clean();
|
163 |
+
|
164 |
+
return $return;
|
165 |
+
|
166 |
+
}
|
167 |
+
|
168 |
+
/**
|
169 |
+
* Add body classes for WC Simple Register page.
|
170 |
+
*
|
171 |
+
* @since 1.2.0
|
172 |
+
* @param array $classes
|
173 |
+
* @return array
|
174 |
+
*/
|
175 |
+
public function body_class( $classes ) {
|
176 |
+
if( is_singular() && $post_data = get_post( get_queried_object_id() ) ){
|
177 |
+
if ( isset( $post_data->post_content ) && has_shortcode( $post_data->post_content, 'woocommerce_simple_registration' ) ) {
|
178 |
+
$classes[] = 'woocommerce-register';
|
179 |
+
$classes[] = 'woocommerce-account';
|
180 |
+
$classes[] = 'woocommerce-page';
|
181 |
+
}
|
182 |
+
}
|
183 |
+
return $classes;
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Add First Name & Last Name
|
188 |
+
* To disable this simply use this code:
|
189 |
+
* `add_filter( 'woocommerce_simple_registration_name_fields', '__return_false' );`
|
190 |
+
* @since 1.3.0
|
191 |
+
*/
|
192 |
+
public function add_name_input(){
|
193 |
+
// Name Field Option.
|
194 |
+
$enabled = 'yes' === WC_Admin_Settings::get_option( 'woocommerce_simple_registration_name_fields', 'yes' ) ? true : false;
|
195 |
+
$required = 'yes' === WC_Admin_Settings::get_option( 'woocommerce_simple_registration_name_fields_required', 'no' ) ? true : false;
|
196 |
+
|
197 |
+
/* Filter to disable this feature. */
|
198 |
+
if( ! apply_filters( 'woocommerce_simple_registration_name_fields', true ) || ! $enabled ){
|
199 |
+
return;
|
200 |
+
}
|
201 |
+
?>
|
202 |
+
<p class="woocommerce-FormRow woocommerce-FormRow--first form-row form-row-first">
|
203 |
+
<label for="reg_sr_firstname"><?php _e( 'First Name', 'woocommerce-simple-registration' ); ?><?php echo( $required ? ' <span class="required">*</span>' : '' ) ?></label>
|
204 |
+
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="sr_firstname" id="reg_sr_firstname" value="<?php if ( ! empty( $_POST['sr_firstname'] ) ) echo esc_attr( $_POST['sr_firstname'] ); ?>" <?php echo( $required ? ' required' : '' ) ?>/>
|
205 |
+
</p>
|
206 |
+
|
207 |
+
<p class="woocommerce-FormRow woocommerce-FormRow--last form-row form-row-last">
|
208 |
+
<label for="reg_sr_lastname"><?php _e( 'Last Name', 'woocommerce-simple-registration' ); ?><?php echo( $required ? ' <span class="required">*</span>' : '' ) ?></label>
|
209 |
+
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="sr_lastname" id="reg_sr_lastname" value="<?php if ( ! empty( $_POST['sr_lastname'] ) ) echo esc_attr( $_POST['sr_lastname'] ); ?>" <?php echo( $required ? ' required' : '' ) ?> />
|
210 |
+
</p>
|
211 |
+
<?php
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Save First Name and Last Name
|
216 |
+
* @since 1.3.0
|
217 |
+
* @see WC/includes/wc-user-functions.php line 114
|
218 |
+
*/
|
219 |
+
public function save_name_input( $customer_id ){
|
220 |
+
// Name Field Option.
|
221 |
+
$enable = 'yes' === WC_Admin_Settings::get_option( 'woocommerce_simple_registration_name_fields', 'yes' ) ? true : false;
|
222 |
+
|
223 |
+
/* Filter to disable this feature. */
|
224 |
+
if( ! apply_filters( 'woocommerce_simple_registration_name_fields', true ) || ! $enable ){
|
225 |
+
return;
|
226 |
+
}
|
227 |
+
|
228 |
+
/* Strip slash everything */
|
229 |
+
$request = stripslashes_deep( $_POST );
|
230 |
+
|
231 |
+
/* Save First Name */
|
232 |
+
if ( isset( $request['sr_firstname'] ) && !empty( $request['sr_firstname'] ) ) {
|
233 |
+
update_user_meta( $customer_id, 'first_name', sanitize_text_field( $request['sr_firstname'] ) );
|
234 |
+
}
|
235 |
+
/* Save Last Name */
|
236 |
+
if ( isset( $request['sr_lastname'] ) && !empty( $request['sr_lastname'] ) ) {
|
237 |
+
update_user_meta( $customer_id, 'last_name', sanitize_text_field( $request['sr_lastname'] ) );
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Settings
|
243 |
+
*
|
244 |
+
* @since 1.5.0
|
245 |
+
*
|
246 |
+
* @param array $settings WooCommerce Accounts Settings.
|
247 |
+
* @return array
|
248 |
+
*/
|
249 |
+
public function account_settings( $settings ) {
|
250 |
+
$page = array(
|
251 |
+
array(
|
252 |
+
'title' => __( 'Registration page', 'woocommerce-simple-registration' ),
|
253 |
+
'desc' => __( 'Use this page as WordPress registration URL. Page contents: [woocommerce_simple_registration]', 'woocommerce-simple-registration' ),
|
254 |
+
'id' => 'woocommerce_simple_registration_register_page',
|
255 |
+
'default' => 0,
|
256 |
+
'type' => 'single_select_page',
|
257 |
+
'args' => array(
|
258 |
+
'option_none_value' => 0,
|
259 |
+
'show_option_none' => esc_html__( 'Select a page…', 'woocommerce-simple-registration' ),
|
260 |
+
),
|
261 |
+
'class' => 'wc-enhanced-select',
|
262 |
+
'css' => 'min-width:300px;',
|
263 |
+
'desc_tip' => true,
|
264 |
+
),
|
265 |
+
);
|
266 |
+
|
267 |
+
array_splice( $settings, 2, 0, $page );
|
268 |
+
|
269 |
+
$name = array(
|
270 |
+
array(
|
271 |
+
'desc' => __( 'Enable first and last name fields.', 'woocommerce-simple-registration' ),
|
272 |
+
'id' => 'woocommerce_simple_registration_name_fields',
|
273 |
+
'default' => 'yes',
|
274 |
+
'checkboxgroup' => '',
|
275 |
+
'type' => 'checkbox',
|
276 |
+
),
|
277 |
+
array(
|
278 |
+
'desc' => __( 'Require first and last name fields.', 'woocommerce-simple-registration' ),
|
279 |
+
'id' => 'woocommerce_simple_registration_name_fields_required',
|
280 |
+
'default' => 'no',
|
281 |
+
'checkboxgroup' => '',
|
282 |
+
'type' => 'checkbox',
|
283 |
+
),
|
284 |
+
);
|
285 |
+
|
286 |
+
array_splice( $settings, 9, 0, $name );
|
287 |
+
|
288 |
+
return $settings;
|
289 |
+
}
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Register URL
|
293 |
+
*
|
294 |
+
* @since 1.5.0
|
295 |
+
*
|
296 |
+
* @param string $url Registration URL.
|
297 |
+
* @return string $url
|
298 |
+
*/
|
299 |
+
public function register_url( $url ) {
|
300 |
+
$register_page = WC_Admin_Settings::get_option( 'woocommerce_simple_registration_register_page', 0 );
|
301 |
+
|
302 |
+
if ( $register_page && get_permalink( $register_page ) ) {
|
303 |
+
$url = esc_url( get_permalink( $register_page ) );
|
304 |
+
}
|
305 |
+
|
306 |
+
return $url;
|
307 |
+
}
|
308 |
+
|
309 |
+
}
|
310 |
+
|
311 |
+
|
312 |
+
/**
|
313 |
+
* The main function responsible for returning the WooCommerce_Simple_Registration object.
|
314 |
+
*
|
315 |
+
* Use this function like you would a global variable, except without needing to declare the global.
|
316 |
+
*
|
317 |
+
* Example: <?php WooCommerce_Simple_Registration()->method_name(); ?>
|
318 |
+
*
|
319 |
+
* @since 1.0.0
|
320 |
+
*
|
321 |
+
* @return object WooCommerce_Simple_Registration class object.
|
322 |
+
*/
|
323 |
+
if ( ! function_exists( 'WooCommerce_Simple_Registration' ) ) :
|
324 |
+
|
325 |
+
function WooCommerce_Simple_Registration() {
|
326 |
+
return WooCommerce_Simple_Registration::instance();
|
327 |
+
}
|
328 |
+
|
329 |
+
endif;
|
330 |
+
|
331 |
+
add_action( 'plugins_loaded', 'WooCommerce_Simple_Registration' );
|