Easy Property Listings 3.5.15 Code Reference
  • Package
  • Class
  • Tree
  • Todo
  • Hook Reference

Packages

  • EPL
    • Admin
      • Actions
      • Classes
        • ContactsTable
        • ReportsGraph
        • Welcome
      • Contacts
      • ContactsActions
      • ContactsFunctions
      • Elements
      • Functions
      • Help
      • HelpSingle
      • Menus
      • MenusAddons
      • MenusExtensions
      • MenusLicenses
      • Plugins
      • Reports
      • ReportsGraphing
      • User
    • Assets
      • ScriptsStyles
      • SVG
    • Classes
      • AuthorLoader
      • AuthorMeta
      • Contact
      • Cron
      • CustomPostType
      • Forms
      • License
      • ListingAdvanced
      • ListingElements
      • MetaboxesCustomFields
      • Pagination
      • PropertyMeta
      • RenderFields
      • RestAPI
      • Search
      • Session
      • Updater
    • Compatibility
      • Extensions
      • Functions
      • Shortcodes
    • Functions
      • Actions
      • ConditionalTags
      • ErrorTracking
      • Formatting
      • Front
      • Global
      • Install
      • Pagination
      • Settings
      • Templates
    • Hooks
      • EnergyCertificate
      • ExternalLinks
      • FloorPlan
      • Map
      • ReadMore
      • WebLink
    • Meta
      • InitCustomFields
      • Meta
    • PostTypes
      • Business
      • Commercial
      • CommercialLand
      • Contact
      • Functions
      • Land
      • Property
      • Rental
      • Rural
    • Shortcode
      • CommercialListingSearch
      • ContactForm
      • Listing
      • ListingAdvanced
      • ListingAuction
      • ListingCategory
      • ListingFeature
      • ListingLocation
      • ListingMetaDoc
      • ListingOpen
      • ListingResults
      • ListingSearch
      • Map
    • Taxonomy
      • BusinessCategories
      • ContactTag
      • Features
      • Location
    • Templates
      • Themes
        • iThemes
        • iThemesBuilder
    • Widget
      • Admin
        • Dashboard
      • Classes
        • Author
        • ContactCapture
        • Gallery
        • Listing
        • Search
      • Functions
  • None
  • WordPress
    • Session

Classes

  • EPL_Advanced_Shortcode_Listing
  • EPL_Author
  • EPL_Author_Loader
  • EPL_Author_Meta
  • EPL_Contact
  • EPL_Contact_Reports_Table
  • EPL_CPT
  • EPL_Cron
  • EPL_FORM_BUILDER
  • EPL_Graph
  • EPL_License
  • EPL_Listing_Elements
  • EPL_METABOX
  • EPL_Pagination_Call
  • EPL_Property_Meta
  • EPL_Render_Fields
  • EPL_Rest_API
  • EPL_SEARCH
  • EPL_Search_Fields
  • EPL_Session
  • EPL_SL_Plugin_Updater
  • EPL_Welcome
  • EPL_Widget_Author
  • EPL_Widget_Contact_Capture
  • EPL_Widget_Property_Gallery
  • EPL_Widget_Property_Search
  • EPL_Widget_Recent_Property

Functions

  • EPL
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 
<?php
/**
 * Contact Object
 *
 * @package     EPL
 * @subpackage  Classes/Contact
 * @copyright   Copyright (c) 2020, Merv Barrett
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       3.0
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// phpcs:disable WordPress.DB.SlowDBQuery

/**
 * EPL_Contact Class
 *
 * @since 3.0.0
 */
class EPL_Contact {

    /**
     * The contact ID
     *
     * @var int $ID Contact ID.
     * @since 3.0.0
     */
    public $ID = 0;

    /**
     * The contact ID Fallback
     *
     * @var int $id Contact ID.
     * @since 3.0.0
     */
    public $id = 0;

    /**
     * The contact's listing count
     *
     * @var int $listing_count Contact listing count.
     * @since 3.0.0
     */
    public $listing_count = 0;

    /**
     * The contact's email
     *
     * @var string $email Contact email address.
     * @since 3.0.0
     */
    public $email;

    /**
     * The contact's name
     *
     * @var string $name Contact name.
     * @since 3.0.0
     */
    public $name;

    /**
     * The contact's creation date
     *
     * @var string $date_created Contact date created.
     * @since 3.0.0
     */
    public $date_created;

    /**
     * The contact's background info
     *
     * @var string $background_info.
     * @since 3.5.0
     */
    public $background_info;

    /**
     * The contact's type
     *
     * @var string $type.
     * @since 3.5.0
     */
    public $type;

    /**
     * The contact's heading
     *
     * @var string $heading.
     * @since 3.5.0
     */
    public $heading;

    /**
     * The listing IDs associated with the contact
     *
     * @var string $listing_ids Contact associated listing ids.
     * @since  3.0
     */
    public $listing_ids;

    /**
     * Contact Notes
     *
     * @var string notes Contact notes.
     * @since  3.0
     */
    public $notes;

    /**
     * Get things going
     *
     * @param bool $_id_or_email Contact ID or email.
     * @since 3.0.0
     */
    public function __construct( $_id_or_email = false ) {

        if ( false === $_id_or_email || ( is_numeric( $_id_or_email ) && absint( $_id_or_email ) !== (int) $_id_or_email ) ) {
            return false;
        }

        if ( is_numeric( $_id_or_email ) ) {
            $field = 'id';
        } else {
            $field = 'email';
        }

        $contact = $this->get_contact_by( $field, $_id_or_email );

        if ( empty( $contact ) || ! is_object( $contact ) ) {
            return false;
        }
        $this->setup_contact( $contact );

    }

    /**
     * Get the primary email of contact / alias of get_primary_email
     *
     * @param int $id Contact ID.
     * @return mixed
     * @since  3.0
     */
    public function get_contact_email( $id ) {
        return $this->get_primary_email( $id );
    }

    /**
     * Update the primary email of contact
     *
     * @param int    $id Contact ID.
     * @param string $value Contact email.
     * @return bool|int
     * @since  3.0
     */
    public function update_contact_email( $id, $value ) {
        $emails          = (array) get_post_meta( $id, 'contact_emails', true );
        $emails['email'] = $value;
        return update_post_meta( $id, 'contact_emails', $emails );
    }

    /**
     * Given the contact data, let's set the variables
     *
     * @since  3.0
     * @param  object $contact The contact object.
     * @return bool If the setup was successful or not.
     * @since 3.5.0 Fixed case of property ID.
     */
    private function setup_contact( $contact ) {

        if ( ! is_object( $contact ) ) {
            return false;
        }

        foreach ( array( 'ID', 'name', 'email', 'notes', 'listing_ids', 'listing_count', 'date_created', 'background_info', 'type', 'heading' ) as $key ) {

            switch ( $key ) {

                case 'ID':
                    $this->$key = $contact->ID;
                    $this->ID   = $contact->ID;
                    break;

                case 'email':
                    $this->$key = $this->get_contact_email( $contact->ID );
                    break;

                case 'notes':
                    $this->$key = $this->get_notes();
                    break;

                case 'listing_ids':
                    $this->$key = $this->get_listings();
                    break;

                case 'listing_count':
                    $this->$key = $this->get_listing_count();
                    break;

                case 'date_created':
                    $this->$key = $contact->post_date;
                    break;

                case 'heading':
                    $this->$key = $contact->post_title;
                    break;

                case 'name':
                    $this->$key = $this->get_meta( 'contact_first_name' ) . ' ' . $this->get_meta( 'contact_last_name' );
                    break;

                case 'background_info':
                    $this->$key = $contact->post_content;
                    break;

                case 'type':
                    $this->$key = $this->get_category_label();
                    break;
            }
        }

        // Contact ID and email are the only things that are necessary, make sure they exist.
        if ( ! empty( $this->ID ) && ! empty( $this->email ) ) {
            return true;
        }

        return false;

    }

    /**
     * Retrieves a single contact from the database
     *
     * @access public
     * @param string $field Type of field option, id or email.
     * @param mixed  $value The Contact ID or email to search.
     * @return mixed Upon success, an object of the contact. Upon failure, NULL
     * @since  3.0
     */
    public function get_contact_by( $field = 'id', $value = 0 ) {

        if ( empty( $field ) || empty( $value ) ) {
            return null;
        }

        if ( 'id' === $field ) {
            // Make sure the value is numeric to avoid casting objects, for example, to int 1.
            if ( ! is_numeric( $value ) ) {
                return false;
            }

            $value = intval( $value );

            if ( $value < 1 ) {
                return false;
            }
        } elseif ( 'email' === $field ) {

            if ( ! is_email( $value ) ) {
                return false;
            }

            $value = trim( $value );
        }

        if ( ! $value ) {
            return false;
        }

        $contact = false;
        switch ( $field ) {
            case 'id':
                $contact = get_post( $value );
                break;
            case 'email':
                $matched_contacts = new WP_Query(
                    array(
                        'post_type'   => 'epl_contact',
                        'post_status' => 'publish',
                        'paged'       => 1,
                        'offset'      => 0,
                        'meta_query'  => array(
                            array(
                                'key'     => 'contact_emails',
                                'value'   => sprintf( ':"%s";', $value ),
                                'compare' => 'LIKE',
                            ),
                        ),
                    )
                );
                if ( ! empty( $matched_contacts->posts ) ) {

                    foreach ( $matched_contacts->posts as $matched_contact ) {
                        $emails = get_post_meta( $matched_contact->ID, 'contact_emails', true );

                        if ( isset( $emails['email'] ) && $emails['email'] === $value ) {
                            $contact = $matched_contacts->post;
                        }
                    }
                }

                break;
            default:
                return false;
        }

        if ( ! $contact ) {
            return false;
        }

        return $contact;
    }

    /**
     * Magic __get function to dispatch a call to retrieve a private property
     *
     * @param string $key Meta key.
     * @return mixed|WP_Error
     * @since 3.0.0
     */
    public function __get( $key ) {

        if ( method_exists( $this, 'get_' . $key ) ) {
            return call_user_func( array( $this, 'get_' . $key ) );
        } else {
            /* Translators: %s is the meta key. */
            return new WP_Error( 'epl-contact-invalid-property', sprintf( __( 'Can\'t get property %s', 'easy-property-listings' ), $key ) );
        }
    }

    /**
     * Creates a contact
     *
     * @since  3.0
     * @param  array $data Array of attributes for a contact.
     * @return mixed False if not a valid creation, Contact ID if user is found or valid creation
     */
    public function create( $data = array() ) {

        if ( 0 !== $this->ID || empty( $data ) ) {
            return false;
        }

        $defaults = array(
            'name'  => '',
            'email' => '',
        );

        $args = wp_parse_args( $data, $defaults );

        if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) {
            return false;
        }

        do_action( 'epl_contact_pre_create', $args );

        $created = false;

        $contact = $this->contact_exists( $args['email'] );

        if ( $contact ) {
            wp_update_post(
                array(
                    'post_title' => $args['name'],
                    'post_type'  => 'epl_contact',
                    'ID'         => $contact->ID,
                )
            );

        } else {

            $inserted = wp_insert_post(
                array(
                    'post_title'  => $args['name'],
                    'post_type'   => 'epl_contact',
                    'post_status' => 'publish',
                )
            );

            if ( $inserted ) {
                $this->update_contact_email( $inserted, $args['email'] );
                $contact = $this->get_contact_by( 'email', $args['email'] );
                $this->setup_contact( $contact );
            }
        }
        $created = $contact->ID;

        do_action( 'epl_contact_post_create', $created, $args );
        return $created;
    }

    /**
     * Checking for contact
     *
     * @param null $email Contact email address.
     * @return bool|WP_Post
     * @since  3.0
     */
    public function contact_exists( $email = null ) {
        $matched_contacts = new WP_Query(
            array(
                'post_type'   => 'epl_contact',
                'post_status' => 'publish',
                'meta_query'  => array(
                    array(
                        'key'     => 'contact_emails',
                        'value'   => sprintf( ':"%s";', $email ),
                        'compare' => 'LIKE',
                    ),
                ),
            )
        );
        if ( ! empty( $matched_contacts->posts ) ) {

            foreach ( $matched_contacts->posts as $matched_contact ) {
                $emails = get_post_meta( $matched_contact->ID, 'contact_emails', true );

                if ( isset( $emails['email'] ) && $emails['email'] === $email ) {
                    return $matched_contacts->post;
                }
            }
        }
        return false;
    }

    /**
     * Update a contact record
     *
     * @since  3.0
     * @param  array $data Array of data attributes for a contact (checked via whitelist).
     * @return bool If the update was successful or not
     */
    public function update( $data = array() ) {

        if ( empty( $data ) ) {
            return false;
        }

        do_action( 'epl_contact_pre_update', $this->ID, $data );

        $updated = false;

        $updated = wp_update_post(
            array(
                'post_title'  => $data['name'],
                'post_type'   => 'epl_contact',
                'ID'          => $this->ID,
                'post_status' => 'publish',
            )
        );

        if ( $updated ) {

            if ( isset( $data['email'] ) && is_email( $data['email'] ) ) {
                // Make sure email is new & not already attached to some other contact.
                if ( ! $this->contact_exists( $data['email'] ) && ( $data['email'] !== $this->email ) ) {
                    $this->update_contact_email( $this->ID, $data['email'] );
                }
            }

            $contact = $this->get_contact_by( 'id', $this->ID );
            $this->setup_contact( $contact );

            $updated = true;
        }

        do_action( 'epl_contact_post_update', $updated, $this->ID, $data );

        return $updated;
    }

    /**
     * Attach listing to the contact then triggers increasing stats
     *
     * @since  3.0
     * @param  int $listing_id The listing ID to attach to the contact.
     * @return bool If the attachment was successfully
     */
    public function attach_listing( $listing_id = 0 ) {

        if ( empty( $listing_id ) ) {
            return false;
        }

        if ( empty( $this->listing_ids ) ) {

            $new_listing_ids = array( $listing_id );

        } else {

            $this->listing_ids[] = $listing_id;

            $new_listing_ids = array_unique( array_values( $this->listing_ids ) );

        }

        do_action( 'epl_contact_pre_attach_listing', $listing_id, $this->ID );

        $listing_added = update_post_meta( $this->ID, 'contact_interested_listings', $new_listing_ids );

        if ( $listing_added ) {

            // Update the contacts of listing as well.
            $contact_ids = get_post_meta( $listing_id, 'epl_interested_contacts', true );
            if ( ! empty( $contact_ids ) ) {
                $contact_ids[] = $this->ID;
            } else {
                $contact_ids = array( $this->ID );
            }
            update_post_meta( $listing_id, 'epl_interested_contacts', $contact_ids );

        }

        do_action( 'epl_contact_post_attach_listing', $listing_added, $listing_id, $this->ID );

        return $listing_added;
    }


    /**
     * Remove a listing from this contact, then triggers reducing stats
     *
     * @since  3.0
     * @param  integer $listing_id The Payment ID to remove.
     * @return boolean If the removal was successful
     */
    public function remove_listing( $listing_id = 0 ) {

        if ( empty( $listing_id ) ) {
            return false;
        }

        $new_listing_ids = '';

        if ( ! empty( $this->listing_ids ) ) {

            $pos = array_search( $listing_id, $this->listing_ids ); // phpcs:ignore
            if ( false === $pos ) {
                return false;
            }

            unset( $this->listing_ids[ $pos ] );
            $listing_ids = array_filter( $this->listing_ids );

            $new_listing_ids = array_unique( array_values( $listing_ids ) );

        }

        do_action( 'epl_contact_pre_remove_listing', $listing_id, $this->ID );

        $listing_added = update_post_meta( $this->ID, 'contact_interested_listings', $new_listing_ids );

        $listing_removed = $listing_added;

        // Update the contacts of listing as well.
        $contact_ids = get_post_meta( $listing_id, 'epl_interested_contacts', true );
        if ( ! empty( $contact_ids ) ) {
            $pos = array_search( $this->ID, $contact_ids ); // phpcs:ignore
            if ( false !== $pos ) {
                unset( $contact_ids[ $pos ] );
                update_post_meta( $listing_id, 'epl_interested_contacts', $contact_ids );
            }
        }

        do_action( 'epl_contact_post_remove_listing', $listing_removed, $listing_id, $this->ID );

        return $listing_removed;

    }


    /**
     * Get listings of contact
     *
     * @since  3.0
     */
    public function get_listings() {

        return get_post_meta( $this->ID, 'contact_interested_listings', true );
    }

    /**
     * Get listings count
     *
     * @since  3.0
     */
    public function get_listing_count() {

        $listings = (array) get_post_meta( $this->ID, 'contact_interested_listings', true );
        $listings = array_filter( $listings );
        return count( $listings );
    }

    /**
     * Get the parsed notes for a contact as an array
     *
     * @param int    $number Number of notes per page.
     * @param int    $paged Paged query.
     * @param string $orderby Order by option.
     * @param string $order Order option.
     *
     * @return array The notes requested
     */
    public function get_notes( $number = 10, $paged = 1, $orderby = 'comment_date', $order = 'DESC' ) {

        $length = is_numeric( $number ) ? $number : 10;
        $offset = is_numeric( $paged ) && 1 !== $paged ? ( ( absint( $paged ) - 1 ) * $number ) : 0;
        $args   = array(
            'meta_key'   => 'epl_contact_id',
            'meta_value' => $this->ID,
            'offset'     => $offset,
            'number'     => $length,
            'orderby'    => $orderby,
            'order'      => $order,
        );

        return get_comments( $args );

    }

    /**
     * Get the total number of notes we have after parsing
     *
     * @since  3.0
     * @return int The number of notes for the contact.
     */
    public function get_notes_count() {

        return get_comments(
            array(
                'meta_key'   => 'epl_contact_id',
                'meta_value' => $this->ID,
                'count'      => true,
            )
        );
    }

    /**
     * Add a note for the contact
     *
     * @param string $note The note to add.
     * @param string $note_type Type of note.
     * @param int    $listing_id Listing ID.
     * @return string|boolean The new note if added successfully, false otherwise
     * @since  3.0
     */
    public function add_note( $note = '', $note_type = 'note', $listing_id = 0 ) {

        $note = trim( $note );
        if ( empty( $note ) ) {
            return false;
        }

        $note = apply_filters( 'epl_contact_add_note_string', $note, $note_type, $listing_id );

        do_action( 'epl_contact_pre_add_note', $note, $this->ID );

        $note_data = array(
            'comment_post_ID'      => absint( $listing_id ),
            'comment_author'       => $this->name,
            'comment_author_email' => $this->email,
            'comment_content'      => $note,
            'comment_type'         => $note_type,
            'comment_parent'       => 0,
            'comment_agent'        => 'easy-property-listings',
        );

        // Insert new note and get the note ID.
        $note_id = wp_insert_comment( $note_data );
        if ( $note_id ) {
            $this->notes = $this->get_notes();
            update_comment_meta( $note_id, 'epl_contact_id', $this->ID );
        }

        do_action( 'epl_contact_post_add_note', $this->notes, $note_data, $this->ID );

        // Return the note object.
        return get_comment( $note_id );

    }

    /**
     * Delete the contact
     *
     * @since  3.0
     */
    public function delete() {
        return wp_delete_post( $this->ID, true );
    }

    /**
     * Update Contact Meta
     *
     * @param string $key Meta key name.
     * @param string $value Meta value.
     * @return bool|int
     * @since  3.0
     */
    public function update_meta( $key, $value ) {
        return update_post_meta( $this->ID, $key, $value );
    }

    /**
     * Get Contact Meta
     *
     * @param string $key Meta key name.
     * @return mixed
     * @since  3.0
     */
    public function get_meta( $key ) {
        return get_post_meta( $this->ID, $key, true );
    }

    /**
     * Returns activity type label for activity type
     *
     * @param string $key Meta key name.
     * @return mixed
     * @since  3.0
     */
    public function get_activity_type( $key ) {
        $activity_types = $this->get_activity_types();
        return isset( $activity_types[ $key ] ) ? $activity_types[ $key ] : $activity_types['epl-admin-note'];
    }

    /**
     * Returns all activity types
     *
     * @return mixed
     * @since 3.0.0
     */
    public static function get_activity_types() {
        return apply_filters(
            'epl_contact_activity_labels',
            array(
                'note'           => __( 'User Activity', 'easy-property-listings' ),
                'epl-admin-note' => __( 'Admin Note', 'easy-property-listings' ),
                'call'           => __( 'Call', 'easy-property-listings' ),
                'email'          => __( 'Email', 'easy-property-listings' ),
                'listing'        => __( 'Listing', 'easy-property-listings' ),
            )
        );
    }

    /**
     * Returns Contact Address
     *
     * @return mixed
     * @since 3.0.0
     */
    public function epl_contact_get_address() {

        $addr           = $this->get_meta( 'contact_street_number' ) . ' ';
        $addr          .= $this->get_meta( 'contact_street_name' ) . ' ';
        $contact_suburb = $this->get_meta( 'contact_suburb' );
        if ( ! empty( $contact_suburb ) ) {
            $addr .= $this->get_meta( 'contact_suburb' ) . ', ';
        }

        $addr .= $this->get_meta( 'contact_state' ) . ' ';
        $addr .= $this->get_meta( 'contact_postcode' ) . ' ';
        $addr .= $this->get_meta( 'contact_country' ) . ' ';

        return apply_filters( 'epl_contact_formatted_address', $addr );
    }

    /**
     * Returns Contact Primary Email
     *
     * @param int $id User ID.
     * @return mixed
     * @since 3.0.0
     */
    public function get_primary_email( $id ) {
        $emails = get_post_meta( $id, 'contact_emails', true );
        return isset( $emails['email'] ) ? $emails['email'] : false;
    }

    /**
     * Returns Contact Email
     *
     * @return mixed
     * @since 3.0.0
     * @since 3.4.1 Added value span wrapper.
     */
    public function get_emails() {

        $emails = (array) $this->get_meta( 'contact_emails' );
        $emails = array_filter( $emails );
        if ( ! empty( $emails ) ) {
            ob_start();
            foreach ( $emails as $mail_name   => $mail_value ) {
                $label = ucwords( str_replace( '_', ' ', $mail_name ) ); ?>
                <span class="contact-email epl-info-item editable" data-key="email">
                    <span class="dashicons dashicons-email epl-contact-icons"></span>
                    <span class="epl-contact-value"><?php echo esc_attr( $label . ' - ' . $mail_value ); ?></span>
                </span>
                <?php
            }
            $email_html = ob_get_clean();
            return apply_filters( 'epl_contact_email_html', $email_html );
        }
    }

    /**
     * Returns Contact Phone
     *
     * @return mixed
     * @since 3.0.0
     * @since 3.4.1 Renamed emails to phones and added value span wrapper.
     */
    public function get_phones() {

        $phone_numbers = $this->get_meta( 'contact_phones' );
        $phone_numbers = array_filter( $phone_numbers );
        if ( ! empty( $phone_numbers ) ) {
            ob_start();
            foreach ( $phone_numbers as $mail_name => $mail_value ) {
                $label = ucwords( str_replace( '_', ' ', $mail_name ) );
                ?>
                <span class="contact-phone epl-info-item editable" data-key="phone">
                    <span class="dashicons dashicons-phone epl-contact-icons"></span>
                    <span class="epl-contact-value"><?php echo esc_attr( $label . ' - ' . $mail_value ); ?></span>
                </span>
                <?php
            }
            $email_html = ob_get_clean();
            return apply_filters( 'epl_contact_phone_html', $email_html );
        }
    }

    /**
     * Returns Contact Category Label
     *
     * @return mixed
     * @since 3.0.0
     */
    public function get_category_label() {
        $cat = $this->get_meta( 'contact_category' );
        return get_category_label( $cat );
    }

    /**
     * Returns Contact Category Name
     *
     * @return mixed
     * @since 3.0.0
     */
    public function get_category_name() {
        return $this->get_meta( 'contact_category' );
    }
}
Easy Property Listings 3.5.15 Code Reference API documentation generated by ApiGen