Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. /*
  3. * Include the URLs for all image sizes in the WordPress Media Library.
  4. * Not normally needed but if you're trying to gather a bunch of URLs it helps.
  5. * Hide the column in Screen Options when not needed.
  6. *
  7. * Drop this in your site plugin or function.php
  8. */
  9.  
  10. // Adds a "Sizes" column
  11. function sizes_column( $cols ) {
  12. $cols["sizes"] = "Sizes";
  13. return $cols;
  14. }
  15.  
  16. // Fill the Sizes column
  17. function sizes_value( $column_name, $id ) {
  18. if ( $column_name == "sizes" ) {
  19.  
  20. // Including the direcory makes the list much longer but required if you use /year/month for uploads
  21. $up_load_dir = wp_upload_dir();
  22. $dir = $up_load_dir['url'];
  23.  
  24. // Get the info for each media item
  25. $meta = wp_get_attachment_metadata($id);
  26.  
  27. // and loop + output
  28. foreach ( $meta['sizes'] as $name=>$info) {
  29. echo "<strong>" . $name . "</strong><br>";
  30. echo "<small>" . $dir . "/" . $info['file'] . " </small><br>";
  31. }
  32. }
  33. }
  34.  
  35. // Hook actions to admin_init
  36. function hook_new_media_columns() {
  37. add_filter( 'manage_media_columns', 'sizes_column' );
  38. add_action( 'manage_media_custom_column', 'sizes_value', 10, 2 );
  39. }
  40. add_action( 'admin_init', 'hook_new_media_columns' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement