Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible implementation of thickbox handling for user search form #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/js/abus_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jQuery( function( $ ) {
;

// Clicking the admin-bar entry focuses the text box
entryButton.on( 'click', function() {
entryButton.addClass('thickbox').on( 'click', function() {
$input.focus();

return false;
return true;
} );

// Navigate through results using arrows
Expand Down
83 changes: 47 additions & 36 deletions includes/Integrations/WordPress/AdminBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class AdminBar
public function __construct()
{
add_action( 'wp_before_admin_bar_render', array( $this, 'output' ), 1 );
// Frontend hook - most themes will implement this
add_action( 'wp_footer', array( $this, 'footer' ), 1);
// Admin footer hook
add_action( 'admin_footer', array( $this, 'footer' ), 1);
add_thickbox();
}

/**
Expand Down Expand Up @@ -44,45 +49,10 @@ public function output()
array(
'id' => 'abus_switch_to_user',
'title' => apply_filters( 'abus_switch_to_text', __( 'Switch to user', 'abus' ) ),
'href' => '#',
'href' => '#TB_inline?height=600&width=390&inlineId=abus_wrapper',
)
);

// Build the user search form markup
$form = '
<div id="abus_wrapper">
<form method="post" action="abus_user_search">
<input id="abus_search_text"
class=""
name="abus_search_text"
type="text"
placeholder="' . __( 'Enter a username', 'abus' ) . '"/>

<input id="abus_search_submit"
class="button"
name="abus_search_submit"
type="submit" value="' . __( 'Search', 'abus' ) . '"/>

<input name="abus_current_url"
type="hidden"
value="' . esc_url( abus_get_current_url() ) . '"/>

<input name="abus_nonce"
type="hidden"
value="' . wp_create_nonce( 'abus_nonce' ) . '" />
</form>
<div id="abus_result"></div>
</div>
';

// Add the admin bar sub menu item for the search form
$wp_admin_bar->add_menu(
array(
'id' => 'abus_user_search',
'parent' => 'abus_switch_to_user',
'title' => apply_filters( 'abus_form_output', $form ),
)
);
}

// Check if there is an old user stored i.e. this logged in user is through switching
Expand All @@ -101,4 +71,45 @@ class="button"
);
}
}

public function footer()
{
// Don't display if the user doesn't have capability to switch users
if ( !current_user_can( apply_filters( 'abus_switch_to_capability', 'edit_users' ) ) ) {
return '';
}

/** @var user_switching $user_switching */
global $user_switching;

// Build the user search form markup
?>
<div id="abus_wrapper">
<form method="post" action="abus_user_search">
<input id="abus_search_text"
class=""
name="abus_search_text"
type="text"
placeholder="<?=__( 'Enter a username', 'abus' ); ?>"/>

<input id="abus_search_submit"
class="button"
name="abus_search_submit"
type="submit" value="<?=__( 'Search', 'abus' ); ?>"/>

<input name="abus_current_url"
type="hidden"
value="<?=esc_url( abus_get_current_url() ); ?>"/>

<input name="abus_nonce"
type="hidden"
value="<?=wp_create_nonce( 'abus_nonce' ); ?>" />
</form>
<p class="result">
<a href="<?=$user_switching->switch_off_url( wp_get_current_user() ); ?>">Guest User / Switch Off</a>
</p>
<div id="abus_result"></div>
</div>
<?php
}
}
3 changes: 3 additions & 0 deletions includes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public function enqueueStyles()
#wpadminbar .quicklinks #wp-admin-bar-abus_switch_to_user ul li .ab-item {
height: auto;
}
#abus_wrapper {
display: none;
}
#abus_search_text {
width: 280px;
margin: 0;
Expand Down