Update API

This commit is contained in:
Hoang Huu 2019-10-04 16:26:23 +07:00
parent 218c914e0d
commit cfd65c5aa4
7 changed files with 317 additions and 261 deletions

View File

@ -50,11 +50,11 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
global $status, $page; global $status, $page;
// Set parent defaults // Set parent defaults
parent::__construct( array( parent::__construct( [
'singular' => esc_html__( 'API Key', 'opalestate-pro' ), // Singular name of the listed records 'singular' => esc_html__( 'API Key', 'opalestate-pro' ), // Singular name of the listed records
'plural' => esc_html__( 'API Keys', 'opalestate-pro' ), // Plural name of the listed records 'plural' => esc_html__( 'API Keys', 'opalestate-pro' ), // Plural name of the listed records
'ajax' => false // Does this table support ajax? 'ajax' => false // Does this table support ajax?
) ); ] );
$this->query(); $this->query();
} }
@ -63,12 +63,12 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* This function renders most of the columns in the list table. * This function renders most of the columns in the list table.
* *
* @access public * @access public
* @since 1.1 * @param array $item Contains all the data of the keys
*
* @param array $item Contains all the data of the keys
* @param string $column_name The name of the column * @param string $column_name The name of the column
* *
* @return string Column Name * @return string Column Name
* @since 1.1
*
*/ */
public function column_default( $item, $column_name ) { public function column_default( $item, $column_name ) {
return $item[ $column_name ]; return $item[ $column_name ];
@ -78,12 +78,12 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Displays the public key rows * Displays the public key rows
* *
* @access public * @access public
* @since 1.1 * @param array $item Contains all the data of the keys
*
* @param array $item Contains all the data of the keys
* @param string $column_name The name of the column * @param string $column_name The name of the column
* *
* @return string Column Name * @return string Column Name
* @since 1.1
*
*/ */
public function column_key( $item ) { public function column_key( $item ) {
return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['key'] ) . '"/>'; return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['key'] ) . '"/>';
@ -93,12 +93,12 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Displays the token rows * Displays the token rows
* *
* @access public * @access public
* @since 1.1 * @param array $item Contains all the data of the keys
*
* @param array $item Contains all the data of the keys
* @param string $column_name The name of the column * @param string $column_name The name of the column
* *
* @return string Column Name * @return string Column Name
* @since 1.1
*
*/ */
public function column_token( $item ) { public function column_token( $item ) {
return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['token'] ) . '"/>'; return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['token'] ) . '"/>';
@ -108,12 +108,12 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Displays the secret key rows * Displays the secret key rows
* *
* @access public * @access public
* @since 1.1 * @param array $item Contains all the data of the keys
*
* @param array $item Contains all the data of the keys
* @param string $column_name The name of the column * @param string $column_name The name of the column
* *
* @return string Column Name * @return string Column Name
* @since 1.1
*
*/ */
public function column_secret( $item ) { public function column_secret( $item ) {
return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['secret'] ) . '"/>'; return '<input onClick="this.setSelectionRange(0, this.value.length)" readonly="readonly" type="text" class="large-text" value="' . esc_attr( $item['secret'] ) . '"/>';
@ -123,43 +123,43 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Renders the column for the user field * Renders the column for the user field
* *
* @access public * @access public
* @since 1.1
* @return void * @return void
* @since 1.1
*/ */
public function column_user( $item ) { public function column_user( $item ) {
$actions = array(); $actions = [];
if ( apply_filters( 'opalestate_api_log_requests', true ) ) { if ( apply_filters( 'opalestate_api_log_requests', true ) ) {
$actions['view'] = sprintf( $actions['view'] = sprintf(
'<a href="%s">%s</a>', '<a href="%s">%s</a>',
esc_url( add_query_arg( array( esc_url( add_query_arg( [
'view' => 'api_requests', 'view' => 'api_requests',
'post_type' => 'opalestate_forms', 'post_type' => 'opalestate_forms',
'page' => 'opalestate-reports', 'page' => 'opalestate-reports',
'tab' => 'logs', 'tab' => 'logs',
's' => $item['email'] 's' => $item['email'],
), 'edit.php' ) ), ], 'edit.php' ) ),
esc_html__( 'View API Log', 'opalestate-pro' ) esc_html__( 'View API Log', 'opalestate-pro' )
); );
} }
$actions['reissue'] = sprintf( $actions['reissue'] = sprintf(
'<a href="%s" class="opalestate-regenerate-api-key">%s</a>', '<a href="%s" class="opalestate-regenerate-api-key">%s</a>',
esc_url( wp_nonce_url( add_query_arg( array( esc_url( wp_nonce_url( add_query_arg( [
'user_id' => $item['id'], 'user_id' => $item['id'],
'opalestate_action' => 'process_api_key', 'opalestate_action' => 'process_api_key',
'opalestate_api_process' => 'regenerate' 'opalestate_api_process' => 'regenerate',
) ), 'opalestate-api-nonce' ) ), ] ), 'opalestate-api-nonce' ) ),
esc_html__( 'Reissue', 'opalestate-pro' ) esc_html__( 'Reissue', 'opalestate-pro' )
); );
$actions['revoke'] = sprintf( $actions['revoke'] = sprintf(
'<a href="%s" class="opalestate-revoke-api-key opalestate-delete">%s</a>', '<a href="%s" class="opalestate-revoke-api-key opalestate-delete">%s</a>',
esc_url( wp_nonce_url( add_query_arg( array( esc_url( wp_nonce_url( add_query_arg( [
'user_id' => $item['id'], 'user_id' => $item['id'],
'opalestate_action' => 'process_api_key', 'opalestate_action' => 'process_api_key',
'opalestate_api_process' => 'revoke' 'opalestate_api_process' => 'revoke',
) ), 'opalestate-api-nonce' ) ), ] ), 'opalestate-api-nonce' ) ),
esc_html__( 'Revoke', 'opalestate-pro' ) esc_html__( 'Revoke', 'opalestate-pro' )
); );
@ -172,16 +172,16 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Retrieve the table columns * Retrieve the table columns
* *
* @access public * @access public
* @since 1.1
* @return array $columns Array of all the list table columns * @return array $columns Array of all the list table columns
* @since 1.1
*/ */
public function get_columns() { public function get_columns() {
$columns = array( $columns = [
'user' => esc_html__( 'Username' , 'opalestate-pro' ), 'user' => esc_html__( 'Username', 'opalestate-pro' ),
'key' => esc_html__( 'Public Key' , 'opalestate-pro' ), 'key' => esc_html__( 'Public Key', 'opalestate-pro' ),
'token' => esc_html__( 'Token' , 'opalestate-pro' ), 'token' => esc_html__( 'Token', 'opalestate-pro' ),
'secret' => esc_html__( 'Secret Key' , 'opalestate-pro' ) 'secret' => esc_html__( 'Secret Key', 'opalestate-pro' ),
); ];
return $columns; return $columns;
} }
@ -189,36 +189,36 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
/** /**
* Generate the table navigation above or below the table * Generate the table navigation above or below the table
* *
* @since 3.1.0
* @access protected
* @param string $which * @param string $which
* @since 3.1.0
* @access protected
*/ */
protected function display_tablenav( $which ) { protected function display_tablenav( $which ) {
if ( 'top' === $which ) { if ( 'top' === $which ) {
wp_nonce_field( 'bulk-' . $this->_args['plural'] ); wp_nonce_field( 'bulk-' . $this->_args['plural'] );
} }
?> ?>
<div class="tablenav <?php echo esc_attr( $which ); ?>"> <div class="tablenav <?php echo esc_attr( $which ); ?>">
<div class="alignleft actions bulkactions"> <div class="alignleft actions bulkactions">
<?php $this->bulk_actions( $which ); ?> <?php $this->bulk_actions( $which ); ?>
</div> </div>
<?php <?php
$this->extra_tablenav( $which ); $this->extra_tablenav( $which );
$this->pagination( $which ); $this->pagination( $which );
?> ?>
<br class="clear" /> <br class="clear"/>
</div> </div>
<?php <?php
} }
/** /**
* Display the key generation form * Display the key generation form
* *
* @access public * @access public
* @since 1.1
* @return void * @return void
* @since 1.1
*/ */
public function bulk_actions( $which = '' ) { public function bulk_actions( $which = '' ) {
// These aren't really bulk actions but this outputs the markup in the right place // These aren't really bulk actions but this outputs the markup in the right place
@ -228,10 +228,12 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
return; return;
} }
?> ?>
<input type="hidden" name="opalestate_action" value="process_api_key"/> <input type="hidden" name="opalestate_action" value="process_api_key"/>
<input type="hidden" name="opalestate_api_process" value="generate"/> <input type="hidden" name="opalestate_api_process" value="generate"/>
<?php wp_nonce_field( 'opalestate-api-nonce' ); ?> <?php wp_nonce_field( 'opalestate-api-nonce' ); ?>
<?php echo OpalEstate()->html->ajax_user_search(); ?> <?php echo OpalEstate()->html->ajax_user_search( [
'name' => esc_html__( 'User', 'opalestate-pro' ),
] ); ?>
<?php submit_button( esc_html__( 'Generate New API Keys', 'opalestate-pro' ), 'secondary', 'submit', false ); ?> <?php submit_button( esc_html__( 'Generate New API Keys', 'opalestate-pro' ), 'secondary', 'submit', false ); ?>
<?php <?php
$opalestate_api_is_bottom = true; $opalestate_api_is_bottom = true;
@ -241,8 +243,8 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Retrieve the current page number * Retrieve the current page number
* *
* @access public * @access public
* @since 1.1
* @return int Current page number * @return int Current page number
* @since 1.1
*/ */
public function get_paged() { public function get_paged() {
return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
@ -252,25 +254,25 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Performs the key query * Performs the key query
* *
* @access public * @access public
* @since 1.1
* @return array * @return array
* @since 1.1
*/ */
public function query() { public function query() {
$users = get_users( array( $users = get_users( [
'meta_value' => 'opalestate_user_secret_key', 'meta_value' => 'opalestate_user_secret_key',
'number' => $this->per_page, 'number' => $this->per_page,
'offset' => $this->per_page * ( $this->get_paged() - 1 ) 'offset' => $this->per_page * ( $this->get_paged() - 1 ),
) ); ] );
$keys = array();
$keys = [];
foreach ( $users as $user ) { foreach ( $users as $user ) {
$keys[ $user->ID ]['id'] = $user->ID; $keys[ $user->ID ]['id'] = $user->ID;
$keys[ $user->ID ]['email'] = $user->user_email; $keys[ $user->ID ]['email'] = $user->user_email;
$keys[ $user->ID ]['user'] = '<a href="' . add_query_arg( 'user_id', $user->ID, 'user-edit.php' ) . '"><strong>' . $user->user_login . '</strong></a>'; $keys[ $user->ID ]['user'] = '<a href="' . add_query_arg( 'user_id', $user->ID, 'user-edit.php' ) . '"><strong>' . $user->user_login . '</strong></a>';
$keys[ $user->ID ]['key'] = OpalEstate()->api_admin->get_user_public_key( $user->ID );
$keys[ $user->ID ]['key'] = OpalEstate()->api->get_user_public_key( $user->ID ); $keys[ $user->ID ]['secret'] = OpalEstate()->api_admin->get_user_secret_key( $user->ID );
$keys[ $user->ID ]['secret'] = OpalEstate()->api->get_user_secret_key( $user->ID ); $keys[ $user->ID ]['token'] = OpalEstate()->api_admin->get_token( $user->ID );
$keys[ $user->ID ]['token'] = OpalEstate()->api->get_token( $user->ID );
} }
return $keys; return $keys;
@ -281,8 +283,8 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Retrieve count of total users with keys * Retrieve count of total users with keys
* *
* @access public * @access public
* @since 1.1
* @return int * @return int
* @since 1.1
*/ */
public function total_items() { public function total_items() {
global $wpdb; global $wpdb;
@ -300,16 +302,16 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
* Setup the final data for the table * Setup the final data for the table
* *
* @access public * @access public
* @since 1.1
* @return void * @return void
* @since 1.1
*/ */
public function prepare_items() { public function prepare_items() {
$columns = $this->get_columns(); $columns = $this->get_columns();
$hidden = array(); // No hidden columns $hidden = []; // No hidden columns
$sortable = array(); // Not sortable... for now $sortable = []; // Not sortable... for now
$this->_column_headers = array( $columns, $hidden, $sortable, 'id' ); $this->_column_headers = [ $columns, $hidden, $sortable, 'id' ];
$data = $this->query(); $data = $this->query();
@ -317,11 +319,11 @@ class Opalestate_API_Keys_Table extends WP_List_Table {
$this->items = $data; $this->items = $data;
$this->set_pagination_args( array( $this->set_pagination_args( [
'total_items' => $total_items, 'total_items' => $total_items,
'per_page' => $this->per_page, 'per_page' => $this->per_page,
'total_pages' => ceil( $total_items / $this->per_page ) 'total_pages' => ceil( $total_items / $this->per_page ),
) ]
); );
} }
} }

View File

@ -49,7 +49,7 @@ class Opalestate_API_Admin {
*/ */
public $user_id = 0; public $user_id = 0;
/** /**
* Instance of OpalJob Stats class * Instance of Opalestate Stats class
* *
* @var object * @var object
* @access private * @access private
@ -63,7 +63,7 @@ class Opalestate_API_Admin {
* @access private * @access private
* @since 1.1 * @since 1.1
*/ */
private $data = array(); private $data = [];
/** /**
* *
* @var bool * @var bool
@ -75,265 +75,291 @@ class Opalestate_API_Admin {
/** /**
* Render Sidebar * Render Sidebar
* *
* Display Sidebar on left side and next is main content * Display Sidebar on left side and next is main content
*
* @since 1.0
* *
* @return string * @return string
* @since 1.0
*
*/ */
public static function get_instance(){ public static function get_instance() {
static $_instance; static $_instance;
if( !$_instance ){ if ( ! $_instance ) {
$_instance = new Opalestate_API_Admin(); $_instance = new Opalestate_API_Admin();
} }
return $_instance; return $_instance;
} }
/** /**
* Setup the OpalJob API * Setup the Opalestate API
* *
* @since 1.1 * @since 1.1
* @access public * @access public
*/ */
public function __construct() { public function __construct() {
if ( is_admin() ) {
$this->register_actions();
}
} }
/** /**
* Registers query vars for API access * Registers query vars for API access
* *
* @access public * @access public
* @since 1.1
*
* @param array $vars Query vars * @param array $vars Query vars
* *
* @return string[] $vars New query vars * @return string[] $vars New query vars
* @since 1.1
*
*/ */
public function register_actions () { public function register_actions() {
add_action( 'admin_init', array( $this,'process_action') ); add_action( 'admin_init', [ $this, 'process_action' ] );
add_action( 'show_user_profile', array( $this, 'user_key_field' ) ); add_action( 'show_user_profile', [ $this, 'user_key_field' ] );
add_action( 'edit_user_profile', array( $this, 'user_key_field' ) ); add_action( 'edit_user_profile', [ $this, 'user_key_field' ] );
add_action( 'personal_options_update', array( $this, 'update_key' ) ); add_action( 'personal_options_update', [ $this, 'update_key' ] );
add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); add_action( 'edit_user_profile_update', [ $this, 'update_key' ] );
add_action( 'opaljob_action', array( $this, 'process_api_key' ) ); add_action( 'opalestate_action', [ $this, 'process_api_key' ] );
// Setup a backwards compatibility check for user API Keys // Setup a backwards compatibility check for user API Keys
add_filter( 'get_user_metadata', array( $this, 'api_key_backwards_compat' ), 10, 4 ); add_filter( 'get_user_metadata', [ $this, 'api_key_backwards_compat' ], 10, 4 );
// Determine if JSON_PRETTY_PRINT is available // Determine if JSON_PRETTY_PRINT is available
$this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null; $this->pretty_print = defined( 'JSON_PRETTY_PRINT' ) ? JSON_PRETTY_PRINT : null;
// Allow API request logging to be turned off // Allow API request logging to be turned off
$this->log_requests = apply_filters( 'opaljob_api_log_requests', $this->log_requests ); $this->log_requests = apply_filters( 'opalestate_api_log_requests', $this->log_requests );
} }
/** /**
* Registers query vars for API access * Registers query vars for API access
* *
* @access public * @access public
* @since 1.1
*
* @param array $vars Query vars * @param array $vars Query vars
* *
* @return string[] $vars New query vars * @return string[] $vars New query vars
* @since 1.1
*
*/ */
public function process_action() { public function process_action() {
if( isset($_REQUEST['opaljob_action']) ){ if ( isset( $_REQUEST['opalestate_action'] ) ) {
$args = array( $args = [
'user_id' => isset( $_REQUEST['user_id'] ) ? sanitize_text_field( $_REQUEST['user_id'] ) : 0, 'user_id' => isset( $_REQUEST['user_id'] ) ? sanitize_text_field( $_REQUEST['user_id'] ) : 0,
'key_permissions' => isset( $_REQUEST['key_permissions'] ) ? sanitize_text_field( $_REQUEST['key_permissions'] ) : 'read', 'key_permissions' => isset( $_REQUEST['key_permissions'] ) ? sanitize_text_field( $_REQUEST['key_permissions'] ) : 'read',
'description' => isset( $_REQUEST['description'] ) ? sanitize_text_field( $_REQUEST['description'] ) : '', 'description' => isset( $_REQUEST['description'] ) ? sanitize_text_field( $_REQUEST['description'] ) : '',
'opaljob_api_process' => isset( $_REQUEST['opaljob_api_process'] ) ? sanitize_text_field( $_REQUEST['opaljob_api_process'] ) : '' 'opalestate_api_process' => isset( $_REQUEST['opalestate_api_process'] ) ? sanitize_text_field( $_REQUEST['opalestate_api_process'] ) : '',
); ];
do_action( 'opaljob_action', $args ); do_action( 'opalestate_action', $args );
} }
} }
/** /**
* Retrieve the user ID based on the public key provided * Retrieve the user ID based on the public key provided
* *
* @access public * @access public
* @since 1.1 * @param string $key Public Key
* @global WPDB $wpdb Used to query the database using the WordPress
* Database API
*
* @param string $key Public Key
* *
* @return bool if user ID is found, false otherwise * @return bool if user ID is found, false otherwise
* @since 1.1
* @global WPDB $wpdb Used to query the database using the WordPress
* Database API
*
*/ */
public function get_user( $key = '' ) { public function get_user( $key = '' ) {
global $wpdb, $wp_query; global $wpdb, $wp_query;
if ( empty( $key ) ) { if ( empty( $key ) ) {
$key = urldecode( $wp_query->query_vars['key'] ); $key = urldecode( $wp_query->query_vars['key'] );
} }
if ( empty( $key ) ) { if ( empty( $key ) ) {
return false; return false;
} }
$user = get_transient( md5( 'opaljob_api_user_' . $key ) );
$user = get_transient( md5( 'opalestate_api_user_' . $key ) );
if ( false === $user ) { if ( false === $user ) {
$user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) ); $user = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s LIMIT 1", $key ) );
set_transient( md5( 'opaljob_api_user_' . $key ), $user, DAY_IN_SECONDS ); set_transient( md5( 'opalestate_api_user_' . $key ), $user, DAY_IN_SECONDS );
} }
if ( $user != null ) { if ( $user != null ) {
$this->user_id = $user; $this->user_id = $user;
return $user; return $user;
} }
return false; return false;
} }
public function get_user_public_key( $user_id = 0 ) { public function get_user_public_key( $user_id = 0 ) {
global $wpdb; global $wpdb;
if ( empty( $user_id ) ) { if ( empty( $user_id ) ) {
return ''; return '';
} }
$cache_key = md5( 'opaljob_api_user_public_key' . $user_id ); $cache_key = md5( 'opalestate_api_user_public_key' . $user_id );
$user_public_key = get_transient( $cache_key ); $user_public_key = get_transient( $cache_key );
if ( empty( $user_public_key ) ) { if ( empty( $user_public_key ) ) {
$user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'opaljob_user_public_key' AND user_id = %d", $user_id ) ); $user_public_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'opalestate_user_public_key' AND user_id = %d", $user_id ) );
set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS ); set_transient( $cache_key, $user_public_key, HOUR_IN_SECONDS );
} }
return $user_public_key; return $user_public_key;
} }
public function get_user_secret_key( $user_id = 0 ) { public function get_user_secret_key( $user_id = 0 ) {
global $wpdb; global $wpdb;
if ( empty( $user_id ) ) { if ( empty( $user_id ) ) {
return ''; return '';
} }
$cache_key = md5( 'opaljob_api_user_secret_key' . $user_id ); $cache_key = md5( 'opalestate_api_user_secret_key' . $user_id );
$user_secret_key = get_transient( $cache_key ); $user_secret_key = get_transient( $cache_key );
if ( empty( $user_secret_key ) ) { if ( empty( $user_secret_key ) ) {
$user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'opaljob_user_secret_key' AND user_id = %d", $user_id ) ); $user_secret_key = $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE meta_value = 'opalestate_user_secret_key' AND user_id = %d", $user_id ) );
set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS ); set_transient( $cache_key, $user_secret_key, HOUR_IN_SECONDS );
} }
return $user_secret_key; return $user_secret_key;
} }
/** /**
* Modify User Profile * Modify User Profile
* *
* Modifies the output of profile.php to add key generation/revocation * Modifies the output of profile.php to add key generation/revocation
* *
* @access public * @access public
* @since 1.1
*
* @param object $user Current user info * @param object $user Current user info
* *
* @return void * @return void
* @since 1.1
*
*/ */
function user_key_field( $user ) { function user_key_field( $user ) {
if ( ( opaljob_options( 'api_allow_user_keys', false ) || current_user_can( 'manage_opaljob_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) { if ( ( opalestate_get_option( 'api_allow_user_keys', false ) || current_user_can( 'manage_opalestate_settings' ) ) && current_user_can( 'edit_user', $user->ID ) ) {
$user = get_userdata( $user->ID ); $user = get_userdata( $user->ID );
?> ?>
<hr class="clearfix clear"> <hr class="clearfix clear">
<table class="property-table"> <table class="property-table">
<tbody> <tbody>
<tr> <tr>
<th> <th>
<?php esc_html_e( 'OpalJob API Keys', 'opaljob' ); ?> <?php esc_html_e( 'Opalestate API Keys', 'opalestate-pro' ); ?>
</th> </th>
<td> <td>
<?php <?php
$public_key = $this->get_user_public_key( $user->ID ); $public_key = $this->get_user_public_key( $user->ID );
$secret_key = $this->get_user_secret_key( $user->ID ); $secret_key = $this->get_user_secret_key( $user->ID );
?> ?>
<?php if ( empty( $user->opaljob_user_public_key ) ) { ?> <?php if ( empty( $user->opalestate_user_public_key ) ) { ?>
<input name="opaljob_set_api_key" type="checkbox" id="opaljob_set_api_key" value="0"/> <input name="opalestate_set_api_key" type="checkbox" id="opalestate_set_api_key" value="0"/>
<span class="description"><?php esc_html_e( 'Generate API Key', 'opaljob' ); ?></span> <span class="description"><?php esc_html_e( 'Generate API Key', 'opalestate-pro' ); ?></span>
<?php } else { ?> <?php } else { ?>
<strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'opaljob' ); ?>&nbsp;</strong> <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Public key:', 'opalestate-pro' ); ?>&nbsp;</strong>
<input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/> <input type="text" disabled="disabled" class="regular-text" id="publickey" value="<?php echo esc_attr( $public_key ); ?>"/>
<br/> <br/>
<strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'opaljob' ); ?>&nbsp;</strong> <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Secret key:', 'opalestate-pro' ); ?>&nbsp;</strong>
<input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/> <input type="text" disabled="disabled" class="regular-text" id="privatekey" value="<?php echo esc_attr( $secret_key ); ?>"/>
<br/> <br/>
<strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'opaljob' ); ?>&nbsp;</strong> <strong style="display:inline-block; width: 125px;"><?php esc_html_e( 'Token:', 'opalestate-pro' ); ?>&nbsp;</strong>
<input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/> <input type="text" disabled="disabled" class="regular-text" id="token" value="<?php echo esc_attr( $this->get_token( $user->ID ) ); ?>"/>
<br/> <br/>
<input name="opaljob_set_api_key" type="checkbox" id="opaljob_set_api_key" value="0"/> <input name="opalestate_set_api_key" type="checkbox" id="opalestate_set_api_key" value="0"/>
<span class="description"><label for="opaljob_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'opaljob' ); ?></label></span> <span class="description"><label for="opalestate_set_api_key"><?php esc_html_e( 'Revoke API Keys', 'opalestate-pro' ); ?></label></span>
<?php } ?> <?php } ?>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<?php } <?php }
} }
/** /**
* Process an API key generation/revocation * Process an API key generation/revocation
* *
* @access public * @access public
* @since 1.1
*
* @param array $args * @param array $args
* *
* @return void * @return void
* @since 1.1
*
*/ */
public function process_api_key( $args ) { public function process_api_key( $args ) {
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'opalestate-api-nonce' ) ) {
if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'opaljob-api-nonce' ) ) { wp_die( esc_html__( 'Nonce verification failed.', 'opalestate-pro' ), esc_html__( 'Error', 'opalestate-pro' ), [ 'response' => 403 ] );
wp_die( esc_html__( 'Nonce verification failed.', 'opaljob' ), esc_html__( 'Error', 'opaljob' ), array( 'response' => 403 ) );
} }
if ( empty( $args['user_id'] ) ) { if ( empty( $args['user_id'] ) ) {
wp_die( esc_html__( 'User ID Required.', 'opaljob' ), esc_html__( 'Error', 'opaljob' ), array( 'response' => 401 ) ); wp_die( esc_html__( 'User ID Required.', 'opalestate-pro' ), esc_html__( 'Error', 'opalestate-pro' ), [ 'response' => 401 ] );
} }
if ( is_numeric( $args['user_id'] ) ) { if ( is_numeric( $args['user_id'] ) ) {
$user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id(); $user_id = isset( $args['user_id'] ) ? absint( $args['user_id'] ) : get_current_user_id();
} else { } else {
$userdata = get_user_by( 'login', $args['user_id'] ); $userdata = get_user_by( 'login', $args['user_id'] );
$user_id = $userdata->ID; $user_id = $userdata->ID;
} }
$process = isset( $args['opaljob_api_process'] ) ? strtolower( $args['opaljob_api_process'] ) : false; $process = isset( $args['opalestate_api_process'] ) ? strtolower( $args['opalestate_api_process'] ) : false;
if ( $user_id == get_current_user_id() && ! opaljob_options( 'allow_user_api_keys' ) && ! current_user_can( 'manage_opaljob_settings' ) ) { if ( $user_id == get_current_user_id() && ! opalestate_options( 'allow_user_api_keys' ) && ! current_user_can( 'manage_opalestate_settings' ) ) {
wp_die( wp_die(
sprintf( sprintf(
/* translators: %s: process */ /* translators: %s: process */
esc_html__( 'You do not have permission to %s API keys for this user.', 'opaljob' ), esc_html__( 'You do not have permission to %s API keys for this user.', 'opalestate-pro' ),
$process $process
), ),
esc_html__( 'Error', 'opaljob' ), esc_html__( 'Error', 'opalestate-pro' ),
array( 'response' => 403 ) [ 'response' => 403 ]
); );
} elseif ( ! current_user_can( 'manage_opaljob_settings' ) ) { } elseif ( ! current_user_can( 'manage_opalestate_settings' ) ) {
wp_die( wp_die(
sprintf( sprintf(
/* translators: %s: process */ /* translators: %s: process */
esc_html__( 'You do not have permission to %s API keys for this user.', 'opaljob' ), esc_html__( 'You do not have permission to %s API keys for this user.', 'opalestate-pro' ),
$process $process
), ),
esc_html__( 'Error', 'opaljob' ), esc_html__( 'Error', 'opalestate-pro' ),
array( 'response' => 403 ) [ 'response' => 403 ]
); );
} }
switch ( $process ) { switch ( $process ) {
case 'generate': case 'generate':
if ( $this->generate_api_key( $user_id ) ) { if ( $this->generate_api_key( $user_id ) ) {
delete_transient( 'opaljob_total_api_keys' ); delete_transient( 'opalestate_total_api_keys' );
wp_redirect( add_query_arg( 'opaljob-message', 'api-key-generated', 'edit.php?post_type=opaljob_job&page=opal-job-settings&tab=api_keys' ) ); wp_redirect( add_query_arg( 'opalestate-message', 'api-key-generated', 'edit.php?post_type=opalestate_property&page=opalestate-settings&tab=api_keys' ) );
exit(); exit();
} else { } else {
wp_redirect( add_query_arg( 'opaljob-message', 'api-key-failed', 'edit.php?post_type=opaljob_job&page=opal-job-settings&tab=api_keys' ) ); wp_redirect( add_query_arg( 'opalestate-message', 'api-key-failed', 'edit.php?post_type=opalestate_property&page=opalestate-settings&tab=api_keys' ) );
exit(); exit();
} }
break; break;
case 'regenerate': case 'regenerate':
$this->generate_api_key( $user_id, true ); $this->generate_api_key( $user_id, true );
delete_transient( 'opaljob_total_api_keys' ); delete_transient( 'opalestate_total_api_keys' );
wp_redirect( add_query_arg( 'opaljob-message', 'api-key-regenerated', 'edit.php?post_type=opaljob_job&page=opal-job-settings&tab=api_keys' ) ); wp_redirect( add_query_arg( 'opalestate-message', 'api-key-regenerated', 'edit.php?post_type=opalestate_property&page=opalestate-settings&tab=api_keys' ) );
exit(); exit();
break; break;
case 'revoke': case 'revoke':
$this->revoke_api_key( $user_id ); $this->revoke_api_key( $user_id );
delete_transient( 'opaljob_total_api_keys' ); delete_transient( 'opalestate_total_api_keys' );
wp_redirect( add_query_arg( 'opaljob-message', 'api-key-revoked', 'edit.php?post_type=opaljob_job&page=opal-job-settings&tab=api_keys' ) ); wp_redirect( add_query_arg( 'opalestate-message', 'api-key-revoked', 'edit.php?post_type=opalestate_property&page=opalestate-settings&tab=api_keys' ) );
exit(); exit();
break; break;
default; default;
break; break;
} }
} }
/** /**
* Generate new API keys for a user * Generate new API keys for a user
* *
* @access public * @access public
* @since 1.1 * @param int $user_id User ID the key is being generated for
*
* @param int $user_id User ID the key is being generated for
* @param boolean $regenerate Regenerate the key for the user * @param boolean $regenerate Regenerate the key for the user
* *
* @return boolean True if (re)generated succesfully, false otherwise. * @return boolean True if (re)generated succesfully, false otherwise.
* @since 1.1
*
*/ */
public function generate_api_key( $user_id = 0, $regenerate = false ) { public function generate_api_key( $user_id = 0, $regenerate = false ) {
if ( empty( $user_id ) ) { if ( empty( $user_id ) ) {
@ -345,28 +371,33 @@ class Opalestate_API_Admin {
} }
$public_key = $this->get_user_public_key( $user_id ); $public_key = $this->get_user_public_key( $user_id );
$secret_key = $this->get_user_secret_key( $user_id ); $secret_key = $this->get_user_secret_key( $user_id );
if ( empty( $public_key ) || $regenerate == true ) { if ( empty( $public_key ) || $regenerate == true ) {
$new_public_key = $this->generate_public_key( $user->user_email ); $new_public_key = $this->generate_public_key( $user->user_email );
$new_secret_key = $this->generate_private_key( $user->ID ); $new_secret_key = $this->generate_private_key( $user->ID );
} else { } else {
return false; return false;
} }
if ( $regenerate == true ) { if ( $regenerate == true ) {
$this->revoke_api_key( $user->ID ); $this->revoke_api_key( $user->ID );
} }
update_user_meta( $user_id, $new_public_key, 'opaljob_user_public_key' );
update_user_meta( $user_id, $new_secret_key, 'opaljob_user_secret_key' ); update_user_meta( $user_id, $new_public_key, 'opalestate_user_public_key' );
update_user_meta( $user_id, $new_secret_key, 'opalestate_user_secret_key' );
return true; return true;
} }
/** /**
* Revoke a users API keys * Revoke a users API keys
* *
* @access public * @access public
* @since 1.1
*
* @param int $user_id User ID of user to revoke key for * @param int $user_id User ID of user to revoke key for
* *
* @return string * @return string
* @since 1.1
*
*/ */
public function revoke_api_key( $user_id = 0 ) { public function revoke_api_key( $user_id = 0 ) {
if ( empty( $user_id ) ) { if ( empty( $user_id ) ) {
@ -378,120 +409,139 @@ class Opalestate_API_Admin {
} }
$public_key = $this->get_user_public_key( $user_id ); $public_key = $this->get_user_public_key( $user_id );
$secret_key = $this->get_user_secret_key( $user_id ); $secret_key = $this->get_user_secret_key( $user_id );
if ( ! empty( $public_key ) ) { if ( ! empty( $public_key ) ) {
delete_transient( md5( 'opaljob_api_user_' . $public_key ) ); delete_transient( md5( 'opalestate_api_user_' . $public_key ) );
delete_transient( md5( 'opaljob_api_user_public_key' . $user_id ) ); delete_transient( md5( 'opalestate_api_user_public_key' . $user_id ) );
delete_transient( md5( 'opaljob_api_user_secret_key' . $user_id ) ); delete_transient( md5( 'opalestate_api_user_secret_key' . $user_id ) );
delete_user_meta( $user_id, $public_key ); delete_user_meta( $user_id, $public_key );
delete_user_meta( $user_id, $secret_key ); delete_user_meta( $user_id, $secret_key );
} else { } else {
return false; return false;
} }
return true; return true;
} }
/**
* Get version.
*
* @return int
*/
public function get_version() { public function get_version() {
return self::VERSION; return self::VERSION;
} }
/** /**
* Generate and Save API key * Generate and Save API key
* *
* Generates the key requested by user_key_field and stores it in the database * Generates the key requested by user_key_field and stores it in the database
* *
* @access public * @access public
* @since 1.1
*
* @param int $user_id * @param int $user_id
* *
* @return void * @return void
* @since 1.1
*
*/ */
public function update_key( $user_id ) { public function update_key( $user_id ) {
if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['opaljob_set_api_key'] ) ) { if ( current_user_can( 'edit_user', $user_id ) && isset( $_POST['opalestate_set_api_key'] ) ) {
$user = get_userdata( $user_id ); $user = get_userdata( $user_id );
$public_key = $this->get_user_public_key( $user_id ); $public_key = $this->get_user_public_key( $user_id );
$secret_key = $this->get_user_secret_key( $user_id ); $secret_key = $this->get_user_secret_key( $user_id );
if ( empty( $public_key ) ) { if ( empty( $public_key ) ) {
$new_public_key = $this->generate_public_key( $user->user_email ); $new_public_key = $this->generate_public_key( $user->user_email );
$new_secret_key = $this->generate_private_key( $user->ID ); $new_secret_key = $this->generate_private_key( $user->ID );
update_user_meta( $user_id, $new_public_key, 'opaljob_user_public_key' ); update_user_meta( $user_id, $new_public_key, 'opalestate_user_public_key' );
update_user_meta( $user_id, $new_secret_key, 'opaljob_user_secret_key' ); update_user_meta( $user_id, $new_secret_key, 'opalestate_user_secret_key' );
} else { } else {
$this->revoke_api_key( $user_id ); $this->revoke_api_key( $user_id );
} }
} }
} }
/** /**
* Generate the public key for a user * Generate the public key for a user
* *
* @access private * @access private
* @since 1.1
*
* @param string $user_email * @param string $user_email
* *
* @return string * @return string
* @since 1.1
*
*/ */
private function generate_public_key( $user_email = '' ) { private function generate_public_key( $user_email = '' ) {
$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
$public = hash( 'md5', $user_email . $auth_key . date( 'U' ) ); $public = hash( 'md5', $user_email . $auth_key . date( 'U' ) );
return $public; return $public;
} }
/** /**
* Generate the secret key for a user * Generate the secret key for a user
* *
* @access private * @access private
* @since 1.1
*
* @param int $user_id * @param int $user_id
* *
* @return string * @return string
* @since 1.1
*
*/ */
private function generate_private_key( $user_id = 0 ) { private function generate_private_key( $user_id = 0 ) {
$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
$secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) ); $secret = hash( 'md5', $user_id . $auth_key . date( 'U' ) );
return $secret; return $secret;
} }
/** /**
* Retrieve the user's token * Retrieve the user's token
* *
* @access private * @access private
* @since 1.1
*
* @param int $user_id * @param int $user_id
* *
* @return string * @return string
* @since 1.1
*
*/ */
public function get_token( $user_id = 0 ) { public function get_token( $user_id = 0 ) {
return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) ); return hash( 'md5', $this->get_user_secret_key( $user_id ) . $this->get_user_public_key( $user_id ) );
} }
/** /**
* API Key Backwards Compatibility * API Key Backwards Compatibility
* *
* A Backwards Compatibility call for the change of meta_key/value for users API Keys * A Backwards Compatibility call for the change of meta_key/value for users API Keys
* *
* @since 1.3.6 * @param string $check Whether to check the cache or not
* * @param int $object_id The User ID being passed
* @param string $check Whether to check the cache or not * @param string $meta_key The user meta key
* @param int $object_id The User ID being passed * @param bool $single If it should return a single value or array
* @param string $meta_key The user meta key
* @param bool $single If it should return a single value or array
* *
* @return string The API key/secret for the user supplied * @return string The API key/secret for the user supplied
* @since 1.3.6
*
*/ */
public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) { public function api_key_backwards_compat( $check, $object_id, $meta_key, $single ) {
if ( $meta_key !== 'opaljob_user_public_key' && $meta_key !== 'opaljob_user_secret_key' ) { if ( $meta_key !== 'opalestate_user_public_key' && $meta_key !== 'opalestate_user_secret_key' ) {
return $check; return $check;
} }
$return = $check; $return = $check;
switch ( $meta_key ) { switch ( $meta_key ) {
case 'opaljob_user_public_key': case 'opalestate_user_public_key':
$return = $this->get_user_public_key( $object_id ); $return = $this->get_user_public_key( $object_id );
break; break;
case 'opaljob_user_secret_key': case 'opalestate_user_secret_key':
$return =$this->get_user_secret_key( $object_id ); $return = $this->get_user_secret_key( $object_id );
break; break;
} }
if ( ! $single ) { if ( ! $single ) {
$return = array( $return ); $return = [ $return ];
} }
return $return; return $return;
} }
} }

View File

@ -22,7 +22,11 @@ class Opalestate_API {
public $base = 'estate-api'; public $base = 'estate-api';
public function __construct() { public function __construct() {
return $this->init(); $this->init();
if ( is_admin() ) {
new Opalestate_API_Admin();
}
} }
/** /**
@ -35,8 +39,8 @@ class Opalestate_API {
* @since 1.1 * @since 1.1
*/ */
public function init() { public function init() {
$this->includes( [ $this->includes( [
'class-opalestate-api-admin.php',
'class-opalestate-base-api.php', 'class-opalestate-base-api.php',
'v1/property.php', 'v1/property.php',
'v1/agent.php', 'v1/agent.php',

View File

@ -36,6 +36,7 @@ class Opalestate_HTML_Elements {
public function ajax_user_search( $args = [] ) { public function ajax_user_search( $args = [] ) {
$defaults = [ $defaults = [
'id' => 'user_id',
'name' => 'user_id', 'name' => 'user_id',
'value' => isset( $args['default'] ) ? $args['default'] : null, 'value' => isset( $args['default'] ) ? $args['default'] : null,
'placeholder' => esc_html__( 'Enter username', 'opalestate-pro' ), 'placeholder' => esc_html__( 'Enter username', 'opalestate-pro' ),
@ -73,8 +74,6 @@ class Opalestate_HTML_Elements {
* *
*/ */
public function text_field( $field_args, $args = [] ) { public function text_field( $field_args, $args = [] ) {
$defaults = [ $defaults = [
'id' => '', 'id' => '',
'value' => isset( $field_args['default'] ) ? $field_args['default'] : null, 'value' => isset( $field_args['default'] ) ? $field_args['default'] : null,

View File

@ -125,10 +125,11 @@ if ( ! class_exists( 'OpalEstate' ) ) {
register_activation_hook( OPALESTATE_PLUGIN_FILE, [ 'Opalestate_Install', 'install' ] ); register_activation_hook( OPALESTATE_PLUGIN_FILE, [ 'Opalestate_Install', 'install' ] );
add_action( 'plugins_loaded', [ self::$instance, 'load_textdomain' ] ); add_action( 'plugins_loaded', [ self::$instance, 'load_textdomain' ] );
self::$instance->setup(); self::$instance->setup();
self::$instance->roles = new Opalestate_Roles(); self::$instance->roles = new Opalestate_Roles();
self::$instance->html = new Opalestate_HTML_Elements(); self::$instance->html = new Opalestate_HTML_Elements();
self::$instance->api = new Opalestate_API(); self::$instance->api = new Opalestate_API();
self::$instance->session = new Opalestate_Session(); self::$instance->api_admin = new Opalestate_API_Admin();
self::$instance->session = new Opalestate_Session();
/** /**
* *

View File

@ -2,38 +2,40 @@
global $post; global $post;
$agency_id = get_the_ID(); $agency_id = get_the_ID();
$limit = apply_filters( 'opalesate_agency_properties_limit', 5 ); $limit = apply_filters( 'opalesate_agency_properties_limit', 5 );
$user_id = get_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'user_id', true ); $user_id = get_post_meta( $agency_id, OPALESTATE_AGENCY_PREFIX . 'user_id', true );
$query = Opalestate_Query::get_agency_property( $agency_id, $user_id , $limit ); $query = Opalestate_Query::get_agency_property( $agency_id, $user_id, $limit );
if ( $query->have_posts() ) :
if( $query->have_posts() ) :
$id = rand(); $id = rand();
?> ?>
<div class="clearfix clear"></div> <div class="clearfix clear"></div>
<div class="opalestate-box-inner property-agency-section"> <div class="opalestate-box-inner property-agency-section">
<h4 class="box-heading hide"><?php echo sprintf( esc_html__('My Properties', 'opalestate-pro'), $query->found_posts );?></h4> <h4 class="box-heading hide"><?php echo sprintf( esc_html__( 'My Properties', 'opalestate-pro' ), $query->found_posts ); ?></h4>
<div class="opalestate-rows"> <div class="opalestate-rows">
<div class="<?php echo apply_filters('opalestate_row_container_class', 'opal-row');?>" id="<?php echo esc_attr( $id ); ?>"> <div class="<?php echo apply_filters( 'opalestate_row_container_class', 'opal-row' ); ?>" id="<?php echo esc_attr( $id ); ?>">
<?php while( $query->have_posts() ) : $query->the_post(); ?> <?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="col-lg-12 col-md-12 col-sm-12"> <div class="col-lg-12 col-md-12 col-sm-12">
<?php echo opalestate_load_template_path( 'content-property-list-v2' ); ?> <?php echo opalestate_load_template_path( 'content-property-list-v2' ); ?>
</div> </div>
<?php endwhile; ?> <?php endwhile; ?>
</div> </div>
<?php if( $query->max_num_pages > 1 ): ?> <?php if ( $query->max_num_pages > 1 ): ?>
<div class="w-pagination"><?php // echo $query->max_num_pages; // opalestate_pagination( $query->max_num_pages ); ?></div> <div class="w-pagination"><?php // echo $query->max_num_pages; // opalestate_pagination( $query->max_num_pages ); ?></div>
<div class="opalestate-load-more text-center" data-post_id="<?php echo $agency_id; ?>" data-action="get_agency_property" data-related="<?php echo esc_attr( $id ); ?>" data-numpage="<?php echo <div class="opalestate-load-more text-center" data-post_id="<?php echo $agency_id; ?>" data-action="get_agency_property" data-related="<?php echo esc_attr( $id ); ?>"
$query->max_num_pages; ?>" data-paged="2"> <button class="btn btn-primary btn-3d"> <?php esc_html_e('Load More', 'opalestate-pro'); ?></button></div> data-numpage="<?php echo
<?php endif; ?> $query->max_num_pages; ?>" data-paged="2">
<button class="btn btn-primary btn-3d"> <?php esc_html_e( 'Load More', 'opalestate-pro' ); ?></button>
</div>
<?php endif; ?>
</div> </div>
</div> </div>
<?php else : ?> <?php else : ?>
<div class="opalestate-message"> <div class="opalestate-message">
<?php esc_html_e( 'My Agency has not any property yet.', 'opalestate-pro' ) ;?> <?php esc_html_e( 'My Agency has not any property yet.', 'opalestate-pro' ); ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php wp_reset_postdata(); ?> <?php wp_reset_postdata(); ?>

View File

@ -4,26 +4,24 @@ global $post;
$limit = apply_filters( 'opalesate_agent_properties_limit', 10 ); $limit = apply_filters( 'opalesate_agent_properties_limit', 10 );
$query = Opalestate_Query::get_agent_property( null, get_the_ID(), $limit ); $query = Opalestate_Query::get_agent_property( null, get_the_ID(), $limit );
if( $query->have_posts() ) : if ( $query->have_posts() ) : ?>
?> <div class="clearfix clear"></div>
<div class="clearfix clear"></div> <div class="opalestate-box-content my-properties-section" id="block-my-properties">
<div class="opalestate-box-content my-properties-section" id="block-my-properties"> <h4 class="outbox-title"><?php echo sprintf( esc_html__( 'My Properties', 'opalestate-pro' ), $query->found_posts ); ?></h4>
<h4 class="outbox-title"><?php echo sprintf( esc_html__('My Properties', 'opalestate-pro'), $query->found_posts );?></h4> <div class="ajax-load-properties" data-paged="1" data-type="agent" data-id="<?php echo get_the_ID(); ?>">
<div class="ajax-load-properties" data-paged="1" data-type="agent" data-id="<?php echo get_the_ID(); ?>"> <div class="opalestate-rows">
<div class="opalestate-rows"> <div class="<?php echo apply_filters( 'opalestate_row_container_class', 'opal-row' ); ?>">
<div class="<?php echo apply_filters('opalestate_row_container_class', 'opal-row');?>"> <?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php while( $query->have_posts() ) : $query->the_post(); ?> <div class="col-lg-6 col-md-6 col-sm-12">
<div class="col-lg-6 col-md-6 col-sm-12"> <?php echo opalestate_load_template_path( 'content-property-grid' ); ?>
<?php echo opalestate_load_template_path( 'content-property-grid' ); ?> </div>
</div> <?php endwhile; ?>
<?php endwhile; ?> </div>
</div> </div>
</div> <?php if ( $query->max_num_pages > 1 ): ?>
<?php if( $query->max_num_pages > 1 ): ?> <div class="w-pagination"><?php opalestate_pagination( $query->max_num_pages ); ?></div>
<div class="w-pagination"><?php opalestate_pagination( $query->max_num_pages ); ?></div> <?php endif; ?>
<?php endif; ?> </div>
</div> </div>
</div>
<?php endif; <?php endif;
wp_reset_postdata(); wp_reset_postdata();
?>