Advertisement
Guest User

Changes Add Media to Add Gallery in the WordPress Dashboard

a guest
May 23rd, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: wp-forums: Always using gallery instead of single media
  4. Plugin URI: https://github.com/aubreypwd/wp-forums/
  5. Description: Changes Add Media to Add Gallery in the WordPress Dashboard
  6. Version: 1.0.0
  7. Author: Aubrey Portwood
  8. Author URI: http://twitter.com/aubreypwd
  9. License: GPL2
  10. Topic URI: https://wordpress.org/support/topic/always-using-gallery-instead-of-single-media
  11. */
  12.  
  13. /*
  14.  * Copyright 2015 Aubrey Portwood <aubreypwd@gmail.com>
  15.  *
  16.  * This program is free software; you can redistribute it and/or modify
  17.  * it under the terms of the GNU General Public License, version 2, as
  18.  * published by the Free Software Foundation.
  19.  *
  20.  * This program is distributed in the hope that it will be useful,
  21.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.  * GNU General Public License for more details.
  24.  *
  25.  * You should have received a copy of the GNU General Public License
  26.  * along with this program; if not, write to the Free Software
  27.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  28.  */
  29.  
  30. /**
  31.  * Change Add Media to Add Gallery on Post Edit Screens.
  32.  *
  33.  * @author Aubrey Portwood
  34.  * @since  1.0.0
  35.  *
  36.  * @param  string $translated_text The translated text.
  37.  * @param  string $text            The original text.
  38.  * @param  string $domain          The text domain.
  39.  *
  40.  * @return string                  If we're on a edit post screen, replace Add Media
  41.  *                                 with Add Gallery.
  42.  */
  43. function wp_forums_aubreypwd_change_add_media( $translated_text, $text, $domain ) {
  44.  
  45.     // Only on the admin side.
  46.     if ( ! is_admin() ) {
  47.         return $translated_text;
  48.     }
  49.  
  50.     // The current screen (because we can't get_current_screen()).
  51.     $self = basename( $_SERVER['PHP_SELF'] );
  52.  
  53.     // Just when editing or adding a new post.
  54.     $screens = array(
  55.         'post-new.php',
  56.         'post.php',
  57.     );
  58.  
  59.     // Only show on the above screens.
  60.     if ( ! in_array( $self, $screens ) ) {
  61.         return $translated_text;
  62.     }
  63.  
  64.     if ( 'Add Media' == $text ) {
  65.         return __( 'Add Gallery' );
  66.     }
  67.  
  68.     return $translated_text;
  69. }
  70. add_filter( 'gettext', 'wp_forums_aubreypwd_change_add_media', 20, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement