'office', 'nopaging' => true, 'orderby' => 'post_title', 'order' => 'ASC', ); $offices = array(); $offices_query = new WP_Query( $args ); if ( $offices_query->have_posts() ) { while ( $offices_query->have_posts() ) { $offices_query->the_post(); $offices[get_the_ID()] = get_the_title(); } } wp_reset_postdata(); $fields = array( 'office_id' => array( 'label' => __( 'Office', 'propertyhive' ), 'description' => '', 'type' => 'select', 'options' => array( '' => __( 'Select an office', 'propertyhive' ) ) + $offices, ), 'telephone_number' => array( 'label' => __( 'Telephone Number', 'propertyhive' ), 'description' => '', 'type' => 'text', ), 'photo_attachment_id' => array( 'label' => __( 'Photo', 'propertyhive' ), 'description' => '', 'type' => 'image', ), ); $user = wp_get_current_user(); $roles = (array)$user->roles; $fields['crm_only_mode'] = array( 'label' => __( 'Property Hive-Only Mode', 'propertyhive' ), 'description' => __( 'Enabling this option will remove all top level WordPress menu items leaving just Property Hive options making it easier to navigate and use as a CRM', 'propertyhive' ), 'type' => in_array('administrator', $roles) ? 'checkbox' : 'hidden', ); $show_fields = array( 'negotiator' => array( 'title' => __( 'Property Hive Negotiator Details', 'propertyhive' ), 'fields' => $fields, ), ); $show_fields = apply_filters( 'propertyhive_user_meta_fields', $show_fields ); return $show_fields; } /** * Show fields on edit user pages. * * @param WP_User $user */ public function extra_user_meta_fields( $user ) { if ( ! current_user_can( 'manage_propertyhive' ) ) { return; } $user_meta = get_userdata($user->ID); $user_roles = $user_meta->roles; if ( ! in_array("administrator", $user_roles) && ! in_array("editor", $user_roles) ) { return; } $show_fields = $this->get_user_meta_fields(); foreach ( $show_fields as $fieldset_key => $fieldset ) : ?>

$field ) : ?>
ID, $key, true ), 1, true ); ?> />
get_user_meta( $user->ID, $key )) ) { echo wp_get_attachment_image( $this->get_user_meta( $user->ID, $key ), 'thumbnail'); } ?>

roles; if ( ! in_array("administrator", $user_roles) && ! in_array("editor", $user_roles) ) { return; } $save_fields = $this->get_user_meta_fields(); foreach ( $save_fields as $fieldset ) { foreach ( $fieldset['fields'] as $key => $field ) { if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) ); } elseif ( isset( $_POST[ $key ] ) ) { update_user_meta( $user_id, $key, ph_clean( $_POST[ $key ] ) ); } } } } /** * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. * * @param int $user_id User ID of the user being edited * @param string $key Key for user meta field * @return string */ protected function get_user_meta( $user_id, $key ) { $value = get_user_meta( $user_id, $key, true ); return $value; } } endif; return new PH_Admin_Profile();