Opened 7 years ago
Last modified 6 years ago
#43830 new enhancement
Being able to set a page as a homepage under the "Page Attribute" meta box
Reported by: | dssaez | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Hi everyone,
As the file attached shows, the idea is to allow the user to set the page as a homepage from the admin panel of the page without going to the "settings" -> "reading" section.
Tank you.
Team from contributor day in Madrid
Attachments (2)
Change History (6)
#1
@
7 years ago
Hi again,
we have uploaded the file "43830.diff".
We have added a checkbox under the "page attributes" on the admin panel of a page to select the page as a homepage. The code has been added on the file meta-boxes.php
And also on the file post.php where the post is being save or update.
Regards from contributor day of Wordcamp Madrid 2018.
#2
@
7 years ago
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.
- src/wp-admin/includes/meta-boxes.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 -->
- src/wp-includes/post.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
"Page attributes" meta box modification