Ticket #2284: edit_page_hooks_2.diff

File edit_page_hooks_2.diff, 5.6 kB (added by steveluscher, 1 year ago)

How about something like this? I tried to change only what was necessary, and tried to preserve the colspan of the "Action" header on the edit-pages screen.

  • wp-admin/includes/template.php

    old new  
    161161        } 
    162162} 
    163163 
    164 function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) { 
     164function page_rows( $page_columns, $parent = 0, $level = 0, $pages = 0, $hierarchy = true) { 
    165165        global $wpdb, $class, $post; 
    166166 
    167167        if (!$pages ) 
     
    175175                if ( $hierarchy && ($post->post_parent != $parent) ) 
    176176                        continue; 
    177177 
    178                 $post->post_title = wp_specialchars( $post->post_title ); 
     178                add_filter('the_title','wp_specialchars'); 
     179                $class = ('alternate' == $class) ? '' : 'alternate'; 
    179180                $pad = str_repeat( '— ', $level ); 
    180181                $id = (int) $post->ID; 
    181                 $class = ('alternate' == $class ) ? '' : 'alternate'; 
    182 ?> 
    183   <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>  
    184     <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th>  
    185     <td> 
    186       <?php echo $pad; ?><?php the_title() ?> 
    187     </td>  
    188     <td><?php the_author() ?></td> 
    189     <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td>  
    190         <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e( 'View' ); ?></a></td> 
    191     <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>  
    192     <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) .  "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>  
    193   </tr>  
    194182 
    195 <?php 
    196                 if ( $hierarchy ) page_rows( $id, $level + 1, $pages ); 
     183                echo '<tr id="page-' . $id . '" class="' . $class . '">'; 
     184 
     185                foreach($page_columns as $column_name=>$column_display_name) { 
     186 
     187                        switch($column_name) { 
     188 
     189                        case 'id': 
     190                                ?> 
     191                                <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th> 
     192                                <?php 
     193                                break; 
     194 
     195                        case 'title': 
     196                                ?> 
     197                                <td> 
     198                             <?php echo $pad; ?><?php the_title() ?> 
     199            </td> 
     200                                <?php 
     201                                break; 
     202                                 
     203                        case 'owner': 
     204                                ?> 
     205                                <td><?php the_author() ?></td> 
     206                                <?php 
     207                                break; 
     208 
     209                        case 'updated': 
     210                                ?> 
     211                                <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td> 
     212                                <?php 
     213                                break; 
     214 
     215                        case 'control_view': 
     216                                ?> 
     217                                <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td> 
     218                                <?php 
     219                                break; 
     220 
     221                        case 'control_edit': 
     222                                ?> 
     223                                <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td> 
     224                                <?php 
     225                                break; 
     226 
     227                        case 'control_delete': 
     228                                ?> 
     229                                <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) .  "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td> 
     230                                <?php 
     231                                break; 
     232 
     233                        default: 
     234                                ?> 
     235                                <td><?php do_action('manage_pages_custom_column', $column_name, $id); ?></td> 
     236                                <?php 
     237                                break; 
     238                        } 
     239                } 
     240                echo '</tr>'; 
     241                 
     242                if($hierarchy) page_rows( $page_columns, $id, $level + 1, $pages ); 
    197243        } 
    198244} 
    199245 
  • wp-admin/edit-pages.php

    old new  
    7070$all = !( $h2_search || $post_status_q ); 
    7171 
    7272if ($posts) { 
     73        // define the columns to display, the syntax is 'internal name' => 'display name' 
     74        $page_columns = array( 
     75                'id'         => '<div style="text-align: center">' . __('ID') . '</div>', 
     76                'title'      => __('Title'), 
     77                'owner'                  => __('Owner'), 
     78                'updated'        => __('Updated') 
     79        ); 
     80        $page_columns = apply_filters('manage_pages_columns', $page_columns); 
     81 
     82        // you can not edit these at the moment 
     83        $page_columns['control_view']   = ''; 
     84        $page_columns['control_edit']   = ''; 
     85        $page_columns['control_delete'] = ''; 
    7386?> 
    7487<table class="widefat">  
    7588  <thead> 
    7689  <tr> 
    77     <th scope="col" style="text-align: center"><?php _e('ID') ?></th> 
    78     <th scope="col"><?php _e('Title') ?></th> 
    79     <th scope="col"><?php _e('Owner') ?></th> 
    80         <th scope="col"><?php _e('Updated') ?></th> 
    81         <th scope="col" colspan="3" style="text-align: center"><?php _e('Action'); ?></th> 
     90    <?php  
     91         $action_colspan = 0; 
     92         foreach($page_columns as $column_type => $column_display_name) { 
     93                if(preg_match('/^control_/', $column_type)) { 
     94             $action_colspan++; 
     95           } else { 
     96                  if($action_colspan > 0) { 
     97                    echo '<th scope="col" style="text-align: center" colspan="' . $action_colspan . '">' . __('Action') . '</th>'; 
     98                         $action_colspan = 0; 
     99                  } 
     100                  echo '<th scope="col">' . $column_display_name . '</th>'; 
     101                } 
     102         } 
     103    if($action_colspan > 0) { 
     104           echo '<th scope="col" style="text-align: center" colspan="' . $action_colspan . '">' . __('Action') . '</th>'; 
     105                $action_colspan = 0; 
     106         } 
     107         ?> 
    82108  </tr> 
    83109  </thead> 
    84110  <tbody id="the-list"> 
    85 <?php page_rows(0, 0, $posts, $all); ?> 
     111<?php page_rows($page_columns, 0, 0, $posts, $all); ?> 
    86112  </tbody> 
    87113</table> 
    88114