ngg_ajax_rebuild_unique_slugs

This rebuild the slugs for albums, galleries and images as ajax routine, max 50 elements per request.

Description

(string) ngg_ajax_rebuild_unique_slugs(); 

Returns (string)

'1'


Usage

  1. if ( !function_exists( 'ngg_ajax_rebuild_unique_slugs' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextcellent-gallery/admin/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = ngg_ajax_rebuild_unique_slugs(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/admin/ajax.php  
  1. function ngg_ajax_rebuild_unique_slugs() { 
  2. global $wpdb; 
  3.  
  4. // check for correct NextGEN capability 
  5. if ( !current_user_can('NextGEN Change options') ) 
  6. die('No access'); 
  7.  
  8. $action = $_POST['_action']; 
  9. $offset = (int) $_POST['offset']; 
  10.  
  11. switch ($action) { 
  12. case 'images': 
  13. $images = $wpdb->get_results("SELECT * FROM $wpdb->nggpictures ORDER BY pid ASC LIMIT $offset, 50", OBJECT_K); 
  14. if ( is_array($images) ) { 
  15. foreach ($images as $image) { 
  16. //slug must be unique, we use the alttext for that 
  17. $image->slug = nggdb::get_unique_slug( sanitize_title( $image->alttext ), 'image', $image->pid ); 
  18. $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->nggpictures SET image_slug= '%s' WHERE pid = '%d'" , $image->slug, $image->pid ) ); 
  19. break; 
  20. case 'gallery': 
  21. $galleries = $wpdb->get_results("SELECT * FROM $wpdb->nggallery ORDER BY gid ASC LIMIT $offset, 50", OBJECT_K); 
  22. if ( is_array($galleries) ) { 
  23. foreach ($galleries as $gallery) { 
  24. //slug must be unique, we use the title for that 
  25. $gallery->slug = nggdb::get_unique_slug( sanitize_title( $gallery->title ), 'gallery', $gallery->gid ); 
  26. $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->nggallery SET slug= '%s' WHERE gid = '%d'" , $gallery->slug, $gallery->gid ) ); 
  27. break; 
  28. case 'album': 
  29. $albumlist = $wpdb->get_results("SELECT * FROM $wpdb->nggalbum ORDER BY id ASC LIMIT $offset, 50", OBJECT_K); 
  30. if ( is_array($albumlist) ) { 
  31. foreach ($albumlist as $album) { 
  32. //slug must be unique, we use the name for that 
  33. $album->slug = nggdb::get_unique_slug( sanitize_title( $album->name ), 'album', $album->id ); 
  34. $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->nggalbum SET slug= '%s' WHERE id = '%d'" , $album->slug, $album->id ) ); 
  35. break; 
  36.  
  37. die(1);