-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
180 additions
and
3,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'react-dom', 'wp-components', 'wp-element'), 'version' => '9ec528758fc3f9592913d4b74a35ca73'); | ||
<?php return array('dependencies' => array('react', 'react-dom', 'wp-components', 'wp-element'), 'version' => '11773b60f52872ed16ec7b3f3137b87b'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Contains the plugin helper methods. | ||
* | ||
* @since 1.0.0 | ||
* @package PQFW | ||
*/ | ||
|
||
namespace PQFW\Classes; | ||
|
||
// if direct access than exit the file. | ||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* Contains the plugin helper methods. | ||
* | ||
* @since 1.0.0 | ||
* @package PQFW | ||
*/ | ||
class Helpers { | ||
|
||
/** | ||
* Replaces placeholders with links to WooCommerce policy pages. | ||
* | ||
* @since 2.0.0 | ||
* @param string $text Text to find/replace within. | ||
* @return string Text with replaced placeholders. | ||
*/ | ||
public function generatePrivacyPolicy( $text ) { | ||
return function_exists( 'wc_replace_policy_page_link_placeholders' ) ? wc_replace_policy_page_link_placeholders( $text ) : $text; | ||
} | ||
|
||
/** | ||
* Sanitize phone number. | ||
* Allows only numbers and "+" (plus sign). | ||
* | ||
* @param string $phone Phone number. | ||
* | ||
* @return string | ||
* @since 1.0.0 | ||
*/ | ||
public function sanitizePhoneNumber( $phone ) { | ||
return preg_replace( '/[^\d+]/', '', $phone ); | ||
} | ||
|
||
/** | ||
* Validate user data. | ||
* | ||
* @since 2.0.0 | ||
* @param array $fields The input fields value to validate. | ||
* return mixed | ||
*/ | ||
public function validate( $fields ) { | ||
$errors = new \WP_Error(); | ||
|
||
$requiredFields = [ | ||
'fullname', | ||
'email' | ||
]; | ||
|
||
foreach ( $requiredFields as $required ) { | ||
if ( empty( $fields[ $required ] ) ) { | ||
$errors->add( 'field', sprintf( '%s %s', $required, __( 'is required.', 'pqfw' ) ) ); | ||
} | ||
} | ||
|
||
if ( $errors->has_errors() ) { | ||
return $errors; | ||
} | ||
|
||
if ( strlen( $fields['fullname'] ) < 4 ) { | ||
$errors->add( 'username_length', __( 'Username too short. At least 4 characters is required', 'pqfw' ) ); | ||
} | ||
|
||
if ( ! validate_username( $fields['fullname'] ) ) { | ||
$errors->add( 'username_invalid', __( 'Sorry, the username you entered is not valid', 'pqfw' ) ); | ||
} | ||
|
||
if ( ! is_email( $fields['email'] ) ) { | ||
$errors->add( 'email_invalid', __( 'Email is not valid', 'pqfw' ) ); | ||
} | ||
|
||
return $errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.