Skip to:
Content

BuddyPress.org

Ticket #5333: 5333.02.patch

File 5333.02.patch, 6.1 KB (added by boonebgorges, 10 years ago)
  • bp-blogs/bp-blogs-functions.php

    diff --git bp-blogs/bp-blogs-functions.php bp-blogs/bp-blogs-functions.php
    index d032cfb..6a7d860 100644
    add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescrip 
    255255 *
    256256 * See #4090, #3746, #2546 for background.
    257257 *
    258  * @since BuddyPress (1.9.0)
     258 * @since BuddyPress (2.0.0)
    259259 *
    260260 * @param string $new_status New status for the post.
    261261 * @param string $old_status Old status for the post.
    262262 * @param object $post Post data.
    263263 */
    264 function bp_blogs_catch_published_post( $new_status, $old_status, $post ) {
     264function bp_blogs_catch_transition_post_status( $new_status, $old_status, $post ) {
    265265
    266         // Only record published posts
    267         if ( 'publish' !== $new_status ) {
     266        // Do nothing for edits
     267        if ( $new_status === $old_status ) {
    268268                return;
    269269        }
    270270
    271         // Don't record edits (publish -> publish)
    272         if ( 'publish' === $old_status ) {
    273                 return;
    274         }
     271        // Publishing a previously unpublished post
     272        if ( 'publish' === $new_status ) {
     273                return bp_blogs_record_post( $post->ID, $post );
    275274
    276         return bp_blogs_record_post( $post->ID, $post );
     275        // Unpublishing a previously published post
     276        } else if ( 'publish' === $old_status ) {
     277                return bp_blogs_remove_post( $post->ID );
     278        }
    277279}
    278 add_action( 'transition_post_status', 'bp_blogs_catch_published_post', 10, 3 );
     280add_action( 'transition_post_status', 'bp_blogs_catch_transition_post_status', 10, 3 );
    279281
    280282/**
    281283 * Record a new blog post in the BuddyPress activity stream.
  • new file p-core/deprecated/2.0.php

    diff --git bp-core/deprecated/2.0.php bp-core/deprecated/2.0.php
    new file mode 100644
    index 0000000..d5b9c5e
    - +  
     1<?php
     2/**
     3 * Deprecated Functions
     4 *
     5 * @package BuddyPress
     6 * @subpackage Core
     7 * @deprecated 2.0.0
     8 */
     9
     10// Exit if accessed directly
     11if ( !defined( 'ABSPATH' ) ) exit;
     12
     13/**
     14 * @deprecated BuddyPress (2.0.0)
     15 */
     16function bp_blogs_catch_published_post() {
     17        _deprecated_function( __FUNCTION__, '2.0', 'bp_blogs_catch_transition_post_status()' );
     18}
  • new file tests/testcases/blogs/functions.php

    diff --git tests/testcases/blogs/functions.php tests/testcases/blogs/functions.php
    new file mode 100644
    index 0000000..452627f
    - +  
     1<?php
     2
     3/**
     4 * @group blogs
     5 * @group functions
     6 */
     7class BP_Tests_Blogs_Functions extends BP_UnitTestCase {
     8        /**
     9         * @group bp_blogs_catch_transition_post_status
     10         */
     11        public function test_transition_post_status_publish_to_publish() {
     12                $post_id = $this->factory->post->create( array(
     13                        'post_status' => 'publish',
     14                        'post_type' => 'post',
     15                ) );
     16                $post = get_post( $post_id );
     17
     18                // 'publish' => 'publish'
     19                $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' );
     20
     21                $post->post_status = 'publish';
     22                $post->post_content .= ' foo';
     23
     24                wp_update_post( $post );
     25
     26                $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity (no change)' );
     27        }
     28
     29        /**
     30         * @group bp_blogs_catch_transition_post_status
     31         */
     32        public function test_transition_post_status_draft_to_draft() {
     33                $post_id = $this->factory->post->create( array(
     34                        'post_status' => 'draft',
     35                        'post_type' => 'post',
     36                ) );
     37                $post = get_post( $post_id );
     38
     39                $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Unpublished post should not have activity' );
     40
     41                $post->post_status = 'draft';
     42                $post->post_content .= ' foo';
     43
     44                wp_update_post( $post );
     45
     46                $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Unpublished post should not have activity (no change)' );
     47        }
     48
     49        /**
     50         * @group bp_blogs_catch_transition_post_status
     51         */
     52        public function test_transition_post_status_draft_to_publish() {
     53                $post_id = $this->factory->post->create( array(
     54                        'post_status' => 'draft',
     55                        'post_type' => 'post',
     56                ) );
     57                $post = get_post( $post_id );
     58
     59                $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Unpublished post should not have activity' );
     60
     61                $post->post_status = 'publish';
     62                $post->post_content .= ' foo';
     63
     64                wp_update_post( $post );
     65
     66                $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' );
     67        }
     68
     69        /**
     70         * @group bp_blogs_catch_transition_post_status
     71         */
     72        public function test_transition_post_status_publish_to_draft() {
     73                $post_id = $this->factory->post->create( array(
     74                        'post_status' => 'publish',
     75                        'post_type' => 'post',
     76                ) );
     77                $post = get_post( $post_id );
     78
     79                $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' );
     80
     81                $post->post_status = 'draft';
     82                $post->post_content .= ' foo';
     83
     84                wp_update_post( $post );
     85
     86                $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Unpublished post should not have activity' );
     87        }
     88
     89        /**
     90         * @group bp_blogs_catch_transition_post_status
     91         */
     92        public function test_transition_post_status_wp_delete_post() {
     93                $post_id = $this->factory->post->create( array(
     94                        'post_status' => 'publish',
     95                        'post_type' => 'post',
     96                ) );
     97                $post = get_post( $post_id );
     98
     99                $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' );
     100
     101                wp_delete_post( $post->ID );
     102
     103                $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Unpublished post should not have activity' );
     104        }
     105
     106        /**
     107         * @group bp_blogs_catch_transition_post_status
     108         */
     109        public function test_transition_post_status_wp_trash_post() {
     110                $post_id = $this->factory->post->create( array(
     111                        'post_status' => 'publish',
     112                        'post_type' => 'post',
     113                ) );
     114                $post = get_post( $post_id );
     115
     116                $this->assertTrue( $this->activity_exists_for_post( $post_id ), 'Published post should have activity' );
     117
     118                wp_trash_post( $post->ID );
     119
     120                $this->assertFalse( $this->activity_exists_for_post( $post_id ), 'Unpublished post should not have activity' );
     121        }
     122
     123        protected function activity_exists_for_post( $post_id ) {
     124                $a = bp_activity_get( array(
     125                        'component' => buddypress()->blogs->id,
     126                        'action' => 'new_blog_post',
     127                        'item_id' => get_current_blog_id(),
     128                        'secondary_item_id' => $post_id,
     129                ) );
     130
     131                return ! empty( $a['total'] );
     132        }
     133}