admin_url('admin-ajax.php'),
'ajax_nonce' => wp_create_nonce('advanced_search_submit'),
);
wp_register_script( 'advanced_admin_search' );
wp_enqueue_script( 'advanced_admin_search' );
wp_localize_script( 'advanced_admin_search', 'advanced_admin_search', $params );
}
function AASKP_SearchBox() {
global $wp_admin_bar;
$wp_admin_bar->add_menu(array(
'id' => 'search_form',
'parent' => 'top-secondary',
'title' => '
'
));
}
function AASKP_displayInput() {
echo '';
}
function AASKP_desktopSearchJavascript() {
echo '';
}
function AASKP_mobileSearchJavascript() {
echo '';
}
function AASKP_searchAction() {
if (isset($_POST['post_search']) && isset($_POST['security']))
{
$post_search = sanitize_text_field( $_POST['post_search'] );
$security_check = sanitize_text_field( $_POST['security'] );
$check = wp_create_nonce('advanced_search_submit');
if($security_check == $check)
{
if(!empty($post_search))
{
$post_types = get_post_types(array('public' => true));
$post_types = array_values($post_types);
// get the register user.
$users = get_users( array( 'search' => "*{$post_search}*", 'fields' => array( 'display_name', 'user_registered', 'id' ) ) );
$countUser = 0;
foreach ( $users as $user ) {
$url = admin_url( 'user-edit.php?user_id='.$user->id );
$getUser = get_userdata( $user->id );
$role = $getUser->roles;
$countUser++;
foreach ($role as $value) {
echo "
" . $user->display_name . "" . $value . "
" . $user->user_registered . "
";
}
}
// get posts and pages
if ($countUser < 10)
{
$postPerPage = 10 - $countUser;
$posts = get_posts(
array(
's' => $post_search,
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'trash'),
'post_type' => 'any',
'posts_per_page' => $postPerPage
)
);
$countPost = count($posts);
foreach ($posts as $post) {
$url = admin_url( 'post.php?post='.$post->ID.'&action=edit' );
$post_type = $post->post_type;
echo "".$post->post_title."". $post->post_status."
Type: ".$post->post_type."
";
}
}
$totalPost = $countPost + $countUser;
// get media libraries
if ($totalPost < 10)
{
$mediaPerPage = 10 - $totalPost;
$mediaPosts = get_posts(
array(
's' => $post_search,
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => $mediaPerPage
)
);
foreach ($mediaPosts as $mediaPost) {
$url = admin_url( 'post.php?post='.$mediaPost->ID.'&action=edit' );
$post_type = $mediaPost->post_type;
$image_url = wp_get_attachment_image_src($mediaPost->ID);
echo "
".$mediaPost->post_title."".$mediaPost->post_date."
";
}
}
$queryPost = get_posts(
array(
's' => $post_search,
'post_type' => 'any',
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
'posts_per_page' => -1
)
);
$countQueryPost = count($queryPost);
$total = $countUser + $countQueryPost;
if ($total == 0)
{
echo "".$total." Result not Found. Please Refine Your Search";
}
else if ($total > 10)
{
echo "'".$post_search."' search has ";
echo "".$total."";
echo " results.";
}
}
}
else
{
echo "Invalid Request";
}
}
else
{
echo "Refine Your Search";
}
wp_die(); // this is required to terminate immediately and return a proper response
}
}
new AASKP_advancedAdminSearch();
?>