| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | class EPL_Contact { |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | public $ID = 0; |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | public $id = 0; |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | public $listing_count = 0; |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | public $email; |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | public $name; |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | public $date_created; |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | |
| 80: | public $background_info; |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | public $type; |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | public $heading; |
| 97: | |
| 98: | |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | public $listing_ids; |
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: | |
| 112: | public $notes; |
| 113: | |
| 114: | |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | public function __construct( $_id_or_email = false ) { |
| 121: | |
| 122: | if ( false === $_id_or_email || ( is_numeric( $_id_or_email ) && absint( $_id_or_email ) !== (int) $_id_or_email ) ) { |
| 123: | return false; |
| 124: | } |
| 125: | |
| 126: | if ( is_numeric( $_id_or_email ) ) { |
| 127: | $field = 'id'; |
| 128: | } else { |
| 129: | $field = 'email'; |
| 130: | } |
| 131: | |
| 132: | $contact = $this->get_contact_by( $field, $_id_or_email ); |
| 133: | |
| 134: | if ( empty( $contact ) || ! is_object( $contact ) ) { |
| 135: | return false; |
| 136: | } |
| 137: | $this->setup_contact( $contact ); |
| 138: | } |
| 139: | |
| 140: | |
| 141: | |
| 142: | |
| 143: | |
| 144: | |
| 145: | |
| 146: | |
| 147: | public function get_contact_email( $id ) { |
| 148: | return $this->get_primary_email( $id ); |
| 149: | } |
| 150: | |
| 151: | |
| 152: | |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | |
| 159: | public function update_contact_email( $id, $value ) { |
| 160: | $emails = (array) get_post_meta( $id, 'contact_emails', true ); |
| 161: | $emails['email'] = $value; |
| 162: | return update_post_meta( $id, 'contact_emails', $emails ); |
| 163: | } |
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: | |
| 173: | private function setup_contact( $contact ) { |
| 174: | |
| 175: | if ( ! is_object( $contact ) ) { |
| 176: | return false; |
| 177: | } |
| 178: | |
| 179: | foreach ( array( 'ID', 'name', 'email', 'notes', 'listing_ids', 'listing_count', 'date_created', 'background_info', 'type', 'heading' ) as $key ) { |
| 180: | |
| 181: | switch ( $key ) { |
| 182: | |
| 183: | case 'ID': |
| 184: | $this->$key = $contact->ID; |
| 185: | $this->ID = $contact->ID; |
| 186: | break; |
| 187: | |
| 188: | case 'email': |
| 189: | $this->$key = $this->get_contact_email( $contact->ID ); |
| 190: | break; |
| 191: | |
| 192: | case 'notes': |
| 193: | $this->$key = $this->get_notes(); |
| 194: | break; |
| 195: | |
| 196: | case 'listing_ids': |
| 197: | $this->$key = $this->get_listings(); |
| 198: | break; |
| 199: | |
| 200: | case 'listing_count': |
| 201: | $this->$key = $this->get_listing_count(); |
| 202: | break; |
| 203: | |
| 204: | case 'date_created': |
| 205: | $this->$key = $contact->post_date; |
| 206: | break; |
| 207: | |
| 208: | case 'heading': |
| 209: | $this->$key = $contact->post_title; |
| 210: | break; |
| 211: | |
| 212: | case 'name': |
| 213: | $this->$key = $this->get_meta( 'contact_first_name' ) . ' ' . $this->get_meta( 'contact_last_name' ); |
| 214: | break; |
| 215: | |
| 216: | case 'background_info': |
| 217: | $this->$key = $contact->post_content; |
| 218: | break; |
| 219: | |
| 220: | case 'type': |
| 221: | $this->$key = $this->get_category_label(); |
| 222: | break; |
| 223: | } |
| 224: | } |
| 225: | |
| 226: | |
| 227: | if ( ! empty( $this->ID ) && ! empty( $this->email ) ) { |
| 228: | return true; |
| 229: | } |
| 230: | |
| 231: | return false; |
| 232: | } |
| 233: | |
| 234: | |
| 235: | |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: | |
| 242: | |
| 243: | public function get_contact_by( $field = 'id', $value = 0 ) { |
| 244: | |
| 245: | if ( empty( $field ) || empty( $value ) ) { |
| 246: | return null; |
| 247: | } |
| 248: | |
| 249: | if ( 'id' === $field ) { |
| 250: | |
| 251: | if ( ! is_numeric( $value ) ) { |
| 252: | return false; |
| 253: | } |
| 254: | |
| 255: | $value = intval( $value ); |
| 256: | |
| 257: | if ( $value < 1 ) { |
| 258: | return false; |
| 259: | } |
| 260: | } elseif ( 'email' === $field ) { |
| 261: | |
| 262: | if ( ! is_email( $value ) ) { |
| 263: | return false; |
| 264: | } |
| 265: | |
| 266: | $value = trim( $value ); |
| 267: | } |
| 268: | |
| 269: | if ( ! $value ) { |
| 270: | return false; |
| 271: | } |
| 272: | |
| 273: | $contact = false; |
| 274: | switch ( $field ) { |
| 275: | case 'id': |
| 276: | $contact = get_post( $value ); |
| 277: | break; |
| 278: | case 'email': |
| 279: | $matched_contacts = new WP_Query( |
| 280: | array( |
| 281: | 'post_type' => 'epl_contact', |
| 282: | 'post_status' => 'publish', |
| 283: | 'paged' => 1, |
| 284: | 'offset' => 0, |
| 285: | 'meta_query' => array( |
| 286: | array( |
| 287: | 'key' => 'contact_emails', |
| 288: | 'value' => sprintf( ':"%s";', $value ), |
| 289: | 'compare' => 'LIKE', |
| 290: | ), |
| 291: | ), |
| 292: | ) |
| 293: | ); |
| 294: | if ( ! empty( $matched_contacts->posts ) ) { |
| 295: | |
| 296: | foreach ( $matched_contacts->posts as $matched_contact ) { |
| 297: | $emails = get_post_meta( $matched_contact->ID, 'contact_emails', true ); |
| 298: | |
| 299: | if ( isset( $emails['email'] ) && $emails['email'] === $value ) { |
| 300: | $contact = $matched_contacts->post; |
| 301: | } |
| 302: | } |
| 303: | } |
| 304: | |
| 305: | break; |
| 306: | default: |
| 307: | return false; |
| 308: | } |
| 309: | |
| 310: | if ( ! $contact ) { |
| 311: | return false; |
| 312: | } |
| 313: | |
| 314: | return $contact; |
| 315: | } |
| 316: | |
| 317: | |
| 318: | |
| 319: | |
| 320: | |
| 321: | |
| 322: | |
| 323: | |
| 324: | public function __get( $key ) { |
| 325: | |
| 326: | if ( method_exists( $this, 'get_' . $key ) ) { |
| 327: | return call_user_func( array( $this, 'get_' . $key ) ); |
| 328: | } else { |
| 329: | |
| 330: | return new WP_Error( 'epl-contact-invalid-property', sprintf( __( 'Can\'t get property %s', 'easy-property-listings' ), $key ) ); |
| 331: | } |
| 332: | } |
| 333: | |
| 334: | |
| 335: | |
| 336: | |
| 337: | |
| 338: | |
| 339: | |
| 340: | |
| 341: | public function create( $data = array() ) { |
| 342: | |
| 343: | if ( 0 !== $this->ID || empty( $data ) ) { |
| 344: | return false; |
| 345: | } |
| 346: | |
| 347: | $defaults = array( |
| 348: | 'name' => '', |
| 349: | 'email' => '', |
| 350: | ); |
| 351: | |
| 352: | $args = wp_parse_args( $data, $defaults ); |
| 353: | |
| 354: | if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) { |
| 355: | return false; |
| 356: | } |
| 357: | |
| 358: | do_action( 'epl_contact_pre_create', $args ); |
| 359: | |
| 360: | $created = false; |
| 361: | |
| 362: | $contact = $this->contact_exists( $args['email'] ); |
| 363: | |
| 364: | if ( $contact ) { |
| 365: | wp_update_post( |
| 366: | array( |
| 367: | 'post_title' => $args['name'], |
| 368: | 'post_type' => 'epl_contact', |
| 369: | 'ID' => $contact->ID, |
| 370: | ) |
| 371: | ); |
| 372: | |
| 373: | } else { |
| 374: | |
| 375: | $inserted = wp_insert_post( |
| 376: | array( |
| 377: | 'post_title' => $args['name'], |
| 378: | 'post_type' => 'epl_contact', |
| 379: | 'post_status' => 'publish', |
| 380: | ) |
| 381: | ); |
| 382: | |
| 383: | if ( $inserted ) { |
| 384: | $this->update_contact_email( $inserted, $args['email'] ); |
| 385: | $contact = $this->get_contact_by( 'email', $args['email'] ); |
| 386: | $this->setup_contact( $contact ); |
| 387: | } |
| 388: | } |
| 389: | $created = $contact->ID; |
| 390: | |
| 391: | do_action( 'epl_contact_post_create', $created, $args ); |
| 392: | return $created; |
| 393: | } |
| 394: | |
| 395: | |
| 396: | |
| 397: | |
| 398: | |
| 399: | |
| 400: | |
| 401: | |
| 402: | public function contact_exists( $email = null ) { |
| 403: | $matched_contacts = new WP_Query( |
| 404: | array( |
| 405: | 'post_type' => 'epl_contact', |
| 406: | 'post_status' => 'publish', |
| 407: | 'meta_query' => array( |
| 408: | array( |
| 409: | 'key' => 'contact_emails', |
| 410: | 'value' => sprintf( ':"%s";', $email ), |
| 411: | 'compare' => 'LIKE', |
| 412: | ), |
| 413: | ), |
| 414: | ) |
| 415: | ); |
| 416: | if ( ! empty( $matched_contacts->posts ) ) { |
| 417: | |
| 418: | foreach ( $matched_contacts->posts as $matched_contact ) { |
| 419: | $emails = get_post_meta( $matched_contact->ID, 'contact_emails', true ); |
| 420: | |
| 421: | if ( isset( $emails['email'] ) && $emails['email'] === $email ) { |
| 422: | return $matched_contacts->post; |
| 423: | } |
| 424: | } |
| 425: | } |
| 426: | return false; |
| 427: | } |
| 428: | |
| 429: | |
| 430: | |
| 431: | |
| 432: | |
| 433: | |
| 434: | |
| 435: | |
| 436: | public function update( $data = array() ) { |
| 437: | |
| 438: | if ( empty( $data ) ) { |
| 439: | return false; |
| 440: | } |
| 441: | |
| 442: | do_action( 'epl_contact_pre_update', $this->ID, $data ); |
| 443: | |
| 444: | $updated = false; |
| 445: | |
| 446: | $updated = wp_update_post( |
| 447: | array( |
| 448: | 'post_title' => $data['name'], |
| 449: | 'post_type' => 'epl_contact', |
| 450: | 'ID' => $this->ID, |
| 451: | 'post_status' => 'publish', |
| 452: | ) |
| 453: | ); |
| 454: | |
| 455: | if ( $updated ) { |
| 456: | |
| 457: | if ( isset( $data['email'] ) && is_email( $data['email'] ) ) { |
| 458: | |
| 459: | if ( ! $this->contact_exists( $data['email'] ) && ( $data['email'] !== $this->email ) ) { |
| 460: | $this->update_contact_email( $this->ID, $data['email'] ); |
| 461: | } |
| 462: | } |
| 463: | |
| 464: | $contact = $this->get_contact_by( 'id', $this->ID ); |
| 465: | $this->setup_contact( $contact ); |
| 466: | |
| 467: | $updated = true; |
| 468: | } |
| 469: | |
| 470: | do_action( 'epl_contact_post_update', $updated, $this->ID, $data ); |
| 471: | |
| 472: | return $updated; |
| 473: | } |
| 474: | |
| 475: | |
| 476: | |
| 477: | |
| 478: | |
| 479: | |
| 480: | |
| 481: | |
| 482: | public function attach_listing( $listing_id = 0 ) { |
| 483: | |
| 484: | if ( empty( $listing_id ) ) { |
| 485: | return false; |
| 486: | } |
| 487: | |
| 488: | if ( empty( $this->listing_ids ) ) { |
| 489: | |
| 490: | $new_listing_ids = array( $listing_id ); |
| 491: | |
| 492: | } else { |
| 493: | |
| 494: | $this->listing_ids[] = $listing_id; |
| 495: | |
| 496: | $new_listing_ids = array_unique( array_values( $this->listing_ids ) ); |
| 497: | |
| 498: | } |
| 499: | |
| 500: | do_action( 'epl_contact_pre_attach_listing', $listing_id, $this->ID ); |
| 501: | |
| 502: | $listing_added = update_post_meta( $this->ID, 'contact_interested_listings', $new_listing_ids ); |
| 503: | |
| 504: | if ( $listing_added ) { |
| 505: | |
| 506: | |
| 507: | $contact_ids = get_post_meta( $listing_id, 'epl_interested_contacts', true ); |
| 508: | if ( ! empty( $contact_ids ) ) { |
| 509: | $contact_ids[] = $this->ID; |
| 510: | } else { |
| 511: | $contact_ids = array( $this->ID ); |
| 512: | } |
| 513: | update_post_meta( $listing_id, 'epl_interested_contacts', $contact_ids ); |
| 514: | |
| 515: | } |
| 516: | |
| 517: | do_action( 'epl_contact_post_attach_listing', $listing_added, $listing_id, $this->ID ); |
| 518: | |
| 519: | return $listing_added; |
| 520: | } |
| 521: | |
| 522: | |
| 523: | |
| 524: | |
| 525: | |
| 526: | |
| 527: | |
| 528: | |
| 529: | |
| 530: | public function remove_listing( $listing_id = 0 ) { |
| 531: | |
| 532: | if ( empty( $listing_id ) ) { |
| 533: | return false; |
| 534: | } |
| 535: | |
| 536: | $new_listing_ids = ''; |
| 537: | |
| 538: | if ( ! empty( $this->listing_ids ) ) { |
| 539: | |
| 540: | $pos = array_search( $listing_id, $this->listing_ids ); |
| 541: | if ( false === $pos ) { |
| 542: | return false; |
| 543: | } |
| 544: | |
| 545: | unset( $this->listing_ids[ $pos ] ); |
| 546: | $listing_ids = array_filter( $this->listing_ids ); |
| 547: | |
| 548: | $new_listing_ids = array_unique( array_values( $listing_ids ) ); |
| 549: | |
| 550: | } |
| 551: | |
| 552: | do_action( 'epl_contact_pre_remove_listing', $listing_id, $this->ID ); |
| 553: | |
| 554: | $listing_added = update_post_meta( $this->ID, 'contact_interested_listings', $new_listing_ids ); |
| 555: | |
| 556: | $listing_removed = $listing_added; |
| 557: | |
| 558: | |
| 559: | $contact_ids = get_post_meta( $listing_id, 'epl_interested_contacts', true ); |
| 560: | if ( ! empty( $contact_ids ) ) { |
| 561: | $pos = array_search( $this->ID, $contact_ids ); |
| 562: | if ( false !== $pos ) { |
| 563: | unset( $contact_ids[ $pos ] ); |
| 564: | update_post_meta( $listing_id, 'epl_interested_contacts', $contact_ids ); |
| 565: | } |
| 566: | } |
| 567: | |
| 568: | do_action( 'epl_contact_post_remove_listing', $listing_removed, $listing_id, $this->ID ); |
| 569: | |
| 570: | return $listing_removed; |
| 571: | } |
| 572: | |
| 573: | |
| 574: | |
| 575: | |
| 576: | |
| 577: | |
| 578: | |
| 579: | public function get_listings() { |
| 580: | |
| 581: | return get_post_meta( $this->ID, 'contact_interested_listings', true ); |
| 582: | } |
| 583: | |
| 584: | |
| 585: | |
| 586: | |
| 587: | |
| 588: | |
| 589: | public function get_listing_count() { |
| 590: | |
| 591: | $listings = (array) get_post_meta( $this->ID, 'contact_interested_listings', true ); |
| 592: | $listings = array_filter( $listings ); |
| 593: | return count( $listings ); |
| 594: | } |
| 595: | |
| 596: | |
| 597: | |
| 598: | |
| 599: | |
| 600: | |
| 601: | |
| 602: | |
| 603: | |
| 604: | |
| 605: | |
| 606: | |
| 607: | public function get_notes( $number = 10, $paged = 1, $orderby = 'comment_date', $order = 'DESC' ) { |
| 608: | |
| 609: | $length = is_numeric( $number ) ? $number : 10; |
| 610: | $offset = is_numeric( $paged ) && 1 !== $paged ? ( ( absint( $paged ) - 1 ) * $number ) : 0; |
| 611: | $args = array( |
| 612: | 'meta_key' => 'epl_contact_id', |
| 613: | 'meta_value' => $this->ID, |
| 614: | 'offset' => $offset, |
| 615: | 'number' => $length, |
| 616: | 'orderby' => $orderby, |
| 617: | 'order' => $order, |
| 618: | |
| 619: | |
| 620: | 'type' => 'all', |
| 621: | ); |
| 622: | |
| 623: | return get_comments( $args ); |
| 624: | } |
| 625: | |
| 626: | |
| 627: | |
| 628: | |
| 629: | |
| 630: | |
| 631: | |
| 632: | |
| 633: | public function get_notes_count() { |
| 634: | |
| 635: | return get_comments( |
| 636: | array( |
| 637: | 'meta_key' => 'epl_contact_id', |
| 638: | 'meta_value' => $this->ID, |
| 639: | 'count' => true, |
| 640: | |
| 641: | 'type' => 'all', |
| 642: | ) |
| 643: | ); |
| 644: | } |
| 645: | |
| 646: | |
| 647: | |
| 648: | |
| 649: | |
| 650: | |
| 651: | |
| 652: | |
| 653: | |
| 654: | |
| 655: | public function add_note( $note = '', $note_type = 'note', $listing_id = 0 ) { |
| 656: | |
| 657: | $note = trim( $note ); |
| 658: | if ( empty( $note ) ) { |
| 659: | return false; |
| 660: | } |
| 661: | |
| 662: | $note = apply_filters( 'epl_contact_add_note_string', $note, $note_type, $listing_id ); |
| 663: | |
| 664: | do_action( 'epl_contact_pre_add_note', $note, $this->ID ); |
| 665: | |
| 666: | $note_data = array( |
| 667: | 'comment_post_ID' => absint( $listing_id ), |
| 668: | 'comment_author' => $this->name, |
| 669: | 'comment_author_email' => $this->email, |
| 670: | 'comment_content' => $note, |
| 671: | 'comment_type' => $note_type, |
| 672: | 'comment_parent' => 0, |
| 673: | 'comment_agent' => 'easy-property-listings', |
| 674: | ); |
| 675: | |
| 676: | |
| 677: | $note_id = wp_insert_comment( $note_data ); |
| 678: | if ( $note_id ) { |
| 679: | $this->notes = $this->get_notes(); |
| 680: | update_comment_meta( $note_id, 'epl_contact_id', $this->ID ); |
| 681: | } |
| 682: | |
| 683: | do_action( 'epl_contact_post_add_note', $this->notes, $note_data, $this->ID ); |
| 684: | |
| 685: | |
| 686: | return get_comment( $note_id ); |
| 687: | } |
| 688: | |
| 689: | |
| 690: | |
| 691: | |
| 692: | |
| 693: | |
| 694: | public function delete() { |
| 695: | return wp_delete_post( $this->ID, true ); |
| 696: | } |
| 697: | |
| 698: | |
| 699: | |
| 700: | |
| 701: | |
| 702: | |
| 703: | |
| 704: | |
| 705: | |
| 706: | public function update_meta( $key, $value ) { |
| 707: | return update_post_meta( $this->ID, $key, $value ); |
| 708: | } |
| 709: | |
| 710: | |
| 711: | |
| 712: | |
| 713: | |
| 714: | |
| 715: | |
| 716: | |
| 717: | public function get_meta( $key ) { |
| 718: | return get_post_meta( $this->ID, $key, true ); |
| 719: | } |
| 720: | |
| 721: | |
| 722: | |
| 723: | |
| 724: | |
| 725: | |
| 726: | |
| 727: | |
| 728: | public function get_activity_type( $key ) { |
| 729: | $activity_types = $this->get_activity_types(); |
| 730: | return isset( $activity_types[ $key ] ) ? $activity_types[ $key ] : $activity_types['epl-admin-note']; |
| 731: | } |
| 732: | |
| 733: | |
| 734: | |
| 735: | |
| 736: | |
| 737: | |
| 738: | |
| 739: | public static function get_activity_types() { |
| 740: | return apply_filters( |
| 741: | 'epl_contact_activity_labels', |
| 742: | array( |
| 743: | 'note' => __( 'User Activity', 'easy-property-listings' ), |
| 744: | 'epl-admin-note' => __( 'Admin Note', 'easy-property-listings' ), |
| 745: | 'call' => __( 'Call', 'easy-property-listings' ), |
| 746: | 'email' => __( 'Email', 'easy-property-listings' ), |
| 747: | 'listing' => __( 'Listing', 'easy-property-listings' ), |
| 748: | ) |
| 749: | ); |
| 750: | } |
| 751: | |
| 752: | |
| 753: | |
| 754: | |
| 755: | |
| 756: | |
| 757: | |
| 758: | public function epl_contact_get_address() { |
| 759: | |
| 760: | $addr = $this->get_meta( 'contact_street_number' ) . ' '; |
| 761: | $addr .= $this->get_meta( 'contact_street_name' ) . ' '; |
| 762: | $contact_suburb = $this->get_meta( 'contact_suburb' ); |
| 763: | if ( ! empty( $contact_suburb ) ) { |
| 764: | $addr .= $this->get_meta( 'contact_suburb' ) . ', '; |
| 765: | } |
| 766: | |
| 767: | $addr .= $this->get_meta( 'contact_state' ) . ' '; |
| 768: | $addr .= $this->get_meta( 'contact_postcode' ) . ' '; |
| 769: | $addr .= $this->get_meta( 'contact_country' ) . ' '; |
| 770: | |
| 771: | return apply_filters( 'epl_contact_formatted_address', $addr ); |
| 772: | } |
| 773: | |
| 774: | |
| 775: | |
| 776: | |
| 777: | |
| 778: | |
| 779: | |
| 780: | |
| 781: | public function get_primary_email( $id ) { |
| 782: | $emails = get_post_meta( $id, 'contact_emails', true ); |
| 783: | return isset( $emails['email'] ) ? $emails['email'] : false; |
| 784: | } |
| 785: | |
| 786: | |
| 787: | |
| 788: | |
| 789: | |
| 790: | |
| 791: | |
| 792: | |
| 793: | public function get_emails() { |
| 794: | |
| 795: | $emails = (array) $this->get_meta( 'contact_emails' ); |
| 796: | $emails = array_filter( $emails ); |
| 797: | if ( ! empty( $emails ) ) { |
| 798: | ob_start(); |
| 799: | foreach ( $emails as $mail_name => $mail_value ) { |
| 800: | $label = ucwords( str_replace( '_', ' ', $mail_name ) ); ?> |
| 801: | <span class="contact-email epl-info-item editable" data-key="email"> |
| 802: | <span class="dashicons dashicons-email epl-contact-icons"></span> |
| 803: | <span class="epl-contact-value"><?php echo esc_attr( $label . ' - ' . $mail_value ); ?></span> |
| 804: | </span> |
| 805: | <?php |
| 806: | } |
| 807: | $email_html = ob_get_clean(); |
| 808: | return apply_filters( 'epl_contact_email_html', $email_html ); |
| 809: | } |
| 810: | } |
| 811: | |
| 812: | |
| 813: | |
| 814: | |
| 815: | |
| 816: | |
| 817: | |
| 818: | |
| 819: | public function get_phones() { |
| 820: | |
| 821: | $phone_numbers = $this->get_meta( 'contact_phones' ); |
| 822: | $phone_numbers = array_filter( $phone_numbers ); |
| 823: | if ( ! empty( $phone_numbers ) ) { |
| 824: | ob_start(); |
| 825: | foreach ( $phone_numbers as $mail_name => $mail_value ) { |
| 826: | $label = ucwords( str_replace( '_', ' ', $mail_name ) ); |
| 827: | ?> |
| 828: | <span class="contact-phone epl-info-item editable" data-key="phone"> |
| 829: | <span class="dashicons dashicons-phone epl-contact-icons"></span> |
| 830: | <span class="epl-contact-value"><?php echo esc_attr( $label . ' - ' . $mail_value ); ?></span> |
| 831: | </span> |
| 832: | <?php |
| 833: | } |
| 834: | $email_html = ob_get_clean(); |
| 835: | return apply_filters( 'epl_contact_phone_html', $email_html ); |
| 836: | } |
| 837: | } |
| 838: | |
| 839: | |
| 840: | |
| 841: | |
| 842: | |
| 843: | |
| 844: | |
| 845: | public function get_category_label() { |
| 846: | $cat = $this->get_meta( 'contact_category' ); |
| 847: | return get_category_label( $cat ); |
| 848: | } |
| 849: | |
| 850: | |
| 851: | |
| 852: | |
| 853: | |
| 854: | |
| 855: | |
| 856: | public function get_category_name() { |
| 857: | return $this->get_meta( 'contact_category' ); |
| 858: | } |
| 859: | } |
| 860: | |