= 1618268400 && get_option( 'propertyhive_hide_demo_data_tab', '' ) != 'yes' ) { $settings[] = include( 'settings/class-ph-settings-demo-data.php' ); } self::$settings = apply_filters( 'propertyhive_get_settings_pages', $settings ); } return self::$settings; } /** * Save the settings */ public static function save() { global $current_section, $current_tab; if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Insufficient permissions', 'propertyhive' ), '', array( 'response' => 403 ) ); } if ( empty( $_REQUEST['_wpnonce'] ) || ! is_string( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'propertyhive-settings' ) ) die( esc_html(__( 'Action failed. Please refresh the page and retry.', 'propertyhive' )) ); // Trigger actions do_action( 'propertyhive_settings_save_' . $current_tab ); do_action( 'propertyhive_update_options_' . $current_tab ); do_action( 'propertyhive_update_options' ); self::add_message( __( 'Your settings have been saved.', 'propertyhive' ) ); update_option( 'propertyhive_queue_flush_rewrite_rules', 'yes' ); do_action( 'propertyhive_settings_saved' ); } /** * Add a message * @param string $text */ public static function add_message( $text ) { self::$messages[] = $text; } /** * Add an error * @param string $text */ public static function add_error( $text ) { self::$errors[] = $text; } /** * Output messages + errors */ public static function show_messages() { if ( sizeof( self::$errors ) > 0 ) { foreach ( self::$errors as $error ) { $allowed_tags = array( 'a' => array( 'href' => array(), ), ); $error = wp_kses($error, $allowed_tags); echo '

' . wp_kses( $error, $allowed_tags ) . '

'; } } elseif ( sizeof( self::$messages ) > 0 ) { foreach ( self::$messages as $message ) { $allowed_tags = array( 'a' => array( 'href' => array(), ), ); $message = wp_kses($message, $allowed_tags); echo '

' . wp_kses( $message, $allowed_tags ) . '

'; } } } /** * Settings page. * * Handles the display of the main propertyhive settings page in admin. * * @access public * @return void */ public static function output() { global $current_section, $current_tab, $redirect_after_save; do_action( 'propertyhive_settings_start' ); //wp_enqueue_script( 'propertyhive_settings', PH()->plugin_url() . '/assets/js/admin/settings.min.js', array( 'jquery'/*, 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'chosen'*/ ), PH()->version, true ); /*wp_localize_script( 'propertyhive_settings', 'propertyhive_settings_params', array( 'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'propertyhive' ) ) );*/ // Include settings pages self::get_settings_pages(); // Get current tab/section // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- These values only select the read-only settings view; settings writes are handled by save_fields() after the settings nonce and capability checks. $request_get = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- These values only select the read-only settings view; settings writes are handled by save_fields() after the settings nonce and capability checks. $request_request = wp_unslash( $_REQUEST ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global. $current_tab = ( isset( $request_get['tab'] ) && is_string( $request_get['tab'] ) && '' !== $request_get['tab'] ) ? sanitize_title( $request_get['tab'] ) : 'general'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Shared admin settings-view state; this global is intentionally used to control the common settings template and is not an arbitrary application global. $current_section = ( isset( $request_request['section'] ) && is_string( $request_request['section'] ) ) ? sanitize_title( $request_request['section'] ) : ''; // Save settings if data has been posted //if ( ! empty( $_POST ) ) // self::save(); // Add any posted messages $message_allowed_tags = array( 'a' => array( 'href' => array(), ), ); if ( isset( $request_get['ph_error'] ) && is_scalar( $request_get['ph_error'] ) && '' !== (string) $request_get['ph_error'] ) self::add_error( wp_kses( (string) $request_get['ph_error'], $message_allowed_tags ) ); if ( isset( $request_get['ph_message'] ) && is_scalar( $request_get['ph_message'] ) && '' !== (string) $request_get['ph_message'] ) self::add_message( wp_kses( (string) $request_get['ph_message'], $message_allowed_tags ) ); self::show_messages(); // Get tabs for the settings page $tabs = apply_filters( 'propertyhive_settings_tabs_array', array() ); include 'views/html-admin-settings.php'; } /** * Get a setting from the settings API. * * @param mixed $option * @return string */ public static function get_option( $option_name, $default = '' ) { // Array value if ( strstr( $option_name, '[' ) ) { parse_str( $option_name, $option_array ); // Option name is first key $option_name = current( array_keys( $option_array ) ); // Get value $option_values = get_option( $option_name, '' ); $key = key( $option_array[ $option_name ] ); if ( isset( $option_values[ $key ] ) ) $option_value = $option_values[ $key ]; else $option_value = null; // Single value } else { $option_value = get_option( $option_name, null ); } if ( is_array( $option_value ) ) $option_value = array_map( 'stripslashes', $option_value ); elseif ( ! is_null( $option_value ) ) $option_value = stripslashes( $option_value ); return $option_value === null ? $default : $option_value; } /** * Output admin fields. * * Loops though the propertyhive options array and outputs each field. * * @access public * @param array $options Opens array to output */ public static function output_fields( $options ) { foreach ( $options as $value ) { if ( ! isset( $value['type'] ) ) continue; if ( ! isset( $value['id'] ) ) $value['id'] = ''; if ( ! isset( $value['title'] ) ) $value['title'] = isset( $value['name'] ) ? $value['name'] : ''; if ( ! isset( $value['class'] ) ) $value['class'] = ''; if ( ! isset( $value['css'] ) ) $value['css'] = ''; if ( ! isset( $value['default'] ) ) $value['default'] = ''; if ( ! isset( $value['desc'] ) ) $value['desc'] = ''; if ( ! isset( $value['desc_tip'] ) ) $value['desc_tip'] = false; // Custom attribute handling $custom_attributes = array(); if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; // Description handling if ( $value['desc_tip'] === true ) { $description = ''; $tip = $value['desc']; } elseif ( ! empty( $value['desc_tip'] ) ) { $description = $value['desc']; $tip = $value['desc_tip']; } elseif ( ! empty( $value['desc'] ) ) { $description = $value['desc']; $tip = ''; } else { $description = $tip = ''; } if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) { $description = '

' . wp_kses_post( $description ) . '

'; } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) { $description = wp_kses_post( $description ); } elseif ( $description ) { $description = '' . wp_kses_post( $description ) . ''; } if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) { $tip = '

' . wp_kses_post( $tip ) . '

'; } elseif ( $tip ) { $tip = ''; } // Switch based on type switch( $value['type'] ) { // Section Titles case 'title': if ( ! empty( $value['title'] ) ) { echo '

' . esc_html( $value['title'] ) . '

'; } if ( ! empty( $value['desc'] ) ) { echo wp_kses_post( wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ) ); } echo ''. "\n\n"; if ( ! empty( $value['id'] ) ) { do_action( 'propertyhive_settings_' . sanitize_title( $value['id'] ) ); } break; // Section Ends case 'sectionend': if ( ! empty( $value['id'] ) ) { do_action( 'propertyhive_settings_' . sanitize_title( $value['id'] ) . '_end' ); } echo '
'; if ( ! empty( $value['id'] ) ) { do_action( 'propertyhive_settings_' . sanitize_title( $value['id'] ) . '_after' ); } break; case 'html': $full_width = ( isset($value['full_width']) && is_bool($value['full_width']) ) ? $value['full_width'] : false; ?> true, 'class' => true, ); $allowed_html['legend'] = array( 'class' => true, ); $allowed_html['label'] = array( 'for' => true, 'class' => true, ); $allowed_html['input'] = array( 'type' => true, 'name' => true, 'id' => true, 'value' => true, 'class' => true, 'style' => true, 'checked' => true, 'disabled' => true, 'placeholder' => true, ); $allowed_html['select'] = array( 'name' => true, 'id' => true, 'class' => true, 'style' => true, 'multiple' => true, 'disabled' => true, ); $allowed_html['option'] = array( 'value' => true, 'selected' => true, 'disabled' => true, ); /** * Scripts are permitted for backward compatibility because existing * Property Hive extensions use HTML settings fields to output inline * administration scripts. To be revised in future after mentioned * extensions have been updated */ $allowed_html['script'] = array( 'type' => true, 'src' => true, ); $allowed_html['a']['data-department'] = true; $allowed_html = apply_filters( 'propertyhive_admin_settings_html_allowed_tags', $allowed_html, $value ); echo wp_kses( $value['html'], $allowed_html ); ?> '; } ?> /> false, 'textarea_rows' => 3, 'teeny' => true ) ); ?> ' . wp_kses_post( $description ); ?> " id="" >*/ ?>
× px > '; } else { echo 'Image doesn\'t exist'; } ?> Select Image (function(fieldId) { jQuery(function($) { $(document.body).on("click", "[data-ph-image-field]", function(event) { if ($(this).attr("data-ph-image-field") !== fieldId) { return; } event.preventDefault(); var frameKey = "file_frame" + fieldId; var frame = wp.media.frames[frameKey] || window[frameKey]; if (frame) { frame.open(); return; } frame = wp.media({ title: $(this).data("uploader_title"), button: { text: $(this).data("uploader_button_text") }, multiple: false }); wp.media.frames[frameKey] = window[frameKey] = frame; frame.on("select", function() { frame.state().get("selection").map(function(attachment) { attachment = attachment.toJSON(); var row = $(document.getElementById("row_" + fieldId + "_uploaded")); row.show().find("td").empty().append($("", { src: attachment.url, width: 150, alt: "" })); $(document.getElementById(fieldId)).val(attachment.id); }); }); frame.open(); }); }); })(' . wp_json_encode( (string) $value['id'], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) . '); '; break; // Single page selects case 'single_select_page' : $args = array( 'name' => $value['id'], 'id' => $value['id'], 'sort_column' => 'menu_order', 'sort_order' => 'ASC', 'show_option_none' => ' ', 'class' => $value['class'], 'echo' => false, 'selected' => absint( self::get_option( $value['id'] ) ) ); if( isset( $value['args'] ) ) $args = wp_parse_args( $value['args'], $args ); ?> countries->countries; if ( strstr( $country_setting, ':' ) ) { $country_setting = explode( ':', $country_setting ); $country = current( $country_setting ); } else { $country = $country_setting; } ?> countries->countries; asort( $countries ); ?> $value ) update_option( $name, $value ); return true; } } endif;