Changeset 2741547
- Timestamp:
- 06/13/2022 10:48:31 AM (4 years ago)
- Location:
- advanced-admin-search/trunk
- Files:
-
- 7 edited
-
README.md (modified) (2 diffs)
-
advanced-admin-search.php (modified) (1 diff)
-
css/style.css (modified) (1 diff)
-
menu.php (modified) (13 diffs)
-
scripts.php (modified) (1 diff)
-
searchbox.php (modified) (2 diffs)
-
searchresults.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
advanced-admin-search/trunk/README.md
r2737296 r2741547 5 5 Requires at least: 3.9 6 6 Tested up to: 6.0 7 Stable tag: 1.1. 37 Stable tag: 1.1.4 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 79 79 == Changelog == 80 80 81 = 1.1.4 = 82 * Security issues fixed 81 83 = 1.1.3 = 82 84 * Bug fixes -
advanced-admin-search/trunk/advanced-admin-search.php
r2737296 r2741547 4 4 * Plugin URI: https://www.kuroit.com/product/advanced-admin-search 5 5 * Description: Easily search everything in WordPress admin panel from one single search field. 6 * Version: 1.1. 36 * Version: 1.1.4 7 7 * Author: Kuroit 8 8 * Author URI: https://www.kuroit.com -
advanced-admin-search/trunk/css/style.css
r2474185 r2741547 465 465 height: 40px !important; 466 466 } 467 .search_r ows1{467 .search_result_rows{ 468 468 text-align: center; 469 cursor: pointer; 469 470 } 470 471 .list_title1 { -
advanced-admin-search/trunk/menu.php
r2737296 r2741547 2 2 use Kuroit\AdvancedAdminSearch\AASKP_searchResults as searchclass; 3 3 4 // Add menu item for the plugin 4 5 add_action('admin_menu', 'aaskp_menu_items'); 5 6 function aaskp_menu_items(){ … … 7 8 } 8 9 10 // Pre search call to fetch user & roles 9 11 add_filter( 'aaskp_pre_search', 'aaskp_pre_search_callback'); 10 12 function aaskp_pre_search_callback($user) { … … 37 39 function aaskp_search_page_callback() { 38 40 41 // Pick all data from query string and sanitise it 39 42 $selectedKeyword = (isset($_GET['keyword'])) ? sanitize_text_field($_GET['keyword']) : ''; 40 43 $selectedFilter = (isset($_GET['select'])) ? sanitize_text_field($_GET['select']) : ''; … … 46 49 $selectedMatchType = (isset($_GET['matchType'])) ? sanitize_text_field($_GET['matchType']) : ''; 47 50 51 // Advance search form view - TODO: switch to separate template later on 48 52 ?> 49 <html>50 53 <div class="advanced-admin-wrapper"> 51 54 <label for="post_search_box1"><h2 class="page_title_AASKP">Advanced Admin Search: Full Search</h2></label> … … 98 101 </form> 99 102 </div> 100 101 </html>102 103 <?php 103 //get the keyword 104 105 // Get search data if keyword is available 104 106 if (isset($selectedKeyword)) { 105 107 $postSearch = sanitize_text_field($selectedKeyword); 106 108 107 109 if (!empty($postSearch)) { 110 111 // Filter keys from search form 108 112 $keys=array('select','status','user','metaKey','metaValue','matchType'); 113 114 // Prep filters data from form 109 115 $filters=array_fill_keys($keys,""); 110 116 if (isset($selectedFilter) && $selectedFilter != ''){ … … 127 133 } 128 134 129 // get all results135 // Get all results 130 136 $results = array(); 131 137 $post_types = get_post_types(array('public' => true)); 132 138 $post_types = array_values($post_types); 133 139 134 // get pre search results fromhook140 // Apply local pre-search hook 135 141 if(!empty($filters['user'])){ 136 142 $user=$filters['user']; … … 142 148 } 143 149 150 // Init search and get search based data 144 151 $object = searchclass::getInstance(); 145 152 switch($filters['select']) { … … 192 199 ); 193 200 } 194 201 202 // Apply local post-search hook 195 203 $post_filtered_result = apply_filters('aaskp_post_search', $postSearch); 196 204 if (is_array($post_filtered_result)) { 197 205 $results = array_merge($results, $post_filtered_result); 198 206 } 207 208 // Start working on pagination 199 209 $numPerPage=10; 200 210 $numPages = ceil(count($results)/$numPerPage); … … 212 222 $start=($offset-1)*$numPerPage; 213 223 $end=min(($offset*$numPerPage),count($results)); 224 225 // Print total search count 214 226 if(count($results) > 1){ 215 echo '<h2 class="search_result_count">Total <span>'.count($results).'</span> Search Results Found</h2>'; 227 // More than one result 228 _e('<h2 class="search_result_count">Total <span>'.count($results).'</span> Search Results Found</h2>', 'advanced-admin-search'); 216 229 }elseif(count($results) == 0){ 217 echo '<h2 class="search_result_count">Total <span>'.count($results).'</span> Search Result Found.</h2>'; 218 } 219 else{ 220 echo '<h2 class="search_result_count">Total <span>'.count($results).'</span> Search Result Found</h2>'; 221 } 222 223 echo "<table class='search_list2 table_fxd' cellpadding='10' border='1'>"; 224 if(count($results)==0){ //no results found 225 echo "<tr><td colspan='5' class='result_row'>Please refine your search</td></tr>"; 226 }else{ //display the found results 227 echo "<tr class='search_rows tb-heading'><th class='table_type'>Type</th><th class='table_type1'>Thumbnail</th><th class='table_type2'>Title</th><th class='table_type1'>Status</th><th class='table_type2'>Info</th></tr>"; 230 // No result found 231 _e('<h2 class="search_result_count">No Search Result Found.</h2>', 'advanced-admin-search'); 232 }else{ 233 // Single result 234 _e('<h2 class="search_result_count">Only <span>'.count($results).'</span> Search Result Found</h2>', 'advanced-admin-search'); 235 } 236 237 // Start printing search results table 238 echo "<table class=\"search_list2 table_fxd\" cellpadding=\"10\" border=\"1\">"; 239 if(count($results)==0){ 240 // No results found - refine it! 241 echo "<tr><td colspan=\"5\" class=\"result_row\">Please refine your search</td></tr>"; 242 }else{ 243 // Display the found results 244 echo "<tr class=\"search_rows tb-heading\"><th class=\"table_type\">Type</th><th class=\"table_type1\">Thumbnail</th><th class=\"table_type2\">Title</th><th class=\"table_type1\">Status</th><th class=\"table_type2\">Info</th></tr>"; 245 228 246 for($i=$start;$i<$end;$i++){ 229 247 $values=$results[$i]; … … 236 254 $title = $values['title']; 237 255 $link = $values['link']; 238 239 $link='"'.$link.'"';240 256 241 257 $info = $values['info']; … … 245 261 if(array_key_exists("image",$values)){ 246 262 $image = $values['image']; 247 $images = "<img class='image_thumb1' src='".$image."'>";263 $images = __("<img class='image_thumb1' src='".$image."'>", "advanced-admin-search"); 248 264 }else{ 249 265 $images="[NO IMAGE]"; … … 259 275 switch($types) { 260 276 case "User": 261 $type = "<label class='color' style='background: #dc3545;'>".$types."</label>";277 $type = __("<label class='color' style='background: #dc3545;'>".$types."</label>", "advanced-admin-search"); 262 278 break; 263 279 case "Post": 264 $type = "<label class='color' style='background: #03254d;'>".$types."</label>";280 $type = __("<label class='color' style='background: #03254d;'>".$types."</label>", "advanced-admin-search"); 265 281 break; 266 282 case "Media": 267 $type = "<label class='color' style='background: #dec610;'>".$types."</label>";283 $type = __("<label class='color' style='background: #dec610;'>".$types."</label>", "advanced-admin-search"); 268 284 break; 269 285 case "Taxonomy": 270 $type = "<label class='color' style='background: #32a852;'>".$types."</label>";286 $type = __("<label class='color' style='background: #32a852;'>".$types."</label>", "advanced-admin-search"); 271 287 break; 272 288 case "PostMeta": 273 $type = "<label class='color' style='background: #c7550e;'>".$types."</label>";289 $type = __("<label class='color' style='background: #c7550e;'>".$types."</label>", "advanced-admin-search"); 274 290 break; 275 291 case "Comment": 276 $type = "<label class='color' style='background: #6c757d;'>".$types."</label>"; 277 break; 278 } 279 echo "<tr class='search_rows search_rows1' onclick='clickLink(".$link.")'><td class='td_rows'>".$type."</td><td class='td_rows'>".$images."</td><td><p class='list_title1'>".$title."</p></td><td class='td_rows'><p class='list_status1'>".$status."</p></td><td><p class='list_type1'>".$info."</p></td></a></tr>"; 280 } 292 $type = __("<label class='color' style='background: #6c757d;'>".$types."</label>", "advanced-admin-search"); 293 break; 294 } 295 296 // Print search row 297 _e("<tr class=\"search_rows search_result_rows\" onclick=\"clickLink('".$link."');\"><td class=\"td_rows\">".$type."</td><td class=\"td_rows\">".$images."</td><td><p class=\"list_title1\">".$title."</p></td><td class=\"td_rows\"><p class=\"list_status1\">".$status."</p></td><td><p class=\"list_type1\">".$info."</p></td></a></tr>", "advanced-admin-search"); 298 } 299 300 // End table 281 301 echo "</table>"; 302 303 // Prep url for pagination 282 304 $adminUrl= get_admin_url(); 283 $url= $adminUrl."tools.php?page=advanced-admin-search&keyword=".$postSearch."&select=".$filters['select']."&status=".$filters['status']."&user=".$filters['user']."&metaKey=".$filters['metaKey']."&metaValue=".$filters['metaValue']."&matchType=".$filters['matchType'];305 $url= __($adminUrl."tools.php?page=advanced-admin-search&keyword=".$postSearch."&select=".$filters['select']."&status=".$filters['status']."&user=".$filters['user']."&metaKey=".$filters['metaKey']."&metaValue=".$filters['metaValue']."&matchType=".$filters['matchType'], "advanced-admin-search"); 284 306 285 307 //pagination for results found … … 296 318 $secondLast=$numPages-1; 297 319 if($numPages>1) { 298 echo "<div class='center'> 299 <div class='pagination'>";320 321 echo "<div class=\"center\"><div class=\"pagination\">"; 300 322 if($offset==1) { 301 echo "<a class= 'isDisabled'>PREV</a>";302 } 303 else {304 echo "<a href='".$url."&offset=".$previousPage."' class='btn-color'>PREV</a>";305 } 306 // results less than 10323 echo "<a class=\"isDisabled\">PREV</a>"; 324 } else { 325 _e("<a href='".$url."&offset=".$previousPage."' class=\"btn-color\">PREV</a>", "advanced-admin-search"); 326 } 327 328 // Results less than 10 307 329 if ($numPages <= 10){ 308 330 for ($counter = 1; $counter <= $numPages; $counter++){ 309 331 if ($counter == $offset) { 310 echo "<a href='".$url."&offset=".$counter."' class='active'>".$counter."</a>";332 _e("<a href=\"".$url."&offset=".$counter."\" class=\"active\">".$counter."</a>", "advanced-admin-search"); 311 333 }else{ 312 echo "<a href='".$url."&offset=".$counter."'>".$counter."</a>";334 _e("<a href=\"".$url."&offset=".$counter."\">".$counter."</a>", "advanced-admin-search"); 313 335 } 314 336 } 315 337 } 316 //results greater than 10 338 339 // Results greater than 10 317 340 elseif ($numPages > 10){ 318 if($offset <= 4) { 341 if($offset <= 4){ 342 319 343 for ($counter = 1; $counter < 8; $counter++){ 320 344 if ($counter == $offset) { 321 echo "<a href='".$url."&offset=".$counter."' class='active'>".$counter."</a>";345 _e("<a href=\"".$url."&offset=".$counter."\" class=\"active\">".$counter."</a>", "advanced-admin-search"); 322 346 }else{ 323 echo "<a href='".$url."&offset=".$counter."'>".$counter."</a>"; 324 } 325 } 326 echo "<a>...</a>"; 327 echo "<a href='".$url."&offset=".$secondLast."'>".$secondLast."</a>"; 328 echo "<a href='".$url."&offset=".$numPages."'>".$numPages."</a>"; 329 } 330 elseif($offset > 4 && $offset < ($numPages - 4)) { 331 echo "<a href='".$url."&offset=1'>1</a>"; 332 echo "<a href='".$url."&offset=2'>2</a>"; 333 echo "<a>...</a>"; 347 _e("<a href=\"".$url."&offset=".$counter."\">".$counter."</a>", "advanced-admin-search"); 348 } 349 } 350 _e("<a>...</a>", "advanced-admin-search"); 351 _e("<a href=\"".$url."&offset=".$secondLast."\">".$secondLast."</a>", "advanced-admin-search"); 352 _e("<a href=\"".$url."&offset=".$numPages."\">".$numPages."</a>", "advanced-admin-search"); 353 354 } elseif ($offset > 4 && $offset < ($numPages - 4)) { 355 356 _e("<a href=\"".$url."&offset=1\">1</a>", "advanced-admin-search"); 357 _e("<a href=\"".$url."&offset=2\">2</a>", "advanced-admin-search"); 358 _e("<a>...</a>", "advanced-admin-search"); 334 359 for ($counter = ($offset - 2);$counter <= ($offset + 2);$counter++) { 335 360 if ($counter == $offset) { 336 echo "<a href='".$url."&offset=".$counter."' class='active'>".$counter."</a>";361 _e("<a href=\"".$url."&offset=".$counter."\" class=\"active\">".$counter."</a>", "advanced-admin-search"); 337 362 }else{ 338 echo "<a href='".$url."&offset=".$counter."'>".$counter."</a>";363 _e("<a href=\"".$url."&offset=".$counter."\">".$counter."</a>", "advanced-admin-search"); 339 364 } 340 365 } 341 echo "<a>...</a>";342 echo "<a href='".$url."&offset=".$secondLast."'>".$secondLast."</a>";343 echo "<a href='".$url."&offset=".$numPages."'>".$numPages."</a>";344 } 345 else {346 echo "<a href='".$url."&offset=1'>1</a>";347 echo "<a href='".$url."&offset=2'>2</a>";348 echo "<a>...</a>";366 _e("<a>...</a>", "advanced-admin-search"); 367 _e("<a href=\"".$url."&offset=".$secondLast."\">".$secondLast."</a>", "advanced-admin-search"); 368 _e("<a href=\"".$url."&offset=".$numPages."\">".$numPages."</a>", "advanced-admin-search"); 369 370 } else { 371 _e("<a href=\"".$url."&offset=1\">1</a>", "advanced-admin-search"); 372 _e("<a href=\"".$url."&offset=2\">2</a>", "advanced-admin-search"); 373 _e("<a>...</a>", "advanced-admin-search"); 349 374 for ($counter=($numPages - 6);$counter <=$numPages;$counter++ 350 375 ) { 351 376 if ($counter == $offset) { 352 echo "<a href='".$url."&offset=".$counter."' class='active'>".$counter."</a>";377 _e("<a href=\"".$url."&offset=".$counter."\" class=\"active\">".$counter."</a>", "advanced-admin-search"); 353 378 }else{ 354 echo "<a href='".$url."&offset=".$counter."'>".$counter."</a>";379 _e("<a href=\"".$url."&offset=".$counter."\">".$counter."</a>", "advanced-admin-search"); 355 380 } 356 381 } 357 382 } 358 383 } 384 359 385 if($offset==$numPages) { 360 echo "<a class= 'isDisabled'>NEXT</a>";386 echo "<a class=\"isDisabled\">NEXT</a>"; 361 387 } 362 388 else { 363 echo "<a href='".$url."&offset=".$nextPage."' class='btn-color'>NEXT</a>"; 364 } 365 echo "</div> 366 </div>"; 389 _e("<a href=\"".$url."&offset=".$nextPage."\" class=\"btn-color\">NEXT</a>", "advanced-admin-search"); 390 } 391 echo "</div></div>"; 367 392 } 368 393 } -
advanced-admin-search/trunk/scripts.php
r2737296 r2741547 41 41 wp_enqueue_script( 'advanced_admin_desktop_search_script' ); 42 42 wp_enqueue_script( 'advanced_admin_mobile_search_script' ); 43 44 43 wp_enqueue_script( 'advanced_admin_page_search_script' ); 45 44 } -
advanced-admin-search/trunk/searchbox.php
r2474185 r2741547 13 13 { 14 14 global $wp_admin_bar; 15 $wp_admin_bar->add_menu(array('id' => 'search_form', 15 $wp_admin_bar->add_menu( 16 array( 17 'id' => 'search_form', 16 18 'parent' => 'top-secondary', 17 'title' => '<ul class="post_search_box">19 'title' => __('<ul class="post_search_box"> 18 20 <li class="advance_search_box"><span class="dashicons dashicons-search" 19 21 onclick="AASKP_displayInputBox()"></span><div class="sf-d"><input … … 26 28 (__FILE__).'image/loading.gif" class="img-responsive" /></div><ul 27 29 class="search_list"></ul></div></li> 28 </ul>')); 30 </ul>', 'advanced-admin-search') 31 ) 32 ); 29 33 } 30 34 public function AASKP_displayInput() 31 35 { 32 echo'<div class="sf-m"><div id="search_fields" style="display:none;">33 <input type="text" placeholder="Search Database" id="mobile_search_fields"34 autocomplete="off" style="line-height:1em;"/><label for="submit"><span35 class="dashicons dashicons-search"></span></label><input type="submit"36 id="submit" name="search" value="Search" style="display:none;"></div>37 <div class="ajax-loading"><img src="'.plugin_dir_url(__FILE__).'image/loading.gif"38 class="img-responsive" /></div><ul class="mobile_search_list">39 </ul></div>';36 _e('<div class="sf-m"><div id="search_fields" style="display:none;"> 37 <input type="text" placeholder="Search Database" id="mobile_search_fields" 38 autocomplete="off" style="line-height:1em;"/><label for="submit"><span 39 class="dashicons dashicons-search"></span></label><input type="submit" 40 id="submit" name="search" value="Search" style="display:none;"></div> 41 <div class="ajax-loading"><img src="'.plugin_dir_url(__FILE__).'image/loading.gif" 42 class="img-responsive" /></div><ul class="mobile_search_list"> 43 </ul></div>', 'advanced-admin-search'); 40 44 } 41 45 } -
advanced-admin-search/trunk/searchresults.php
r2737296 r2741547 6 6 { 7 7 protected static $instance = false; 8 public function __construct() // instantiation9 {8 public function __construct() { 9 // Init the search results 10 10 add_action('wp_ajax_search_result', array($this, 'AASKP_searchAction')); 11 11 } 12 public function AASKP_searchAction() //retrieve the results 13 { 12 13 // Ajax search callback function 14 public function AASKP_searchAction() { 15 16 // Start fetching the results 14 17 if (isset($_POST['post_search']) && isset($_POST['security'])) { 18 19 // Get POST data and sanitise it 15 20 $post_search = sanitize_text_field($_POST['post_search']); 16 21 $security_check = sanitize_text_field($_POST['security']); 22 23 // Check nonce first 17 24 $check = wp_create_nonce('advanced_search_submit'); 18 25 if ($security_check == $check) { 19 $results = array(); // all results available for search 26 27 // Prep result array 28 $results = array(); 29 20 30 if (!empty($post_search)) { 31 32 // Prep filters array 21 33 $filters=array(); 34 35 // Fetch post types available 22 36 $post_types = get_post_types(array('public' => true)); 23 37 $post_types = array_values($post_types); 38 24 39 // get pre search results from hook 25 40 $pre_filtered_result = apply_filters('aaskp_pre_search', $post_search); 26 27 41 if (is_array($pre_filtered_result)) { 28 42 $results = array_merge($results, $pre_filtered_result); 29 43 } 44 30 45 $results = array_merge( 31 46 $results, // pre search … … 37 52 $this->AASKP_getComments($post_search,$filters) // comments 38 53 ); 54 39 55 $post_filtered_result = apply_filters('aaskp_post_search', $post_search); 40 56 if (is_array($post_filtered_result)) { 41 57 $results = array_merge($results, $post_filtered_result); 42 58 } 43 //results conversion to json 44 echo json_encode(array('result'=>'success', 'data'=>$results, 'count'=>count($results), 'search'=>$post_search));59 60 _e(json_encode(array('result'=>'success', 'data'=>$results, 'count'=>count($results), 'search'=>$post_search)), "advanced-admin-search"); 45 61 } 46 62 else { 47 echo json_encode(array('result'=>'success', 'count'=> count($results)));63 _e(json_encode(array('result'=>'success', 'count'=> count($results))), "advanced-admin-search"); 48 64 } 49 65 } else { 50 echo json_encode(array('result'=>'error', 'message'=>'Invalid Request'));66 _e(json_encode(array('result'=>'error', 'message'=>'Invalid Request')), "advanced-admin-search"); 51 67 } 52 68 } else { 53 echo json_encode(array('result'=>'none', 'message'=>'Refine Your Search'));69 _e(json_encode(array('result'=>'none', 'message'=>'Refine Your Search')), "advanced-admin-search"); 54 70 } 55 71 wp_die(); 56 72 } 57 public function AASKP_getUsers($post_search,$filters,$flag = false) 58 { 59 73 74 75 public function AASKP_getUsers($post_search,$filters,$flag = false) { 76 60 77 $output = array(); 61 78 if($flag) { … … 83 100 return $output; 84 101 } 85 public function AASKP_getPostsAndPages($post_search,$filters,$flag = false) 86 {102 103 public function AASKP_getPostsAndPages($post_search,$filters,$flag = false) { 87 104 $output = array(); 88 105 $args = array( … … 90 107 'post_type' => 'any', 91 108 'post_status' => array('publish', 'pending', 'draft', 92 'auto-draft', 'future', 'private', 'trash'),109 'auto-draft', 'future', 'private', 'trash'), 93 110 'posts_per_page' => -1 94 111 ); … … 98 115 } 99 116 if(!empty($filters['user'])) { 100 if (is_numeric($filters['user'])) {117 if (is_numeric($filters['user'])) { 101 118 $args['author'] = $filters['user']; 102 } 103 else { 104 $args['author_name'] = $filters['user']; 105 } 106 } 107 119 } else { 120 $args['author_name'] = $filters['user']; 121 } 122 } 123 108 124 $metaQuery= array(); 109 125 if (!empty($filters['metaKey'])) { 110 126 $metaQuery=array( 111 'key' => $filters['metaKey']127 'key' => $filters['metaKey'] 112 128 ); 113 129 } … … 117 133 switch($matchType) { 118 134 case "starting": 119 $compare='REGEXP';120 $value='^'.$value;121 break;135 $compare='REGEXP'; 136 $value='^'.$value; 137 break; 122 138 case "ending": 123 $compare='REGEXP';124 $value=$value.'$';125 break;139 $compare='REGEXP'; 140 $value=$value.'$'; 141 break; 126 142 case 0: 127 143 case "exact": 128 $compare='=';144 $compare='='; 129 145 } 130 146 $metaValueQuery=array( 131 'value' => $value,132 'compare' => $compare133 );147 'value' => $value, 148 'compare' => $compare 149 ); 134 150 $metaQuery= array_merge($metaQuery,$metaValueQuery); 135 151 } 136 152 if(!empty($metaQuery)) { 137 153 138 154 $args['meta_query']=array($metaQuery); 139 155 } 140 156 } 141 157 $query = new \WP_Query($args); 142 158 143 159 $posts = $query->posts; 144 160 foreach ($posts as $post) { 145 $url = admin_url('post.php?post='.$post->ID.'&action=edit');146 $post_type = $post->post_type;147 $output[]=array(148 'link' => $url,149 'title' => $post->post_title,150 'status' => $post->post_status,151 'info' => 'Type: '.$post->post_type,152 'type' => 'Post'153 );154 } 155 return $output; 156 } 157 public function AASKP_getMedia($post_search,$filters,$flag = false) 158 {161 $url = admin_url('post.php?post='.$post->ID.'&action=edit'); 162 $post_type = $post->post_type; 163 $output[]=array( 164 'link' => $url, 165 'title' => $post->post_title, 166 'status' => $post->post_status, 167 'info' => 'Type: '.$post->post_type, 168 'type' => 'Post' 169 ); 170 } 171 return $output; 172 } 173 174 public function AASKP_getMedia($post_search,$filters,$flag = false) { 159 175 $output = array(); 160 176 $args=array( … … 171 187 $args['post_status']=$filters['status']; 172 188 } 173 189 174 190 if(!empty($filters['user'])) { 175 191 if(is_numeric($filters['user'])) { … … 183 199 $mediaPosts = get_posts($args); 184 200 foreach ($mediaPosts as $mediaPost) { 185 $url = admin_url('post.php?post='.$mediaPost->ID.'&action=edit'); 186 $post_type = $mediaPost->post_type; 187 $image_url = wp_get_attachment_image_src($mediaPost->ID); 188 $image_url_main = $image_url[0]; 189 if($image_url_main == false){ 190 $image_url = ''; 191 } 192 $output[]=array( 193 'link' => $url, 194 'title' => $mediaPost->post_title, 195 'info' => $mediaPost->post_date, 196 'image'=> $image_url_main, 197 'type' => 'Media' 198 ); 199 } 200 return $output; 201 } 202 public function AASKP_getTaxonomies($post_search,$filters,$flag = false) 203 { 204 $output = array(); 205 if($flag) { 206 if(!empty($filters['status']) || !empty($filters['user']) || !empty($filters['metaKey']) || !empty($filters['metaValue'])) { 207 return $output; 208 } 209 } 210 211 $taxonomies = get_terms( 212 array('search' => $post_search) 201 $url = admin_url('post.php?post='.$mediaPost->ID.'&action=edit'); 202 $post_type = $mediaPost->post_type; 203 $image_url = wp_get_attachment_image_src($mediaPost->ID); 204 $image_url_main = $image_url[0]; 205 if($image_url_main == false){ 206 $image_url = ''; 207 } 208 $output[]=array( 209 'link' => $url, 210 'title' => $mediaPost->post_title, 211 'info' => $mediaPost->post_date, 212 'image'=> $image_url_main, 213 'type' => 'Media' 213 214 ); 215 } 216 return $output; 217 } 218 219 public function AASKP_getTaxonomies($post_search,$filters,$flag = false) { 220 $output = array(); 221 if($flag) { 222 if(!empty($filters['status']) || !empty($filters['user']) || !empty($filters['metaKey']) || !empty($filters['metaValue'])) { 223 return $output; 224 } 225 } 226 227 $taxonomies = get_terms( 228 array('search' => $post_search) 229 ); 214 230 foreach ($taxonomies as $taxonomy) { 215 $url = admin_url('term.php?taxonomy='.$taxonomy->taxonomy.231 $url = admin_url('term.php?taxonomy='.$taxonomy->taxonomy. 216 232 '&tag_ID='.$taxonomy->term_id.'&post_type=post&wp_http_referer 217 233 =%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dcategory'); 218 $output[]=array(219 'link' => $url,220 'title' => $taxonomy->name,221 'info' => 'Taxonomy: '.$taxonomy->taxonomy,222 'type' => 'Taxonomy'223 );224 } 225 return $output; 226 } 227 public function AASKP_getPostMeta($post_search,$filters,$flag = false) 228 {234 $output[]=array( 235 'link' => $url, 236 'title' => $taxonomy->name, 237 'info' => 'Taxonomy: '.$taxonomy->taxonomy, 238 'type' => 'Taxonomy' 239 ); 240 } 241 return $output; 242 } 243 244 public function AASKP_getPostMeta($post_search,$filters,$flag = false) { 229 245 $output = array(); 230 246 if($flag) { … … 233 249 } 234 250 } 251 235 252 global $wpdb; 236 $postMeta = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."postmeta WHERE meta_key LIKE '%".$post_search."%' OR meta_value LIKE '%".$post_search."%'"); 253 $metaTableName = $wpdb->prefix . "postmeta"; 254 $queryMeta = $wpdb->prepare( 255 "SELECT * FROM {$metaTableName} WHERE meta_key LIKE %s OR meta_value LIKE %s;", 256 array( 257 '%' . $post_search . '%', 258 '%' . $post_search . '%', 259 ) 260 ); 261 $postMeta = $wpdb->get_results($queryMeta); 262 237 263 foreach ($postMeta as $meta) { 238 264 $url = admin_url('post.php?post='.$meta->post_id.'&action=edit'); … … 250 276 ); 251 277 } 252 } 253 else { 278 } else { 254 279 if(empty($filters['status'])) { 255 280 $output[]=array( … … 260 285 'type' => 'PostMeta' 261 286 ); 262 } 263 else { 287 } else { 264 288 if(strcmp($getPost->post_status, $filters['status']) == 0) { 265 289 $output[]=array( … … 273 297 } 274 298 } 275 } 276 277 else { 299 } else { 278 300 if (strpos($meta->meta_key, $post_search) !== false) { 279 280 $output[]=array( 281 'link' => $url, 282 'title' => $getPost->post_title, 283 'status' =>'PostMeta', 284 'info' => strip_tags($meta->meta_value), 285 'type' => 'PostMeta' 286 ); 287 } 288 else { 289 301 302 $output[]=array( 303 'link' => $url, 304 'title' => $getPost->post_title, 305 'status' =>'PostMeta', 306 'info' => strip_tags($meta->meta_value), 307 'type' => 'PostMeta' 308 ); 309 } else { 310 290 311 $output[]=array( 291 312 'link' => $url, … … 300 321 return $output; 301 322 } 302 public function AASKP_getComments($post_search,$filters,$flag = false) 303 {323 324 public function AASKP_getComments($post_search,$filters,$flag = false) { 304 325 $output = array(); 305 326 $args=array('search' => $post_search); … … 312 333 if(is_numeric($user)) { 313 334 $args['user_id'] = $user; 314 } 315 else { 335 } else { 316 336 $userData=get_user_by('login', $user); 317 337 $args['user_id'] = $userData->ID; … … 331 351 return $output; 332 352 } 333 public static function getInstance(){ 353 354 public static function getInstance() { 334 355 if(self::$instance == false){ 335 356 self::$instance = new AASKP_searchResults();
Note: See TracChangeset
for help on using the changeset viewer.