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 
<?php
/**
 * Render HTML Fields
 *
 * @package     EPL
 * @subpackage  Classes/RenderFields
 * @copyright   Copyright (c) 2020, Merv Barrett
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       2.3
 * @since       3.4.29 Moved from meta-boxes into its own class for more extensibility.
 * @since       3.4.44 Added help field type in meta boxes fields.
 */

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

/**
 * EPL_Render_Fields class.
 *
 * Handles rendering of html fields for EPL settings, meta boxes etc.
 *
 * @since 2.3
 * @since 3.4.29 Moved from meta-boxes into its own class for more extensibility.
 * @since 3.4.48 New: Field type textarea_html which works like the editor field type but without loading the MCE buttons.
 */
class EPL_Render_Fields {

    /**
     * Default class prefix.
     *
     * @var string $class_prefix
     */
    public $class_prefix = 'epl-form-field-';

    /**
     * Post object.
     *
     * @var array $post
     */
    public $post;

    /**
     * Constructs a new instance.
     */
    public function __construct() {

        add_action( 'epl_render_field_select', array( $this, 'select' ), 10, 2 );
        add_action( 'epl_render_field_select_multiple', array( $this, 'select' ), 10, 2 );
        add_action( 'epl_render_field_checkbox', array( $this, 'checkbox' ), 10, 2 );
        add_action( 'epl_render_field_checkbox_option', array( $this, 'checkbox_option' ), 10, 2 );
        add_action( 'epl_render_field_checkbox_single', array( $this, 'checkbox_single' ), 10, 2 );
        add_action( 'epl_render_field_radio', array( $this, 'radio' ), 10, 2 );
        add_action( 'epl_render_field_file', array( $this, 'file' ), 10, 2 ); // File and image.
        add_action( 'epl_render_field_image', array( $this, 'file' ), 10, 2 ); // File and image.
        add_action( 'epl_render_field_editor', array( $this, 'editor' ), 10, 2 );
        add_action( 'epl_render_field_textarea', array( $this, 'textarea' ), 10, 2 );
        add_action( 'epl_render_field_textarea_html', array( $this, 'textarea_html' ), 10, 2 );
        add_action( 'epl_render_field_decimal', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_number', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_date', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_auction-date', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_sold-date', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_email', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_url', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_button', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_color', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_text', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_hidden', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_submit', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_password', array( $this, 'render_default' ), 10, 2 );
        add_action( 'epl_render_field_locked', array( $this, 'locked' ), 10, 2 );
        add_action( 'epl_render_field_help', array( $this, 'help' ), 10, 2 );
        add_action( 'epl_render_field_html', array( $this, 'html' ), 10, 2 );
    }

    /**
     * Process field paramaters.
     *
     * @param array  $field The field.
     * @param string $val   The value.
     *
     * @return array The array of fields.
     */
    public function process_field_params( $field, $val ) {

        $field = apply_filters( 'pre_process_field_params', $field );

        if ( 'date' === $field['type'] ) {
            $field['data-format']     = isset( $field['format'] ) ? $field['format'] : 'Y-m-d';
            $field['data-timepicker'] = isset( $field['timepicker'] ) ? $field['timepicker'] : false;
        }

        $field['id']           = $this->get_id( $field );
        $field['name']         = $this->get_name( $field );
        $field['class']        = $this->get_class( $field );
        $field['data']         = $this->get_data_attributes( $field );
        $field['min']          = $this->get_min( $field );
        $field['max']          = $this->get_max( $field );
        $field['maxlength']    = $this->get_maxlength( $field );
        $field['placeholder']  = $this->get_placeholder( $field );
        $field['autocomplete'] = $this->get_autocomplete( $field );
        $field['multiple']     = $this->is_multiple( $field );
        $field['required']     = $this->is_required( $field );
        $field['value']        = 'button' === $field['type'] ? $field['value'] : $val;
        return apply_filters( 'post_process_field_params', $field );
    }

    /**
     * Gets the minimum.
     *
     * @param array $field The field.
     *
     * @return string The minimum.
     */
    public function get_min( $field ) {
        return isset( $field['min'] ) ? $field['min'] : '';
    }

    /**
     * Determines whether the specified field is multiple.
     *
     * @param array $field The field.
     *
     * @return boolean True if the specified field is multiple, False otherwise.
     */
    public function is_multiple( $field ) {
        return 'select_multiple' === $field['type'] ? ' multiple ' : '';
    }

    /**
     * Gets the maximum.
     *
     * @param array $field The field.
     *
     * @return string The maximum.
     */
    public function get_max( $field ) {
        return isset( $field['max'] ) ? $field['max'] : '';
    }

    /**
     * Gets the maxlength.
     *
     * @param array $field The field.
     *
     * @return string The maxlength.
     */
    public function get_maxlength( $field ) {
        return isset( $field['maxlength'] ) ? (int) $field['maxlength'] : '';
    }

    /**
     * Gets the placeholder.
     *
     * @param array $field The field.
     *
     * @return string The placeholder.
     */
    public function get_placeholder( $field ) {
        return isset( $field['placeholder'] ) ? $field['placeholder'] : '';
    }

    /**
     * Gets the autocomplete.
     *
     * @param array $field The field.
     *
     * @return string The autocomplete.
     */
    public function get_autocomplete( $field ) {
        return isset( $field['autocomplete'] ) ? $field['autocomplete'] : '';
    }

    /**
     * Determines whether the specified field is required.
     *
     * @param array $field The field.
     *
     * @return boolean True if the specified field is required, False otherwise.
     */
    public function is_required( $field ) {
        return ! empty( $field['required'] ) ? ' required ' : '';
    }

    /**
     * Gets the identifier.
     *
     * @param array $field The field.
     *
     * @return boolean The identifier.
     */
    public function get_id( $field ) {
        $id = isset( $field['id'] ) ? $field['id'] : '';

        if ( empty( $id ) ) {
            $id = isset( $field['name'] ) ? $field['name'] : '';
        }

        return $id;
    }

    /**
     * Gets the name.
     *
     * @param array $field The field.
     *
     * @return string The name.
     */
    public function get_name( $field ) {
        return isset( $field['name'] ) ? $field['name'] : '';
    }

    /**
     * Gets the decimal validation class.
     *
     * @param array $field The field.
     *
     * @return string The decimal validation class.
     */
    public function get_decimal_validation_class( $field = array() ) {
        return apply_filters( 'epl_form_field_decimal_validation_class', 'validate[custom[onlyNumberWithDecimal]]', $field );
    }

    /**
     * Gets the number validation class.
     *
     * @param array $field The field.
     *
     * @return string The number validation class.
     */
    public function get_number_validation_class( $field = array() ) {
        return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[onlyNumber]]', $field );
    }

    /**
     * Gets the email validation class.
     *
     * @param array $field The field.
     *
     * @return string The email validation class.
     */
    public function get_email_validation_class( $field = array() ) {
        return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[email]]', $field );
    }

    /**
     * Gets the url validation class.
     *
     * @param array $field The field.
     *
     * @return string The The url validation class.
     */
    public function get_url_validation_class( $field = array() ) {
        return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[url]]', $field );
    }

    /**
     * Gets the class.
     *
     * @param array $field The field.
     *
     * @return boolean The class.
     */
    public function get_class( $field ) {

        $classes = isset( $field['class'] ) ? $field['class'] : '';

        if ( ! is_array( $classes ) ) {
            $classes = explode( ' ', $classes );
        }
        $classes = implode( ' ', array_map( 'sanitize_html_class', $classes ) );

        // Append validation classes.
        if ( 'decimal' === $field['type'] ) {
            $classes .= ' ' . $this->get_decimal_validation_class( $field );
        } elseif ( 'number' === $field['type'] ) {
            $classes .= ' ' . $this->get_number_validation_class( $field );
        } elseif ( 'email' === $field['type'] ) {
            $classes .= ' ' . $this->get_email_validation_class( $field );
        } elseif ( 'url' === $field['type'] ) {
            $classes .= ' ' . $this->get_url_validation_class( $field );
        } elseif ( 'date' === $field['type'] ) {
            $classes .= ' epldatepicker ';
        }

        // Append type class.
        $classes .= ' ' . $this->class_prefix . sanitize_text_field( $field['type'] );
        return $classes;
    }

    /**
     * Gets the data attributes.
     *
     * @param array $field The field.
     *
     * @return string
     */
    public function get_data_attributes( $field ) {

        $atts_html = '';
        if ( ! empty( $field['data'] ) ) {
            foreach ( $field['data'] as $data_key => $data_value ) {

                if ( ! epl_starts_with( $data_key, 'data-' ) ) {
                    $data_key = 'data-' . $data_key;
                }

                if ( ! is_array( $data_value ) && ! is_object( $data_value ) ) {
                    $atts_html .= $data_key . "='" . $data_value . "'";
                } else {
                    $atts_html .= $data_key . "='" . wp_json_encode( $data_value ) . "'";
                }
            }
        }

        foreach ( $field as $key => $value ) {

            if ( epl_starts_with( $key, 'data-' ) ) {
                if ( ! is_array( $value ) && ! is_object( $value ) ) {
                    $atts_html .= $key . "='" . $value . "'";
                } else {
                    $atts_html .= $key . "='" . wp_json_encode( $value ) . "'";
                }
            }
        }

        return $atts_html;

    }

    /**
     * Determines whether the specified field is name array.
     *
     * @param array $field The field.
     *
     * @return boolean True if the specified field is name array, False otherwise.
     */
    public function is_name_array( $field ) {

        $name_arrays = apply_filters( 'epl_form_field_name_arrays', array( 'select_multiple', 'checkbox' ) );
        return in_array( $field['type'], $name_arrays, true ) ? true : false;

    }

    /**
     * Gets the opening field tag.
     *
     * @param string  $tag        The tag.
     * @param array   $field      The field.
     * @param boolean $self_close The self close.
     *
     * @return     string   The opening field tag.
     *
     * @since 2.3.0
     * @since 3.4.38 PHP 8.0 fix for Required parameter $field follows optional parameter $tag.
     * @since 3.5    data attributes support for field type help.
     */
    public function get_opening_field_tag( $tag = 'input', $field = array(), $self_close = false ) {

        $tag = sanitize_key( $tag );

        $html = '<' . $tag . ' ';

        if ( ! empty( $field['type'] ) && ! in_array( $field['type'], array( 'select', 'select_multiple', 'textarea', 'help' ), true ) ) {
            $html .= ' type ="' . esc_attr( $field['type'] ) . '" ';
            $html .= ' value ="' . esc_attr( stripslashes( $field['value'] ) ) . '" ';
        }

        if ( ! empty( $field['multiple'] ) ) {
            $html .= esc_attr( $field['multiple'] );
        }

        if ( ! empty( $field['min'] ) ) {
            $html .= ' min ="' . esc_attr( $field['min'] ) . '" ';
        }

        if ( ! empty( $field['max'] ) ) {
            $html .= ' max ="' . esc_attr( $field['max'] ) . '" ';
        }

        if ( ! empty( $field['maxlength'] ) ) {
            $html .= ' maxlength ="' . esc_attr( $field['maxlength'] ) . '" ';
        }

        if ( ! empty( $field['class'] ) ) {
            $html .= ' class ="' . esc_attr( $field['class'] ) . '" ';
        }

        if ( ! empty( $field['name'] ) ) {
            $name = esc_attr( $field['name'] );
            if ( $this->is_name_array( $field ) ) {
                $name .= '[]';
            }
            $html .= ' name ="' . $name . '" ';
        }

        if ( ! empty( $field['id'] ) ) {
            $html .= ' id ="' . esc_attr( $field['id'] ) . '" ';
        }

        if ( ! empty( $field['placeholder'] ) ) {
            $html .= ' placeholder ="' . esc_attr( $field['placeholder'] ) . '" ';
        }

        if ( ! empty( $field['autocomplete'] ) ) {
            $html .= ' autocomplete ="' . esc_attr( $field['autocomplete'] ) . '" ';
        }

        if ( ! empty( $field['data'] ) ) {
            $html .= ' ' . wp_kses_post( $field['data'] );
        }

        $html .= $self_close ? '/>' : '>';

        return $html;
    }

    /**
     * Renders the field based on field type
     *
     * @param array  $field The field.
     * @param string $val   The value.
     */
    public function render( $field = array(), $val = '' ) {

        global $post;

        if ( ! is_null( $post ) ) {
            $this->post = $post;
        }

        $type  = sanitize_text_field( $field['type'] );
        $field = $this->process_field_params( $field, $val );
        do_action( 'epl_render_field_' . $type, $field, $val );

        if ( isset( $field['geocoder'] ) ) {
            if ( 'true' == $field['geocoder'] ) { //phpcs:ignore
                echo '<span class="epl-geocoder-button"></span>';
            }

            do_action( 'epl_admin_listing_map', esc_attr( stripslashes( $val ) ) );
        }

        if ( isset( $field['help'] ) ) {
            $field['help'] = trim( $field['help'] );
            if ( ! empty( $field['help'] ) ) {
                echo '<span class="epl-help-text">' . wp_kses_post( $field['help'] ) . '</span>';
            }
        }
    }

    /**
     * Renders select
     *
     * @param array  $field The field.
     * @param string $val   The value.
     */
    public function select( $field, $val ) {

        if ( $this->is_multiple( $field ) ) {
            $val = (array) $val;
        }

        echo $this->get_opening_field_tag( 'select', $field ); //phpcs:ignore

        if ( isset( $field['opts'] ) && ! empty( $field['opts'] ) ) {

            foreach ( $field['opts'] as $k => $v ) {
                $selected = '';

                if ( $this->is_multiple( $field ) ) {
                    if ( in_array( $k, $val ) ) { //phpcs:ignore
                        $selected = 'selected';
                    }
                } else {
                    if ( $val == $k ) { //phpcs:ignore
                        $selected = 'selected';
                    }
                }

                if ( is_array( $v ) ) {
                    if ( isset( $v['exclude'] ) && ! empty( $v['exclude'] ) ) {
                        if ( ! is_null( $this->post ) && in_array( $this->post->post_type, $v['exclude'], true ) ) {
                            continue;
                        }
                    }

                    if ( isset( $v['include'] ) && ! empty( $v['include'] ) ) {
                        if ( ! is_null( $this->post ) && ! in_array( $this->post->post_type, $v['include'], true ) ) {
                            continue;
                        }
                    }
                    $v = $v['label'];
                }

                echo '<option value="' . esc_attr( $k ) . '" ' . esc_attr( $selected ) . '>' . esc_html( $v ) . '</option>';
            }
        } else {
            echo '<option value=""> </option>';
        }
        echo '</select>';
    }

    /**
     * Renders checkbox
     *
     * @param array  $field The field.
     * @param string $val  The value.
     */
    public function checkbox( $field, $val ) {

        if ( ! empty( $field['opts'] ) ) {
            foreach ( $field['opts'] as $k => $v ) {
                $checked = '';

                if ( ! empty( $val ) ) {

                    $val = (array) $val;
                    if ( in_array( $k, $val ) ) { //phpcs:ignore
                        $checked = 'checked';
                    }
                }
                echo '<span class="epl-field-row">
                        <input type="checkbox" name="' . esc_attr( $field['name'] ) . '[]" 
                            ' . wp_kses_post( $field['data'] ) . ' 
                            class="' . esc_attr( $field['class'] ) . '"  
                            id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" 
                            value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> 
                        <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label>
                    </span>';
            }
        }
    }

    /**
     * Renders checkbox single
     *
     * @param array  $field The field.
     * @param string $val   The value.
     *
     * @since 3.4.34 Tweak: Added hidden empty field for checkboxes so that they always show up in $_POST data while saving.
     */
    public function checkbox_single( $field, $val ) {

        if ( ! empty( $field['opts'] ) ) {
            foreach ( $field['opts'] as $k => $v ) {
                $checked = '';
                if ( ! empty( $val ) ) {
                    $checkbox_single_options = apply_filters( 'epl_checkbox_single_check_options', array( 1, 'yes', 'on', 'true', '1' ) );
                    if ( $k == $val || in_array( $val, $checkbox_single_options, true ) ) { //phpcs:ignore
                        $checked = 'checked';
                    }
                }
                if ( 1 === count( $field['opts'] ) ) {
                    $v = $field['label'];
                }
                echo '<span class="epl-field-row">
                <input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="" />
                <input type="checkbox" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" ' . wp_kses_post( $field['data'] ) . ' id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>';
            }
        }
    }

    /**
     * Renders checkbox option
     *
     * @param array  $field The field.
     * @param string $val   The value.
     *
     * @since 3.4.34 Tweak: Added hidden empty field for checkboxes so that they always show up in $_POST data while saving.
     */
    public function checkbox_option( $field, $val ) {

        if ( ! empty( $field['opts'] ) ) {
            foreach ( $field['opts'] as $k => $v ) {
                $checked = '';
                if ( ! empty( $val ) ) {
                    if ( $k == $val ) { //phpcs:ignore
                        $checked = 'checked';
                    }
                }
                echo '<span class="epl-field-row">
                <input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="" />
                <input type="checkbox" name="' . esc_attr( $field['name'] ) . '" ' . wp_kses_post( $field['data'] ) . ' id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" class="' . esc_attr( $field['class'] ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>';
            }
        }
    }

    /**
     * Renders radio
     *
     * @param array  $field The field.
     * @param string $val   The value.
     */
    public function radio( $field, $val ) {

        if ( ! empty( $field['opts'] ) ) {
            foreach ( $field['opts'] as $k => $v ) {
                $checked = '';
                if ( $val == $k ) { //phpcs:ignore
                    $checked = 'checked';
                }
                echo '<span class="epl-field-row"><input type="radio" name="' . esc_attr( $field['name'] ) . '" ' . wp_kses_post( $field['data'] ) . ' class="' . esc_attr( $field['class'] ) . '"  id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>';
            }
        }
    }

    /**
     * Renders file / image
     *
     * @param array  $field The field.
     * @param string $val   The value.
     */
    public function file( $field, $val ) {
        if ( is_array( $val ) ) {
            $val = isset( $val['image_url_or_path'] ) ? $val['image_url_or_path'] : '';
        }

        if ( ! empty( $val ) ) {
            $img = esc_attr( stripslashes( $val ) );
        } else {
            $img = plugin_dir_url( __DIR__ ) . 'assets/images/no_image.png'; //phpcs:ignore
        }

        echo '
            <div class="epl-media-row">
                <input type="text" ' . wp_kses_post( $field['data'] ) . ' class="' . esc_attr( $field['class'] ) . '"  name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( stripslashes( $val ) ) . '" />
                &nbsp;&nbsp;<input type="button" name="epl_upload_button" class="button" value="' . esc_html__( 'Add File', 'easy-property-listings' ) . '" />';

        if ( in_array( pathinfo( $img, PATHINFO_EXTENSION ), array( 'jpg', 'jpeg', 'png', 'gif' ), true ) ) {
            echo '&nbsp;&nbsp;<img src="' . esc_url( $img ) . '" alt="" />';
        }
        echo '<div class="epl-clear"></div>
            </div>
        ';
    }

    /**
     * Renders editor
     *
     * @param array  $field The field.
     * @param string $val   The value.
     */
    public function editor( $field, $val ) {
        wp_editor(
            stripslashes( $val ),
            esc_attr( $field['id'] ),
            $settings = array(
                'textarea_rows' => 5,
                'editor_class'  => $field['class'],
            )
        );
    }

    /**
     * Renders textarea
     *
     * @param array  $field The field.
     * @param string $val   The value.
     */
    public function textarea( $field, $val ) {
        echo $this->get_opening_field_tag( 'textarea', $field ); //phpcs:ignore
        echo wp_kses_post( stripslashes( $val ) );
        echo '</textarea>';
    }

    /**
     * Renders textarea_html
     *
     * @param array  $field The field.
     * @param string $val   The value.
     *
     * @since 3.4.48
     */
    public function textarea_html( $field, $val ) {
        echo $this->get_opening_field_tag( 'textarea', $field ); //phpcs:ignore
        echo esc_textarea( $val );
        echo '</textarea>';
    }

    /**
     * Renders locked
     *
     * @param array  $field The field.
     * @param string $val   The value.
     */
    public function locked( $field, $val ) {
        echo '<span>' . esc_attr( stripslashes( $field['value'] ) ) . '</span>';
    }

    /**
     * Renders help
     *
     * @param array  $field The field.
     * @param string $val   The value.
     *
     * @since 3.4.48 Added escaping on id.
     */
    public function help( $field, $val ) {

        $content = isset( $field['content'] ) ? $field['content'] : '';
        $help_id = isset( $field['name'] ) ? sanitize_key( $field['name'] ) : '';
        //phpcs:ignore
        echo '<div class="epl-help-container">
                        ' . $this->get_opening_field_tag( 'div', $field ) . '
                ' . wp_kses_post( $content ) . '
            </div></div>';
    }

    /**
     * Renders html
     *
     * @param array  $field The field.
     * @param string $val   The value.
     *
     * @since 3.4.48 Added escaping on id.
     */
    public function html( $field, $val ) {

        $content = isset( $field['content'] ) ? $field['content'] : '';
        $help_id = isset( $field['name'] ) ? sanitize_key( $field['name'] ) : '';
        //phpcs:ignore
        echo '<div class="epl-html-container" id="' . esc_attr( $help_id ) . '">
                ' . wp_kses_post( $content ) . '
            </div>';
    }

    /**
     * Renders default input types
     *
     * @param array  $field The field.
     * @param string $val   The value.
     * @since 3.4.35 fixed hidden field rendering.
     */
    public function render_default( $field, $val ) {

        if ( ! in_array( $field['type'], array( 'button', 'number', 'color', 'submit' ), true ) ) {
            $field['type'] = 'text';
        }
        echo $this->get_opening_field_tag( 'input', $field, true ); //phpcs:ignore
    }
}
Easy Property Listings 3.5.15 Code Reference API documentation generated by ApiGen