Make WordPress Core

Opened 4 years ago

Closed 2 years ago

Last modified 2 years ago

#17906 closed enhancement (maybelater)

Refactor submit box code

Reported by: scribu Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch
Focuses: Cc:


The code for the post submit metabox is a mess. It should be cleaned up, so that changes such as #17028 can be done more easily.

Will post a patch shortly.

Attachments (2)

17906.diff (6.0 KB) - added by scribu 4 years ago.
first pass
17906.2.diff (6.1 KB) - added by scribu 4 years ago.

Download all attachments as: .zip

Change History (15)

@scribu4 years ago

first pass

comment:1 @scribu4 years ago

  • Keywords has-patch 3.3-early added

comment:2 @GaryJ4 years ago

In your patch, the posts_status dropdown option value for future gets changed from future to publish.

(Some code standards whitespace missing in the first two green blocks too.)

@scribu4 years ago

comment:3 @scribu4 years ago

A very good catch. See 17906.2.diff.

I noticed a similar bug in the current code, where private posts get the status 'publish':

<option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e('Privately Published') ?></option>

comment:4 @GaryJ4 years ago

I noticed that too, but assumed that privately published or publicly published posts still had the same post_status (I was only checking your patch, not the wider code).

Thinking slightly wider (may be out of scope for this ticket), as the $status_labels are likely used elsewhere (Quick Edit for instance), could the array be wrapped in a function and placed somewhere suitable so all instances of post status labels could access it?

comment:5 @scribu4 years ago

Actually, I was thinking of moving them to their respective post status object label array.

comment:6 @scribu4 years ago

After grepping through the source code, these strings seem to be specific to the submit box. The only other place where the 'Privately Published' string appears, for example, is in wp-includes/script-loader.php.

comment:7 @GaryJ4 years ago

wp-admin/includes/class-wp-posts-list-table.php includes similar strings for the Quick Edit - the question to ask might be why is there an inconsistent use of "Private" in one place and "Privately Published" in another, which makes code un-DRY and makes more work for translators.

comment:8 @scribu4 years ago

Related: #12706

comment:9 @scribu4 years ago

There's still a bug in my patch, related to setting a password for a post. It reverts to private.

comment:10 @scribu4 years ago

One way to simplify the logic would be to completely separate visibility from status.

So, you would have statuses, related to editorial flow:

  • draft
  • pending
  • published
  • scheduled

And visibility:

  • public
  • private
  • password protected

Thus, you could have private drafts etc.

comment:11 in reply to: ↑ description @c3mdigital2 years ago

  • Keywords 3.3-early removed
  • Resolution set to maybelater
  • Status changed from new to closed

Replying to scribu:

The code for the post submit metabox is a mess. It should be cleaned up, so that changes such as #17028 can be done more easily.

Will post a patch shortly.

I agree this is a mess but while there are logic improvements this is mostly refactoring for coding standards and readability and there has been no activity in 2 years. See: http://make.wordpress.org/core/2011/03/23/code-refactoring/

comment:12 @nacin2 years ago

I do like the gist of 17906.2.diff but this no longer applies cleanly and likely needs some other tweaks.

comment:13 @SergeyBiryukov2 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.