/** * AJAX Handler. * Saves WPP Settings * * @author peshkov@UD * @since 1.38.3 */ public static function save_settings() { global $wp_properties; $data = self::parse_str($_REQUEST['data']); $return = array('success' => true, 'message' => '', 'redirect' => admin_url("edit.php?post_type=property&page=property_settings&message=updated")); try { if (empty($data['wpp_settings']) || !wp_verify_nonce($data['_wpnonce'], 'wpp_setting_save')) { throw new Exception(__('Request can not be verified.', ud_get_wp_property()->domain)); } //** Allow features to preserve their settings that are not configured on the settings page */ $wpp_settings = apply_filters('wpp_settings_save', $data['wpp_settings'], $wp_properties); //** Prevent removal of featured settings configurations if they are not present */ if (!empty($wp_properties['configuration']['feature_settings'])) { foreach ($wp_properties['configuration']['feature_settings'] as $feature_type => $preserved_settings) { if (empty($data['wpp_settings']['configuration']['feature_settings'][$feature_type])) { $wpp_settings['configuration']['feature_settings'][$feature_type] = $preserved_settings; } } } update_option('wpp_settings', $wpp_settings); do_action('wpp::save_settings', $data); /* Remove all WordPress cache items. */ if (function_exists('wp_cache_flush')) { wp_cache_flush(); } /* Flush WPP cache */ WPP_F::clear_cache(); } catch (Exception $e) { $return['success'] = false; $return['message'] = $e->getMessage(); } return json_encode($return); }
/** * Hooks into save_post function and saves additional property data * * @todo Add some sort of custom capability so not only admins can make properties as featured. i.e. Agents can make their own properties featured. * @since 1.04 * @param null $post_id * @return null */ function save_property($post_id = null) { global $wp_properties, $wp_version; $_wpnonce = (version_compare($wp_version, '3.5', '>=') ? 'update-post_' : 'update-property_') . $post_id; if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], $_wpnonce) || $_POST['post_type'] !== 'property') { return $post_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } $update_data = $_REQUEST['wpp_data']['meta']; //** Neccessary meta data which is required by Supermap Premium Feature. Should be always set even the Supermap disabled. peshkov@UD */ if (empty($_REQUEST['exclude_from_supermap'])) { if (!metadata_exists('post', $post_id, 'exclude_from_supermap')) { $update_data['exclude_from_supermap'] = 'false'; } } if (!isset($update_data['latitude']) || (double) $update_data['latitude'] == 0) { $update_data['latitude'] = ''; } if (!isset($update_data['longitude']) || (double) $update_data['longitude'] == 0) { $update_data['longitude'] = ''; } /* get old coordinates and location */ $old_lat = get_post_meta($post_id, 'latitude', true); $old_lng = get_post_meta($post_id, 'longitude', true); $geo_data = array('old_coordinates' => empty($old_lat) || empty($old_lng) ? "" : array('lat' => $old_lat, 'lng' => $old_lng), 'old_location' => !empty($wp_properties['configuration']['address_attribute']) ? get_post_meta($post_id, $wp_properties['configuration']['address_attribute'], true) : ''); // die( '<pre>' . $post_id . print_r( $update_data, true ) . '</pre>' ); foreach ($update_data as $meta_key => $meta_value) { $attribute_data = UsabilityDynamics\WPP\Attributes::get_attribute_data($meta_key); $meta_value = html_entity_decode($meta_value); $meta_value = stripslashes($meta_value); /* Handle logic for featured property. */ if ($meta_key == 'featured') { //* Only admins can mark properties as featured. */ if (!current_user_can('manage_options')) { //** But be sure that meta 'featured' exists at all */ if (!metadata_exists('post', $post_id, $meta_key)) { $meta_value = 'false'; } else { continue; } } do_action('wpp::toggle_featured', $meta_value, $post_id); } //* Remove certain characters */ if (isset($attribute_data['currency']) || isset($attribute_data['numeric'])) { $meta_value = str_replace(array("\$", ","), '', $meta_value); } //* Overwrite old post meta allowing only one value */ delete_post_meta($post_id, $meta_key); add_post_meta($post_id, $meta_key, $meta_value); } //* Check if property has children */ $children = get_children(array('post_parent' => $post_id, 'post_type' => 'property')); //* Write any data to children properties that are supposed to inherit things */ //* 1) Go through all children */ foreach ((array) $children as $child_id => $child_data) { //* Determine child property_type */ $child_property_type = get_post_meta($child_id, 'property_type', true); //* Check if child's property type has inheritence rules, and if meta_key exists in inheritance array */ if (isset($wp_properties['property_inheritance'][$child_property_type]) && is_array($wp_properties['property_inheritance'][$child_property_type])) { foreach ($wp_properties['property_inheritance'][$child_property_type] as $i_meta_key) { $parent_meta_value = get_post_meta($post_id, $i_meta_key, true); //* inheritance rule exists for this property_type for this meta_key */ update_post_meta($child_id, $i_meta_key, $parent_meta_value); } } } $_gpid = WPP_F::maybe_set_gpid($post_id); do_action('save_property', $post_id, array('children' => $children, 'gpid' => $_gpid, 'update_data' => $update_data, 'geo_data' => $geo_data)); /** * Flush all object caches related to current property */ \UsabilityDynamics\WPP\Property_Factory::flush_cache($post_id); /** * Flush WP-Property caches */ \WPP_F::clear_cache(); }
/** * Instantaite class. */ public function init() { global $wp_properties; /** * Duplicates UsabilityDynamics\WP\Bootstrap_Plugin::load_textdomain(); * * There is a bug with localisation in lib-wp-bootstrap 1.1.3 and lower. * So we load textdomain here again, in case old version lib-wp-bootstrap is being loaded * by another plugin. * * @since 2.0.2 */ load_plugin_textdomain($this->domain, false, dirname(plugin_basename($this->boot_file)) . '/static/languages/'); /** This Version */ if (!defined('WPP_Version')) { define('WPP_Version', $this->args['version']); } /** Loads general functions used by WP-Property */ include_once $this->path('lib/class_functions.php', 'dir'); /** Loads Admin Tools feature */ include_once $this->path('lib/class_admin_tools.php', 'dir'); /** Loads all the metaboxes for the property page */ include_once $this->path('lib/class_core.php', 'dir'); /** Load set of static methods for mail notifications */ include_once $this->path('lib/class_mail.php', 'dir'); /** Load in hooks that deal with legacy and backwards-compat issues */ include_once $this->path('lib/class_legacy.php', 'dir'); $upload_dir = wp_upload_dir(); //** Init Settings */ $this->settings = new Settings(array('key' => 'wpp_settings', 'store' => 'options', 'data' => array('name' => $this->name, 'version' => $this->args['version'], 'domain' => $this->domain, 'cache_dir' => $upload_dir['basedir'] . '/wpp_cache', 'cache_url' => $upload_dir['baseurl'] . '/wpp_cache'))); //** Initiate Attributes Handler */ new Attributes(); //** Initiate AJAX Handler */ new Ajax(); //** Handles Export (XML/JSON/CSV) functionality */ new Export(); //** Initiate Admin UI */ if (is_admin()) { //** Initiate Admin Handler */ new Admin(); //** Initiate Meta Box Handler */ new Meta_Box(); //** Setup Gallery Meta Box ( wp-gallery-metabox ) */ add_action('be_gallery_metabox_post_types', function ($post_types = array()) { return array('property'); }); add_filter('be_gallery_metabox_remove', '__return_false'); } /** * Load WP List Table library. */ new \UsabilityDynamics\WPLT\Bootstrap(); /** * May be load Shortcodes */ add_action('init', function () { ud_get_wp_property()->load_files(ud_get_wp_property()->path('lib/shortcodes', 'dir')); }, 999); /** * May be load Widgets */ add_action('widgets_init', function () { ud_get_wp_property()->load_files(ud_get_wp_property()->path('lib/widgets', 'dir')); }, 1); /** Legacy filters and hooks */ include_once $this->path('lib/default_api.php', 'dir'); /** * Initiate the plugin */ $this->core = new \WPP_Core(); /** * Flush WP-Property cache */ if (get_transient('wpp_cache_flush')) { \WPP_F::clear_cache(); delete_transient('wpp_cache_flush'); } }