Origin commit
This commit is contained in:
141
inc/classes/class-opalestate-abs-query.php
Executable file
141
inc/classes/class-opalestate-abs-query.php
Executable file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* @class OpalEstate_Agent
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
class OpalEstate_Abstract_Query{
|
||||
|
||||
/**
|
||||
* Preserve args
|
||||
*
|
||||
* @since $id
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $group;
|
||||
|
||||
/**
|
||||
* Preserve args
|
||||
*
|
||||
* @since $id
|
||||
* @access public
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_args = array();
|
||||
|
||||
/**
|
||||
* The args to pass to the give_get_payments() query
|
||||
*
|
||||
* @since $id
|
||||
* @access public
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $args = array();
|
||||
|
||||
/**
|
||||
* The collection found based on the criteria set
|
||||
*
|
||||
* @since $id
|
||||
* @access public
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $collection = array();
|
||||
|
||||
public function set_filters() {
|
||||
}
|
||||
|
||||
public function unset_filters() {
|
||||
}
|
||||
|
||||
|
||||
public function get_list(){
|
||||
|
||||
}
|
||||
|
||||
public function status() {
|
||||
}
|
||||
|
||||
public function page() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts Per Page
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function per_page() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Order by
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function orderby() {
|
||||
}
|
||||
|
||||
public function get_by_user() {
|
||||
|
||||
}
|
||||
|
||||
public function search () {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a query variable.
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*
|
||||
* @param $query_var
|
||||
* @param $value
|
||||
*/
|
||||
public function __set( $query_var, $value ) {
|
||||
if ( in_array( $query_var, array( 'meta_query', 'tax_query' ) ) ) {
|
||||
$this->args[ $query_var ][] = $value;
|
||||
} else {
|
||||
$this->args[ $query_var ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset a query variable.
|
||||
*
|
||||
* @since 1.0
|
||||
* @access public
|
||||
*
|
||||
* @param $query_var
|
||||
*/
|
||||
public function __unset( $query_var ) {
|
||||
unset( $this->args[ $query_var ] );
|
||||
}
|
||||
}
|
||||
686
inc/classes/class-opalestate-cache.php
Executable file
686
inc/classes/class-opalestate-cache.php
Executable file
@@ -0,0 +1,686 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
class Opalestate_Cache {
|
||||
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* @since 1.8.7
|
||||
* @access private
|
||||
* @var Opalestate_Cache
|
||||
*/
|
||||
static private $instance;
|
||||
|
||||
/**
|
||||
* Flag to check if caching enabled or not.
|
||||
*
|
||||
* @since 2.0
|
||||
* @access private
|
||||
* @var
|
||||
*/
|
||||
private $is_cache;
|
||||
|
||||
/**
|
||||
* Singleton pattern.
|
||||
*
|
||||
* @since 1.8.7
|
||||
* @access private
|
||||
* Opalestate_Cache constructor.
|
||||
*/
|
||||
private function __construct() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get instance.
|
||||
*
|
||||
* @since 1.8.7
|
||||
* @access public
|
||||
* @return static
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Opalestate_Cache ) ) {
|
||||
self::$instance = new Opalestate_Cache();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup hooks.
|
||||
*
|
||||
* @since 1.8.7
|
||||
* @access public
|
||||
*/
|
||||
public function setup() {
|
||||
// Currently enable cache only for backend.
|
||||
self::$instance->is_cache = ( defined( 'GIVE_CACHE' ) ? GIVE_CACHE : opalestate_is_setting_enabled( opalestate_get_option( 'cache', 'enabled' ) ) ) && is_admin();
|
||||
|
||||
// weekly delete all expired cache.
|
||||
Give_Cron::add_weekly_event( array( $this, 'delete_all_expired' ) );
|
||||
|
||||
add_action( 'save_post_opalestate_forms', array( $this, 'delete_form_related_cache' ) );
|
||||
add_action( 'save_post_opalestate_payment', array( $this, 'delete_payment_related_cache' ) );
|
||||
add_action( 'opalestate_deleted_opalestate-donors_cache', array( $this, 'delete_donor_related_cache' ), 10, 3 );
|
||||
add_action( 'opalestate_deleted_opalestate-donations_cache', array( $this, 'delete_donations_related_cache' ), 10, 3 );
|
||||
|
||||
add_action( 'opalestate_save_settings_opalestate_settings', array( __CLASS__, 'flush_cache' ) );
|
||||
|
||||
add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
|
||||
add_action( 'admin_notices', array( $this, '__notices' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent caching on certain pages
|
||||
*
|
||||
* @since 2.0.5
|
||||
* @access public
|
||||
* @credit WooCommerce
|
||||
*/
|
||||
public static function prevent_caching() {
|
||||
if ( ! is_blog_installed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$page_ids = array_filter( array(
|
||||
opalestate_get_option( 'success_page' ),
|
||||
opalestate_get_option( 'failure_page' ),
|
||||
opalestate_get_option( 'history_page' ),
|
||||
) );
|
||||
|
||||
if (
|
||||
is_page( $page_ids )
|
||||
|| is_singular( 'opalestate_forms' )
|
||||
) {
|
||||
self::set_nocache_constants();
|
||||
nocache_headers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set constants to prevent caching by some plugins.
|
||||
*
|
||||
* @since 2.0.5
|
||||
* @access public
|
||||
* @credit WooCommerce
|
||||
*
|
||||
* @param mixed $return Value to return. Previously hooked into a filter.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function set_nocache_constants( $return = true ) {
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notices function.
|
||||
*
|
||||
* @since 2.0.5
|
||||
* @access public
|
||||
* @credit WooCommerce
|
||||
*/
|
||||
public function __notices() {
|
||||
if ( ! function_exists( 'w3tc_pgcache_flush' ) || ! function_exists( 'w3_instance' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$config = w3_instance( 'W3_Config' );
|
||||
$enabled = $config->get_integer( 'dbcache.enabled' );
|
||||
$settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) );
|
||||
|
||||
if ( $enabled && ! in_array( 'opalestate-pro', $settings, true ) ) {
|
||||
?>
|
||||
<div class="error">
|
||||
<p><?php echo wp_kses_post( sprintf( esc_html__( 'In order for <strong>database caching</strong> to work with Give you must add %1$s to the "Ignored query stems" option in <a href="%2$s">W3 Total Cache settings</a>.', 'opalestate-pro' ), '<code>opalestate</code>', esc_url( admin_url( 'admin.php?page=w3tc_dbcache#dbcache_reject_sql' ) ) ) ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache key.
|
||||
*
|
||||
* @since 1.8.7
|
||||
*
|
||||
* @param string $action Cache key prefix.
|
||||
* @param array $query_args (optional) Query array.
|
||||
* @param bool $is_prefix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_key( $action, $query_args = null, $is_prefix = true ) {
|
||||
// Bailout.
|
||||
if ( empty( $action ) ) {
|
||||
return new WP_Error( 'opalestate_invalid_cache_key_action', esc_html__( 'Do not pass empty action to generate cache key.', 'opalestate-pro' ) );
|
||||
}
|
||||
|
||||
// Set cache key.
|
||||
$cache_key = $is_prefix ? "opalestate_cache_{$action}" : $action;
|
||||
|
||||
// Bailout.
|
||||
if ( ! empty( $query_args ) ) {
|
||||
$cache_key = "{$cache_key}_" . substr( md5( serialize( $query_args ) ), 0, 15 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the cache key name.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
return apply_filters( 'opalestate_get_cache_key', $cache_key, $action, $query_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache.
|
||||
*
|
||||
* @since 1.8.7
|
||||
*
|
||||
* @param string $cache_key
|
||||
* @param bool $custom_key
|
||||
* @param mixed $query_args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get( $cache_key, $custom_key = false, $query_args = array() ) {
|
||||
if ( ! self::is_valid_cache_key( $cache_key ) ) {
|
||||
if( empty( $cache_key ) ) {
|
||||
return new WP_Error( 'opalestate_empty_cache_key', esc_html__( 'Do not pass invalid empty cache key', 'opalestate-pro' ) );
|
||||
}elseif ( ! $custom_key ) {
|
||||
return new WP_Error( 'opalestate_invalid_cache_key', esc_html__( 'Cache key format should be opalestate_cache_*', 'opalestate-pro' ) );
|
||||
}
|
||||
|
||||
$cache_key = self::get_key( $cache_key, $query_args );
|
||||
}
|
||||
|
||||
$option = get_option( $cache_key );
|
||||
|
||||
// Backward compatibility (<1.8.7).
|
||||
if ( ! is_array( $option ) || empty( $option ) || ! array_key_exists( 'expiration', $option ) ) {
|
||||
return $option;
|
||||
}
|
||||
|
||||
// Get current time.
|
||||
$current_time = current_time( 'timestamp', 1 );
|
||||
|
||||
if ( empty( $option['expiration'] ) || ( $current_time < $option['expiration'] ) ) {
|
||||
$option = $option['data'];
|
||||
} else {
|
||||
$option = false;
|
||||
}
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache.
|
||||
*
|
||||
* @since 1.8.7
|
||||
*
|
||||
* @param string $cache_key
|
||||
* @param mixed $data
|
||||
* @param int|null $expiration Timestamp should be in GMT format.
|
||||
* @param bool $custom_key
|
||||
* @param mixed $query_args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function set( $cache_key, $data, $expiration = null, $custom_key = false, $query_args = array() ) {
|
||||
if ( ! self::is_valid_cache_key( $cache_key ) ) {
|
||||
if ( ! $custom_key ) {
|
||||
return new WP_Error( 'opalestate_invalid_cache_key', esc_html__( 'Cache key format should be opalestate_cache_*', 'opalestate-pro' ) );
|
||||
}
|
||||
|
||||
$cache_key = self::get_key( $cache_key, $query_args );
|
||||
}
|
||||
|
||||
$option_value = array(
|
||||
'data' => $data,
|
||||
'expiration' => ! is_null( $expiration )
|
||||
? ( $expiration + current_time( 'timestamp', 1 ) )
|
||||
: null,
|
||||
);
|
||||
|
||||
$result = update_option( $cache_key, $option_value, false );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete cache.
|
||||
*
|
||||
* Note: only for internal use
|
||||
*
|
||||
* @since 1.8.7
|
||||
*
|
||||
* @param string|array $cache_keys
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public static function delete( $cache_keys ) {
|
||||
$result = true;
|
||||
$invalid_keys = array();
|
||||
|
||||
if ( ! empty( $cache_keys ) ) {
|
||||
$cache_keys = is_array( $cache_keys ) ? $cache_keys : array( $cache_keys );
|
||||
|
||||
foreach ( $cache_keys as $cache_key ) {
|
||||
if ( ! self::is_valid_cache_key( $cache_key ) ) {
|
||||
$invalid_keys[] = $cache_key;
|
||||
$result = false;
|
||||
}
|
||||
|
||||
delete_option( $cache_key );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $result ) {
|
||||
$result = new WP_Error(
|
||||
'opalestate_invalid_cache_key',
|
||||
__( 'Cache key format should be opalestate_cache_*', 'opalestate-pro' ),
|
||||
$invalid_keys
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all logging cache.
|
||||
*
|
||||
* Note: only for internal use
|
||||
*
|
||||
* @since 1.8.7
|
||||
* @access public
|
||||
* @global wpdb $wpdb
|
||||
*
|
||||
* @param bool $force If set to true then all cached values will be delete instead of only expired
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete_all_expired( $force = false ) {
|
||||
global $wpdb;
|
||||
$options = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT option_name, option_value
|
||||
FROM {$wpdb->options}
|
||||
Where option_name
|
||||
LIKE '%%%s%%'",
|
||||
'opalestate_cache'
|
||||
),
|
||||
ARRAY_A
|
||||
);
|
||||
|
||||
// Bailout.
|
||||
if ( empty( $options ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current_time = current_time( 'timestamp', 1 );
|
||||
|
||||
// Delete log cache.
|
||||
foreach ( $options as $option ) {
|
||||
$option['option_value'] = maybe_unserialize( $option['option_value'] );
|
||||
|
||||
if (
|
||||
(
|
||||
! self::is_valid_cache_key( $option['option_name'] )
|
||||
|| ! is_array( $option['option_value'] ) // Backward compatibility (<1.8.7).
|
||||
|| ! array_key_exists( 'expiration', $option['option_value'] ) // Backward compatibility (<1.8.7).
|
||||
|| empty( $option['option_value']['expiration'] )
|
||||
|| ( $current_time < $option['option_value']['expiration'] )
|
||||
)
|
||||
&& ! $force
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self::delete( $option['option_name'] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of options like.
|
||||
*
|
||||
* Note: only for internal use
|
||||
*
|
||||
* @since 1.8.7
|
||||
* @access public
|
||||
*
|
||||
* @param string $option_name
|
||||
* @param bool $fields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_options_like( $option_name, $fields = false ) {
|
||||
global $wpdb;
|
||||
|
||||
$field_names = $fields ? 'option_name, option_value' : 'option_name';
|
||||
|
||||
if ( $fields ) {
|
||||
$options = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT {$field_names }
|
||||
FROM {$wpdb->options}
|
||||
Where option_name
|
||||
LIKE '%%%s%%'",
|
||||
"opalestate_cache_{$option_name}"
|
||||
),
|
||||
ARRAY_A
|
||||
);
|
||||
} else {
|
||||
$options = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
"SELECT *
|
||||
FROM {$wpdb->options}
|
||||
Where option_name
|
||||
LIKE '%%%s%%'",
|
||||
"opalestate_cache_{$option_name}"
|
||||
),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $options ) && $fields ) {
|
||||
foreach ( $options as $index => $option ) {
|
||||
$option['option_value'] = maybe_unserialize( $option['option_value'] );
|
||||
$options[ $index ] = $option;
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check cache key validity.
|
||||
*
|
||||
* @since 1.8.7
|
||||
* @access public
|
||||
*
|
||||
* @param $cache_key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_valid_cache_key( $cache_key ) {
|
||||
$is_valid = ( false !== strpos( $cache_key, 'opalestate_cache_' ) );
|
||||
|
||||
|
||||
/**
|
||||
* Filter the flag which tell about cache key valid or not
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
return apply_filters( 'opalestate_is_valid_cache_key', $is_valid, $cache_key );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get cache from group
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $group
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_group( $id, $group = '' ) {
|
||||
$cached_data = null;
|
||||
|
||||
// Bailout.
|
||||
if ( self::$instance->is_cache && ! empty( $id ) ) {
|
||||
$group = self::$instance->filter_group_name( $group );
|
||||
|
||||
$cached_data = wp_cache_get( $id, $group );
|
||||
$cached_data = false !== $cached_data ? $cached_data : null;
|
||||
}
|
||||
|
||||
return $cached_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache small chunks inside group
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*
|
||||
* @param int $id
|
||||
* @param mixed $data
|
||||
* @param string $group
|
||||
* @param int $expire
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function set_group( $id, $data, $group = '', $expire = 0 ) {
|
||||
$status = false;
|
||||
|
||||
// Bailout.
|
||||
if ( ! self::$instance->is_cache || empty( $id ) ) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
$group = self::$instance->filter_group_name( $group );
|
||||
|
||||
$status = wp_cache_set( $id, $data, $group, $expire );
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache small db query chunks inside group
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*
|
||||
* @param int $id
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function set_db_query( $id, $data ) {
|
||||
$status = false;
|
||||
|
||||
// Bailout.
|
||||
if ( ! self::$instance->is_cache || empty( $id ) ) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
return self::set_group( $id, $data, 'opalestate-db-queries', 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache from group
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_db_query( $id ) {
|
||||
return self::get_group( $id, 'opalestate-db-queries' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete group cache
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*
|
||||
* @param int|array $ids
|
||||
* @param string $group
|
||||
* @param int $expire
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete_group( $ids, $group = '', $expire = 0 ) {
|
||||
$status = false;
|
||||
|
||||
// Bailout.
|
||||
if ( ! self::$instance->is_cache || empty( $ids ) ) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
$group_prefix = $group;
|
||||
$group = self::$instance->filter_group_name( $group );
|
||||
|
||||
// Delete single or multiple cache items from cache.
|
||||
if ( ! is_array( $ids ) ) {
|
||||
$status = wp_cache_delete( $ids, $group );
|
||||
self::$instance->get_incrementer( true );
|
||||
|
||||
/**
|
||||
* Fire action when cache deleted for specific id.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param string $ids
|
||||
* @param string $group
|
||||
* @param int $expire
|
||||
*/
|
||||
do_action( "opalestate_deleted_{$group_prefix}_cache", $ids, $group, $expire, $status );
|
||||
|
||||
} else {
|
||||
foreach ( $ids as $id ) {
|
||||
$status = wp_cache_delete( $id, $group );
|
||||
self::$instance->get_incrementer( true );
|
||||
|
||||
/**
|
||||
* Fire action when cache deleted for specific id .
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param string $ids
|
||||
* @param string $group
|
||||
* @param int $expire
|
||||
*/
|
||||
do_action( "opalestate_deleted_{$group_prefix}_cache", $id, $group, $expire, $status );
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get unique incrementer.
|
||||
*
|
||||
* @see https://core.trac.wordpress.org/ticket/4476
|
||||
* @see https://www.tollmanz.com/invalidation-schemes/
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*
|
||||
* @param bool $refresh
|
||||
* @param string $incrementer_key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_incrementer( $refresh = false, $incrementer_key = 'opalestate-cache-incrementer-db-queries' ) {
|
||||
$incrementer_value = wp_cache_get( $incrementer_key );
|
||||
|
||||
if ( false === $incrementer_value || true === $refresh ) {
|
||||
$incrementer_value = (string) microtime( true );
|
||||
wp_cache_set( $incrementer_key, $incrementer_value );
|
||||
}
|
||||
|
||||
return $incrementer_value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flush cache on cache setting enable/disable
|
||||
* Note: only for internal use
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*
|
||||
* @param bool $force Delete cache forcefully.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function flush_cache( $force = false ) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filter the group name
|
||||
*
|
||||
* @since 2.0
|
||||
* @access private
|
||||
*
|
||||
* @param $group
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function filter_group_name( $group ) {
|
||||
/**
|
||||
* Filter the group name
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
$filtered_group = apply_filters( 'opalestate_cache_filter_group_name', '', $group );
|
||||
|
||||
if ( empty( $filtered_group ) ) {
|
||||
|
||||
switch ( $group ) {
|
||||
case 'opalestate-db-queries':
|
||||
$incrementer = self::$instance->get_incrementer();
|
||||
break;
|
||||
|
||||
default:
|
||||
$incrementer = self::$instance->get_incrementer( false, 'opalestate-cache-incrementer' );
|
||||
|
||||
}
|
||||
|
||||
$current_blog_id = get_current_blog_id();
|
||||
$filtered_group = "{$group}_{$current_blog_id}_{$incrementer}";
|
||||
}
|
||||
|
||||
return $filtered_group;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disable cache.
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*/
|
||||
public static function disable() {
|
||||
self::get_instance()->is_cache = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable cache.
|
||||
*
|
||||
* @since 2.0
|
||||
* @access public
|
||||
*/
|
||||
public static function enable() {
|
||||
self::get_instance()->is_cache = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize
|
||||
Opalestate_Cache::get_instance()->setup();
|
||||
111
inc/classes/class-opalestate-geolocation.php
Executable file
111
inc/classes/class-opalestate-geolocation.php
Executable file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
class OpalEstate_GeoLocation {
|
||||
|
||||
/*
|
||||
* function to geocode address, it will return false if unable to geocode address
|
||||
*/
|
||||
public static function get_points_in_miles( $latitude, $longitude, $miles ) {
|
||||
|
||||
$equator = 69.172;
|
||||
|
||||
$maxlat = $latitude + $miles / $EQUATOR_LAT_MILE;
|
||||
$minlat = $latitude - ($maxlat - $latitude);
|
||||
$maxlong = $longitude + $miles / (cos($minlat * M_PI / 180) * $equator);
|
||||
$minlong = $longitude - ($maxlong - $longitude);
|
||||
|
||||
return array(
|
||||
'minlat' => $minlat,
|
||||
'maxlat' => $maxlat,
|
||||
'minlong' => $minlong,
|
||||
'maxlong' => $maxlong
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* function to geocode address, it will return false if unable to geocode address
|
||||
*/
|
||||
public static function calculate( $lat1, $long1, $lat2, $long2 ) {
|
||||
|
||||
$EARTH_RADIUS_MILES = 3963;
|
||||
$dist = 0;
|
||||
|
||||
//convert degrees to radians
|
||||
$lat1 = $lat1 * M_PI / 180;
|
||||
$long1 = $long1 * M_PI / 180;
|
||||
$lat2 = $lat2 * M_PI / 180;
|
||||
$long2 = $long2 * M_PI / 180;
|
||||
|
||||
if ($lat1 != $lat2 || $long1 != $long2) {
|
||||
|
||||
$dist = sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($long2 - $long1);
|
||||
$dist = $EARTH_RADIUS_MILES * (-1 * atan($dist / sqrt(1 - $dist * $dist)) + M_PI / 2);
|
||||
}
|
||||
return $dist;
|
||||
}
|
||||
|
||||
/*
|
||||
* function to geocode address, it will return false if unable to geocode address
|
||||
*/
|
||||
public static function geocode( $address ){
|
||||
|
||||
// url encode the address
|
||||
$address = urlencode($address);
|
||||
|
||||
// google map geocode api url
|
||||
$url = opalestate_get_map_search_api_uri( $address );
|
||||
|
||||
// get the json response
|
||||
// $resp_json = file get contents($url);
|
||||
$resp_json = wp_remote_get($url);
|
||||
|
||||
// decode the json
|
||||
$resp = json_decode($resp_json, true);
|
||||
|
||||
|
||||
// response status will be 'OK', if able to geocode given address
|
||||
if($resp['status']=='OK'){
|
||||
|
||||
// get the important data
|
||||
$lati = isset($resp['results'][0]['geometry']['location']['lat']) ? $resp['results'][0]['geometry']['location']['lat'] : "";
|
||||
$longi = isset($resp['results'][0]['geometry']['location']['lng']) ? $resp['results'][0]['geometry']['location']['lng'] : "";
|
||||
$formatted_address = isset($resp['results'][0]['formatted_address']) ? $resp['results'][0]['formatted_address'] : "";
|
||||
|
||||
// verify if data is complete
|
||||
if($lati && $longi && $formatted_address){
|
||||
// put the data in the array
|
||||
$data_arr = array();
|
||||
array_push(
|
||||
$data_arr,
|
||||
$lati,
|
||||
$longi,
|
||||
$formatted_address
|
||||
);
|
||||
|
||||
return $data_arr;
|
||||
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
290
inc/classes/class-opalestate-metabox-user.php
Executable file
290
inc/classes/class-opalestate-metabox-user.php
Executable file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Opalestate_User_MetaBox
|
||||
*
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Opalestate_User_MetaBox {
|
||||
|
||||
public function get_front_base_field( $prefix ) {
|
||||
$management = [
|
||||
[
|
||||
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'avatar',
|
||||
'type' => 'hidden',
|
||||
'single' => 1,
|
||||
'limit' => 1,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Avatar Picture', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'avatar_id',
|
||||
'type' => 'uploader',
|
||||
'single' => 1,
|
||||
'limit' => 1,
|
||||
|
||||
],
|
||||
|
||||
[
|
||||
'id' => 'first_name',
|
||||
'name' => esc_html__( 'First Name', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
[
|
||||
'id' => 'last_name',
|
||||
'name' => esc_html__( 'Last Name', 'opalestate-pro' ),
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
[
|
||||
'id' => 'description',
|
||||
'name' => esc_html__( 'Biographical Info', 'opalestate-pro' ),
|
||||
'type' => 'textarea',
|
||||
'description' => esc_html__( 'Share a little biographical information to fill out your profile. This may be shown publicly.', 'opalestate-pro' ),
|
||||
'after_row' => '<hr>',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
return $management;
|
||||
}
|
||||
|
||||
public function get_avatar_fields( $prefix ) {
|
||||
return [
|
||||
[
|
||||
'name' => esc_html__( 'Avatar Pictures', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'avatar',
|
||||
'type' => is_admin() ? 'file' : 'opal_upload',
|
||||
'avatar' => true,
|
||||
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function get_address_fields( $prefix ) {
|
||||
return [
|
||||
[
|
||||
'name' => esc_html__( 'Location', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'Select one, to add new you create in location of estate panel', 'opalestate-pro' ),
|
||||
'id' => $prefix . "location",
|
||||
'taxonomy' => 'opalestate_location', //Enter Taxonomy Slug
|
||||
'type' => 'taxonomy_select',
|
||||
'before_row' => '<div class="field-row-3">',
|
||||
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'State / Province', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'Select one, to add new you create in state of estate panel', 'opalestate-pro' ),
|
||||
'id' => $prefix . "state",
|
||||
'taxonomy' => 'opalestate_state', //Enter Taxonomy Slug
|
||||
'type' => 'taxonomy_select',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'City / Town', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'Select one, to add new you create in city of estate panel', 'opalestate-pro' ),
|
||||
'id' => $prefix . "city",
|
||||
'taxonomy' => 'opalestate_city', //Enter Taxonomy Slug
|
||||
'type' => 'taxonomy_select',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Address', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}address",
|
||||
'type' => 'text',
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
[
|
||||
'id' => "{$prefix}map",
|
||||
'name' => esc_html__( 'Map Location', 'opalestate-pro' ),
|
||||
'type' => 'opal_map',
|
||||
'sanitization_cb' => 'opal_map_sanitise',
|
||||
'split_values' => true,
|
||||
'attributes' => [
|
||||
'required' => 'required',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function get_job_fields( $prefix ) {
|
||||
return [
|
||||
[
|
||||
'name' => esc_html__( 'Job', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}job",
|
||||
'type' => 'text',
|
||||
'before_row' => '<div class="field-row-2">',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Company', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}company",
|
||||
'type' => 'text',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function get_office_fields( $prefix ) {
|
||||
return $this->get_base_fields( $prefix );
|
||||
}
|
||||
|
||||
public function get_base_front_fields( $prefix ) {
|
||||
return [
|
||||
[
|
||||
'name' => esc_html__( 'Email', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}email",
|
||||
'type' => 'text',
|
||||
'before_row' => '<div class="field-row-2">',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Website', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}web",
|
||||
'type' => 'text_url',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}phone",
|
||||
'type' => 'text',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Mobile', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}mobile",
|
||||
'type' => 'text',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Fax', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}fax",
|
||||
'type' => 'text',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function get_base_fields( $prefix ) {
|
||||
return [
|
||||
[
|
||||
'id' => "{$prefix}featured",
|
||||
'name' => esc_html__( 'Is Featured', 'opalestate-pro' ),
|
||||
'type' => 'switch',
|
||||
'description' => esc_html__( 'Set member as featured', 'opalestate-pro' ),
|
||||
'options' => [
|
||||
0 => esc_html__( 'No', 'opalestate-pro' ),
|
||||
1 => esc_html__( 'Yes', 'opalestate-pro' ),
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'id' => "{$prefix}trusted",
|
||||
'name' => esc_html__( 'Trusted', 'opalestate-pro' ),
|
||||
'type' => 'switch',
|
||||
'description' => esc_html__( 'Set this member as Trusted Member', 'opalestate-pro' ),
|
||||
'options' => [
|
||||
0 => esc_html__( 'No', 'opalestate-pro' ),
|
||||
1 => esc_html__( 'Yes', 'opalestate-pro' ),
|
||||
],
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Avatar Pictures', 'opalestate-pro' ),
|
||||
'desc' => esc_html__( 'This image will display in user detail and profile box information', 'opalestate-pro' ),
|
||||
'id' => $prefix . 'avatar',
|
||||
'type' => is_admin() ? 'file' : 'uploader',
|
||||
'single' => true,
|
||||
'avatar' => true,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Email', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}email",
|
||||
'type' => 'text',
|
||||
'before_row' => '<div class="field-row-2">',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Website', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}web",
|
||||
'type' => 'text_url',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Phone', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}phone",
|
||||
'type' => 'text',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Mobile', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}mobile",
|
||||
'type' => 'text',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Fax', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}fax",
|
||||
'type' => 'text',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function get_social_fields( $prefix ) {
|
||||
return [
|
||||
[
|
||||
'name' => esc_html__( 'Twitter', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}twitter",
|
||||
'type' => 'text_url',
|
||||
'before_row' => '<div class="field-row-2">',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Facebook', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}facebook",
|
||||
'type' => 'text_url',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Google', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}google",
|
||||
'type' => 'text_url',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'LinkedIn', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}linkedin",
|
||||
'type' => 'text_url',
|
||||
],
|
||||
|
||||
[
|
||||
'name' => esc_html__( 'Pinterest', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}pinterest",
|
||||
'type' => 'text_url',
|
||||
],
|
||||
[
|
||||
'name' => esc_html__( 'Instagram', 'opalestate-pro' ),
|
||||
'id' => "{$prefix}instagram",
|
||||
'type' => 'text_url',
|
||||
'after_row' => '</div>',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
157
inc/classes/class-opalestate-multilingual.php
Executable file
157
inc/classes/class-opalestate-multilingual.php
Executable file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
class Opalestate_Multilingual {
|
||||
/**
|
||||
* The current language.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $current_language;
|
||||
|
||||
/**
|
||||
* The default language.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $default_language;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
// Make sure to create class after/within 'setup_theme' action.
|
||||
if ( ! did_action( 'setup_theme' ) ) {
|
||||
_doing_it_wrong(
|
||||
__CLASS__ . '::' . __FUNCTION__,
|
||||
'The class must be call after "setup_theme" has been fire.',
|
||||
'1.0'
|
||||
);
|
||||
} else {
|
||||
$this->check();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current language.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_current_language() {
|
||||
return $this->current_language ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main language.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function get_default_language() {
|
||||
return $this->default_language ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the original post.
|
||||
*
|
||||
* @param int $post_id The post ID.
|
||||
* @return int
|
||||
*/
|
||||
public function get_original_post( $post_id ) {
|
||||
return $this->get_original_object( $post_id, 'post' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the original object ID (post, taxonomy, etc...).
|
||||
*
|
||||
* @param int $id The object id.
|
||||
* @param string $type Optional, post type or taxonomy name of the object, defaults to 'post'.
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_original_object( $id, $type = 'post' ) {
|
||||
return icl_object_id( $id, $type, true, $this->get_default_language() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform check the language.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
public function check() {
|
||||
switch ( true ) {
|
||||
case ( static::is_wpml() ):
|
||||
global $sitepress;
|
||||
$this->current_language = $sitepress->get_current_language();
|
||||
$this->default_language = $sitepress->get_default_language();
|
||||
break;
|
||||
|
||||
case ( static::is_polylang() ):
|
||||
$this->default_language = pll_default_language( 'slug' );
|
||||
$this->current_language = pll_current_language( 'slug' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified language.
|
||||
*
|
||||
* @param string|null $language The language name.
|
||||
* @return void
|
||||
*/
|
||||
public function set_language( $language = null ) {
|
||||
if ( static::is_polylang() ) {
|
||||
$this->set_polylang_language( $language );
|
||||
} elseif ( static::is_wpml() ) {
|
||||
global $sitepress;
|
||||
$sitepress->switch_lang( $language, ! headers_sent() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified language on PLL.
|
||||
*
|
||||
* @sse \PLL_Choose_Lang::set_language()
|
||||
*
|
||||
* @param string|null $language The language name.
|
||||
* @return void
|
||||
*/
|
||||
public function set_polylang_language( $language = null ) {
|
||||
if ( ! static::is_polylang() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* @var \Polylang $polylang */
|
||||
$polylang = PLL();
|
||||
|
||||
// In frontend, if no language given, get the preferred language
|
||||
// according to the browser preferences.
|
||||
if ( empty( $language ) && ( ! is_admin() && ! defined( 'DOING_CRON' ) ) ) {
|
||||
$curlang = $polylang->choose_lang->get_preferred_language();
|
||||
} else {
|
||||
$curlang = $polylang->model->get_language( trim( $language ) );
|
||||
}
|
||||
|
||||
if ( $curlang instanceof \PLL_Language ) {
|
||||
$polylang->curlang = $curlang;
|
||||
$GLOBALS['text_direction'] = $curlang->is_rtl ? 'rtl' : 'ltr'; // @codingStandardsIgnoreLine
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we're using WPML.
|
||||
*
|
||||
* Since PolyLang has a compatibility layer for WPML, we'll have to consider that too.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_wpml() {
|
||||
return ( defined( 'ICL_SITEPRESS_VERSION' ) && ! static::is_polylang() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we're using PolyLang.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_polylang() {
|
||||
return class_exists( 'Polylang' ) && function_exists( 'pll_current_language' );
|
||||
}
|
||||
}
|
||||
299
inc/classes/class-opalestate-session.php
Executable file
299
inc/classes/class-opalestate-session.php
Executable file
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
/**
|
||||
* $Desc$
|
||||
*
|
||||
* @version $Id$
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
* @copyright Copyright (C) 2019 wpopal.com. All Rights Reserved.
|
||||
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* @website http://www.wpopal.com
|
||||
* @support http://www.wpopal.com/support/forum.html
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Give_Session Class
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Opalestate_Session {
|
||||
|
||||
/**
|
||||
* Holds our session data
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
* @since 1.0
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* Whether to use PHP $_SESSION or WP_Session
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
* @since 1.0
|
||||
*/
|
||||
private $use_php_sessions = false;
|
||||
|
||||
/**
|
||||
* Expiration Time
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
* @since 1.0
|
||||
*/
|
||||
private $exp_option = false;
|
||||
|
||||
/**
|
||||
* Session index prefix
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
* @since 1.0
|
||||
*/
|
||||
private $prefix = '';
|
||||
|
||||
/**
|
||||
* Get things started
|
||||
*
|
||||
* Defines our WP_Session constants, includes the necessary libraries and
|
||||
* retrieves the WP Session instance
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->use_php_sessions = $this->use_php_sessions();
|
||||
$this->exp_option = 604800; //opalestate_get_option( 'session_lifetime' );
|
||||
|
||||
if ( $this->use_php_sessions ) {
|
||||
|
||||
if ( is_multisite() ) {
|
||||
$this->prefix = '_' . get_current_blog_id();
|
||||
}
|
||||
|
||||
// Use PHP SESSION (must be enabled via the OPALMEMBERSHIP_USE_PHP_SESSIONS constant)
|
||||
add_action( 'init', array( $this, 'maybe_start_session' ), - 2 );
|
||||
|
||||
} else {
|
||||
|
||||
// Use WP_Session (default)
|
||||
if ( ! defined( 'WP_SESSION_COOKIE' ) ) {
|
||||
define( 'WP_SESSION_COOKIE', 'opalestate_wp_session' );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Recursive_ArrayAccess' ) ) {
|
||||
// require_once OPALESTATE_PLUGIN_DIR . 'inc/libraries/class-recursive-arrayaccess.php';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_Session' ) ) {
|
||||
require_once OPALESTATE_PLUGIN_DIR . 'inc/libraries/wp_session/class-wp-session.php';
|
||||
require_once OPALESTATE_PLUGIN_DIR . 'inc/libraries/wp-session.php';
|
||||
}
|
||||
|
||||
add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 );
|
||||
add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 );
|
||||
|
||||
}
|
||||
|
||||
if ( empty( $this->session ) && ! $this->use_php_sessions ) {
|
||||
add_action( 'plugins_loaded', array( $this, 'init' ), - 1 );
|
||||
} else {
|
||||
add_action( 'init', array( $this, 'init' ), - 1 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the WP_Session instance
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @return array $this->session
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
if ( $this->use_php_sessions ) {
|
||||
$this->session = isset( $_SESSION[ 'opalestate-pro' . $this->prefix ] ) && is_array( $_SESSION[ 'opalestate-pro' . $this->prefix ] ) ? $_SESSION[ 'opalestate-pro' . $this->prefix ] : array();
|
||||
} else {
|
||||
$this->session = WP_Session::get_instance();
|
||||
}
|
||||
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve session ID
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @return string Session ID
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->session->session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a session variable
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
*
|
||||
* @param string $key Session key
|
||||
*
|
||||
* @return string Session variable
|
||||
*/
|
||||
public function get( $key = '', $default = false ) {
|
||||
$key = sanitize_key( $key );
|
||||
|
||||
return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a session variable
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param $key $_SESSION key
|
||||
* @param $value $_SESSION variable
|
||||
*
|
||||
* @return mixed Session variable
|
||||
*/
|
||||
public function set( $key, $value ) {
|
||||
|
||||
$key = sanitize_key( $key );
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
$this->session[ $key ] = serialize( $value );
|
||||
} else {
|
||||
$this->session[ $key ] = $value;
|
||||
}
|
||||
|
||||
if ( $this->use_php_sessions ) {
|
||||
$_SESSION[ 'opalestate-pro' . $this->prefix ] = $this->session;
|
||||
}
|
||||
|
||||
return $this->session[ $key ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Cookie Variant Time
|
||||
*
|
||||
* @description Force the cookie expiration variant time to custom expiration option, less and hour; defaults to 23 hours (set_expiration_variant_time used in WP_Session)
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function set_expiration_variant_time() {
|
||||
return ( ! empty( $this->exp_option ) ? ( intval( $this->exp_option ) - 3600 ) : 30 * 60 * 23 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Cookie Expiration
|
||||
*
|
||||
* @description Force the cookie expiration time if set, default to 24 hours
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function set_expiration_time() {
|
||||
return ( ! empty( $this->exp_option ) ? intval( $this->exp_option ) : 30 * 60 * 24 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new session if one hasn't started yet.
|
||||
*
|
||||
* @return null
|
||||
* Checks to see if the server supports PHP sessions
|
||||
* or if the OPALMEMBERSHIP_USE_PHP_SESSIONS constant is defined
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @return bool $ret True if we are using PHP sessions, false otherwise
|
||||
*/
|
||||
public function use_php_sessions() {
|
||||
|
||||
$ret = false;
|
||||
|
||||
// If the database variable is already set, no need to run autodetection
|
||||
$opalestate_use_php_sessions = (bool) get_option( 'opalestate_use_php_sessions' );
|
||||
|
||||
if ( ! $opalestate_use_php_sessions ) {
|
||||
|
||||
// Attempt to detect if the server supports PHP sessions
|
||||
if ( function_exists( 'session_start' ) && ! ini_get( 'safe_mode' ) ) {
|
||||
|
||||
$this->set( 'opalestate_use_php_sessions', 1 );
|
||||
|
||||
if ( $this->get( 'opalestate_use_php_sessions' ) ) {
|
||||
|
||||
$ret = true;
|
||||
|
||||
// Set the database option
|
||||
update_option( 'opalestate_use_php_sessions', true );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$ret = $opalestate_use_php_sessions;
|
||||
}
|
||||
|
||||
// Enable or disable PHP Sessions based on the OPALMEMBERSHIP_USE_PHP_SESSIONS constant
|
||||
if ( defined( 'OPALMEMBERSHIP_USE_PHP_SESSIONS' ) && OPALMEMBERSHIP_USE_PHP_SESSIONS ) {
|
||||
$ret = true;
|
||||
} else if ( defined( 'OPALMEMBERSHIP_USE_PHP_SESSIONS' ) && ! OPALMEMBERSHIP_USE_PHP_SESSIONS ) {
|
||||
$ret = false;
|
||||
}
|
||||
|
||||
return (bool) apply_filters( 'opalestate_use_php_sessions', $ret );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe Start Session
|
||||
*
|
||||
* @description Starts a new session if one hasn't started yet.
|
||||
* @see http://php.net/manual/en/function.session-set-cookie-params.php
|
||||
*/
|
||||
public function maybe_start_session() {
|
||||
|
||||
// session_destroy(); //Uncomment for testing ONLY
|
||||
|
||||
if ( ! session_id() && ! headers_sent() ) {
|
||||
$lifetime = current_time( 'timestamp' ) + $this->set_expiration_time();
|
||||
session_start();
|
||||
setcookie( session_name(), session_id(), $lifetime ); //
|
||||
setcookie( session_name() . '_expiration', $lifetime, $lifetime );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Session Expiration
|
||||
*
|
||||
* @description Looks at the session cookies and returns the expiration date for this session if applicable
|
||||
*
|
||||
*/
|
||||
public function get_session_expiration() {
|
||||
|
||||
$expiration = false;
|
||||
|
||||
if ( session_id() && isset( $_COOKIE[ session_name() . '_expiration' ] ) ) {
|
||||
$expiration = date( 'D, d M Y h:i:s', intval( $_COOKIE[ session_name() . '_expiration' ] ) );
|
||||
}
|
||||
|
||||
return $expiration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
185
inc/classes/class-opalestate-walkscore.php
Executable file
185
inc/classes/class-opalestate-walkscore.php
Executable file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_WalkScore
|
||||
*
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of the Walk Score API in PHP.
|
||||
*
|
||||
* @see http://www.walkscore.com/
|
||||
*/
|
||||
class Opalestate_WalkScore {
|
||||
|
||||
/**
|
||||
* Constructs a WalkScore object
|
||||
*
|
||||
* @param string $wsapikey
|
||||
* Walk Score API key obtainable at http://www.walkscore.com/request-api-key.php
|
||||
*/
|
||||
function __construct($wsapikey) {
|
||||
// a Walk Score API key is required
|
||||
if (!isset($wsapikey)) {
|
||||
throw new Exception("Walk Score API key required");
|
||||
}
|
||||
$this->wsapikey = $wsapikey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the API call using curl
|
||||
*
|
||||
* @param string $url
|
||||
* The URL to send the request to
|
||||
* @param array $options
|
||||
* The options to send as the query appended to the URL
|
||||
*/
|
||||
private function make_api_call($url, $options) {
|
||||
$options['wsapikey'] = $this->wsapikey;
|
||||
$options['format'] = 'json';
|
||||
$query = http_build_query($options);
|
||||
$response_url = $url . '?' . $query;
|
||||
|
||||
$response = wp_remote_get($response_url);
|
||||
$response = wp_remote_retrieve_body( $response );
|
||||
$response = json_decode($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the Walk Score Public Transit API
|
||||
*
|
||||
* @param string $call
|
||||
* Which call to make to the Public Transit API
|
||||
* - score: Returns the Transit Score for a given location.
|
||||
* - stop search: Returns information about stops near a given location.
|
||||
* - network search: Returns connected stops and routes near a given location.
|
||||
* - stop detail: Returns details for a single stop.
|
||||
* - route detail: eturns details for a single route.
|
||||
* - supported cities: Returns a list of cities for which scores are available.
|
||||
* @param array $options
|
||||
* Options to send to the Public Transit API. Keys and values are dependent
|
||||
* on the call made.
|
||||
* @return
|
||||
* An object containing the results of the call.
|
||||
* @see http://www.walkscore.com/services/public-transit-api.php
|
||||
*/
|
||||
public function PublicTransit($call, $options = array()) {
|
||||
|
||||
$api_url = 'http://transit.walkscore.com/transit/';
|
||||
$calls = array(
|
||||
'score' => 'score/',
|
||||
'stop search' => 'search/stops/',
|
||||
'network search' => 'search/network/',
|
||||
'stop detail' => 'stop/ID/',
|
||||
'route detail' => 'route/ID/',
|
||||
'supported cities' => 'supported/cities/',
|
||||
);
|
||||
|
||||
|
||||
$api_url .= $calls[$call];
|
||||
return $this->make_api_call($api_url, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the Walk Score API
|
||||
*
|
||||
* @param array $options
|
||||
* An array of options. The array keys to pass are:
|
||||
* - mode: string, one of 'walk', 'bike', 'drive', or 'transit'.
|
||||
* - origin: string containing a comma-separated lat,lng.
|
||||
* - destination: string containing a comma-separated lat,lng.
|
||||
* @todo Multiple destinations.
|
||||
* @ see http://www.walkscore.com/professional/travel-time-api.php
|
||||
*/
|
||||
public function TravelTime($options = array()) {
|
||||
if (!is_array($options)) {
|
||||
throw new Exception("Input parameter must be an array.");
|
||||
}
|
||||
$modes = array('walk', 'bike', 'drive', 'transit');
|
||||
if (!in_array($options['mode'], $modes)) {
|
||||
throw new Exception("Mode parameter must be one of 'walk', 'bike', 'drive', or 'transit'.");
|
||||
}
|
||||
$response = $this->make_api_call('http://www.walkscore.com/api/v1/traveltime/json', $options);
|
||||
return $response->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the Walk Score API
|
||||
*
|
||||
* @param array $options
|
||||
* An array of options. The array keys to pass are:
|
||||
* - address: string containing the street address of the location
|
||||
* - lat: string or number containing the latitude of the location
|
||||
* - lon: string or number containing the longitude of the location
|
||||
* @return
|
||||
* An object containing the results of the call. An added property
|
||||
* called status_description gives a human-readable description of
|
||||
* the numeric status code returned in the object
|
||||
* @see http://www.walkscore.com/services/api.php
|
||||
*/
|
||||
public function WalkScore($options = array()) {
|
||||
if (!is_array($options)) {
|
||||
throw new Exception("Input parameter must be an array.");
|
||||
}
|
||||
|
||||
$response = $this->make_api_call('http://api.walkscore.com/score', $options);
|
||||
|
||||
// stuff the status code description in the response object
|
||||
// so you don't have to look it up on the Walk Score website
|
||||
$status_descriptions = array(
|
||||
1 => 'Walk Score successfully returned.',
|
||||
2 => 'Score is being calculated and is not currently available.',
|
||||
30 => 'Invalid latitude/longitude.',
|
||||
40 => 'Your WSAPIKEY is invalid.',
|
||||
41 => 'Your daily API quota has been exceeded.',
|
||||
42 => 'Your IP address has been blocked.',
|
||||
);
|
||||
|
||||
$response->status_description = $status_descriptions[$response->status];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the Walk Shed API
|
||||
*
|
||||
* @param array $options
|
||||
* An array of options. The array keys to pass are:
|
||||
* - lat: string or number containing the latitude of the location
|
||||
* - lon: string or number containing the longitude of the location
|
||||
* @return
|
||||
* An object containing the results of the call. An added property
|
||||
* called status_description gives a human-readable description of
|
||||
* the numeric status code returned in the object
|
||||
* @see http://www.walkscore.com/services/api.php
|
||||
*/
|
||||
public function WalkShed($options = array()) {
|
||||
|
||||
if (!is_array($options)) {
|
||||
throw new Exception("Input parameter must be an array.");
|
||||
}
|
||||
|
||||
$response = $this->make_api_call('http://api.walkscore.com/walk_shed', $options);
|
||||
|
||||
// stuff the status code description in the response object
|
||||
// so you don't have to look it up on the Walk Score website
|
||||
$status_descriptions = array(
|
||||
1 => 'Walk shed successfully returned.',
|
||||
2 => 'Walk shed unavailable.',
|
||||
30 => 'Invalid latitude/longitude.',
|
||||
31 => 'Walk Score API internal error.',
|
||||
40 => 'Your WSAPIKEY is invalid.',
|
||||
41 => 'Your daily API quota has been exceeded.',
|
||||
);
|
||||
$response->status_description = $status_descriptions[$response->status];
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
250
inc/classes/class-opalestate-yelp.php
Executable file
250
inc/classes/class-opalestate-yelp.php
Executable file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* Opalestate_Yelp
|
||||
*
|
||||
* @package opalestate
|
||||
* @author Opal Team <info@wpopal.com >
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Opalestate_Yelp {
|
||||
// API constants, you shouldn't have to change these.
|
||||
const API_HOST = "https://api.yelp.com";
|
||||
const SEARCH_PATH = "/v3/businesses/search";
|
||||
const BUSINESS_PATH = "/v3/businesses/"; // Business ID will come after slash.
|
||||
const TOKEN_PATH = "/oauth2/token";
|
||||
const GRANT_TYPE = "client_credentials";
|
||||
|
||||
public static function get_client_id() {
|
||||
return opalestate_get_option( 'yelp_app_id', '' );
|
||||
}
|
||||
|
||||
public static function get_app_secret() {
|
||||
return opalestate_get_option( 'yelp_app_secret', '' );
|
||||
}
|
||||
|
||||
public static function get_app_key() {
|
||||
return opalestate_get_option( 'yelp_app_key', '' );
|
||||
}
|
||||
|
||||
public static function get_categories() {
|
||||
return opalestate_get_option( 'yelp_categories', [] );
|
||||
}
|
||||
|
||||
public static function get_category_results_limit() {
|
||||
return opalestate_get_option( 'yelp_number_results', 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a bearer token, send a GET request to the API.
|
||||
*
|
||||
* @return OAuth bearer token, obtained using client_id and client_secret.
|
||||
*/
|
||||
public function obtain_bearer_token() {
|
||||
$yelp_client_id = static::get_client_id();
|
||||
$yelp_client_secret = static::get_app_secret();
|
||||
$yelp_app_key = static::get_app_key();
|
||||
|
||||
return $yelp_app_key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Makes a request to the Yelp API and returns the response
|
||||
*
|
||||
* @param $bearer_token API bearer token from obtain_bearer_token
|
||||
* @param $host The domain host of the API
|
||||
* @param $path The path of the API after the domain.
|
||||
* @param $url_params Array of query-string parameters.
|
||||
* @return The JSON response from the request
|
||||
*/
|
||||
public function request( $bearer_token, $host, $path, $url_params = [] ) {
|
||||
// Send Yelp API Call
|
||||
try {
|
||||
$url = $host . $path . "?" . http_build_query( $url_params );
|
||||
$args = [
|
||||
'timeout' => 30,
|
||||
'redirection' => 10,
|
||||
'httpversion' => CURL_HTTP_VERSION_1_1,
|
||||
'user-agent' => '',
|
||||
'headers' => [
|
||||
'authorization' => 'Bearer ' . $bearer_token,
|
||||
],
|
||||
'sslverify' => false,
|
||||
];
|
||||
|
||||
$response = wp_remote_get( $url, $args );
|
||||
$response = wp_remote_retrieve_body( $response );
|
||||
} catch ( Exception $e ) {
|
||||
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the Search API by a search term and location
|
||||
*
|
||||
* @param $bearer_token API bearer token from obtain_bearer_token
|
||||
* @param $term The search term passed to the API
|
||||
* @param $location The search location passed to the API
|
||||
* @return The JSON response from the request
|
||||
*/
|
||||
public function search( $bearer_token, $term, $latitude, $longitude ) {
|
||||
$url_params = [];
|
||||
|
||||
$url_params['term'] = $term;
|
||||
$url_params['latitude'] = $latitude;
|
||||
$url_params['longitude'] = $longitude;
|
||||
$url_params['limit'] = static::get_category_results_limit();
|
||||
|
||||
return $this->request( $bearer_token, static::API_HOST, static::SEARCH_PATH, $url_params );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the Business API by business_id
|
||||
*
|
||||
* @param $bearer_token API bearer token from obtain_bearer_token
|
||||
* @param $business_id The ID of the business to query
|
||||
* @return The JSON response from the request
|
||||
*/
|
||||
public function get_business( $bearer_token, $business_id ) {
|
||||
$business_path = $GLOBALS['BUSINESS_PATH'] . urlencode( $business_id );
|
||||
|
||||
return $this->request( $bearer_token, $GLOBALS['API_HOST'], $business_path );
|
||||
}
|
||||
|
||||
public function query_api( $term, $latitude, $longitude ) {
|
||||
$bearer_token = $this->obtain_bearer_token();
|
||||
|
||||
$response = json_decode( $this->search( $bearer_token, $term, $latitude, $longitude ) );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function get_results( $term, $latitude, $longitude ) {
|
||||
if ( ! static::get_categories() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$results = $this->query_api( $term, $latitude, $longitude );
|
||||
if ( isset( $results->error ) && $results->error ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function get_all_categories() {
|
||||
return apply_filters( 'opalestate_yelp_all_categories',
|
||||
[
|
||||
'active' => [
|
||||
'category' => esc_html__( 'Active Life', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-bicycle',
|
||||
],
|
||||
'arts' => [
|
||||
'category' => esc_html__( 'Arts & Entertainment', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-music',
|
||||
],
|
||||
'auto' => [
|
||||
'category' => esc_html__( 'Automotive', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-car',
|
||||
],
|
||||
'beautysvc' => [
|
||||
'category' => esc_html__( 'Beauty & Spas', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-female',
|
||||
],
|
||||
'education' => [
|
||||
'category' => esc_html__( 'Education', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-graduation-cap',
|
||||
],
|
||||
'eventservices' => [
|
||||
'category' => esc_html__( 'Event Planning & Services', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-birthday-cake',
|
||||
],
|
||||
'financialservices' => [
|
||||
'category' => esc_html__( 'Financial Services', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-money',
|
||||
],
|
||||
'food' => [
|
||||
'category' => esc_html__( 'Food', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa fa-cutlery',
|
||||
],
|
||||
'health' => [
|
||||
'category' => esc_html__( 'Health & Medical', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-medkit',
|
||||
],
|
||||
'homeservices' => [
|
||||
'category' => esc_html__( 'Home Services ', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-wrench',
|
||||
],
|
||||
'hotelstravel' => [
|
||||
'category' => esc_html__( 'Hotels & Travel', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-bed',
|
||||
],
|
||||
'localflavor' => [
|
||||
'category' => esc_html__( 'Local Flavor', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-coffee',
|
||||
],
|
||||
'localservices' => [
|
||||
'category' => esc_html__( 'Local Services', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-dot-circle-o',
|
||||
],
|
||||
'massmedia' => [
|
||||
'category' => esc_html__( 'Mass Media', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-television',
|
||||
],
|
||||
'nightlife' => [
|
||||
'category' => esc_html__( 'Nightlife', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-glass',
|
||||
],
|
||||
'pets' => [
|
||||
'category' => esc_html__( 'Pets', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-paw',
|
||||
],
|
||||
'professional' => [
|
||||
'category' => esc_html__( 'Professional Services', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-suitcase',
|
||||
],
|
||||
'publicservicesgovt' => [
|
||||
'category' => esc_html__( 'Public Services & Government', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-university',
|
||||
],
|
||||
'realestate' => [
|
||||
'category' => esc_html__( 'Real Estate', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-building-o',
|
||||
],
|
||||
'religiousorgs' => [
|
||||
'category' => esc_html__( 'Religious Organizations', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-cloud',
|
||||
],
|
||||
'restaurants' => [
|
||||
'category' => esc_html__( 'Restaurants', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-cutlery',
|
||||
],
|
||||
'shopping' => [
|
||||
'category' => esc_html__( 'Shopping', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-shopping-bag',
|
||||
],
|
||||
'transport' => [
|
||||
'category' => esc_html__( 'Transportation', 'opalestate-pro' ),
|
||||
'category_sign' => 'fa fa-bus',
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public static function get_all_categories_options() {
|
||||
$categories = static::get_all_categories();
|
||||
|
||||
$options = [];
|
||||
foreach ( $categories as $key => $term ) {
|
||||
$options[ $key ] = $term['category'];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user