Added: Require login to show Author box, Search field settings.

This commit is contained in:
Hoang Huu
2020-02-20 10:39:15 +07:00
parent 0c1b3b7ef1
commit 103f4954aa
11 changed files with 227 additions and 140 deletions

View File

@@ -280,19 +280,27 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
}
$fields[] = [
'name' => esc_html__( 'Search type ', 'opalestate-pro' ) . $meta['name'],
'options' => [
'name' => $meta['name'],
'desc' => '',
'type' => 'opalestate_title',
'id' => 'opalestate_title_search_field_' . $meta['id'],
'before_row' => '<hr>',
];
$fields[] = [
'name' => esc_html__( 'Field type', 'opalestate-pro' ),
'options' => [
'select' => esc_html__( 'Select', 'opalestate-pro' ),
'range' => esc_html__( 'Range', 'opalestate-pro' ),
'text' => esc_html__( 'Text', 'opalestate-pro' ),
],
'id' => $meta['id'] . '_search_type',
'type' => 'radio_inline',
'default' => 'select',
'id' => $meta['id'] . '_search_type',
'type' => 'radio_inline',
'default' => 'select',
];
$fields[] = [
'name' => esc_html__( 'Options select ', 'opalestate-pro' ) . $meta['name'],
'name' => esc_html__( 'Options', 'opalestate-pro' ),
'description' => esc_html__( 'Options value select. Use "," to separate values.', 'opalestate-pro' ),
'id' => $meta['id'] . '_options_value',
'type' => 'text',
@@ -300,7 +308,7 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
];
$fields[] = [
'name' => esc_html__( 'Min range ', 'opalestate-pro' ) . $meta['name'],
'name' => esc_html__( 'Min range', 'opalestate-pro' ),
'description' => esc_html__( 'Min range', 'opalestate-pro' ),
'id' => $meta['id'] . '_min_range',
'type' => 'text',
@@ -308,7 +316,7 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
];
$fields[] = [
'name' => esc_html__( 'Max range ', 'opalestate-pro' ) . $meta['name'],
'name' => esc_html__( 'Max range', 'opalestate-pro' ),
'description' => esc_html__( 'Max range', 'opalestate-pro' ),
'id' => $meta['id'] . '_max_range',
'type' => 'text',
@@ -316,7 +324,14 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
];
$fields[] = [
'name' => esc_html__( 'Default text ', 'opalestate-pro' ) . $meta['name'],
'name' => esc_html__( 'Unit thousand', 'opalestate-pro' ),
'description' => esc_html__( 'Unit thousand', 'opalestate-pro' ),
'id' => $meta['id'] . '_unit_thousand',
'type' => 'text',
];
$fields[] = [
'name' => esc_html__( 'Default text', 'opalestate-pro' ),
'description' => esc_html__( 'Default text value', 'opalestate-pro' ),
'id' => $meta['id'] . '_default_text',
'type' => 'text',
@@ -491,6 +506,17 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
],
];
$fields[] = [
'name' => esc_html__( 'Login to show Author box', 'opalestate-pro' ),
'desc' => esc_html__( 'Require users login to show Author box', 'opalestate-pro' ),
'id' => 'enable_single_login_to_show_author_box',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
];
$fields[] = [
'name' => esc_html__( 'Show Enquire form', 'opalestate-pro' ),
'desc' => esc_html__( 'Show Enquire form in the single property page.', 'opalestate-pro' ),

View File

@@ -42,19 +42,20 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
break;
default:
$setting_search_type = 'opalestate_ppt_' . $field . '_search_type';
$setting_search_type_options = 'opalestate_ppt_' . $field . '_options_value';
$setting_search_min_range = 'opalestate_ppt_' . $field . '_min_range';
$setting_search_max_range = 'opalestate_ppt_' . $field . '_max_range';
$setting_search_default_text = 'opalestate_ppt_' . $field . '_default_text';
$setting_search_type = 'opalestate_ppt_' . $field . '_search_type';
$setting_search_type_options = 'opalestate_ppt_' . $field . '_options_value';
$setting_search_min_range = 'opalestate_ppt_' . $field . '_min_range';
$setting_search_max_range = 'opalestate_ppt_' . $field . '_max_range';
$setting_search_unit_thousand = 'opalestate_ppt_' . $field . '_unit_thousand';
$setting_search_default_text = 'opalestate_ppt_' . $field . '_default_text';
$display_type_search = opalestate_options( $setting_search_type, 'select' );
if ( $display_type_search == 'select' ) {
$option_values = (array) explode( ',', opalestate_options( $setting_search_type_options, '1,2,3,4,5,6,7,8,9,10' ) );
$template = '<label class="opalestate-label opalestate-label--' . sanitize_html_class( $label ) . '">' . esc_html( $label ) . '</label>';
$template .= '<select class="form-control" name="info[%s]"><option value="">%s</option>';
$template = '<label class="opalestate-label opalestate-label--' . sanitize_html_class( $label ) . '">' . esc_html( $label ) . '</label>';
$template .= '<select class="form-control" name="info[%s]"><option value="">%s</option>';
foreach ( $option_values as $value ) {
$selected = $value == $qvalue ? 'selected="selected"' : '';
@@ -66,8 +67,8 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
} elseif ( $display_type_search == 'text' ) {
$option_values = opalestate_options( $setting_search_default_text, '' );
$qvalue = $qvalue ? $qvalue : $option_values;
$template = '<label class="opalestate-label opalestate-label--' . sanitize_html_class( $label ) . '">' . esc_html( $label ) . '</label>';
$template .= '<input class="form-control" type="text" name="info[%s]" value="%s"/>';
$template = '<label class="opalestate-label opalestate-label--' . sanitize_html_class( $label ) . '">' . esc_html( $label ) . '</label>';
$template .= '<input class="form-control" type="text" name="info[%s]" value="%s"/>';
$template = sprintf( $template, $field, $qvalue );
} elseif ( $display_type_search == 'range' ) {
@@ -78,12 +79,13 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
$search_max = (int) isset( $_GET[ $max_name ] ) ? $_GET[ $max_name ] : opalestate_options( $setting_search_max_range, 1000 );
$data = [
'id' => $field,
'unit' => '',
'ranger_min' => opalestate_options( $setting_search_min_range, 0 ),
'ranger_max' => opalestate_options( $setting_search_max_range, 1000 ),
'input_min' => $search_min,
'input_max' => $search_max,
'id' => $field,
'unit' => '',
'ranger_min' => opalestate_options( $setting_search_min_range, 0 ),
'ranger_max' => opalestate_options( $setting_search_max_range, 1000 ),
'input_min' => $search_min,
'input_max' => $search_max,
'unit_thousand' => apply_filters( 'opalestate_search_range_unit_thousand', opalestate_options( $setting_search_unit_thousand ), $field ),
];
ob_start();
@@ -117,8 +119,8 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
* Render area size field.
*/
function opalestate_property_areasize_field_template( $template = '' ) {
$search_min = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : opalestate_options( 'search_min_area', 0 );
$search_max = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : opalestate_options( 'search_max_area', 1000 );
$search_min = isset( $_GET['min_area'] ) ? sanitize_text_field( $_GET['min_area'] ) : opalestate_options( 'search_min_area', 0 );
$search_max = isset( $_GET['max_area'] ) ? sanitize_text_field( $_GET['max_area'] ) : opalestate_options( 'search_max_area', 1000 );
$measurement_units = opalestate_get_measurement_units();
$unit = opalestate_options( 'measurement_unit', 'sqft' );
if ( isset( $measurement_units[ $unit ] ) ) {

View File

@@ -1292,6 +1292,11 @@ function opalestate_is_enable_areasize_field() {
return 'on' == opalestate_get_option( 'opalestate_ppt_areasize_opt', 'on' );
}
function opalestate_is_require_login_to_show_author_box() {
$require = opalestate_get_option( 'enable_single_login_to_show_author_box', 'off' );
return ! ( $require == 'on' ) || ( $require == 'on' && is_user_logged_in() );
}
/**
* Clean variables using sanitize_text_field. Arrays are cleaned recursively.
* Non-scalar values are ignored.