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

Packages

  • EPL
    • Admin
      • Actions
      • Classes
        • ContactsTable
        • EPL
          • Admin
            • Images
        • 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_Admin_Images
  • 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  859  860  861  862  863  864  865  866  867  868  869  870  871  872  873  874  875  876  877  878  879  880  881  882  883  884  885  886  887  888  889  890  891  892  893  894  895  896  897  898  899  900  901  902  903  904  905  906  907  908  909  910  911  912  913  914  915  916  917  918  919  920  921  922  923  924  925  926  927  928  929  930  931  932  933  934  935  936  937  938  939  940  941  942  943  944  945  946  947  948  949  950  951  952  953  954  955  956  957  958  959  960  961  962  963  964  965  966  967  968  969  970  971  972  973  974  975  976  977  978  979  980  981  982  983  984  985  986  987  988  989  990  991  992  993  994  995  996  997  998  999 1000 1001 1002 1003 
<?php
/**
 * EPL Admin Functions
 *
 * @package     EPL
 * @subpackage  Admin/Functions
 * @copyright   Copyright (c) 2020, Merv Barrett
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.0
 */

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

if ( ! function_exists( 'cal_days_in_month' ) ) {
    /**
     * Fallback in case the calendar extension is not loaded in PHP
     *
     * @param string $calendar Calendar type.
     * @param int    $month The month.
     * @param int    $year The year.
     *
     * @return string
     * @since 3.3.3
     */
    function cal_days_in_month( $calendar, $month, $year ) {
        return gmdate( 't', mktime( 0, 0, 0, $month, 1, $year ) );
    }
}

/**
 * Flush Rewrite Rules
 *
 * @since 1.0
 */
function epl_flush_rewrite_rules() {
    $epl_rewrite_rules = get_option( 'epl_rewrite_rules' );
    if ( ! $epl_rewrite_rules ) {
        flush_rewrite_rules();
        update_option( 'epl_rewrite_rules', true );
    }
}
add_action( 'admin_init', 'epl_flush_rewrite_rules' );
add_action( 'init', 'epl_flush_rewrite_rules' );

/**
 * Notice on Dashboard Widget
 *
 * @since 3.1.6
 */
function epl_dashboard_widget_offer_rough() {

    if ( has_filter( 'epl_extensions_options_filter_new' ) || get_transient( 'epl_admin_notices_display' ) === '1' ) {
        return;
    }

    echo '<div class="epl-internal-ad">';
        echo '<div>' . esc_html__( 'Remove these ads?', 'easy-property-listings' ) . '</div>';

        echo '<div><a href="https://easypropertylistings.com.au/extensions/?utm_source=offers&utm_medium=description_tab&utm_content=settings_link&utm_campaign=epl_extension_store">' . esc_html__( 'Purchase an extension remove me', 'easy-property-listings' ) . '</a></div>';
    echo '</div>';
}

/**
 * Notice presented on settings page, removed if extension is present and activated
 *
 * @since 3.1.6
 */
function epl_admin_sidebar() {

    if ( has_filter( 'epl_extensions_options_filter_new' ) || get_transient( 'epl_admin_notices_display' ) === '1' ) {
        return;
    }

    $service_banners = array(
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/core-bundle/?utm_source=offers&utm_medium=description_tab&utm_content=settings_link&utm_campaign=epl_extension_core',
            'img'   => 'banner-dash-wide.png',
            'alt'   => esc_html__( 'Core bundle for Easy Property Listings', 'easy-property-listings' ),
            'width' => 261,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/advanced-mapping/?utm_source=offers&utm_medium=description_tab&utm_content=settings_link&utm_campaign=epl_extension_advanced_map',
            'img'   => 'offer-advanced-mapping.png',
            'alt'   => esc_html__( 'Advanced Mapping', 'easy-property-listings' ),
            'width' => 261,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/sliders/?utm_source=offers&utm_medium=description_tab&utm_content=settings_link&utm_campaign=epl_extension_sliders',
            'img'   => 'offer-sliders.png',
            'alt'   => esc_html__( 'Sliders extension', 'easy-property-listings' ),
            'width' => 261,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/staff-directory/?utm_source=offers&utm_medium=description_tab&utm_content=settings_link&utm_campaign=epl_extension_staff_directory',
            'img'   => 'offer-staff-directory.png',
            'alt'   => esc_html__( 'Staff Directory', 'easy-property-listings' ),
            'width' => 261,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/listing-templates/?utm_source=offers&utm_medium=description_tab&utm_content=settings_link&utm_campaign=epl_extension_listing_templates',
            'img'   => 'offer-templates.png',
            'alt'   => esc_html__( 'Listing Templates', 'easy-property-listings' ),
            'width' => 261,
        ),
    );
    $i               = 0;
    foreach ( $service_banners as $banner ) {
        echo '<a target="_blank" href="' . esc_url( $banner['url'] ) . '"><img width="' . esc_attr( $banner['width'] ) . '" src="' . esc_url( plugins_url( 'lib/assets/images/' . $banner['img'], EPL_PLUGIN_FILE ) ) . '" alt="' . esc_attr( $banner['alt'] ) . '"/></a><br/><br/>';
        ++$i;
    }
    ?>
    <div class="epl-admin-offer" style="margin-bottom: 1em;">
        <div><span><?php esc_html_e( 'Remove these ads?', 'easy-property-listings' ); ?><span></div>
        <div><a href="http://easypropertylistings.com.au/extensions/?utm_source=offers&utm_medium=description_tab&utm_content=settings_link&utm_campaign=epl_extension_store"><?php esc_html_e( 'Purchase and activate any extension', 'easy-property-listings' ); ?> &#x27F6;</a></div>
    </div>
    <?php
}

/**
 * Notice presented on dashboard widget, removed if extension is present and activated
 *
 * @since 3.1.6
 */
function epl_dashboard_widget_offer() {
    if ( has_filter( 'epl_extensions_options_filter_new' ) || get_transient( 'epl_admin_notices_display' ) === '1' ) {
        return;
    }

    $service_banners = array(
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/core-bundle/?utm_source=offers&utm_medium=description_tab&utm_content=extensions_link&utm_campaign=epl_extension_core',
            'img'   => 'banner-dash-wide.png',
            'alt'   => esc_html__( 'Check out the premium extensions', 'easy-property-listings' ),
            'width' => 261,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/?utm_source=offers&utm_medium=description_tab&utm_content=extensions_link&utm_campaign=epl_extension_store',
            'img'   => 'banner-dash-wide-store.png',
            'alt'   => esc_html__( 'Browse the extension store', 'easy-property-listings' ),
            'width' => 125,
        ),
    );
    $i               = 0;
    foreach ( $service_banners as $banner ) {
        echo '<a target="_blank" href="' . esc_url( $banner['url'] ) . '">
            <img style="margin-right: 0.5em" width="' . esc_attr( $banner['width'] ) . '" src="' . esc_url( plugins_url( 'lib/assets/images/' . $banner['img'], EPL_PLUGIN_FILE ) ) . '" alt="' . esc_attr( $banner['alt'] ) . '"/>
              </a>';
        ++$i;
    }
    ?>

    <div class="epl-admin-offer" style="margin-bottom: 1em;">
        <div><span><?php esc_html_e( 'Remove these ads?', 'easy-property-listings' ); ?><span></div>
        <div><a href="http://easypropertylistings.com.au/extensions/"><?php esc_html_e( 'Purchase and activate any extension', 'easy-property-listings' ); ?> &#x27F6;</a></div>
    </div>
    <?php
}

/**
 * Notice presented on post types, removed if extension is present and activated
 *
 * @since 3.1.6
 */
function epl_dashboard_widget_offer_post_types() {
    if ( has_filter( 'epl_extensions_options_filter_new' ) || get_transient( 'epl_admin_notices_display' ) === '1' ) {
        return;
    }

    $service_banners = array(
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/?utm_source=offers&utm_medium=description_tab&utm_content=post_link&utm_campaign=epl_extensions',
            'img'   => 'banner-dash-wide-store.png',
            'alt'   => esc_html__( 'Browse the extension store', 'easy-property-listings' ),
            'width' => 125,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/advanced-mapping/?utm_source=offers&utm_medium=description_tab&utm_content=post_link&utm_campaign=epl_extension_advanced_map',
            'img'   => 'offer-advanced-mapping.png',
            'alt'   => esc_html__( 'Advanced Mapping', 'easy-property-listings' ),
            'width' => 175,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/sliders/?utm_source=offers&utm_medium=description_tab&utm_content=post_link&utm_campaign=epl_extension_sliders',
            'img'   => 'offer-sliders.png',
            'alt'   => esc_html__( 'Sliders extension', 'easy-property-listings' ),
            'width' => 175,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/staff-directory/?utm_source=offers&utm_medium=description_tab&utm_content=post_link&utm_campaign=epl_extension_staff_directory',
            'img'   => 'offer-staff-directory.png',
            'alt'   => esc_html__( 'Staff Directory', 'easy-property-listings' ),
            'width' => 175,
        ),
        array(
            'url'   => 'https://easypropertylistings.com.au/extensions/listing-templates/?utm_source=offers&utm_medium=description_tab&utm_content=post_link&utm_campaign=epl_extension_listing_templates',
            'img'   => 'offer-templates.png',
            'alt'   => esc_html__( 'Listing Templates', 'easy-property-listings' ),
            'width' => 175,
        ),
    );
    $i               = 0;
    foreach ( $service_banners as $banner ) {
        echo '<a target="_blank" href="' . esc_url( $banner['url'] ) . '">
            <img style="display: block; float: left; margin: 0.5em 0.5em 0.5em 0" width="' . esc_attr( $banner['width'] ) . '" src="' . esc_url( plugins_url( 'lib/assets/images/' . $banner['img'], EPL_PLUGIN_FILE ) ) . '" alt="' . esc_attr( $banner['alt'] ) . '"/>
              </a>';
        ++$i;
    }
    ?>
    <?php
}

/**
 * Notice presented on post types, removed if extension is present and activated
 *
 * @since 3.1.6
 */
function epl_dashboard_widget_offer_post_types_last() {
    if ( has_filter( 'epl_extensions_options_filter_new' ) || get_transient( 'epl_admin_notices_display' ) === '1' ) {
        return;
    }

    echo '<a target="_blank" href="https://easypropertylistings.com.au/extensions/?utm_source=offers&utm_medium=description_tab&utm_content=extensions_link&utm_campaign=epl_extension_store">
            <img style="display: block; float: right; margin: 0.5em 0 0.5em 0.5em" width="125" src="' . esc_url( plugins_url( 'lib/assets/images/banner-dash-wide-store-reverse.png', EPL_PLUGIN_FILE ) ) . '" alt="' . esc_html__( 'Purchase and activate any extension to remove these ads', 'easy-property-listings' ) . '"/>
        </a>';
    ?>
    <?php
}

/**
 * Admin notices
 *
 * @since 3.1.6
 */
function epl_extension_notice_offer() {

    if ( has_filter( 'epl_extensions_options_filter_new' ) || get_transient( 'epl_admin_notices_display' ) === '1' ) {
        return;
    }

    $screen = get_current_screen();

    if ( is_epl_core_post() === true || 'easy-property-listings_page_epl-reports' === $screen->id || 'easy-property-listings_page_epl-contacts' === $screen->id || 'toplevel_page_epl-general' === $screen->id ) {

        echo '<div class="notice notice-success" style="max-height: 130px; overflow: hidden;">';
            echo '<div class="epl-offers epl-offers-left" style="box-sizing: border-box; width: 85%; float: left; height: 125px">';
                epl_dashboard_widget_offer_post_types();
            echo '</div>';

            echo '<div class="epl-offers epl-offers-right" style="box-sizing: border-box; width: 15%; float: left;  height: 125px">';
                epl_dashboard_widget_offer_post_types_last();
            echo '</div>';
        echo '</div>';
    }
}
add_action( 'admin_notices', 'epl_extension_notice_offer' );

/**
 * Check if a given extensions has beta support enabled
 *
 * @since  3.3.0
 * @param  string $slug The slug of the extension to check.
 * @return bool True if enabled, false otherwise.
 */
function epl_extension_has_beta_support( $slug ) {

    $enabled_betas = epl_get_option( 'enabled_betas', array() );
    $return        = false;
    if ( in_array( $slug, $enabled_betas, true ) ) {
        $return = true;
    }
    return $return;
}

/**
 * EPL Tools Tabs
 *
 * @since  3.3.0
 */
function epl_get_tools_tab() {

    $default_tabs = array(
        'tools' => array(
            'label'    => esc_html__( 'Import/Export', 'easy-property-listings' ),
            'callback' => 'epl_settings_import_export',
        ),
    );

    if ( epl_show_reset_tab() ) :

        $default_tabs['reset'] = array(
            'label'    => esc_html__( 'Reset Settings', 'easy-property-listings' ),
            'callback' => 'epl_settings_reset',
        );

    endif;

    if ( epl_show_upgrade_tab() ) :

        $default_tabs['upgrade'] = array(
            'label'    => esc_html__( 'Upgrade', 'easy-property-listings' ),
            'callback' => 'epl_settings_upgrade_tab',
        );

    endif;

    return apply_filters( 'epl_get_tools_tab', $default_tabs );
}

/**
 * Display Upgrade Tab
 *
 * @since       3.3
 */
function epl_show_upgrade_tab() {
    // phpcs:disable WordPress.Security.NonceVerification
    $upgraded_to = get_option( 'epl_db_upgraded_to' );

    if ( ! isset( $_GET['dev'] ) && empty( $upgraded_to ) ) {
        return false;
    }

    $upgraded = $upgraded_to < 3.3 ? true : false;

    $upgraded = isset( $_GET['dev'] ) ? true : $upgraded;

    return $upgraded;
}

/**
 * Display Upgrade Tab
 *
 * @since 3.3.5
 */
function epl_show_reset_tab() {
    $show = false;

    $show = isset( $_GET['dev'] ) ? true : $show;

    return $show;
}

/**
 * Serialize Variable
 *
 * @since  3.3.0
 * @param  string $data String of data to serialize.
 * @return string.
 */
function epl_serialize( $data ) {
    return base64_encode( serialize( $data ) ); //phpcs:ignore
}

/**
 * Safely unserialize base64 encoded data.
 *
 * This helper decodes a base64 encoded string and attempts to unserialize it
 * while applying several validation steps to reduce security risks.
 *
 * Security improvements:
 * - Uses strict base64 decoding to prevent malformed input.
 * - Validates that the decoded value is actually a serialized string before
 *   attempting to unserialize it.
 * - Prevents object injection by disabling object instantiation via the
 *   `allowed_classes => false` option.
 *
 * If the input cannot be decoded or is not a valid serialized value, the
 * function safely returns false instead of attempting to unserialize it.
 *
 * @since  3.3.0
 * @since  3.5.21 Hardened unserialize handling by enforcing strict base64 decoding, validating serialized input, and disabling object instantiation.
 *
 * @param string $data Base64 encoded serialized data.
 * @return mixed|false Returns the unserialized value on success, or false if the
 *                     input is invalid or cannot be safely unserialized.
 */
function epl_unserialize( $data ) {
    $decoded_data = base64_decode( trim( (string) $data ), true );

    if ( false === $decoded_data || ! is_serialized( $decoded_data ) ) {
        return false;
    }

    return unserialize( $decoded_data, array( 'allowed_classes' => false ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
}

/**
 * Import/Export Tools Settings Screen
 *
 * @since 3.3
 * @since 3.5.21 Added nonce protection to the export request to prevent CSRF.
 */
function epl_settings_import_export() {

    do_action( 'epl_pre_import_fields' );

    echo '<h2>' . esc_html__( 'Import Options', 'easy-property-listings' ) . '</h2>';
    ?>

    <div class="epl-field">
        <div class="epl-label-wrap">
            <label class="epl-label epl-label-epl_import" for="epl_import">
                <?php
                    esc_html_e( 'Import data', 'easy-property-listings' );
                ?>
            </label>
        </div>
        <div class="epl-input-wrap">
            <input type="file" name="epl_import" id="epl_import" />
            <span class="epl-help-text">
                <?php
                    esc_html_e( 'Import exported file here. Warning! This will override all existing settings to default values.', 'easy-property-listings' );
                ?>
            </span>
        </div>
    </div>

    <input type="hidden" name="action" value="import">
    <div class="">
        <input type="submit" name="epl_tools_submit" value="<?php esc_html_e( 'Import', 'easy-property-listings' ); ?>" class="epl-tools-submit button button-primary"/>
        <span style="color:#f00"><?php esc_html_e( 'WARNING! This will overwrite all existing option values, please proceed with caution.', 'easy-property-listings' ); ?></span>
    </div>


    <?php

    do_action( 'epl_post_import_fields' );

    echo '<h2>' . esc_html__( 'Export Options', 'easy-property-listings' ) . '</h2>';

    $tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'tools';

    $export_url = add_query_arg(
        array(
            'page'             => 'epl-tools',
            'tab'              => $tab,
            'action'           => 'export',
            'epl_tools_submit' => 'true',
        ),
        admin_url( 'admin.php' )
    );
    $export_url = wp_nonce_url( $export_url, 'epl_tools_export', 'epl_tools_export_nonce' );

    echo "<a class='button button-primary' href='" . esc_url( $export_url ) . "'>" . esc_html__( 'Download File', 'easy-property-listings' ) . '</a>';
    ?>
    <span style="color:#f00"><?php esc_html_e( 'The following settings are exported. Easy Property Listings settings screen and any Extension settings', 'easy-property-listings' ); ?></span>
    <?php

    do_action( 'epl_pre_export_fields' );

    do_action( 'epl_post_export_fields' );
}

/**
 * Reset EPL Settings :  Tools Settings Screen
 *
 * @since 3.3.5
 */
function epl_settings_reset() {

    do_action( 'epl_pre_settings_reset_fields' );

    if ( isset( $_GET['epl_tools_submit'] ) && 'true' === sanitize_text_field( wp_unslash( $_GET['epl_tools_submit'] ) ) ) {
        ?>
        <br>
        <span style="color:#080"><?php esc_html_e( 'Settings reset successfully!', 'easy-property-listings' ); ?></span>
        <?php
    }

    $url = '?page=epl-tools&tab=reset&action=reset&epl_tools_submit=true';
    $url = add_query_arg( array( 'dev' => 'true' ), $url );

    $url     = wp_nonce_url( $url, $action = 'epl_reset_settings', $name = '_reset_wpnonce' );
    $confirm = esc_html__( 'Are you sure you want to reset all Easy Property Listings settings?', 'easy-property-listings' );
    echo '<h2>' . esc_html__( 'Reset Easy Property Listings to installation defaults', 'easy-property-listings' ) . '</h2>';

    echo "<a class='button button-primary' href='" . esc_url( $url ) . "' onclick='return confirm(\"" . esc_html( $confirm ) . "\")'>" . esc_html__( 'Reset', 'easy-property-listings' ) . '</a>';
    ?>
    <br>
    <span style="color:#f00"><?php esc_html_e( 'Warning! This will reset all your Easy Property Listings settings to their default values including extension settings.', 'easy-property-listings' ); ?></span>
    <?php

    do_action( 'epl_post_settings_reset_fields' );
}

/**
 * Settings upgrade tab screen
 *
 * @since 3.3.0
 */
function epl_settings_upgrade_tab() {

    echo '<h2>' . esc_html__( 'Upgrade Options', 'easy-property-listings' ) . '</h2>';

    echo '<div style="color:red">' . esc_html__( 'Upgrading the database will copy all the listing pricing info into a unified price data column for searching and ordering. We recommend taking a database backup before performing this action.', 'easy-property-listings' ) . '</div>';

    echo "<div><br><a class='button button-primary epl-upgrade-btn' data-upgrade='3.3' href='#'>" . esc_html__( 'Upgrade Database', 'easy-property-listings' ) . '</a></div>';

    echo '<div style="display:none;" class="epl-ajax-notice">' . esc_html__( 'Processing...', 'easy-property-listings' ) . '</div>';
}

/**
 * Import and Export Form
 *
 * @since 3.3.0
 * @since 3.5 Fixed import function.
 * @since 3.5.10 Fix: Tools Import function adjusted with more checked before performing the settings import.
 * @since 3.5.21 Hardened tools request handling with capability checks, stricter sanitization, action allowlisting, and export nonce verification.
 */
function epl_handle_tools_form() {
    $page = isset( $_REQUEST['page'] ) ? sanitize_key( wp_unslash( $_REQUEST['page'] ) ) : '';
    if ( 'epl-tools' !== $page || ! isset( $_REQUEST['epl_tools_submit'] ) ) {
        return;
    }

    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }

    if ( ! isset( $_REQUEST['action'] ) ) {
        return;
    }

    $action = sanitize_key( wp_unslash( $_REQUEST['action'] ) );
    if ( ! in_array( $action, array( 'export', 'import', 'reset' ), true ) ) {
        return;
    }

    if ( 'export' === $action ) {
        epl_verify_export_nonce();
    }

    if ( 'import' === $action ) {
        epl_verify_nonce();
        epl_validate_import_file();
    }

    switch ( $action ) {
        case 'export':
            epl_export_settings();
            break;

        case 'import':
            epl_import_settings();
            break;

        case 'reset':
            epl_reset_settings();
            break;
    }
}
add_action( 'admin_init', 'epl_handle_tools_form' );

/**
 * Verify nonce for export tools action.
 *
 * @since 3.5.20
 */
function epl_verify_export_nonce() {
    if (
        ! isset( $_GET['epl_tools_export_nonce'] ) ||
        ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['epl_tools_export_nonce'] ) ), 'epl_tools_export' )
    ) {
        wp_die( esc_html__( 'Sorry, your nonce did not verify.', 'easy-property-listings' ) );
    }
}

/**
 * Verify nonce for the tools form.
 *
 * @since 3.5.10
 */
function epl_verify_nonce() {
    if (
        ! isset( $_POST['epl_nonce_tools_form'] ) ||
        ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['epl_nonce_tools_form'] ) ), 'epl_nonce_tools_form' )
    ) {
        wp_die( esc_html__( 'Sorry, your nonce did not verify.', 'easy-property-listings' ) );
    }
}

/**
 * Validate the import file.
 *
 * @since 3.5.10
 * @since 3.5.21 Added stricter import upload validation (uploaded file checks, size limits, and file type/extension verification).
 */
function epl_validate_import_file() {

    if ( empty( $_FILES['epl_import'] ) || empty( $_FILES['epl_import']['name'] ) ) {
        wp_die( esc_html__( 'Missing import file. Please provide an import file.', 'easy-property-listings' ) );
    }

    $file_name = sanitize_file_name( wp_unslash( $_FILES['epl_import']['name'] ) );
    $tmp_name  = isset( $_FILES['epl_import']['tmp_name'] ) ? wp_unslash( $_FILES['epl_import']['tmp_name'] ) : '';
    $file_size = isset( $_FILES['epl_import']['size'] ) ? (int) $_FILES['epl_import']['size'] : 0;

    if ( isset( $_FILES['epl_import']['error'] ) && $_FILES['epl_import']['error'] > 0 ) {
        wp_die( esc_html__( 'Error uploading the import file.', 'easy-property-listings' ) );
    }

    if ( empty( $tmp_name ) || ! is_uploaded_file( $tmp_name ) || ! is_readable( $tmp_name ) ) {
        wp_die( esc_html__( 'Invalid import upload.', 'easy-property-listings' ) );
    }

    if ( $file_size <= 0 || $file_size > wp_max_upload_size() ) {
        wp_die( esc_html__( 'The selected import file size is not valid.', 'easy-property-listings' ) );
    }

    $file_check = wp_check_filetype_and_ext( $tmp_name, $file_name, array( 'txt' => 'text/plain' ) );
    if ( empty( $file_check['ext'] ) || 'txt' !== strtolower( $file_check['ext'] ) ) {
        wp_die( esc_html__( 'The file you uploaded does not appear to be a valid import file.', 'easy-property-listings' ) );
    }
}

/**
 * Export the settings.
 *
 * @since 3.5.10
 */
function epl_export_settings() {
    $export = get_option( 'epl_settings' );

    header( 'Content-Description: File Transfer' );
    header( 'Content-Type: application/octet-stream' );
    header( 'Content-Disposition: attachment; filename=epl-settings-export.txt' );
    header( 'Content-Transfer-Encoding: binary' );
    header( 'Expires: 0' );
    header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
    header( 'Pragma: public' );
    ob_clean();
    flush();
    echo epl_serialize( $export ); // phpcs:ignore
    die;
}

/**
 * Import the settings.
 *
 * @since 3.5.10
 * @since 3.5.18 Check for data before continue.
 * @since 3.5.21 Hardened import processing by reading from the uploaded temp file, validating file contents, and verifying unserialized data before updating options.
 */
function epl_import_settings() {
    if ( ! isset( $_FILES['epl_import']['tmp_name'] ) ) {
        return;
    }

    $tmp_name = wp_unslash( $_FILES['epl_import']['tmp_name'] );
    if ( ! is_readable( $tmp_name ) ) {
        wp_die( esc_html__( 'Unable to read import file.', 'easy-property-listings' ) );
    }

    $imported_raw_data = file_get_contents( $tmp_name ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
    if ( false === $imported_raw_data || '' === $imported_raw_data ) {
        wp_die( esc_html__( 'Unable to read import file.', 'easy-property-listings' ) );
    }

    $imported_data = epl_unserialize( $imported_raw_data );
    if ( ! is_array( $imported_data ) ) {
        wp_die( esc_html__( 'The import file data is invalid.', 'easy-property-listings' ) );
    }

    $options_backup = get_option( 'epl_settings' );
    update_option( 'epl_settings_backup', $options_backup );
    update_option( 'epl_settings', $imported_data );
}

/**
 * Reset the settings.
 *
 * @since 3.5.10
 */
function epl_reset_settings() {
    if ( ! isset( $_GET['_reset_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_reset_wpnonce'] ) ), 'epl_reset_settings' ) ) {
        wp_die( esc_html__( 'Sorry, your nonce did not verify.', 'easy-property-listings' ) );
    } else {
        $epl_settings = epl_get_default_settings();
        update_option( 'epl_settings', $epl_settings );
    }
}

/**
 * Upgrade Database Notice
 *
 * @since 3.3.0
 * @since 3.5.18 Check user can manage options.
 */
function epl_upgrade_admin_notice() {

    $upgraded_to = get_option( 'epl_db_upgraded_to' );

    if ( ! empty( $upgraded_to ) && $upgraded_to < 3.3 && current_user_can( 'manage_options' ) ) :

        $head = esc_html__( 'It looks like you upgraded to latest version of Easy Property Listings', 'easy-property-listings' );

        $msg = esc_html__( 'For better performance, we need to upgrade the database. You can upgrade the database by visiting tools page', 'easy-property-listings' );

        echo '<div class="notice notice-warning epl-upgrade-notice is-dismissible">
            <p><strong>' . esc_html( $head ) . '</strong></p>
            <p>' . esc_html( $msg ) . '</p>
            <p><a class="button" href="' . esc_url( admin_url( 'admin.php?page=epl-tools&tab=upgrade&dev=true' ) ) . '">' . esc_html__( 'Take me to the upgrade tool', 'easy-property-listings' ) . '</a></p>
        </div>';
    endif;
}
add_action( 'admin_notices', 'epl_upgrade_admin_notice' );

/**
 * Upgrade EPL Database to 3.3
 *
 * @since 3.3.0
 * @since 3.5.18 Added nonce check.
 */
function epl_upgrade_db() {

    if ( ! current_user_can( 'manage_options' ) ) {
        wp_die(
            wp_json_encode(
                array(
                    'status' => 'fail',
                    'msg'    => esc_html__(
                        'Unauthorized',
                        'easy-property-listings'
                    ),
                )
            )
        );
    }

    check_ajax_referer( 'epl_ajax_nonce', '_epl_nonce' );

    if ( ! isset( $_POST['upgrade_to'] ) ) {
        wp_die(
            wp_json_encode(
                array(
                    'status' => 'fail',
                    'msg'    => esc_html__(
                        'Some error occured',
                        'easy-property-listings'
                    ),
                )
            )
        );
    }

    $ver = abs( floatval( $_POST['upgrade_to'] ) );

    switch ( $ver ) {

        case '3.3':
            epl_upgrade_db_to_3_3();
            break;
    }
}
add_action( 'wp_ajax_epl_upgrade_db', 'epl_upgrade_db' );

/**
 * Update user note comment type to note
 *
 * @since 3.3.0
 */
function epl_update_user_note_type() {

    $comments_query = new WP_Comment_Query();

    $comments = $comments_query->query(
        array(
            'type__in' => array( 'epl_user_note' ),
        )
    );

    if ( ! empty( $comments ) ) {
        foreach ( $comments as $comment ) {
            wp_update_comment(
                array(
                    'comment_ID'   => $comment->comment_ID,
                    'comment_type' => 'note',
                )
            );
        }
    }
}

/**
 * Check if need to upgrade EPL Database to 3.3
 *
 * @since 3.3.0
 */
function epl_upgrade_db_to_3_3() {

    $updated_listings = (array) get_option( 'epl_updated_global_price' );
    $current_batch    = array();

    $args = array(
        'post_type'   => epl_get_core_post_types(),
        'post_status' => 'any',
        'numberposts' => 200, // phpcs:ignore
        // 200 listings in single batch.
        'exclude'     => $updated_listings,
    );

    $all_posts = get_posts( $args );

    if ( ! empty( $all_posts ) ) {

        foreach ( $all_posts as $single ) {

            switch ( $single->post_type ) {

                case 'rental':
                    $price = get_post_meta( $single->ID, 'property_rent', true );
                    update_post_meta( $single->ID, 'property_price_global', $price );
                    break;

                case 'commercial':
                    $price = get_post_meta( $single->ID, 'property_price', true );
                    if ( empty( $price ) ) {
                        $price = get_post_meta( $single->ID, 'property_com_rent', true );
                    }
                    update_post_meta( $single->ID, 'property_price_global', $price );
                    break;

                default:
                    $price = get_post_meta( $single->ID, 'property_price', true );
                    update_post_meta( $single->ID, 'property_price_global', $price );
                    break;
            }
            $current_batch[]    = $single->ID;
            $updated_listings[] = $single->ID;
        }

        update_option( 'epl_updated_global_price', $updated_listings );
        wp_die(
            wp_json_encode(
                array(
                    'status' => 'success',
                    'buffer' => 'processing',
                    /* Translators: %s is a string of listing post ids. */
                    'msg'    => sprintf( esc_html__( 'Database upgrade in process, following listings updated : %s. Please wait...', 'easy-property-listings' ), implode( ', ', $current_batch ) ),
                )
            )
        );

    } else {

        update_option( 'epl_db_upgraded_to', '3.3' );
        wp_die(
            wp_json_encode(
                array(
                    'status' => 'success',
                    'buffer' => 'complete',
                    'msg'    => esc_html__( 'Database upgraded successfully', 'easy-property-listings' ),
                )
            )
        );
    }
}

/**
 * Update the property_price_global when saving or updating an EPL post
 *
 * @param int   $post_id The post id.
 * @param array $post The post object.
 * @param array $_update Update.
 *
 * @since 3.3.0
 * @since 3.5.18 Private variable $_update.
 */
function epl_sync_property_price_global( $post_id, $post, $_update ) {

    if ( is_epl_post() ) {

        if ( 'rental' === $post->post_type ) {
            $price = get_post_meta( $post_id, 'property_rent', true );
            update_post_meta( $post_id, 'property_price_global', $price );

        } elseif ( 'commercial' === $post->post_type ) {

            $price = get_post_meta( $post_id, 'property_price', true );
            if ( empty( $price ) ) {
                $price = get_post_meta( $post_id, 'property_com_rent', true );
            }
            update_post_meta( $post_id, 'property_price_global', $price );

        } else {

            $price = get_post_meta( $post_id, 'property_price', true );
            update_post_meta( $post_id, 'property_price_global', $price );
        }
    }
}

add_action( 'save_post', 'epl_sync_property_price_global', 40, 3 );

/**
 * Filter the contacts comments
 *
 * @param array  $avatar Update.
 * @param string $id_or_email User ID or email address.
 * @param array  $_args Arguments.
 *
 * @return array|string $avatar
 *
 * @since 3.3.0
 * @since 3.5.18 Private variable $_args.
 */
function epl_get_avatar_filter( $avatar, $id_or_email, $_args ) {

    if ( ! is_object( $id_or_email ) ) {
        return $avatar;
    }

    if ( 'easy-property-listings' !== $id_or_email->comment_agent ) {
        return $avatar;
    }

    $label = esc_html__( 'Note', 'easy-property-listings' );

    switch ( $id_or_email->comment_type ) {

        case 'call':
            $label = esc_html__( 'Call', 'easy-property-listings' );
            break;

        case 'email':
            $label = esc_html__( 'Mail', 'easy-property-listings' );
            break;

        case 'note':
            $label = esc_html__( 'Note', 'easy-property-listings' );
            break;

        case 'listing_alert':
            $label = esc_html__( 'Alert', 'easy-property-listings' );
            break;

        default:
            $label = esc_html__( 'Note', 'easy-property-listings' );
            break;
    }

    return '<div class="avatar epl-notes-grav">
            <div class="epl-notes-icon">
                ' . substr( $label, 0, 1 ) . '
            </div>
            <div class="epl-notes-label">
                ' . $label . '
            </div>
        </div>';
}
add_filter( 'pre_get_avatar', 'epl_get_avatar_filter', 10, 5 );

/**
 * Update a featured listing when pressing the star icon
 *
 * @since 3.3.0
 * @since 3.5.23 Fix: Broken Access Control in epl_update_featured_listing (CVE-2025-64242).
 */
function epl_update_featured_listing() {

    check_ajax_referer( 'epl_ajax_nonce', '_epl_nonce' );

    $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0;

    if ( $id <= 0 ) {
        return;
    }

    if ( ! current_user_can( 'edit_post', $id ) ) {
        wp_die(
            wp_json_encode(
                array(
                    'status'   => 'unauthorized',
                    'featured' => 'no',
                )
            )
        );
    }

    $featured    = get_post_meta( $id, 'property_featured', true );
    $is_featured = 'no';

    if ( 'yes' === $featured ) {
        update_post_meta( $id, 'property_featured', '' );
        $is_featured = 'no';
    } else {
        update_post_meta( $id, 'property_featured', 'yes' );
        $is_featured = 'yes';
    }

    wp_die(
        wp_json_encode(
            array(
                'status'   => 'successful',
                'featured' => $is_featured,
            )
        )
    );
}
add_action( 'wp_ajax_epl_update_featured_listing', 'epl_update_featured_listing' );
Easy Property Listings 3.5.24 Code Reference API documentation generated by ApiGen