Opened 9 years ago
Closed 9 years ago
#35600 closed enhancement (fixed)
Hooks for post sticky status changes
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.6 | Priority: | normal |
Severity: | normal | Version: | 2.7 |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Currently sticky post status changes are hookable using the update_option
hook variants which are fired when stick_post
and unstick_post
functions are called.
Getting the sticked post in those hooks is a little bit annoying, as you have to parse old and new values for an updated option.
I'd suggest adding action hooks to stick_post
and unstick_post
to fire some action called such as
<?php do_action('post_sticked', $post->ID); do_action('post_unsticked', $post->ID);
I could not find any straightforward hook that allows hooking as described above.
Let me know if there is a feature like the one above which I could not find, and whether the suggested enhancement would be good or bad, or in need of more discussion.
One thing I would like to know whether this would have broader benefits or whether this would be considered a small goal for a very small portion of developers.
Marked the version as latest stable, but I presume the feature is not available in any version which has included sticky posts.
Attachments (5)
Change History (24)
#2
@
9 years ago
- Keywords needs-docs added
New hooks need to be documented as per the documentation standards.
#3
@
9 years ago
Oh boy, completely forgot about that one. Let me adjust the patch and send a new one.
#4
@
9 years ago
- Keywords needs-docs removed
I used @since 4.5.0
as saw that one elsewhere too. Should be adjusted in case this is implemented to some earlier version.
#5
@
9 years ago
- Version changed from 4.4.1 to 2.7
Changed the version to 2.7 as hooks in their current state were introduced in 2.1 and sticky posts arrived in version 2.7.
#7
@
9 years ago
@ojrask The tests must be compatible with PHP 5.2. For testing hooks I suggest to use MockAction
from /tests/phpunit/includes/utils.php.
This ticket was mentioned in Slack in #core by chriscct7. View the logs.
9 years ago
#10
@
9 years ago
How is this different from using the action "update_option_sticky_posts" ? Just asking.
#11
@
9 years ago
@ojrask In addition to updating the unit tests to be PHP 5.2 compatible, the hook names should be post_stuck
and post_unstuck
as stuck is the past (past participle) of stick. The dead line for enhancements for 4.6 is about a month away (June 29) if you're still interested in pursuing this patch.
#12
@
9 years ago
@voldemortensen I'll see that the patch is updated accordingly. Stuck and unstuck do make sense.
@screamingdev Using the update_option_$key
hook is cumbersome and requires the developer to do some option value juggling (to parse the difference before and after), instead of a hook providing the exact post ID which was stuck or unstuck. Please correct me if this is not the case. :)
#13
@
9 years ago
Added a revised patch (35600-2.diff
), which renames stick -> stuck
and unstick -> unstuck
, also adjusts tests so they should work fine in PHP 5.2. Additionally changed @since
from 4.5.0
to 4.6.0
.
Let me know if something is still in need of adjustments. :)
#15
@
9 years ago
- Keywords needs-refresh added
@ojrask The tests should also use the same Orwellian Newspeak unstuck
rather than unstickied
, unstick
, unsticking
etc :)
Patch for #35600, includes logic and tests.