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 
<?php
/**
 * Contact Functions
 *
 * @package     EPL
 * @subpackage  Admin/ContactsFunctions
 * @copyright   Copyright (c) 2019, 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;
}

/**
 * Register a view for the single contact view
 *
 * @since  3.0
 * @param  array $views An array of existing views.
 * @return array        The altered list of views
 */
function epl_register_default_contact_views( $views ) {

    $default_views = array(
        'overview'    => 'epl_contacts_view',
        'delete'      => 'epl_contacts_delete_view',
        'notes'       => 'epl_contact_notes_view',
        'meta'        => 'epl_contact_meta_view',
        'listings'    => 'epl_contacts_listing_view',
        'new-contact' => 'epl_new_contact_view',
        'all_tags'    => 'epl_all_tags_view',
    );

    return array_merge( $views, $default_views );
}
add_filter( 'epl_contact_views', 'epl_register_default_contact_views', 1, 1 );

/**
 * Register a tab for the single contact view
 *
 * @since  3.0
 * @param  array $tabs An array of existing tabs.
 * @return array       The altered list of tabs
 */
function epl_register_default_contact_tabs( $tabs ) {

    $default_tabs = array(
        'overview' => array(
            'dashicon' => 'dashicons-admin-users',
            'title'    => __( 'Contact Profile', 'easy-property-listings' ),
        ),
        'meta'     => array(
            'dashicon' => 'dashicons-edit',
            'title'    => __( 'Contact Info', 'easy-property-listings' ),
        ),
        'listings' => array(
            'dashicon' => 'dashicons-admin-home',
            'title'    => __( 'Listings', 'easy-property-listings' ),
        ),
        'notes'    => array(
            'dashicon' => 'dashicons-admin-comments',
            'title'    => __( 'Contact Notes', 'easy-property-listings' ),
        ),
    );

    return array_merge( $tabs, $default_tabs );
}
add_filter( 'epl_contact_tabs', 'epl_register_default_contact_tabs', 1, 1 );

/**
 * Register the Delete icon as late as possible so it's at the bottom
 *
 * @since  3.0
 * @param  array $tabs An array of existing tabs.
 * @return array       The altered list of tabs, with 'delete' at the bottom
 */
function epl_register_delete_contact_tab( $tabs ) {

    $tabs['delete'] = array(
        'dashicon' => 'dashicons-trash',
        'title'    => __( 'Delete Contact', 'easy-property-listings' ),
    );

    return $tabs;
}
add_filter( 'epl_contact_tabs', 'epl_register_delete_contact_tab', PHP_INT_MAX, 1 );

/**
 * Next contact link
 *
 * @param [type] $contact_id Contact ID.
 *
 * @return string|void
 * @since  3.0
 */
function epl_get_next_contact_link( $contact_id ) {
    if ( absint( $contact_id ) < 1 ) {
        return;
    }

    $contact_id = absint( $contact_id );
    global $wpdb;

    $where = " `post_type` = 'epl_contact'
        AND `post_status`   = 'publish'
        AND `ID` > {$contact_id} ";

    $where = apply_filters( 'epl_get_next_contact_link_query', $where );

    $query = "
        SELECT *
        FROM {$wpdb->prefix}posts
        WHERE " . $where . '
        ORDER BY `ID` DESC
        LIMIT 1
    ';
    // phpcs:ignore WordPress.DB
    $next = $wpdb->get_col( $query );

    if ( ! empty( $next ) ) {
        return admin_url( 'admin.php?page=epl-contacts&view=overview&id=' . $next[0] );
    }
}

/**
 * Previous contact link
 *
 * @param [type] $contact_id Contact ID.
 *
 * @return string|void
 * @since  3.0
 */
function epl_get_prev_contact_link( $contact_id ) {

    if ( absint( $contact_id ) < 1 ) {
        return;
    }

    $contact_id = absint( $contact_id );
    global $wpdb;

    $where = " `post_type` = 'epl_contact'
        AND `post_status`   = 'publish'
        AND `ID` < {$contact_id} ";

    $where = apply_filters( 'epl_get_prev_contact_link_query', $where );

    $query = "
        SELECT *
        FROM {$wpdb->prefix}posts
        WHERE " . $where . '
        ORDER BY `ID` DESC
        LIMIT 1
    ';
    // phpcs:ignore WordPress.DB
    $next = $wpdb->get_col( $query );

    if ( ! empty( $next ) ) {
        return admin_url( 'admin.php?page=epl-contacts&view=overview&id=' . $next[0] );
    }
}

/**
 * Contact Fields
 *
 * @param array $contact_fields Contact fields.
 * @param array $contact The contact.
 *
 * @return array
 * @since  3.0
 */
function epl_contact_contact_fields( $contact_fields, $contact ) {
    $fields = array();
    $phones = (array) $contact->get_meta( 'contact_phones' );
    $phones = array_filter( $phones );
    if ( ! empty( $phones ) ) {
        foreach ( $phones as $phone_name  => $phone_value ) {
            $label    = ucwords( str_replace( '_', ' ', $phone_name ) );
            $fields[] = array(
                'name'      => "contact_phones[$phone_name]",
                'label'     => $label,
                'type'      => 'text',
                'class'     => 'epl-contact-addable',
                'maxlength' => '60',
                'value'     => $phone_value,
            );
        }
    }
    $emails = (array) $contact->get_meta( 'contact_emails' );
    $emails = array_filter( $emails );
    if ( ! empty( $emails ) ) {
        foreach ( $emails as $mail_name   => $mail_value ) {
            $label    = ucwords( str_replace( '_', ' ', $mail_name ) );
            $fields[] = array(
                'name'      => "contact_emails[$mail_name]",
                'label'     => $label,
                'type'      => 'email',
                'class'     => 'epl-contact-addable-email',
                'maxlength' => '60',
                'value'     => $mail_value,
            );
        }
    }
    $merged_fields = array_merge( $fields, $contact_fields );
    return array_intersect_key( $merged_fields, array_unique( array_map( 'serialize', $merged_fields ) ) );
}
add_filter( 'epl_contact_contact_fields', 'epl_contact_contact_fields', 10, 2 );

/**
 * Contact Access Roles
 *
 * @since  3.0
 */
function epl_contact_access() {
    $allowed = epl_get_option( 'min_contact_access' );
    $allowed = empty( $allowed ) ? 'level_10' : $allowed;
    $return  = current_user_can( $allowed ) ? true : false;
    return apply_filters( 'epl_contact_access', $return );
}

Easy Property Listings 3.5.15 Code Reference API documentation generated by ApiGen