* @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 } /** * Wrapper function around cmb2_get_option * * @param string $key Options array key * * @return mixed Option value * @since 0.1.0 * */ function opalestate_get_option( $key = '', $default = false ) { global $opalestate_options; $value = ! empty( $opalestate_options[ $key ] ) ? $opalestate_options[ $key ] : $default; $value = apply_filters( 'opalestate_get_option', $value, $key, $default ); return apply_filters( 'opalestate_get_option_' . $key, $value, $key, $default ); } /** * Update an option * * Updates an opalestate setting value in both the db and the global variable. * Warning: Passing in an empty, false or null string value will remove * the key from the opalestate_options array. * * @param string $key The Key to update * @param string|bool|int $value The value to set the key to * * @return boolean True if updated, false if not. * @since 1.0 * */ function opalestate_update_option( $key = '', $value = false ) { // If no key, exit if ( empty( $key ) ) { return false; } if ( empty( $value ) ) { $remove_option = opalestate_delete_option( $key ); return $remove_option; } // First let's grab the current settings $options = get_option( 'opalestate_settings' ); // Let's let devs alter that value coming in $value = apply_filters( 'opalestate_update_option', $value, $key ); // Next let's try to update the value $options[ $key ] = $value; $did_update = update_option( 'opalestate_settings', $options ); // If it updated, let's update the global variable if ( $did_update ) { global $opalestate_options; $opalestate_options[ $key ] = $value; } return $did_update; } /** * Remove an option * * Removes an opalestate setting value in both the db and the global variable. * * @param string $key The Key to delete * * @return boolean True if updated, false if not. * @since 1.0 * */ function opalestate_delete_option( $key = '' ) { // If no key, exit if ( empty( $key ) ) { return false; } // First let's grab the current settings $options = get_option( 'opalestate_settings' ); // Next let's try to update the value if ( isset( $options[ $key ] ) ) { unset( $options[ $key ] ); } $did_update = update_option( 'opalestate_settings', $options ); // If it updated, let's update the global variable if ( $did_update ) { global $opalestate_options; $opalestate_options = $options; } return $did_update; } /** * Get Settings * * Retrieves all Opalestate plugin settings * * @return array Opalestate settings * @since 1.0 */ function opalestate_get_settings() { $settings = get_option( 'opalestate_settings' ); return (array) apply_filters( 'opalestate_get_settings', $settings ); } /** * Gateways Callback * * Renders gateways fields. * * @return void * @global $opalestate_options Array of all the Opalestate Options * @since 1.0 * */ function opalestate_enabled_gateways_callback( $field_object, $escaped_value, $object_id, $object_type, $field_type_object ) { $id = $field_type_object->field->args['id']; $field_description = $field_type_object->field->args['desc']; $gateways = opalestate_get_payment_gateways(); echo '
Opalestate REST API to retrieve donation data in JSON or XML for external applications or devices, such as Zapi_keyser.', 'opalestate-pro' ), 'https://wpopal.com/opalestate/documentation/opalestate-api_keys-reference/', 'https://wpopal.com/addons/opalestate/' ); ?>
'attachment', 'post_status' => 'inherit', 'date_query' => [ 'column' => 'post_date', 'before' => date( 'Y-m-d', strtotime( '-1 days' ) ), ], 'meta_query' => [ [ 'key' => '_pending_to_use_', 'value' => 1, 'compare' => '>=', ], ], ] ); // clean up per day if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); wp_delete_attachment( get_the_ID() ); } } wp_reset_postdata(); } /** * Searches for users via ajax and returns a list of results * * @return void * @since 1.0 * */ function opalestate_ajax_search_agencies() { if ( current_user_can( 'manage_opalestate_settings' ) ) { $search_query = trim( $_GET['q'] ); $agents_objects = Opalestate_Query::get_agencies( [ 'posts_per_page' => -1, 's' => $search_query, ] ); $agents = []; if ( ! empty( $agents_objects->posts ) && is_array( $agents_objects->posts ) ) { foreach ( $agents_objects->posts as $object ) { $agents[] = [ 'id' => $object->ID, 'name' => $object->post_title, 'avatar_url' => 'https://avatars1.githubusercontent.com/u/9919?v=4', 'full_name' => $object->post_title, 'description' => 'okokok', ]; } } $output = [ 'total_count' => count( $agents ), 'items' => $agents, 'incomplete_results' => false, ]; echo json_encode( $output ); } die(); } add_action( 'wp_ajax_opalestate_search_agencies', 'opalestate_ajax_search_agencies' ); /** * Searches for users via ajax and returns a list of results * * @return void * @since 1.0 * */ function opalestate_ajax_search_agents() { if ( current_user_can( 'manage_opalestate_settings' ) ) { $search_query = trim( $_GET['q'] ); $agents_objects = Opalestate_Query::get_agents( [ 'posts_per_page' => -1, 's' => $search_query, ] ); $agents = []; if ( ! empty( $agents_objects->posts ) && is_array( $agents_objects->posts ) ) { foreach ( $agents_objects->posts as $object ) { $agents[] = [ 'id' => $object->ID, 'name' => $object->post_title, 'avatar_url' => 'https://avatars1.githubusercontent.com/u/9919?v=4', 'full_name' => $object->post_title, 'description' => 'okokok', ]; } } $output = [ 'total_count' => count( $agents ), 'items' => $agents, 'incomplete_results' => false, ]; echo json_encode( $output ); } die(); } add_action( 'wp_ajax_opalestate_search_agents', 'opalestate_ajax_search_agents' ); /** * Searches for users via ajax and returns a list of results * * @return void * @since 1.0 * */ function opalestate_ajax_search_users() { if ( current_user_can( 'manage_opalestate_settings' ) ) { $search_query = trim( $_GET['q'] ); $get_users_args = [ 'number' => 9999, 'search' => $search_query . '*', ]; if ( ! empty( $exclude ) ) { $exclude_array = explode( ',', $exclude ); $get_users_args['exclude'] = $exclude_array; } $get_users_args = apply_filters( 'opalestate_search_users_args', $get_users_args ); $found_users = apply_filters( 'opalestate_ajax_found_users', get_users( $get_users_args ), $search_query ); $user_list = '