Skip to:
Content

bbPress.org

Changeset 6922


Ignore:
Timestamp:
11/07/2019 07:40:16 PM (2 weeks ago)
Author:
johnjamesjacoby
Message:

Statuses: normalize status related functions across post types.

This commit adds 2 missing functions for forum statuses, and relocates all of them to the correct functions.php files for their post types.

Location:
trunk/src/includes
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/functions.php

    r6920 r6922  
    18691869        // Forum
    18701870        case bbp_get_forum_post_type() :
    1871             $post_status = array( bbp_get_private_status_id(), bbp_get_hidden_status_id() );
     1871            $post_status = bbp_get_non_public_forum_statuses();
    18721872            break;
    18731873
     
    18791879        // Reply
    18801880        case bbp_get_reply_post_type() :
     1881            $post_status = bbp_get_non_public_reply_statuses();
     1882            break;
     1883
     1884        // Any
    18811885        default :
    1882             $post_status = bbp_get_non_public_reply_statuses();
     1886            $post_status = bbp_get_public_status_id();
    18831887            break;
    18841888    }
     
    19121916    }
    19131917
    1914     // Get the public post status
    1915     $post_status = array( bbp_get_public_status_id() );
    1916 
    1917     // Add closed status if topic post type
    1918     if ( bbp_get_topic_post_type() === $post_type ) {
    1919         $post_status[] = bbp_get_closed_status_id();
     1918    // Which statuses
     1919    switch ( $post_type ) {
     1920
     1921        // Forum
     1922        case bbp_get_forum_post_type() :
     1923            $post_status = bbp_get_public_forum_statuses();
     1924            break;
     1925
     1926        // Topic
     1927        case bbp_get_topic_post_type() :
     1928            $post_status = bbp_get_public_topic_statuses();
     1929            break;
     1930
     1931        // Reply
     1932        case bbp_get_reply_post_type() :
     1933        default :
     1934            $post_status = bbp_get_public_reply_statuses();
     1935            break;
    19201936    }
    19211937
     
    19391955        'no_found_rows'          => true
    19401956    ) );
    1941     $child_ids = ! empty( $query->posts ) ? $query->posts : array();
     1957
     1958    $child_ids = ! empty( $query->posts )
     1959        ? $query->posts
     1960        : array();
     1961
    19421962    unset( $query );
    19431963
     
    19631983    }
    19641984
    1965     // Check cache key
    1966     $key          = md5( serialize( array( 'parent_id' => $parent_id, 'post_type' => $post_type ) ) );
     1985    // Make cache key
     1986    $not_in = array( 'draft', 'future' );
     1987    $key    = md5( serialize( array(
     1988        'parent_id'   => $parent_id,
     1989        'post_type'   => $post_type,
     1990        'post_status' => $not_in
     1991    ) ) );
     1992
     1993    // Check last changed
    19671994    $last_changed = wp_cache_get_last_changed( 'bbpress_posts' );
    19681995    $cache_key    = "bbp_child_ids:{$key}:{$last_changed}";
     
    19701997    // Check for cache and set if needed
    19711998    $child_ids = wp_cache_get( $cache_key, 'bbpress_posts' );
     1999
     2000    // Not already cached
    19722001    if ( false === $child_ids ) {
    19732002
    19742003        // Join post statuses to specifically exclude together
    1975         $not_in      = array( 'draft', 'future' );
    19762004        $post_status = "'" . implode( "', '", $not_in ) . "'";
    19772005        $bbp_db      = bbp_db();
  • trunk/src/includes/forums/functions.php

    r6855 r6922  
    18221822 * Return an associative array of available topic statuses
    18231823 *
     1824 * Developers note: these statuses are actually stored as meta data, and
     1825 * Visibilities are stored in post_status.
     1826 *
    18241827 * @since 2.4.0 bbPress (r5059)
    18251828 *
     
    18571860/**
    18581861 * Return an associative array of forum visibility
     1862 *
     1863 * Developers note: these visibilities are actually stored in post_status, and
     1864 * Statuses are stored in meta data.
    18591865 *
    18601866 * @since 2.4.0 bbPress (r5059)
     
    18721878        bbp_get_hidden_status_id()  => _x( 'Hidden',  'Make forum hidden',  'bbpress' )
    18731879    ), $forum_id );
     1880}
     1881
     1882/**
     1883 * Return array of public forum statuses.
     1884 *
     1885 * @since 2.6.0 bbPress (r6921)
     1886 *
     1887 * @return array
     1888 */
     1889function bbp_get_public_forum_statuses() {
     1890    $statuses = array(
     1891        bbp_get_public_status_id()
     1892    );
     1893
     1894    // Filter & return
     1895    return (array) apply_filters( 'bbp_get_public_forum_statuses', $statuses );
     1896}
     1897
     1898/**
     1899 * Return array of non-public forum statuses.
     1900 *
     1901 * @since 2.6.0 bbPress (r6921)
     1902 *
     1903 * @return array
     1904 */
     1905function bbp_get_non_public_forum_statuses() {
     1906    $statuses = array(
     1907        bbp_get_private_status_id(),
     1908        bbp_get_hidden_status_id()
     1909    );
     1910
     1911    // Filter & return
     1912    return (array) apply_filters( 'bbp_get_non_public_forum_statuses', $statuses );
    18741913}
    18751914
     
    21432182        'no_found_rows'          => true
    21442183    ) );
     2184
    21452185    $reply_id = array_shift( $query->posts );
     2186
    21462187    unset( $query );
    21472188
  • trunk/src/includes/replies/functions.php

    r6918 r6922  
    16621662}
    16631663
     1664/**
     1665 * Return array of public reply statuses.
     1666 *
     1667 * @since 2.6.0 bbPress (r6705)
     1668 *
     1669 * @return array
     1670 */
     1671function bbp_get_public_reply_statuses() {
     1672    $statuses = array(
     1673        bbp_get_public_status_id()
     1674    );
     1675
     1676    // Filter & return
     1677    return (array) apply_filters( 'bbp_get_public_reply_statuses', $statuses );
     1678}
     1679
     1680/**
     1681 * Return array of non-public reply statuses.
     1682 *
     1683 * @since 2.6.0 bbPress (r6791)
     1684 *
     1685 * @return array
     1686 */
     1687function bbp_get_non_public_reply_statuses() {
     1688    $statuses = array(
     1689        bbp_get_trash_status_id(),
     1690        bbp_get_spam_status_id(),
     1691        bbp_get_pending_status_id()
     1692    );
     1693
     1694    // Filter & return
     1695    return (array) apply_filters( 'bbp_get_non_public_reply_statuses', $statuses );
     1696}
     1697
    16641698/** Reply Actions *************************************************************/
    16651699
  • trunk/src/includes/replies/template.php

    r6903 r6922  
    829829
    830830/**
    831  * Return array of public reply statuses.
    832  *
    833  * @since 2.6.0 bbPress (r6705)
    834  *
    835  * @return array
    836  */
    837 function bbp_get_public_reply_statuses() {
    838     $statuses = array(
    839         bbp_get_public_status_id()
    840     );
    841 
    842     // Filter & return
    843     return (array) apply_filters( 'bbp_get_public_reply_statuses', $statuses );
    844 }
    845 
    846 /**
    847  * Return array of non-public reply statuses.
    848  *
    849  * @since 2.6.0 bbPress (r6791)
    850  *
    851  * @return array
    852  */
    853 function bbp_get_non_public_reply_statuses() {
    854     $statuses = array(
    855         bbp_get_trash_status_id(),
    856         bbp_get_spam_status_id(),
    857         bbp_get_pending_status_id()
    858     );
    859 
    860     // Filter & return
    861     return (array) apply_filters( 'bbp_get_non_public_reply_statuses', $statuses );
    862 }
    863 
    864 /**
    865831 * Is the reply publicly viewable?
    866832 *
  • trunk/src/includes/topics/functions.php

    r6918 r6922  
    19001900}
    19011901
     1902/**
     1903 * Return array of public topic statuses.
     1904 *
     1905 * @since 2.6.0 bbPress (r6383)
     1906 *
     1907 * @return array
     1908 */
     1909function bbp_get_public_topic_statuses() {
     1910    $statuses = array(
     1911        bbp_get_public_status_id(),
     1912        bbp_get_closed_status_id()
     1913    );
     1914
     1915    // Filter & return
     1916    return (array) apply_filters( 'bbp_get_public_topic_statuses', $statuses );
     1917}
     1918
     1919/**
     1920 * Return array of non-public topic statuses.
     1921 *
     1922 * @since 2.6.0 bbPress (r6642)
     1923 *
     1924 * @return array
     1925 */
     1926function bbp_get_non_public_topic_statuses() {
     1927    $statuses = array(
     1928        bbp_get_trash_status_id(),
     1929        bbp_get_spam_status_id(),
     1930        bbp_get_pending_status_id()
     1931    );
     1932
     1933    // Filter & return
     1934    return (array) apply_filters( 'bbp_get_non_public_topic_statuses', $statuses );
     1935}
     1936
    19021937/** Stickies ******************************************************************/
    19031938
     
    36353670
    36363671    // Statuses to count
    3637     $object_statuses = array(
    3638         bbp_get_public_status_id(),
    3639         bbp_get_closed_status_id()
    3640     );
     3672    $object_statuses = bbp_get_public_topic_statuses();
    36413673
    36423674    // Get database
  • trunk/src/includes/topics/template.php

    r6921 r6922  
    10561056
    10571057/**
    1058  * Return array of public topic statuses.
    1059  *
    1060  * @since 2.6.0 bbPress (r6383)
    1061  *
    1062  * @return array
    1063  */
    1064 function bbp_get_public_topic_statuses() {
    1065     $statuses = array(
    1066         bbp_get_public_status_id(),
    1067         bbp_get_closed_status_id()
    1068     );
    1069 
    1070     // Filter & return
    1071     return (array) apply_filters( 'bbp_get_public_topic_statuses', $statuses );
    1072 }
    1073 
    1074 /**
    1075  * Return array of non-public topic statuses.
    1076  *
    1077  * @since 2.6.0 bbPress (r6642)
    1078  *
    1079  * @return array
    1080  */
    1081 function bbp_get_non_public_topic_statuses() {
    1082     $statuses = array(
    1083         bbp_get_trash_status_id(),
    1084         bbp_get_spam_status_id(),
    1085         bbp_get_pending_status_id()
    1086     );
    1087 
    1088     // Filter & return
    1089     return (array) apply_filters( 'bbp_get_non_public_topic_statuses', $statuses );
    1090 }
    1091 
    1092 /**
    10931058 * Is the topic closed to new replies?
    10941059 *
Note: See TracChangeset for help on using the changeset viewer.