Website Summary Files Commits Branches @commit @diff @stats
path: root / wp-content / plugins / dx-users / class.cm.php
diff options
context:
space:
mode:
Commit79c17fdac6607c54098614aae8e5e6248b5651cb (patch)
Author
 pgmatev <petargabriel.matev@gmail.com>
2020-07-08 16:41:24 +0300
Committer
 pgmatev <petargabriel.matev@gmail.com>
2020-07-08 16:41:24 +0300
Files95befcfbc5109a63d9f263bd4e0fd89daed4880a /wp-content/plugins/dx-users/class.cm.php
tues-interns-2020-79c17fdac6607c54098614aae8e5e6248b5651cb.tar
tues-interns-2020-79c17fdac6607c54098614aae8e5e6248b5651cb.tar.gz
tues-interns-2020-79c17fdac6607c54098614aae8e5e6248b5651cb.zip
Parentb4d0ab60a0da25c1ee95134d936b998e1e491975 (diff)
Validation works; Problem with saving
1 files changed, 30 insertions, 12 deletions
-rw-r--r--wp-content/plugins/dx-users/class.cm.php42
diff --git a/wp-content/plugins/dx-users/class.cm.php b/wp-content/plugins/dx-users/class.cm.php
index 23d07e4..dae01a8 100644
--- a/wp-content/plugins/dx-users/class.cm.php
+++ b/wp-content/plugins/dx-users/class.cm.php
@@ -2,13 +2,14 @@
class Users {
function init() {
// add_filter( 'user_contactmethods', array( $this, 'add_custom_box_user' ), 10, 1 );
- add_action( 'show_user_profile', 'renderProfileFields' );
- add_action( 'edit_user_profile', 'renderProfileFields' );
+ add_action( 'show_user_profile', array( $this, 'render_profile_fields' ) );
+ add_action( 'edit_user_profile', array( $this, 'render_profile_fields' ) );
// validate profile fields
- add_action( 'user_profile_update_errors', 'validateProfileFields', 10, 3 );
+ add_action( 'user_profile_update_errors', array( $this, 'validate_profile_phone' ), 10, 3 );
+ add_action( 'user_profile_update_errors', array( $this, 'validate_profile_address' ), 10, 3 );
// save profile fields
- add_action( 'edit_user_profile_update', 'saveProfileFields' );
- add_action( 'personal_options_update', 'saveProfileFields' );
+ // add_action( 'edit_user_profile_update', array( $this, 'save_profile_fields' ), 10 );
+ // add_action( 'personal_options_update', array( $this, 'save_profile_fields' ) );
}
// function add_custom_box_user($contact_methods) {
// $new_methods = array(
@@ -30,7 +31,7 @@ class Users {
// return $contact_methods;
// }
- function renderProfileFields( WP_User $user ) { ?>
+ function render_profile_fields( $user ) { ?>
<h3>More Information</h3>
<table class="form-table">
@@ -51,18 +52,35 @@ class Users {
<?php }
- function validateProfileFields( WP_Error &$errors, $update, &$user ) {
+ function validate_profile_phone( &$errors, $update, &$user ) {
// validate input fields
if ( !empty( $_POST['phone'] ) && strlen( $_POST['phone'] ) > 10 && !empty( $_POST['phone'] ) )
$errors->add( 'phone', "<strong>ERROR</strong>: The maximum phone length is 10 characters." );
+
+ if( !empty( $errors ) )
+ return $errors;
+ else {
+ add_action( 'edit_user_profile_update', array( $this, 'save_profile_fields' ) );
+ add_action( 'personal_options_update', array( $this, 'save_profile_fields' ) );
+ }
- if ( !empty( $_POST['address'] ) && strlen( $_POST['address'] ) > 255 && !empty( $_POST['address'] ) )
- $errors->add( 'address', "<strong>ERROR</strong>: The maximum address length is 255 characters." ); //Unsure what address validation to use
-
- return $errors;
}
- function saveProfileFields( $id ) {
+ function validate_profile_address( &$errors, $update, &$user ) {
+ // validate input fields
+ if ( !empty( $_POST['address'] ) && strlen( $_POST['address'] ) > 255 && !empty( $_POST['address'] ) )
+ $errors->add( 'address', "<strong>ERROR</strong>: The maximum address length is 255 characters." ); //test validation; TO DO define proper validation
+
+ if( !empty( $errors ) )
+ return $errors;
+ else {
+ add_action( 'edit_user_profile_update', array( $this, 'save_profile_fields' ) );
+ add_action( 'personal_options_update', array( $this, 'save_profile_fields' ) );
+ }
+
+ }
+
+ function save_profile_fields( $id ) {
// save input fields values
if ( !current_user_can( 'edit_user', $id ) )
return false;