[wp-trac] [WordPress Trac] #43830: Being able to set a page as a homepage under the "Page Attribute" meta box

WordPress Trac noreply at wordpress.org
Mon Apr 23 09:47:26 UTC 2018


#43830: Being able to set a page as a homepage under the "Page Attribute" meta box
-------------------------+------------------------------
 Reporter:  dssaez       |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:  trunk
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------

Comment (by oscarpg41):

 Hi @dssaez.

 I've made a small change in your code. A validation has been added so that
 this new functionality can only be executed if the user has proper
 permission level.
 In this case, check box is only displayed and the options information is
 modified if current _user_can ( 'manage_options') is true.

 I enclose the changes in case you consider appropiate to attach them in
 your new diff.

 1. src/wp-admin/includes/meta-boxes.php
 {{{#!php
 <?php if ( current_user_can( 'manage_options' )) : ?> <!--- THIS IS NEW
 LINE: 967 -->
 <p>
         <label for="homepage">
                 <?php $checked = ( $post->ID == get_option(
 'page_on_front' ) ? 'checked' : 0 ); ?>
                 <input name="homepage" id="homepage" value="0"
 type="checkbox" <?php echo $checked; ?>>
                 <?php _e( 'Set as a hompage' ); ?>
         </label>
 </p>
 <?php endif;?><!--- THIS IS NEW LINE: 975 -->
 }}}

 2. src/wp-includes/post.php
 {{{#!php
 // Set page as a homepage
 if ( current_user_can( 'manage_options' )) { <!--- THIS IS NEW LINE: 3725
 -->
         if ( get_post_type( $post_ID ) == 'page' )
                 if ( isset( $_POST[ 'homepage' ] ) )
                 {
                         update_option( 'page_on_front', $post_ID );
                         update_option( 'show_on_front', 'page' );
                 }
                 else if ( get_option( 'page_on_front' ) == $post_ID )
                 {
                         update_option( 'page_on_front', '0' );
                         update_option( 'show_on_front', 'posts' );
                 }
 } <!--- THIS IS NEW LINE: 3737 -->
 }}}


 If you want, you can add these changes in your next diff.

 Another attendance to the WordCamp Madrid 2018
 Best regards

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43830#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list