Making WordPress.org

Changeset 7621


Ignore:
Timestamp:
08/17/2018 05:48:26 PM (6 years ago)
Author:
obenland
Message:

O2 Private Posts: Handle private posts from wp-admin

Fixes a bug where ToDo status and post tags were not properly set, when a private post was published from wp-admin. The o2 plugin only accounts for public posts.

Fixes #3768.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/o2-private-posts/o2-private-posts.php

    r7618 r7621  
    2828    add_filter( 'o2_create_post', __NAMESPACE__ . '\set_post_status', 10, 2 );
    2929    add_action( 'o2_writeapi_post_created', __NAMESPACE__ . '\handle_meta_data', 10, 2 );
     30    add_action( 'transition_post_status', __NAMESPACE__ . '\handle_admin_meta_data', 12, 3 );
    3031}
    3132add_filter( 'init', __NAMESPACE__ . '\init' );
     
    100101
    101102    if ( class_exists( 'o2_Tags' ) ) {
    102         $post      = get_post( $post_id );
    103         $post_tags = o2_Tags::find_tags( $post->post_content, true );
    104         $post_tags = array_unique( $post_tags );
     103        $post = get_post( $post_id );
     104
     105        if ( ! empty( $GLOBALS['o2'] ) ) {
     106            $post_tags = $GLOBALS['o2']->tags->gather_all_tags( $post );
     107        } else {
     108            $post_tags = o2_Tags::find_tags( $post->post_content, true );
     109            $post_tags = array_unique( $post_tags );
     110        }
    105111
    106112        if ( ! empty( $post_tags ) ) {
     
    109115    }
    110116}
     117
     118/**
     119 * Sets O2_ToDo state and post tags when a private post is published from wp-admin.
     120 *
     121 * @param string   $new  Status being switched to.
     122 * @param string   $old  Status being switched from.
     123 * @param \WP_Post $post The full Post object.
     124 */
     125function handle_admin_meta_data( $new, $old, $post ) {
     126    if ( 'private' === $new ) {
     127        handle_meta_data( $post->ID, (object) [ '_post_privately' => true ] );
     128    }
     129}
Note: See TracChangeset for help on using the changeset viewer.