WordPress.org

Plugin Directory

Changeset 541709


Ignore:
Timestamp:
05/09/12 03:04:19 (2 years ago)
Author:
jamescollins
Message:

Custom Post Type Editor v1.0.1

Location:
cpt-editor/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • cpt-editor/trunk/cpt-editor.php

    r541683 r541709  
    44Plugin URI: http://om4.com.au/wordpress-plugins/custom-post-type-editor/ 
    55Description: Customise the text labels/names for any registered custom post type. 
    6 Version: 1.0 
     6Version: 1.0.1 
    77Author: OM4 
    88Author URI: http://om4.com.au/ 
     
    7070        $this->url = trailingslashit( plugins_url( '', __FILE__ ) ); 
    7171 
    72         register_activation_hook( __FILE__, array( &$this, 'Activate' ) ); 
     72        register_activation_hook( __FILE__, array( $this, 'Activate' ) ); 
    7373 
    7474        add_action( 'plugins_loaded', array( $this, 'LoadDomain' ) ); 
     
    9494     */ 
    9595    function LoadDomain() { 
    96         load_plugin_textdomain( 'om4-cpt-editor', WP_PLUGIN_DIR . '/' . dirname( plugin_basename( __FILE__ ) ) ); 
     96        load_plugin_textdomain( 'om4-cpt-editor', false, "{$this->dirname}/languages" ); 
    9797    } 
    9898 
     
    132132        global $wp_post_types; 
    133133 
    134         if ( $this->IsSettingsPage() && !isset($this->cpt_originals[$post_type]) ) { 
     134        if ( $this->NeedToBackupCustomPostTypes() && !isset($this->cpt_originals[$post_type]) ) { 
    135135            // Save a copy of the original (unmodified) version of this post type 
    136136            $this->cpt_originals[$post_type] = unserialize(serialize( $wp_post_types[$post_type] )); 
     
    173173    public function AdminMenu() { 
    174174        add_options_page( __( 'Custom Post Types', 'om4-cpt-editor' ), __( 'Custom Post Types', 'om4-cpt-editor' ), 'manage_options', basename( __FILE__ ), array( $this, 'AdminPage' ) ); 
     175 
     176        $this->OverrideBuiltInCustomPostTypeMenuLabels(); 
     177    } 
     178 
     179    /** 
     180     * Unfortunately WordPress' built-in Custom Post Types (post, page, attachment) don't automatically use their defined labels in the Dashboard menu. 
     181     * Instead, they are hard-coded in wp-admin/menu.php. 
     182     * 
     183     * This function checks to see if the user has modified the labels for any of these built-in custom post types, 
     184     * and if so it manually overrides the dashboard menu so that it uses these defined labels. 
     185     */ 
     186    private function OverrideBuiltInCustomPostTypeMenuLabels() { 
     187        global $menu, $submenu; 
     188 
     189        $builtins_that_need_overrides = array( 
     190            'post' 
     191            ,'page' 
     192            ,'attachment' 
     193        ); 
     194 
     195        if ( is_array( $this->settings['types'] ) ) { 
     196            foreach ( $builtins_that_need_overrides as $post_type ) { 
     197 
     198                if ( !is_array($this->settings['types'][$post_type]['labels']) ) { 
     199                    // The user hasn't customised the labels for this built-in CPT 
     200                    continue; 
     201                } 
     202 
     203                // Override built-in CPT labels 
     204                $admin_labels_that_need_overrides = array( 
     205                    'menu_name' 
     206                    , 'all_items' 
     207                    ,'add_new' 
     208                ); 
     209                foreach ( $admin_labels_that_need_overrides as $label_name_to_override ) { 
     210 
     211                    if ( isset($this->settings['types'][$post_type]['labels'][$label_name_to_override]) ) { 
     212                        // The user has customised this label 
     213 
     214                        $id = null; 
     215                        $file = null; 
     216                        // These $id and $file values are taken from wp-admin/menu.php (where they are hard-coded) 
     217                        switch ( $post_type ) { 
     218                            case 'post': // Posts 
     219                                $id = 5; 
     220                                $file = 'edit.php'; 
     221                                break; 
     222                            case 'attachment': // Media 
     223                                $id = 10; 
     224                                $file = 'upload.php'; 
     225                                break; 
     226                            case 'page'; // Pages 
     227                                $id = 20; 
     228                                $file = 'edit.php?post_type=page'; 
     229                                break; 
     230                        } 
     231 
     232                        if ( !is_null($id) ) { 
     233                            switch ( $label_name_to_override ) { 
     234                                case 'menu_name': // Top level menu item label 
     235                                    if ( isset($menu[$id][0]) ) 
     236                                        $menu[$id][0] = $this->settings['types'][$post_type]['labels'][$label_name_to_override]; 
     237                                    break; 
     238                                case 'all_items': // 'All Items' sub menu label 
     239                                    if ( isset($submenu[$file][5][0]) ) 
     240                                        $submenu[$file][5][0] = $this->settings['types'][$post_type]['labels'][$label_name_to_override]; 
     241                                    break; 
     242                                case 'add_new': // 'Add New' sub menu label 
     243                                    if ( isset($submenu[$file][10][0]) ) 
     244                                        $submenu[$file][10][0] = $this->settings['types'][$post_type]['labels'][$label_name_to_override]; 
     245                                    break; 
     246                            } 
     247                        } 
     248                    } 
     249                } 
     250            } 
     251        } 
    175252    } 
    176253 
     
    247324        $labels['singular_name']['description'] = __('Name for one object of this post type.', 'om4-cpt-editor' ); 
    248325 
    249         $labels['add_new']['name'] = __( 'Add New:', 'om4-cpt-editor' ); 
    250         $labels['add_new']['description'] =  __('The add new text.', 'om4-cpt-editor' ); 
    251  
    252326        $labels['add_new_item']['name'] = __( 'Add New Item:', 'om4-cpt-editor' ); 
    253327        $labels['add_new_item']['description'] = __('The add new item text.', 'om4-cpt-editor' ); 
     
    279353 
    280354        $labels['all_items']['name'] = __( 'All Items:', 'om4-cpt-editor' ); 
    281         $labels['all_items']['description'] = __('The text used in the Dashboard menu\'s \'all items\' menu item.', 'om4-cpt-editor' ); 
     355        $labels['all_items']['description'] = __('The text used in the Dashboard menu\'s \'all items\' submenu item.', 'om4-cpt-editor' ); 
     356 
     357        $labels['add_new']['name'] = __( 'Add New:', 'om4-cpt-editor' ); 
     358        $labels['add_new']['description'] =  __('The text used in the Dashboard menu\'s \'add new\' submenu item.', 'om4-cpt-editor' ); 
    282359 
    283360        $labels['name_admin_bar']['name'] = __( 'Admin Bar Name:', 'om4-cpt-editor' ); 
  • cpt-editor/trunk/readme.txt

    r541683 r541709  
    55Requires at least: 3.2 
    66Tested up to: 3.4 
    7 Stable tag: 1.0 
     7Stable tag: trunk 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    2020* The `Pages` Custom Post Type (created by WordPress Core) 
    2121* The `Media` Custom Post Type (created by WordPress Core) 
    22 * The `Revisions` Custom Post Type (created by WordPress Core) 
    2322* Any Custom Post Type that is created by a WordPress plugin 
    2423* Any Custom Post Type that is created by a WordPress theme 
     
    5251No. If you deactivate this plugin, your Custom Post Type definitions will revert to their defaults. 
    5352 
     53= I found a bug. How can I contribute a patch or bug fix? = 
     54Fork our [Github Repository](https://github.com/OM4/cpt-editor) and send us a pull request. 
     55 
    5456== Screenshots == 
    55571. The list of registered Custom Post Types 
     
    5860== Changelog == 
    5961 
     62= 1.0.1 = 
     63* Add support for customising WordPress' built-in Posts, Pages and Media dashboard menu labels. Thanks to Aaron Rutley for testing this. 
     64 
    6065= 1.0 = 
    6166* Initial release. 
     67 
     68== Upgrade Notice == 
     69 
     70= 1.0.1 = 
     71* Adds support for customising WordPress' built-in Posts, Pages and Media dashboard menu labels. 
Note: See TracChangeset for help on using the changeset viewer.