diff options
| Commit | cf1261ebf098dc0e644544ca2e57ceadfe51c476 (patch) | |
|---|---|---|
| Author | 2020-07-13 19:03:33 +0300 | |
| Committer | 2020-07-13 19:03:33 +0300 | |
| Files | 83da65e5bfc806bdd311201e5cc27354612dbe04 | |
| tues-interns-2020-feature-users-cm.tar tues-interns-2020-feature-users-cm.tar.gz tues-interns-2020-feature-users-cm.zip | ||
| Parent | a31eb16e5edbb293e8714f70c5f88d89dcc5e29d (diff) | |
fixed saving after validation; changed file names to match proposed naming feature-users-cm
4 files changed, 62 insertions, 44 deletions
| -rw-r--r-- | wp-content/plugins/dx-cars/car-info-display-callback.php | 27 | ||||
| -rw-r--r-- | wp-content/plugins/dx-cars/dx-vehicles.php (renamed from wp-content/plugins/dx-cars/dx-cars.php) | 0 | ||||
| -rw-r--r-- | wp-content/plugins/dx-users/dx-users.php | 2 | ||||
| -rw-r--r-- | wp-content/plugins/dx-users/users-class.php (renamed from wp-content/plugins/dx-users/class.cm.php) | 77 |
diff --git a/wp-content/plugins/dx-cars/car-info-display-callback.php b/wp-content/plugins/dx-cars/car-info-display-callback.php new file mode 100644 index 0000000..b8931aa --- /dev/null +++ b/wp-content/plugins/dx-cars/car-info-display-callback.php @@ -0,0 +1,27 @@ +<table> + <tr> + <td><?php _e( 'Year:' ) ?></td> + <td><input type="text" name="car-year" value="<?php echo( sanitize_text_field( get_post_meta( get_the_ID(), __( 'car-year' ), true ) ) ) ?>"></td> + </tr> + <tr> + <td><?php _e( 'Millage:' ) ?></td> + <td><input type="text" name="car-millage" value="<?php echo( sanitize_text_field( get_post_meta( get_the_ID(), __( 'car-millage' ), true ) ) ) ?>"></td> + </tr> + <tr> + <td><?php _e( 'Price:' ) ?></td> + <td><input type="text" name="car-price" value="<?php echo( sanitize_text_field( get_post_meta( get_the_ID(), __( 'car-price' ), true ) ) ) ?>"></td> + </tr> + <tr> + <td><?php _e( 'Photo:' ) ?></td> + <td><input type="file" name="car-images[]" value="" multiple></td> + </tr> + <tr> + <td><?php _e( 'Uploaded photo<br>(might need page refresh):' ) ?></td> + <?php + $images = ( array )json_decode( get_post_meta( get_the_ID(), __( 'car-images' ), true ) ); + foreach ( $images as $image ) { + echo( '<td> <img src="' . $image . '" alt=""></td>' ); + } + ?> + </tr> +</table> diff --git a/wp-content/plugins/dx-cars/dx-cars.php b/wp-content/plugins/dx-cars/dx-vehicles.php index e4bdaf0..e4bdaf0 100644 --- a/wp-content/plugins/dx-cars/dx-cars.php +++ b/wp-content/plugins/dx-cars/dx-vehicles.php diff --git a/wp-content/plugins/dx-users/dx-users.php b/wp-content/plugins/dx-users/dx-users.php index a12b985..f85b596 100644 --- a/wp-content/plugins/dx-users/dx-users.php +++ b/wp-content/plugins/dx-users/dx-users.php @@ -11,7 +11,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); -include 'class.cm.php'; +include 'users-class.php'; $users = new Users; $users->init(); diff --git a/wp-content/plugins/dx-users/class.cm.php b/wp-content/plugins/dx-users/users-class.php index beb0b1c..958d12b 100644 --- a/wp-content/plugins/dx-users/class.cm.php +++ b/wp-content/plugins/dx-users/users-class.php @@ -4,12 +4,19 @@ class Users { // add_filter( 'user_contactmethods', array( $this, 'add_custom_box_user' ), 10, 1 ); 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', 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', array( $this, 'save_profile_fields' ), 10 ); - // add_action( 'personal_options_update', array( $this, 'save_profile_fields' ) ); + // // validate profile fields + // add_action( 'user_profile_update_errors', array( $this, 'validate_profile_phone' ), 0, 3 ); + // add_action( 'user_profile_update_errors', array( $this, 'validate_profile_address' ), 0, 3 ); + // // save profile fields + // // add_action( 'edit_user_profile_update', array( $this, 'save_profile_fields' ), 10 ); + // // add_action( 'personal_options_update', array( $this, 'save_profile_fields' ) ); + // add_action( 'user_profile_update_errors', array( $this, 'validate_profile_fields' ), 0, 3 ); + // validate profile field + add_action( 'user_profile_update_errors', array( $this, 'validate_profile_fields' ), 0, 3 ); + +// save profile fields to your own profile and others. + add_action( 'edit_user_profile_update', array( $this, 'save_profile_fields' ) ); + add_action( 'personal_options_update', array( $this, 'save_profile_fields' ) ); } // function add_custom_box_user($contact_methods) { // $new_methods = array( @@ -52,57 +59,41 @@ class Users { <?php } - function validate_profile_phone( $errors, $update, $user ) { - $error_check = false; + + function validate_profile_fields( &$errors, $update, &$user ) { $phone_regex = "/08[789]\d{7}/u"; - // validate input fields + if ( !empty( $_POST['phone'] ) && strlen( $_POST['phone'] ) > 10) { + $errors->add( 'phone', "<strong>ERROR</strong>: The maximum phone length is 10 characters." ); - $error_check = true; - } + } if ( preg_match( $phone_regex, $_POST['phone'] ) == 0 ) { + $errors->add( 'phone', "<strong>ERROR</strong>: Not a valid phone number." ); - $error_check = true; } - if( $error_check ) { - error_log("shareni bomboni"); - return $errors; - } - - error_log("shareni bomboni sled if"); - add_action( 'edit_user_profile_update', array( $this, 'save_profile_fields' ) ); - add_action( 'personal_options_update', array( $this, 'save_profile_fields' ) ); + return $errors; } - function validate_profile_address( $errors, $update, $user ) { - $error_check = false; - // validate input fields - if ( !empty( $_POST['address'] ) && strlen( $_POST['address'] ) > 255 ) { - $errors->add( 'address', "<strong>ERROR</strong>: The maximum address length is 255 characters." ); //test validation; TO DO define proper validation - $error_check = true; - } + function save_profile_fields( $id ) { + + // save input fields values + $phone_regex = "/08[789]\d{7}/u"; + + if ( !current_user_can( 'edit_user', $id ) ) + return false; - if( $error_check ){ - return $errors; - } + if ( isset( $_POST['phone'] )) { - add_action( 'edit_user_profile_update', array( $this, 'save_profile_fields' ) ); - add_action( 'personal_options_update', array( $this, 'save_profile_fields' ) ); - + if ( preg_match( $phone_regex, $_POST['phone'] ) == 1 ) { + update_user_meta( $id, 'phone', sanitize_text_field( $_POST['phone'] ) ); + } } - function save_profile_fields( $id ) { - // save input fields values - if ( !current_user_can( 'edit_user', $id ) ) - return false; - - if ( isset( $_POST['phone'] ) ) - update_user_meta( $id, 'phone', $_POST['phone'] ); - - if ( isset( $_POST['address'] ) ) - update_user_meta( $id, 'address', $_POST['address'] ); + if ( isset( $_POST['address'] ) ) { + update_user_meta( $id, 'address', sanitize_text_field( $_POST['address'] ) ); + } } }
\ No newline at end of file |
