WordPress.org

Make WordPress Core

Opened 18 months ago

Last modified 9 months 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:
PR Number:

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)

Selection_007.png (108.9 KB) - added by dssaez 18 months ago.
"Page attributes" meta box modification
43830.diff (2.5 KB) - added by dssaez 18 months ago.

Download all attachments as: .zip

Change History (6)

@dssaez
18 months ago

"Page attributes" meta box modification

@dssaez
18 months ago

#1 @dssaez
18 months 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 @oscarpg41
18 months 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.

  1. 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 -->
    
  1. 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

#3 @seusmaniqbal
18 months ago

Hello @dssaez,

Welcome to the WordPress Core Trac.

Thanks,

#4 @pento
9 months ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.