Skip to:
Content

bbPress.org

Changeset 3899


Ignore:
Timestamp:
05/14/2012 08:41:02 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Core:

  • Add new bbp-core-functions.php file to bbp-includes.
  • Move functions out of bbp-common-functions.php and into bbp-core-functions.php and bbp-topic-template.php.
  • Paves way for bbPress function map API.
Location:
branches/plugin
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-common-functions.php

    r3858 r3899  
    1010// Exit if accessed directly
    1111if ( !defined( 'ABSPATH' ) ) exit;
    12 
    13 /** Versions ******************************************************************/
    14 
    15 /**
    16  * Output the bbPress version
    17  *
    18  * @since bbPress (r3468)
    19  * @uses bbp_get_version() To get the bbPress version
    20  */
    21 function bbp_version() {
    22     echo bbp_get_version();
    23 }
    24     /**
    25      * Return the bbPress version
    26      *
    27      * @since bbPress (r3468)
    28      * @retrun string The bbPress version
    29      */
    30     function bbp_get_version() {
    31         return bbpress()->version;
    32     }
    33 
    34 /**
    35  * Output the bbPress database version
    36  *
    37  * @since bbPress (r3468)
    38  * @uses bbp_get_version() To get the bbPress version
    39  */
    40 function bbp_db_version() {
    41     echo bbp_get_db_version();
    42 }
    43     /**
    44      * Return the bbPress database version
    45      *
    46      * @since bbPress (r3468)
    47      * @retrun string The bbPress version
    48      */
    49     function bbp_get_db_version() {
    50         return bbpress()->db_version;
    51     }
    52 
    53 /**
    54  * Output the bbPress database version directly from the database
    55  *
    56  * @since bbPress (r3468)
    57  * @uses bbp_get_version() To get the current bbPress version
    58  */
    59 function bbp_db_version_raw() {
    60     echo bbp_get_db_version_raw();
    61 }
    62     /**
    63      * Return the bbPress database version directly from the database
    64      *
    65      * @since bbPress (r3468)
    66      * @retrun string The current bbPress version
    67      */
    68     function bbp_get_db_version_raw() {
    69         return get_option( '_bbp_db_version', '' );
    70     }
    71 
    72 /** Post Meta *****************************************************************/
    73 
    74 /**
    75  * Update a posts forum meta ID
    76  *
    77  * @since bbPress (r3181)
    78  *
    79  * @param int $post_id The post to update
    80  * @param int $forum_id The forum
    81  */
    82 function bbp_update_forum_id( $post_id, $forum_id ) {
    83 
    84     // Allow the forum ID to be updated 'just in time' before save
    85     $forum_id = apply_filters( 'bbp_update_forum_id', $forum_id, $post_id );
    86 
    87     // Update the post meta forum ID
    88     update_post_meta( $post_id, '_bbp_forum_id', (int) $forum_id );
    89 }
    90 
    91 /**
    92  * Update a posts topic meta ID
    93  *
    94  * @since bbPress (r3181)
    95  *
    96  * @param int $post_id The post to update
    97  * @param int $forum_id The forum
    98  */
    99 function bbp_update_topic_id( $post_id, $topic_id ) {
    100 
    101     // Allow the topic ID to be updated 'just in time' before save
    102     $topic_id = apply_filters( 'bbp_update_topic_id', $topic_id, $post_id );
    103 
    104     // Update the post meta topic ID
    105     update_post_meta( $post_id, '_bbp_topic_id', (int) $topic_id );
    106 }
    107 
    108 /**
    109  * Update a posts reply meta ID
    110  *
    111  * @since bbPress (r3181)
    112  *
    113  * @param int $post_id The post to update
    114  * @param int $forum_id The forum
    115  */
    116 function bbp_update_reply_id( $post_id, $reply_id ) {
    117 
    118     // Allow the reply ID to be updated 'just in time' before save
    119     $reply_id = apply_filters( 'bbp_update_reply_id', $reply_id, $post_id );
    120 
    121     // Update the post meta reply ID
    122     update_post_meta( $post_id, '_bbp_reply_id',(int) $reply_id );
    123 }
    12412
    12513/** Formatting ****************************************************************/
     
    339227
    340228/**
    341  * The plugin version of bbPress comes with two topic display options:
    342  * - Traditional: Topics are included in the reply loop (default)
    343  * - New Style: Topics appear as "lead" posts, ahead of replies
    344  *
    345  * @since bbPress (r2954)
    346  *
    347  * @param $show_lead Optional. Default false
    348  * @return bool Yes if the topic appears as a lead, otherwise false
    349  */
    350 function bbp_show_lead_topic( $show_lead = false ) {
    351     return apply_filters( 'bbp_show_lead_topic', (bool) $show_lead );
    352 }
    353 
    354 /**
    355229 * Append 'view=all' to query string if it's already there from referer
    356230 *
     
    387261 */
    388262function bbp_remove_view_all( $original_link = '' ) {
    389 
    390     // Are we appending the view=all vars?
    391     $link = remove_query_arg( 'view', $original_link );
    392 
    393     return apply_filters( 'bbp_add_view_all', $link, $original_link );
     263    return apply_filters( 'bbp_add_view_all', remove_query_arg( 'view', $original_link ), $original_link );
    394264}
    395265
     
    404274 */
    405275function bbp_get_view_all( $cap = 'moderate' ) {
    406 
    407276    $retval = ( ( !empty( $_GET['view'] ) && ( 'all' == $_GET['view'] ) && current_user_can( $cap ) ) );
    408 
    409277    return apply_filters( 'bbp_get_view_all', (bool) $retval );
    410278}
     
    689557}
    690558
    691 /** Views *********************************************************************/
    692 
    693 /**
    694  * Get the registered views
    695  *
    696  * Does nothing much other than return the {@link $bbp->views} variable
    697  *
    698  * @since bbPress (r2789)
    699  *
    700  * @return array Views
    701  */
    702 function bbp_get_views() {
    703     return bbpress()->views;
    704 }
    705 
    706 /**
    707  * Register a bbPress view
    708  *
    709  * @todo Implement feeds - See {@link http://trac.bbpress.org/ticket/1422}
    710  *
    711  * @since bbPress (r2789)
    712  *
    713  * @param string $view View name
    714  * @param string $title View title
    715  * @param mixed $query_args {@link bbp_has_topics()} arguments.
    716  * @param bool $feed Have a feed for the view? Defaults to true. NOT IMPLEMENTED
    717  * @uses sanitize_title() To sanitize the view name
    718  * @uses esc_html() To sanitize the view title
    719  * @return array The just registered (but processed) view
    720  */
    721 function bbp_register_view( $view, $title, $query_args = '', $feed = true ) {
    722     $bbp   = bbpress();
    723     $view  = sanitize_title( $view );
    724     $title = esc_html( $title );
    725 
    726     if ( empty( $view ) || empty( $title ) )
    727         return false;
    728 
    729     $query_args = bbp_parse_args( $query_args, '', 'register_view' );
    730 
    731     // Set exclude_stickies to true if it wasn't supplied
    732     if ( !isset( $query_args['show_stickies'] ) )
    733         $query_args['show_stickies'] = false;
    734 
    735     $bbp->views[$view]['title'] = $title;
    736     $bbp->views[$view]['query'] = $query_args;
    737     $bbp->views[$view]['feed']  = $feed;
    738 
    739     return $bbp->views[$view];
    740 }
    741 
    742 /**
    743  * Deregister a bbPress view
    744  *
    745  * @since bbPress (r2789)
    746  *
    747  * @param string $view View name
    748  * @uses sanitize_title() To sanitize the view name
    749  * @return bool False if the view doesn't exist, true on success
    750  */
    751 function bbp_deregister_view( $view ) {
    752     $bbp  = bbpress();
    753     $view = sanitize_title( $view );
    754 
    755     if ( !isset( $bbp->views[$view] ) )
    756         return false;
    757 
    758     unset( $bbp->views[$view] );
    759 
    760     return true;
    761 }
    762 
    763 /**
    764  * Run the view's query
    765  *
    766  * @since bbPress (r2789)
    767  *
    768  * @param string $view Optional. View id
    769  * @param mixed $new_args New arguments. See {@link bbp_has_topics()}
    770  * @uses bbp_get_view_id() To get the view id
    771  * @uses bbp_get_view_query_args() To get the view query args
    772  * @uses sanitize_title() To sanitize the view name
    773  * @uses bbp_has_topics() To make the topics query
    774  * @return bool False if the view doesn't exist, otherwise if topics are there
    775  */
    776 function bbp_view_query( $view = '', $new_args = '' ) {
    777 
    778     $view = bbp_get_view_id( $view );
    779     if ( empty( $view ) )
    780         return false;
    781 
    782     $query_args = bbp_get_view_query_args( $view );
    783 
    784     if ( !empty( $new_args ) ) {
    785         $new_args   = bbp_parse_args( $new_args, '', 'view_query' );
    786         $query_args = array_merge( $query_args, $new_args );
    787     }
    788 
    789     return bbp_has_topics( $query_args );
    790 }
    791 
    792 /**
    793  * Return the view's query arguments
    794  *
    795  * @since bbPress (r2789)
    796  *
    797  * @param string $view View name
    798  * @uses bbp_get_view_id() To get the view id
    799  * @return array Query arguments
    800  */
    801 function bbp_get_view_query_args( $view ) {
    802     $view   = bbp_get_view_id( $view );
    803     $retval = !empty( $view ) ? bbpress()->views[$view]['query'] : false;
    804 
    805     return apply_filters( 'bbp_get_view_query_args', $retval, $view );
    806 }
    807 
    808559/** New/edit topic/reply helpers **********************************************/
    809560
     
    18231574}
    18241575
    1825 /** Errors ********************************************************************/
    1826 
    1827 /**
    1828  * Adds an error message to later be output in the theme
    1829  *
    1830  * @since bbPress (r3381)
    1831  *
    1832  * @see WP_Error()
    1833  * @uses WP_Error::add();
    1834  *
    1835  * @param string $code Unique code for the error message
    1836  * @param string $message Translated error message
    1837  * @param string $data Any additional data passed with the error message
    1838  */
    1839 function bbp_add_error( $code = '', $message = '', $data = '' ) {
    1840     bbpress()->errors->add( $code, $message, $data );
    1841 }
    1842 
    1843 /**
    1844  * Check if error messages exist in queue
    1845  *
    1846  * @since bbPress (r3381)
    1847  *
    1848  * @see WP_Error()
    1849  *
    1850  * @uses is_wp_error()
    1851  * @usese WP_Error::get_error_codes()
    1852  */
    1853 function bbp_has_errors() {
    1854 
    1855     // Assume no errors
    1856     $has_errors = false;
    1857 
    1858     // Check for errors
    1859     if ( bbpress()->errors->get_error_codes() )
    1860         $has_errors = true;
    1861 
    1862     // Filter return value
    1863     $has_errors = apply_filters( 'bbp_has_errors', $has_errors, bbpress()->errors );
    1864 
    1865     return $has_errors;
    1866 }
    1867 
    18681576/** Templates ******************************************************************/
    18691577
     
    19171625}
    19181626
    1919 /** Post Statuses *************************************************************/
    1920 
    1921 /**
    1922  * Return the public post status ID
    1923  *
    1924  * @since bbPress (r3504)
    1925  *
    1926  * @return string
    1927  */
    1928 function bbp_get_public_status_id() {
    1929     return bbpress()->public_status_id;
    1930 }
    1931 
    1932 /**
    1933  * Return the pending post status ID
    1934  *
    1935  * @since bbPress (r3581)
    1936  *
    1937  * @return string
    1938  */
    1939 function bbp_get_pending_status_id() {
    1940     return bbpress()->pending_status_id;
    1941 }
    1942 
    1943 /**
    1944  * Return the private post status ID
    1945  *
    1946  * @since bbPress (r3504)
    1947  *
    1948  * @return string
    1949  */
    1950 function bbp_get_private_status_id() {
    1951     return bbpress()->private_status_id;
    1952 }
    1953 
    1954 /**
    1955  * Return the hidden post status ID
    1956  *
    1957  * @since bbPress (r3504)
    1958  *
    1959  * @return string
    1960  */
    1961 function bbp_get_hidden_status_id() {
    1962     return bbpress()->hidden_status_id;
    1963 }
    1964 
    1965 /**
    1966  * Return the closed post status ID
    1967  *
    1968  * @since bbPress (r3504)
    1969  *
    1970  * @return string
    1971  */
    1972 function bbp_get_closed_status_id() {
    1973     return bbpress()->closed_status_id;
    1974 }
    1975 
    1976 /**
    1977  * Return the spam post status ID
    1978  *
    1979  * @since bbPress (r3504)
    1980  *
    1981  * @return string
    1982  */
    1983 function bbp_get_spam_status_id() {
    1984     return bbpress()->spam_status_id;
    1985 }
    1986 
    1987 /**
    1988  * Return the trash post status ID
    1989  *
    1990  * @since bbPress (r3504)
    1991  *
    1992  * @return string
    1993  */
    1994 function bbp_get_trash_status_id() {
    1995     return bbpress()->trash_status_id;
    1996 }
    1997 
    1998 /**
    1999  * Return the orphan post status ID
    2000  *
    2001  * @since bbPress (r3504)
    2002  *
    2003  * @return string
    2004  */
    2005 function bbp_get_orphan_status_id() {
    2006     return bbpress()->orphan_status_id;
    2007 }
    2008 
    2009 /** Rewrite IDs ***************************************************************/
    2010 
    2011 /**
    2012  * Return the unique ID for user profile rewrite rules
    2013  *
    2014  * @since bbPress (r3762)
    2015  * @return string
    2016  */
    2017 function bbp_get_user_rewrite_id() {
    2018     return bbpress()->user_id;
    2019 }
    2020 
    2021 /**
    2022  * Return the enique ID for all edit rewrite rules (forum|topic|reply|tag|user)
    2023  *
    2024  * @since bbPress (r3762)
    2025  * @return string
    2026  */
    2027 function bbp_get_edit_rewrite_id() {
    2028     return bbpress()->edit_id;
    2029 }
    2030 
    2031 /**
    2032  * Return the unique ID for topic view rewrite rules
    2033  *
    2034  * @since bbPress (r3762)
    2035  * @return string
    2036  */
    2037 function bbp_get_view_rewrite_id() {
    2038     return bbpress()->view_id;
    2039 }
    2040 
    20411627?>
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r3861 r3899  
    3535        return apply_filters( 'bbp_get_topic_post_type', bbpress()->topic_post_type );
    3636    }
     37
     38/**
     39 * The plugin version of bbPress comes with two topic display options:
     40 * - Traditional: Topics are included in the reply loop (default)
     41 * - New Style: Topics appear as "lead" posts, ahead of replies
     42 *
     43 * @since bbPress (r2954)
     44 * @param $show_lead Optional. Default false
     45 * @return bool Yes if the topic appears as a lead, otherwise false
     46 */
     47function bbp_show_lead_topic( $show_lead = false ) {
     48    return (bool) apply_filters( 'bbp_show_lead_topic', (bool) $show_lead );
     49}
    3750
    3851/** Topic Loop ****************************************************************/
  • branches/plugin/bbpress.php

    r3833 r3899  
    266266    public $options = array();
    267267
     268    /** Function Overload *****************************************************/
     269
     270    /**
     271     * @var array Optional Overloads WordPress functions with new functions.
     272     */
     273    public $functions = array();
     274
    268275    /** Singleton *************************************************************/
    269276
     
    420427        require( $this->plugin_dir . 'bbp-includes/bbp-core-actions.php'    ); // All actions
    421428        require( $this->plugin_dir . 'bbp-includes/bbp-core-filters.php'    ); // All filters
    422         require( $this->plugin_dir . 'bbp-includes/bbp-core-options.php'    ); // Configuration Options
     429        require( $this->plugin_dir . 'bbp-includes/bbp-core-functions.php'  ); // Core functions
     430        require( $this->plugin_dir . 'bbp-includes/bbp-core-options.php'    ); // Configuration options
    423431        require( $this->plugin_dir . 'bbp-includes/bbp-core-caps.php'       ); // Roles and capabilities
    424432        require( $this->plugin_dir . 'bbp-includes/bbp-core-classes.php'    ); // Common classes
Note: See TracChangeset for help on using the changeset viewer.