This commit is contained in:
Hoang Huu
2019-09-25 15:34:38 +07:00
parent c93c699a77
commit 7ee9f6ecb0
8 changed files with 272 additions and 90 deletions

View File

@@ -0,0 +1,49 @@
(function( $ ) {
'use strict';
$( document ).ready( function() {
$( ".adduser-team" ).delegate( ".remove-user", "click", function() {
if( confirm( $(this).data('alert') ) ){
$(this).parents( '.user-team' ).remove();
}
});
$( '.opalestate-add-user-field' ).each( function() {
var $this = $(this);
$('.button', this).click( function () {
var user_search = $( '.opalestate-adduser-search', $(this).parent().parent() ).val();
$('.opalestate-ajax').show();
var data = {
action: 'opalestate_ajax_search_username',
user_name: user_search,
};
$.ajax({
type: "POST",
data: data,
dataType: "json",
url: ajaxurl,
success: function ( response ) {
if( response.status == true ){
var template = wp.template( 'adduser-team-template' );
$('.adduser-team', $this ).append( template( response.user ) );
}else {
alert( response.message );
}
}
});
} );
} );
} );
})( jQuery );

View File

@@ -0,0 +1,29 @@
.adduser-team{
width: 80%;
}
.user-team{
padding: 12px 10px;
display: block;
border-bottom: solid 1px #f3f3f3
}
.user-team > div{
display: inline-block;
width: 33%;
}
.user-team > div img{
width: 30px;
height: 30px;
border: solid 3px #CCC;
border-radius: 50%;
float: left;
margin-right: 6px;
}
.remove-user {
cursor: pointer;
}
.remove-user:hover {
color: red;
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Opalestate_Field_Iconpicker
*
* @package opalestate
* @author Opal Team <info@wpopal.com >
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Opalestate_Field_Iconpicker {
/**
* Current version number
*/
const VERSION = '1.0.0';
/**
* Initialize the plugin by hooking into CMB2
*/
public static function init() {
add_filter( 'cmb2_render_opal_iconpicker', [ __CLASS__, 'render_iconpicker' ], 10, 5 );
add_filter( 'cmb2_sanitize_opal_iconpicker', [ __CLASS__, 'sanitize_map' ], 10, 4 );
}
/**
* Render field
*/
public static function render_iconpicker( $field, $field_escaped_value, $field_object_id, $field_object_type, $field_type_object ) {
self::setup_admin_scripts();
$users = $field->value;
echo '<div class="opalestate-add-user-field ' . apply_filters( 'opalestate_row_container_class', 'row opal-row' ) . '"> '; ?>
<div class="col-lg-12">
<h5 class=""><?php esc_html_e( 'As an author, you can add other users to your agency.', 'opalestate-pro' ); ?></h5>
<div>
<p><?php esc_html_e( 'Add someone to your agency, please enter extractly username in below input:', 'opalestate-pro' ); ?></p>
<div class="<?php echo apply_filters( 'opalestate_row_container_class', 'row opal-row' ); ?>">
<div class="col-lg-8"><input class="regular-text opalestate-adduser-search" name="opalestate_adduser_search" id="opalestate_adduser_search" value="" type="text"></div>
<div class="col-lg-4"><input name="search" class="button button-primary button-large pull-left" id="publish" value="<?php esc_html_e( 'add', 'opalestate-pro' ); ?>" type="button">
</div>
</div>
<div class="clear clearfix"></div>
</div>
<div class="adduser-team">
<?php if ( $users ): $users = array_unique( $users ); ?>
<?php foreach ( $users as $user_id ): $user = get_user_by( 'id', $user_id );
$user = $user->data ?>
<div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' ) ?>[]" value="<?php echo $user_id; ?>">
<div>
<img src="<?php echo get_avatar_url( $user_id ); ?>">
<a href="<?php get_author_posts_url( $user_id ); ?>" target="_blank"> <?php echo $user->user_login; ?> </a></div>
<div><span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove',
'opalestate-pro' ); ?></span></div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<script type="text/html" id="tmpl-adduser-team-template">
<div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' ) ?>[]" value="{{{data.ID}}}">
<div><img src="{{{data.avatar}}}"> <a href="{{{data.author_link}}}" target="_blank"> {{{data.user_login}}} </a></div>
<div><span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove', 'opalestate-pro' ); ?></span></div>
</div>
</script>
<?php echo '</div>';
}
/**
* Optionally save the latitude/longitude values into two custom fields
*/
public static function sanitize_map( $override_value, $value, $object_id, $field_args ) {
return $value;
}
/**
* Enqueue scripts and styles
*/
public static function setup_admin_scripts() {
wp_enqueue_script( 'opalestate-adduser', plugins_url( 'assets/script.js', __FILE__ ), [], self::VERSION );
wp_enqueue_style( 'opalestate-adduser', plugins_url( 'assets/style.css', __FILE__ ), [], self::VERSION );
}
}
Opalestate_Field_Iconpicker::init();

View File

@@ -1,20 +1,15 @@
<?php
/**
* $Desc$
* Opalestate_Field_Adduser
*
* @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_Field_Adduser {
/**
@@ -26,8 +21,8 @@ class Opalestate_Field_Adduser {
* Initialize the plugin by hooking into CMB2
*/
public static function init() {
add_filter( 'cmb2_render_adduser', array( __CLASS__, 'render_map' ), 10, 5 );
add_filter( 'cmb2_sanitize_adduser', array( __CLASS__, 'sanitize_map' ), 10, 4 );
add_filter( 'cmb2_render_adduser', [ __CLASS__, 'render_map' ], 10, 5 );
add_filter( 'cmb2_sanitize_adduser', [ __CLASS__, 'sanitize_map' ], 10, 4 );
}
/**
@@ -38,53 +33,53 @@ class Opalestate_Field_Adduser {
$users = $field->value;
// echo '<pre>'.print_r( $value, 1 );die;
echo '<div class="opalestate-add-user-field '.apply_filters('opalestate_row_container_class', 'row opal-row').'"> '; ?>
<div class="col-lg-12">
<h5 class=""><?php esc_html_e( 'As an author, you can add other users to your agency.', 'opalestate-pro'); ?></h5>
<div>
<p><?php esc_html_e( 'Add someone to your agency, please enter extractly username in below input:', 'opalestate-pro' ); ?></p>
<div class="<?php echo apply_filters('opalestate_row_container_class', 'row opal-row'); ?>">
echo '<div class="opalestate-add-user-field ' . apply_filters( 'opalestate_row_container_class', 'row opal-row' ) . '"> '; ?>
<div class="col-lg-12">
<h5 class=""><?php esc_html_e( 'As an author, you can add other users to your agency.', 'opalestate-pro' ); ?></h5>
<div>
<p><?php esc_html_e( 'Add someone to your agency, please enter extractly username in below input:', 'opalestate-pro' ); ?></p>
<div class="col-lg-8"><input class="regular-text opalestate-adduser-search" name="opalestate_adduser_search" id="opalestate_adduser_search" value="" type="text"></div>
<div class="col-lg-4"><input name="search" class="button button-primary button-large pull-left" id="publish" value="<?php esc_html_e( 'add', 'opalestate-pro' ); ?>" type="button"></div>
</div>
<div class="clear clearfix"></div>
</div>
<div class="adduser-team">
<?php if( $users ): $users = array_unique( $users ); ?>
<?php foreach( $users as $user_id ): $user = get_user_by( 'id', $user_id ); $user = $user->data ?>
<div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' )?>[]" value="<?php echo $user_id; ?>">
<div>
<img src="<?php echo get_avatar_url( $user_id ) ; ?>">
<a href="<?php get_author_posts_url( $user_id ); ?>" target="_blank"> <?php echo $user->user_login; ?> </a> </div>
<div> <span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove', 'opalestate-pro' ); ?></span></div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<div class="<?php echo apply_filters( 'opalestate_row_container_class', 'row opal-row' ); ?>">
<script type="text/html" id="tmpl-adduser-team-template">
<div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' )?>[]" value="{{{data.ID}}}">
<div> <img src="{{{data.avatar}}}"> <a href="{{{data.author_link}}}" target="_blank"> {{{data.user_login}}} </a> </div>
<div> <span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove', 'opalestate-pro' ); ?></span></div>
</div>
</script>
<div class="col-lg-8"><input class="regular-text opalestate-adduser-search" name="opalestate_adduser_search" id="opalestate_adduser_search" value="" type="text"></div>
<div class="col-lg-4"><input name="search" class="button button-primary button-large pull-left" id="publish" value="<?php esc_html_e( 'add', 'opalestate-pro' ); ?>" type="button">
</div>
</div>
<div class="clear clearfix"></div>
</div>
<div class="adduser-team">
<?php if ( $users ): $users = array_unique( $users ); ?>
<?php foreach ( $users as $user_id ): $user = get_user_by( 'id', $user_id );
$user = $user->data ?>
<div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' ) ?>[]" value="<?php echo $user_id; ?>">
<div>
<img src="<?php echo get_avatar_url( $user_id ); ?>">
<a href="<?php get_author_posts_url( $user_id ); ?>" target="_blank"> <?php echo $user->user_login; ?> </a></div>
<div><span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove',
'opalestate-pro' ); ?></span></div>
</div>
<?php endforeach; ?>
<?php echo '</div>';
<?php endif; ?>
</div>
</div>
<script type="text/html" id="tmpl-adduser-team-template">
<div class="user-team">
<input type="hidden" name="<?php echo $field->args( '_name' ) ?>[]" value="{{{data.ID}}}">
<div><img src="{{{data.avatar}}}"> <a href="{{{data.author_link}}}" target="_blank"> {{{data.user_login}}} </a></div>
<div><span class="remove-user" data-alert="<?php esc_html_e( 'Are you sure to delete this', 'opalestate-pro' ); ?>"><?php esc_html_e( 'Remove', 'opalestate-pro' ); ?></span></div>
</div>
</script>
<?php echo '</div>';
}
/**
* Optionally save the latitude/longitude values into two custom fields
*/
public static function sanitize_map( $override_value, $value, $object_id, $field_args ) {
return $value;
}
@@ -92,8 +87,8 @@ class Opalestate_Field_Adduser {
* Enqueue scripts and styles
*/
public static function setup_admin_scripts() {
wp_enqueue_script( 'opalestate-adduser', plugins_url( 'assets/script.js', __FILE__ ), array( ), self::VERSION );
wp_enqueue_style( 'opalestate-adduser', plugins_url( 'assets/style.css', __FILE__ ), array(), self::VERSION );
wp_enqueue_script( 'opalestate-adduser', plugins_url( 'assets/script.js', __FILE__ ), [], self::VERSION );
wp_enqueue_style( 'opalestate-adduser', plugins_url( 'assets/style.css', __FILE__ ), [], self::VERSION );
}
}