User::profile_edit()


Source

File: classes/User.php

	public function profile_edit() {

		dozent_checking_nonce();

		$user_id = get_current_user_id();

		$submit_btn = dozent_input_text( 'submit_btn' );
		if ( $submit_btn === 'delete_profile_photo' ) {
			delete_user_meta( $user_id, '_dozent_profile_photo' );
			dozent_redirect();
		}

		$config = apply_filters( 'dozent_profile_edit_form_validation_rules', [
			[
				'field' => 'first_name',
				'label' => __( 'First Name', 'dozent' ),
				'rules' => 'required',
			],
			[
				'field' => 'last_name',
				'label' => __( 'Last Name', 'dozent' ),
				'rules' => 'required',
			],
		] );

		$validator = dozent_form_validate( $config );

		/**
		 * If validator fail, stop script
		 */
		if ( ! $validator->success ) {
			return;
		}

		$first_name   = dozent_input_text( 'first_name' );
		$last_name    = dozent_input_text( 'last_name' );
		$display_name = dozent_input_text( 'display_name' );

		$userdata = array(
			'ID'           => $user_id,
			'first_name'   => $first_name,
			'last_name'    => $last_name,
			'display_name' => $display_name,
		);
		$user_id  = wp_update_user( $userdata );

		if ( ! is_wp_error( $user_id ) ) {

			$bio       = dozent_input_textarea( 'dozent_profile_bio' );
			$job_title = dozent_input_text( 'dozent_profile_job_title' );

			update_user_meta( $user_id, '_dozent_profile_bio', $bio );
			update_user_meta( $user_id, '_dozent_profile_job_title', $job_title );

			$social_links = dozent_get_user_social_links();
			foreach ( $social_links as $key => $link ) {
				$user_social_value = dozent_input_text( $key );
				if ( $user_social_value ) {
					update_user_meta( $user_id, $key, $user_social_value );
				} else {
					delete_user_meta( $user_id, $key );
				}
			}

			$this->photo_upload( $user_id );
		}

		do_action( 'dozent_profile_update_after', $user_id );

		dozent_set_flash_message( __( 'Profile has been udpated', 'dozent' ) );
		dozent_redirect();

	}