diff --git a/inc/admin/agency/class-agency.php b/inc/admin/agency/class-agency.php index cb929ac1..c31248d7 100755 --- a/inc/admin/agency/class-agency.php +++ b/inc/admin/agency/class-agency.php @@ -1,38 +1,32 @@ -ID) && $post->ID ){ + $post = get_post( $related_id ); + if ( isset( $post->ID ) && $post->ID ) { OpalEstate_Agency::update_data_from_user( $related_id ); } } @@ -56,101 +50,120 @@ class Opalestate_Admin_Agency { } /** + * Update some user metas. * + * @param int $related_id Post ID. */ - public function metaboxes_fields( $prefix = '' ){ - - if ( ! $prefix ) { - $prefix = OPALESTATE_AGENCY_PREFIX; + public static function update_user_metas( $user_id ) { + $terms = [ + 'location', + 'state', + 'city', + ]; + + foreach ( $terms as $term ) { + if ( isset( $_POST[ OPALESTATE_USER_PROFILE_PREFIX . $term ] ) ) { + update_user_meta( $user_id, OPALESTATE_USER_PROFILE_PREFIX . $term, $_POST[ OPALESTATE_USER_PROFILE_PREFIX . $term ] ); + } } - - $fields = array( - - - - array( - 'name' => esc_html__('Gallery' ,'opalestate-pro'), - 'desc' => esc_html__('Select one, to add new you create in location of estate panel','opalestate-pro'), - 'id' => $prefix."gallery", - 'type' => 'file_list', - ) , - - array( - 'name' => esc_html__( 'Slogan', 'opalestate-pro' ), - 'id' => "{$prefix}slogan", - 'type' => 'text' - ) - ); - - return apply_filters( 'opalestate_postype_agency_metaboxes_fields' , $fields ); } /** * */ - public function metaboxes( ){ + public function metaboxes_fields( $prefix = '' ) { - global $pagenow; + if ( ! $prefix ) { + $prefix = OPALESTATE_AGENCY_PREFIX; + } + + $fields = [ + + + [ + 'name' => esc_html__( 'Gallery', 'opalestate-pro' ), + 'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ), + 'id' => $prefix . "gallery", + 'type' => 'file_list', + ], + + [ + 'name' => esc_html__( 'Slogan', 'opalestate-pro' ), + 'id' => "{$prefix}slogan", + 'type' => 'text', + ], + ]; + + return apply_filters( 'opalestate_postype_agency_metaboxes_fields', $fields ); + } + + /** + * + */ + public function metaboxes() { + + global $pagenow; + + if ( ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) ) { - if( ($pagenow == 'post.php' || $pagenow == 'post-new.php') ) { - $prefix = OPALESTATE_AGENCY_PREFIX; - $metabox = new Opalestate_Agency_MetaBox(); - - $fields = $this->metaboxes_fields(); - $fields = array_merge_recursive( $fields , - $metabox->get_office_fields( $prefix ), + $metabox = new Opalestate_Agency_MetaBox(); + + $fields = $this->metaboxes_fields(); + $fields = array_merge_recursive( $fields, + $metabox->get_office_fields( $prefix ), $metabox->get_address_fields( $prefix ) ); - $box_options = array( + $box_options = [ 'id' => $prefix . 'edit', 'title' => esc_html__( 'Metabox', 'opalestate-pro' ), - 'object_types' => array( 'opalestate_agency' ), + 'object_types' => [ 'opalestate_agency' ], 'show_names' => true, - ); + ]; // Setup meta box $cmb = new_cmb2_box( $box_options ); // Setting tabs - $tabs_setting = array( + $tabs_setting = [ 'config' => $box_options, 'layout' => 'vertical', // Default : horizontal - 'tabs' => array() - ); + 'tabs' => [], + ]; - $tabs_setting['tabs'][] = array( + $tabs_setting['tabs'][] = [ 'id' => 'p-general', - 'icon' => 'dashicons-admin-home', + 'icon' => 'dashicons-admin-home', 'title' => esc_html__( 'General', 'opalestate-pro' ), - 'fields' => $fields - ); + 'fields' => $fields, + ]; - $tabs_setting['tabs'][] = array( + $tabs_setting['tabs'][] = [ 'id' => 'p-socials', - 'icon' => 'dashicons-share', + 'icon' => 'dashicons-share', 'title' => esc_html__( 'Socials', 'opalestate-pro' ), - 'fields' => $metabox->get_social_fields( $prefix ) - ); + 'fields' => $metabox->get_social_fields( $prefix ), + ]; - $tabs_setting['tabs'][] = array( + $tabs_setting['tabs'][] = [ 'id' => 'p-target', - 'icon' => 'dashicons-admin-tools', + 'icon' => 'dashicons-admin-tools', 'title' => esc_html__( 'Team', 'opalestate-pro' ), - 'fields' => $metabox->metaboxes_target() - ); + 'fields' => $metabox->metaboxes_target(), + ]; // Set tabs - $cmb->add_field( array( + $cmb->add_field( [ 'id' => '__tabs', 'type' => 'tabs', - 'tabs' => $tabs_setting - ) ); + 'tabs' => $tabs_setting, + ] ); } } } + new Opalestate_Admin_Agency(); diff --git a/inc/agency/class-opalestate-agency.php b/inc/agency/class-opalestate-agency.php index 8db9ebd4..0bb6f05a 100755 --- a/inc/agency/class-opalestate-agency.php +++ b/inc/agency/class-opalestate-agency.php @@ -36,7 +36,7 @@ class OpalEstate_Agency { * * @access protected */ - public $author; + public $author; /** * @var Boolean $is_featured @@ -61,13 +61,13 @@ class OpalEstate_Agency { * Constructor */ public function __construct( $post_id = null ) { - global $post ; + global $post; - if( $post == null ) { + if ( $post == null ) { $post = WP_Post::get_instance( $post_id ); - } - - $this->post = $post; + } + + $this->post = $post; $this->post_id = $post_id ? $post_id : get_the_ID(); $this->author = get_userdata( $post->post_author ); $this->author_name = ! empty( $this->author ) ? sprintf( '%s %s', $this->author->first_name, $this->author->last_name ) : null; @@ -114,15 +114,15 @@ class OpalEstate_Agency { /** * Get url of user avatar by agency id */ - public static function get_avatar_url( $userID, $size='thumbnail' ) { - - $id = get_post_meta( $userID, OPALESTATE_AGENCY_PREFIX . 'avatar_id', true ); - $url = wp_get_attachment_image_url( $id, $size ); + public static function get_avatar_url( $userID, $size = 'thumbnail' ) { - if( $url ) { + $id = get_post_meta( $userID, OPALESTATE_AGENCY_PREFIX . 'avatar_id', true ); + $url = wp_get_attachment_image_url( $id, $size ); + + if ( $url ) { return $url; - } - + } + return get_post_meta( $userID, OPALESTATE_AGENCY_PREFIX . 'avatar', true ); } @@ -239,7 +239,7 @@ class OpalEstate_Agency { ]; } - $url = self::get_avatar_url( $agency_id ); + $url = self::get_avatar_url( $agency_id ); return [ 'name' => $agency->post_title, @@ -313,7 +313,7 @@ class OpalEstate_Agency { * @param string $context What the value is for. Valid values are view and edit. * @return int */ - public function get_category_tax ( ) { + public function get_category_tax() { return wp_get_post_terms( $this->post_id, 'opalestate_agency_cat' ); } @@ -330,7 +330,7 @@ class OpalEstate_Agency { /** * Update user data. * - * @param $user_id User ID. + * @param int $user_id User ID. */ public static function update_user_data( $user_id ) { $fields = self::metaboxes_fields(); @@ -349,7 +349,9 @@ class OpalEstate_Agency { } } - // update for others + static::update_user_object_terms( $user_id ); + + // Update for others foreach ( $others as $key => $value ) { $kpos = OPALESTATE_AGENCY_PREFIX . $key; if ( isset( $_POST[ $kpos ] ) ) { @@ -362,7 +364,7 @@ class OpalEstate_Agency { /** * Update data from user. * - * @param $related_id Post ID + * @param int $related_id Post ID */ public static function update_data_from_user( $related_id ) { $fields = self::metaboxes_fields(); @@ -382,7 +384,9 @@ class OpalEstate_Agency { } } - // update for others + static::update_post_object_terms( $related_id ); + + // Update for others. foreach ( $others as $key => $value ) { $kpos = OPALESTATE_USER_PROFILE_PREFIX . $key; if ( isset( $_POST[ $kpos ] ) ) { @@ -391,4 +395,42 @@ class OpalEstate_Agency { } } } + + /** + * Update object terms. + * + * @param int $related_id Post ID. + */ + public static function update_user_object_terms( $user_id ) { + $terms = [ + 'location', + 'state', + 'city', + ]; + + foreach ( $terms as $term ) { + if ( isset( $_POST[ OPALESTATE_AGENCY_PREFIX . $term ] ) ) { + wp_set_object_terms( $user_id, $_POST[ OPALESTATE_AGENCY_PREFIX . $term ], 'opalestate_' . $term ); + } + } + } + + /** + * Update object terms. + * + * @param int $related_id Post ID. + */ + public static function update_post_object_terms( $related_id ) { + $terms = [ + 'location', + 'state', + 'city', + ]; + + foreach ( $terms as $term ) { + if ( isset( $_POST[ OPALESTATE_USER_PROFILE_PREFIX . $term ] ) ) { + wp_set_object_terms( $related_id, $_POST[ OPALESTATE_USER_PROFILE_PREFIX . $term ], 'opalestate_' . $term ); + } + } + } } diff --git a/inc/api/v1/user.php b/inc/api/v1/user.php index 6c6573f6..3cecc610 100644 --- a/inc/api/v1/user.php +++ b/inc/api/v1/user.php @@ -380,6 +380,8 @@ class Opalestate_User_Api extends Opalestate_Base_API { } } + $this->update_object_terms( $request['id'], $request ); + // Update for others. foreach ( $others as $key => $value ) { $kpos = OPALESTATE_AGENCY_PREFIX . $key;