= 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 ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_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 '

' . $error . '

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

' . $message . '

'; } } } /** * 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 $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] ); $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] ); // Save settings if data has been posted //if ( ! empty( $_POST ) ) // self::save(); // Add any posted messages if ( ! empty( $_GET['ph_error'] ) ) self::add_error( stripslashes( $_GET['ph_error'] ) ); if ( ! empty( $_GET['ph_message'] ) ) self::add_message( stripslashes( $_GET['ph_message'] ) ); 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 = '

' . $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 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; ?> '; } ?> /> false, 'textarea_rows' => 3, 'teeny' => true ) ); ?> ' . $description; ?> " id="" >*/ ?>
× px > '; } else { echo 'Image doesn\'t exist'; } ?> Select Image var file_frame' . $value['id'] . '; jQuery(document).ready(function() { jQuery(\'body\').on(\'click\', \'.ph_upload_photo_button' . $value['id'] . '\', function( event ){ event.preventDefault(); // If the media frame already exists, reopen it. if ( file_frame' . $value['id'] . ' ) { file_frame' . $value['id'] . '.open(); return; } // Create the media frame. file_frame' . $value['id'] . ' = wp.media.frames.file_frame' . $value['id'] . ' = wp.media({ title: jQuery( this ).data( \'uploader_title\' ), button: { text: jQuery( this ).data( \'uploader_button_text\' ), }, multiple: false // Set to true to allow multiple files to be selected }); // When an image is selected, run a callback. file_frame' . $value['id'] . '.on( \'select\', function() { var selection = file_frame' . $value['id'] . '.state().get(\'selection\'); selection.map( function( attachment ) { attachment = attachment.toJSON(); // Do something with attachment.id and/or attachment.url here console.log(attachment.url); // Add selected image to page //add_photo_attachment_to_grid(attachment); jQuery(\'#row_' . esc_attr( $value['id'] ) . '_uploaded\').show(); jQuery(\'#row_' . esc_attr( $value['id'] ) . '_uploaded td\').html(\'\'); jQuery(\'#' . esc_attr( $value['id'] ) . '\').val(attachment.id); }); }); // Finally, open the modal file_frame' . $value['id'] . '.open(); }); }); '; 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;