Advertisement
Guest User

Untitled

a guest
Aug 4th, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 37.14 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * The bbPress Plugin
  5.  *
  6.  * bbPress is forum software with a twist from the creators of WordPress.
  7.  *
  8.  * $Id: bbpress.php 4891 2013-05-06 21:42:11Z johnjamesjacoby $
  9.  *
  10.  * @package bbPress
  11.  * @subpackage Main
  12.  */
  13.  
  14. /**
  15.  * Plugin Name: bbPress
  16.  * Plugin URI:  http://bbpress.org
  17.  * Description: bbPress is forum software with a twist from the creators of WordPress.
  18.  * Author:      The bbPress Community
  19.  * Author URI:  http://bbpress.org
  20.  * Version:     2.3.2
  21.  * Text Domain: bbpress
  22.  * Domain Path: /languages/
  23.  */
  24.  
  25. // Exit if accessed directly
  26. if ( !defined( 'ABSPATH' ) ) exit;
  27.  
  28. if ( !class_exists( 'bbPress' ) ) :
  29. /**
  30.  * Main bbPress Class
  31.  *
  32.  * "How doth the little busy bee, improve each shining hour..."
  33.  *
  34.  * @since bbPress (r2464)
  35.  */
  36. final class bbPress {
  37.  
  38.     /** Magic *****************************************************************/
  39.  
  40.     /**
  41.      * bbPress uses many variables, several of which can be filtered to
  42.      * customize the way it operates. Most of these variables are stored in a
  43.      * private array that gets updated with the help of PHP magic methods.
  44.      *
  45.      * This is a precautionary measure, to avoid potential errors produced by
  46.      * unanticipated direct manipulation of bbPress's run-time data.
  47.      *
  48.      * @see bbPress::setup_globals()
  49.      * @var array
  50.      */
  51.     private $data;
  52.  
  53.     /** Not Magic *************************************************************/
  54.  
  55.     /**
  56.      * @var mixed False when not logged in; WP_User object when logged in
  57.      */
  58.     public $current_user = false;
  59.  
  60.     /**
  61.      * @var obj Add-ons append to this (Akismet, BuddyPress, etc...)
  62.      */
  63.     public $extend;
  64.  
  65.     /**
  66.      * @var array Topic views
  67.      */
  68.     public $views        = array();
  69.  
  70.     /**
  71.      * @var array Overloads get_option()
  72.      */
  73.     public $options      = array();
  74.  
  75.     /**
  76.      * @var array Overloads get_user_meta()
  77.      */
  78.     public $user_options = array();
  79.  
  80.     /** Singleton *************************************************************/
  81.  
  82.     /**
  83.      * @var bbPress The one true bbPress
  84.      */
  85.     private static $instance;
  86.  
  87.     /**
  88.      * Main bbPress Instance
  89.      *
  90.      * bbPress is fun
  91.      * Please load it only one time
  92.      * For this, we thank you
  93.      *
  94.      * Insures that only one instance of bbPress exists in memory at any one
  95.      * time. Also prevents needing to define globals all over the place.
  96.      *
  97.      * @since bbPress (r3757)
  98.      * @staticvar array $instance
  99.      * @uses bbPress::setup_globals() Setup the globals needed
  100.      * @uses bbPress::includes() Include the required files
  101.      * @uses bbPress::setup_actions() Setup the hooks and actions
  102.      * @see bbpress()
  103.      * @return The one true bbPress
  104.      */
  105.     public static function instance() {
  106.         if ( ! isset( self::$instance ) ) {
  107.             self::$instance = new bbPress;
  108.             self::$instance->setup_globals();
  109.             self::$instance->includes();
  110.             self::$instance->setup_actions();
  111.         }
  112.         return self::$instance;
  113.     }
  114.  
  115.     /** Magic Methods *********************************************************/
  116.  
  117.     /**
  118.      * A dummy constructor to prevent bbPress from being loaded more than once.
  119.      *
  120.      * @since bbPress (r2464)
  121.      * @see bbPress::instance()
  122.      * @see bbpress();
  123.      */
  124.     private function __construct() { /* Do nothing here */ }
  125.  
  126.     /**
  127.      * A dummy magic method to prevent bbPress from being cloned
  128.      *
  129.      * @since bbPress (r2464)
  130.      */
  131.     public function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bbpress' ), '2.1' ); }
  132.  
  133.     /**
  134.      * A dummy magic method to prevent bbPress from being unserialized
  135.      *
  136.      * @since bbPress (r2464)
  137.      */
  138.     public function __wakeup() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'bbpress' ), '2.1' ); }
  139.  
  140.     /**
  141.      * Magic method for checking the existence of a certain custom field
  142.      *
  143.      * @since bbPress (r3951)
  144.      */
  145.     public function __isset( $key ) { return isset( $this->data[$key] ); }
  146.  
  147.     /**
  148.      * Magic method for getting bbPress variables
  149.      *
  150.      * @since bbPress (r3951)
  151.      */
  152.     public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; }
  153.  
  154.     /**
  155.      * Magic method for setting bbPress variables
  156.      *
  157.      * @since bbPress (r3951)
  158.      */
  159.     public function __set( $key, $value ) { $this->data[$key] = $value; }
  160.  
  161.     /**
  162.      * Magic method for unsetting bbPress variables
  163.      *
  164.      * @since bbPress (r4628)
  165.      */
  166.     public function __unset( $key ) { if ( isset( $this->data[$key] ) ) unset( $this->data[$key] ); }
  167.  
  168.     /**
  169.      * Magic method to prevent notices and errors from invalid method calls
  170.      *
  171.      * @since bbPress (r4252)
  172.      */
  173.     public function __call( $name = '', $args = array() ) { unset( $name, $args ); return null; }
  174.  
  175.     /** Private Methods *******************************************************/
  176.  
  177.     /**
  178.      * Set some smart defaults to class variables. Allow some of them to be
  179.      * filtered to allow for early overriding.
  180.      *
  181.      * @since bbPress (r2626)
  182.      * @access private
  183.      * @uses plugin_dir_path() To generate bbPress plugin path
  184.      * @uses plugin_dir_url() To generate bbPress plugin url
  185.      * @uses apply_filters() Calls various filters
  186.      */
  187.     private function setup_globals() {
  188.  
  189.         /** Versions **********************************************************/
  190.  
  191.         $this->version    = '2.3.2';
  192.         $this->db_version = '230';
  193.  
  194.         /** Paths *************************************************************/
  195.  
  196.         // Setup some base path and URL information
  197.         $this->file       = __FILE__;
  198.         $this->basename   = apply_filters( 'bbp_plugin_basenname', plugin_basename( $this->file ) );
  199.         $this->plugin_dir = apply_filters( 'bbp_plugin_dir_path',  plugin_dir_path( $this->file ) );
  200.         $this->plugin_url = apply_filters( 'bbp_plugin_dir_url',   plugin_dir_url ( $this->file ) );
  201.  
  202.         // Includes
  203.         $this->includes_dir = apply_filters( 'bbp_includes_dir', trailingslashit( $this->plugin_dir . 'includes'  ) );
  204.         $this->includes_url = apply_filters( 'bbp_includes_url', trailingslashit( $this->plugin_url . 'includes'  ) );
  205.  
  206.         // Languages
  207.         $this->lang_dir     = apply_filters( 'bbp_lang_dir',     trailingslashit( $this->plugin_dir . 'languages' ) );
  208.  
  209.         // Templates
  210.         $this->themes_dir   = apply_filters( 'bbp_themes_dir',   trailingslashit( $this->plugin_dir . 'templates' ) );
  211.         $this->themes_url   = apply_filters( 'bbp_themes_url',   trailingslashit( $this->plugin_url . 'templates' ) );
  212.  
  213.         /** Identifiers *******************************************************/
  214.  
  215.         // Post type identifiers
  216.         $this->forum_post_type   = apply_filters( 'bbp_forum_post_type',  'forum'     );
  217.         $this->topic_post_type   = apply_filters( 'bbp_topic_post_type',  'topic'     );
  218.         $this->reply_post_type   = apply_filters( 'bbp_reply_post_type',  'reply'     );
  219.         $this->topic_tag_tax_id  = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' );
  220.  
  221.         // Status identifiers
  222.         $this->spam_status_id    = apply_filters( 'bbp_spam_post_status',    'spam'    );
  223.         $this->closed_status_id  = apply_filters( 'bbp_closed_post_status',  'closed'  );
  224.         $this->orphan_status_id  = apply_filters( 'bbp_orphan_post_status',  'orphan'  );
  225.         $this->public_status_id  = apply_filters( 'bbp_public_post_status',  'publish' );
  226.         $this->pending_status_id = apply_filters( 'bbp_pending_post_status', 'pending' );
  227.         $this->private_status_id = apply_filters( 'bbp_private_post_status', 'private' );
  228.         $this->hidden_status_id  = apply_filters( 'bbp_hidden_post_status',  'hidden'  );
  229.         $this->trash_status_id   = apply_filters( 'bbp_trash_post_status',   'trash'   );
  230.  
  231.         // Other identifiers
  232.         $this->user_id           = apply_filters( 'bbp_user_id',   'bbp_user'   );
  233.         $this->tops_id           = apply_filters( 'bbp_tops_id',   'bbp_tops'   );
  234.         $this->reps_id           = apply_filters( 'bbp_reps_id',   'bbp_reps'   );
  235.         $this->favs_id           = apply_filters( 'bbp_favs_id',   'bbp_favs'   );
  236.         $this->subs_id           = apply_filters( 'bbp_subs_id',   'bbp_subs'   );
  237.         $this->view_id           = apply_filters( 'bbp_view_id',   'bbp_view'   );
  238.         $this->search_id         = apply_filters( 'bbp_search_id', 'bbp_search' );
  239.         $this->edit_id           = apply_filters( 'bbp_edit_id',   'edit'       );
  240.  
  241.         /** Queries ***********************************************************/
  242.  
  243.         $this->current_forum_id     = 0; // Current forum id
  244.         $this->current_topic_id     = 0; // Current topic id
  245.         $this->current_reply_id     = 0; // Current reply id
  246.         $this->current_topic_tag_id = 0; // Current topic tag id
  247.  
  248.         $this->forum_query    = new stdClass(); // Main forum query
  249.         $this->topic_query    = new stdClass(); // Main topic query
  250.         $this->reply_query    = new stdClass(); // Main reply query
  251.         $this->search_query   = new stdClass(); // Main search query
  252.  
  253.         /** Theme Compat ******************************************************/
  254.  
  255.         $this->theme_compat   = new stdClass(); // Base theme compatibility class
  256.         $this->filters        = new stdClass(); // Used when adding/removing filters
  257.  
  258.         /** Users *************************************************************/
  259.  
  260.         $this->current_user   = new stdClass(); // Currently logged in user
  261.         $this->displayed_user = new stdClass(); // Currently displayed user
  262.  
  263.         /** Misc **************************************************************/
  264.  
  265.         $this->domain         = 'bbpress';      // Unique identifier for retrieving translated strings
  266.         $this->extend         = new stdClass(); // Plugins add data here
  267.         $this->errors         = new WP_Error(); // Feedback
  268.         $this->tab_index      = apply_filters( 'bbp_default_tab_index', 100 );
  269.     }
  270.  
  271.     /**
  272.      * Include required files
  273.      *
  274.      * @since bbPress (r2626)
  275.      * @access private
  276.      * @uses is_admin() If in WordPress admin, load additional file
  277.      */
  278.     private function includes() {
  279.  
  280.         /** Core **************************************************************/
  281.  
  282.         require( $this->includes_dir . 'core/sub-actions.php'        );
  283.         require( $this->includes_dir . 'core/functions.php'          );
  284.         require( $this->includes_dir . 'core/cache.php'              );
  285.         require( $this->includes_dir . 'core/options.php'            );
  286.         require( $this->includes_dir . 'core/capabilities.php'       );
  287.         require( $this->includes_dir . 'core/update.php'             );
  288.         require( $this->includes_dir . 'core/template-functions.php' );
  289.         require( $this->includes_dir . 'core/template-loader.php'    );
  290.         require( $this->includes_dir . 'core/theme-compat.php'       );
  291.  
  292.         /** Components ********************************************************/
  293.  
  294.         // Common
  295.         require( $this->includes_dir . 'common/ajax.php'           );
  296.         require( $this->includes_dir . 'common/classes.php'        );
  297.         require( $this->includes_dir . 'common/functions.php'      );
  298.         require( $this->includes_dir . 'common/formatting.php'     );
  299.         require( $this->includes_dir . 'common/template-tags.php'  );
  300.         require( $this->includes_dir . 'common/widgets.php'        );
  301.         require( $this->includes_dir . 'common/shortcodes.php'     );
  302.  
  303.         // Forums
  304.         require( $this->includes_dir . 'forums/capabilities.php'   );
  305.         require( $this->includes_dir . 'forums/functions.php'      );
  306.         require( $this->includes_dir . 'forums/template-tags.php'  );
  307.  
  308.         // Topics
  309.         require( $this->includes_dir . 'topics/capabilities.php'   );
  310.         require( $this->includes_dir . 'topics/functions.php'      );
  311.         require( $this->includes_dir . 'topics/template-tags.php'  );
  312.  
  313.         // Replies
  314.         require( $this->includes_dir . 'replies/capabilities.php'  );
  315.         require( $this->includes_dir . 'replies/functions.php'     );
  316.         require( $this->includes_dir . 'replies/template-tags.php' );
  317.  
  318.         // Search
  319.         require( $this->includes_dir . 'search/functions.php'      );
  320.         require( $this->includes_dir . 'search/template-tags.php'  );
  321.  
  322.         // Users
  323.         require( $this->includes_dir . 'users/capabilities.php'    );
  324.         require( $this->includes_dir . 'users/functions.php'       );
  325.         require( $this->includes_dir . 'users/template-tags.php'   );
  326.         require( $this->includes_dir . 'users/options.php'         );
  327.  
  328.         /** Hooks *************************************************************/
  329.  
  330.         require( $this->includes_dir . 'core/extend.php'  );
  331.         require( $this->includes_dir . 'core/actions.php' );
  332.         require( $this->includes_dir . 'core/filters.php' );
  333.  
  334.         /** Admin *************************************************************/
  335.  
  336.         // Quick admin check and load if needed
  337.         if ( is_admin() ) {
  338.             require( $this->includes_dir . 'admin/admin.php'   );
  339.             require( $this->includes_dir . 'admin/actions.php' );
  340.         }
  341.     }
  342.  
  343.     /**
  344.      * Setup the default hooks and actions
  345.      *
  346.      * @since bbPress (r2644)
  347.      * @access private
  348.      * @uses add_action() To add various actions
  349.      */
  350.     private function setup_actions() {
  351.  
  352.         // Add actions to plugin activation and deactivation hooks
  353.         add_action( 'activate_'   . $this->basename, 'bbp_activation'   );
  354.         add_action( 'deactivate_' . $this->basename, 'bbp_deactivation' );
  355.  
  356.         // If bbPress is being deactivated, do not add any actions
  357.         if ( bbp_is_deactivation( $this->basename ) )
  358.             return;
  359.  
  360.         // Array of bbPress core actions
  361.         $actions = array(
  362.             'setup_theme',              // Setup the default theme compat
  363.             'setup_current_user',       // Setup currently logged in user
  364.             'register_post_types',      // Register post types (forum|topic|reply)
  365.             'register_post_statuses',   // Register post statuses (closed|spam|orphan|hidden)
  366.             'register_taxonomies',      // Register taxonomies (topic-tag)
  367.             'register_shortcodes',      // Register shortcodes (bbp-login)
  368.             'register_views',           // Register the views (no-replies)
  369.             'register_theme_packages',  // Register bundled theme packages (bbp-theme-compat/bbp-themes)
  370.             'load_textdomain',          // Load textdomain (bbpress)
  371.             'add_rewrite_tags',         // Add rewrite tags (view|user|edit|search)
  372.             'generate_rewrite_rules'    // Generate rewrite rules (view|edit|search)
  373.         );
  374.  
  375.         // Add the actions
  376.         foreach( $actions as $class_action )
  377.             add_action( 'bbp_' . $class_action, array( $this, $class_action ), 5 );
  378.  
  379.         // All bbPress actions are setup (includes bbp-core-hooks.php)
  380.         do_action_ref_array( 'bbp_after_setup_actions', array( &$this ) );
  381.     }
  382.  
  383.     /** Public Methods ********************************************************/
  384.  
  385.     /**
  386.      * Register bundled theme packages
  387.      *
  388.      * Note that since we currently have complete control over bbp-themes and
  389.      * the bbp-theme-compat folders, it's fine to hardcode these here. If at a
  390.      * later date we need to automate this, and API will need to be built.
  391.      *
  392.      * @since bbPress (r3829)
  393.      */
  394.     public function register_theme_packages() {
  395.  
  396.         // Register the default theme compatibility package
  397.         bbp_register_theme_package( array(
  398.             'id'      => 'default',
  399.             'name'    => __( 'bbPress Default', 'bbpress' ),
  400.             'version' => bbp_get_version(),
  401.             'dir'     => trailingslashit( $this->themes_dir . 'default' ),
  402.             'url'     => trailingslashit( $this->themes_url . 'default' )
  403.         ) );
  404.  
  405.         // Register the basic theme stack. This is really dope.
  406.         bbp_register_template_stack( 'get_stylesheet_directory', 10 );
  407.         bbp_register_template_stack( 'get_template_directory',   12 );
  408.         bbp_register_template_stack( 'bbp_get_theme_compat_dir', 14 );
  409.     }
  410.  
  411.     /**
  412.      * Setup the default bbPress theme compatibility location.
  413.      *
  414.      * @since bbPress (r3778)
  415.      */
  416.     public function setup_theme() {
  417.  
  418.         // Bail if something already has this under control
  419.         if ( ! empty( $this->theme_compat->theme ) )
  420.             return;
  421.  
  422.         // Setup the theme package to use for compatibility
  423.         bbp_setup_theme_compat( bbp_get_theme_package_id() );
  424.     }
  425.  
  426.     /**
  427.      * Load the translation file for current language. Checks the languages
  428.      * folder inside the bbPress plugin first, and then the default WordPress
  429.      * languages folder.
  430.      *
  431.      * Note that custom translation files inside the bbPress plugin folder
  432.      * will be removed on bbPress updates. If you're creating custom
  433.      * translation files, please use the global language folder.
  434.      *
  435.      * @since bbPress (r2596)
  436.      *
  437.      * @uses apply_filters() Calls 'bbpress_locale' with the
  438.      *                        {@link get_locale()} value
  439.      * @uses load_textdomain() To load the textdomain
  440.      * @return bool True on success, false on failure
  441.      */
  442.     public function load_textdomain() {
  443.  
  444.         // Traditional WordPress plugin locale filter
  445.         $locale        = apply_filters( 'plugin_locale',  get_locale(), $this->domain );
  446.         $mofile        = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
  447.  
  448.         // Setup paths to current locale file
  449.         $mofile_local  = $this->lang_dir . $mofile;
  450.         $mofile_global = WP_LANG_DIR . '/bbpress/' . $mofile;
  451.  
  452.         // Look in global /wp-content/languages/bbpress folder
  453.         if ( file_exists( $mofile_global ) ) {
  454.             return load_textdomain( $this->domain, $mofile_global );
  455.  
  456.         // Look in local /wp-content/plugins/bbpress/bbp-languages/ folder
  457.         } elseif ( file_exists( $mofile_local ) ) {
  458.             return load_textdomain( $this->domain, $mofile_local );
  459.         }
  460.  
  461.         // Nothing found
  462.         return false;
  463.     }
  464.  
  465.     /**
  466.      * Setup the post types for forums, topics and replies
  467.      *
  468.      * @since bbPress (r2597)
  469.      * @uses register_post_type() To register the post types
  470.      * @uses apply_filters() Calls various filters to modify the arguments
  471.      *                        sent to register_post_type()
  472.      */
  473.     public static function register_post_types() {
  474.  
  475.         // Define local variable(s)
  476.         $post_type = array();
  477.  
  478.         /** Forums ************************************************************/
  479.  
  480.         // Forum labels
  481.         $post_type['labels'] = array(
  482.             'name'               => __( 'Forums',                   'bbpress' ),
  483.             'menu_name'          => __( 'Forums',                   'bbpress' ),
  484.             'singular_name'      => __( 'Forum',                    'bbpress' ),
  485.             'all_items'          => __( 'All Forums',               'bbpress' ),
  486.             'add_new'            => __( 'New Forum',                'bbpress' ),
  487.             'add_new_item'       => __( 'Create New Forum',         'bbpress' ),
  488.             'edit'               => __( 'Edit',                     'bbpress' ),
  489.             'edit_item'          => __( 'Edit Forum',               'bbpress' ),
  490.             'new_item'           => __( 'New Forum',                'bbpress' ),
  491.             'view'               => __( 'View Forum',               'bbpress' ),
  492.             'view_item'          => __( 'View Forum',               'bbpress' ),
  493.             'search_items'       => __( 'Search Forums',            'bbpress' ),
  494.             'not_found'          => __( 'No forums found',          'bbpress' ),
  495.             'not_found_in_trash' => __( 'No forums found in Trash', 'bbpress' ),
  496.             'parent_item_colon'  => __( 'Parent Forum:',            'bbpress' )
  497.         );
  498.  
  499.         // Forum rewrite
  500.         $post_type['rewrite'] = array(
  501.             'slug'       => bbp_get_forum_slug(),
  502.             'with_front' => false
  503.         );
  504.  
  505.         // Forum supports
  506.         $post_type['supports'] = array(
  507.             'title',
  508.             'editor',
  509.             'revisions'
  510.         );
  511.  
  512.         // Register Forum content type
  513.         register_post_type(
  514.             bbp_get_forum_post_type(),
  515.             apply_filters( 'bbp_register_forum_post_type', array(
  516.                 'labels'              => $post_type['labels'],
  517.                 'rewrite'             => $post_type['rewrite'],
  518.                 'supports'            => $post_type['supports'],
  519.                 'description'         => __( 'bbPress Forums', 'bbpress' ),
  520.                 'capabilities'        => bbp_get_forum_caps(),
  521.                 'capability_type'     => array( 'forum', 'forums' ),
  522.                 'menu_position'       => 555555,
  523.                 'has_archive'         => bbp_get_root_slug(),
  524.                 'exclude_from_search' => true,
  525.                 'show_in_nav_menus'   => true,
  526.                 'public'              => true,
  527.                 'show_ui'             => current_user_can( 'bbp_forums_admin' ),
  528.                 'can_export'          => true,
  529.                 'hierarchical'        => true,
  530.                 'query_var'           => true,
  531.                 'menu_icon'           => ''
  532.             ) )
  533.         );
  534.  
  535.         /** Topics ************************************************************/
  536.  
  537.         // Topic labels
  538.         $post_type['labels'] = array(
  539.             'name'               => __( 'Topics',                   'bbpress' ),
  540.             'menu_name'          => __( 'Topics',                   'bbpress' ),
  541.             'singular_name'      => __( 'Topic',                    'bbpress' ),
  542.             'all_items'          => __( 'All Topics',               'bbpress' ),
  543.             'add_new'            => __( 'New Topic',                'bbpress' ),
  544.             'add_new_item'       => __( 'Create New Topic',         'bbpress' ),
  545.             'edit'               => __( 'Edit',                     'bbpress' ),
  546.             'edit_item'          => __( 'Edit Topic',               'bbpress' ),
  547.             'new_item'           => __( 'New Topic',                'bbpress' ),
  548.             'view'               => __( 'View Topic',               'bbpress' ),
  549.             'view_item'          => __( 'View Topic',               'bbpress' ),
  550.             'search_items'       => __( 'Search Topics',            'bbpress' ),
  551.             'not_found'          => __( 'No topics found',          'bbpress' ),
  552.             'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ),
  553.             'parent_item_colon'  => __( 'Forum:',                   'bbpress' )
  554.         );
  555.  
  556.         // Topic rewrite
  557.         $post_type['rewrite'] = array(
  558.             'slug'       => bbp_get_topic_slug(),
  559.             'with_front' => false
  560.         );
  561.  
  562.         // Topic supports
  563.         $post_type['supports'] = array(
  564.             'title',
  565.             'editor',
  566.             'revisions'
  567.         );
  568.  
  569.         // Register Topic content type
  570.         register_post_type(
  571.             bbp_get_topic_post_type(),
  572.             apply_filters( 'bbp_register_topic_post_type', array(
  573.                 'labels'              => $post_type['labels'],
  574.                 'rewrite'             => $post_type['rewrite'],
  575.                 'supports'            => $post_type['supports'],
  576.                 'description'         => __( 'bbPress Topics', 'bbpress' ),
  577.                 'capabilities'        => bbp_get_topic_caps(),
  578.                 'capability_type'     => array( 'topic', 'topics' ),
  579.                 'menu_position'       => 555555,
  580.                 'has_archive'         => bbp_get_topic_archive_slug(),
  581.                 'exclude_from_search' => true,
  582.                 'show_in_nav_menus'   => false,
  583.                 'public'              => true,
  584.                 'show_ui'             => current_user_can( 'bbp_topics_admin' ),
  585.                 'can_export'          => true,
  586.                 'hierarchical'        => false,
  587.                 'query_var'           => true,
  588.                 'menu_icon'           => ''
  589.             )
  590.         ) );
  591.  
  592.         /** Replies ***********************************************************/
  593.  
  594.         // Reply labels
  595.         $post_type['labels'] = array(
  596.             'name'               => __( 'Replies',                   'bbpress' ),
  597.             'menu_name'          => __( 'Replies',                   'bbpress' ),
  598.             'singular_name'      => __( 'Reply',                     'bbpress' ),
  599.             'all_items'          => __( 'All Replies',               'bbpress' ),
  600.             'add_new'            => __( 'New Reply',                 'bbpress' ),
  601.             'add_new_item'       => __( 'Create New Reply',          'bbpress' ),
  602.             'edit'               => __( 'Edit',                      'bbpress' ),
  603.             'edit_item'          => __( 'Edit Reply',                'bbpress' ),
  604.             'new_item'           => __( 'New Reply',                 'bbpress' ),
  605.             'view'               => __( 'View Reply',                'bbpress' ),
  606.             'view_item'          => __( 'View Reply',                'bbpress' ),
  607.             'search_items'       => __( 'Search Replies',            'bbpress' ),
  608.             'not_found'          => __( 'No replies found',          'bbpress' ),
  609.             'not_found_in_trash' => __( 'No replies found in Trash', 'bbpress' ),
  610.             'parent_item_colon'  => __( 'Topic:',                    'bbpress' )
  611.         );
  612.  
  613.         // Reply rewrite
  614.         $post_type['rewrite'] = array(
  615.             'slug'       => bbp_get_reply_slug(),
  616.             'with_front' => false
  617.         );
  618.  
  619.         // Reply supports
  620.         $post_type['supports'] = array(
  621.             'title',
  622.             'editor',
  623.             'revisions'
  624.         );
  625.  
  626.         // Register reply content type
  627.         register_post_type(
  628.             bbp_get_reply_post_type(),
  629.             apply_filters( 'bbp_register_reply_post_type', array(
  630.                 'labels'              => $post_type['labels'],
  631.                 'rewrite'             => $post_type['rewrite'],
  632.                 'supports'            => $post_type['supports'],
  633.                 'description'         => __( 'bbPress Replies', 'bbpress' ),
  634.                 'capabilities'        => bbp_get_reply_caps(),
  635.                 'capability_type'     => array( 'reply', 'replies' ),
  636.                 'menu_position'       => 555555,
  637.                 'exclude_from_search' => true,
  638.                 'has_archive'         => false,
  639.                 'show_in_nav_menus'   => false,
  640.                 'public'              => true,
  641.                 'show_ui'             => current_user_can( 'bbp_replies_admin' ),
  642.                 'can_export'          => true,
  643.                 'hierarchical'        => false,
  644.                 'query_var'           => true,
  645.                 'menu_icon'           => ''
  646.             ) )
  647.         );
  648.     }
  649.  
  650.     /**
  651.      * Register the post statuses used by bbPress
  652.      *
  653.      * We do some manipulation of the 'trash' status so trashed topics and
  654.      * replies can be viewed from within the theme.
  655.      *
  656.      * @since bbPress (r2727)
  657.      * @uses register_post_status() To register post statuses
  658.      * @uses $wp_post_statuses To modify trash and private statuses
  659.      * @uses current_user_can() To check if the current user is capable &
  660.      *                           modify $wp_post_statuses accordingly
  661.      */
  662.     public static function register_post_statuses() {
  663.  
  664.         // Closed
  665.         register_post_status(
  666.             bbp_get_closed_status_id(),
  667.             apply_filters( 'bbp_register_closed_post_status', array(
  668.                 'label'             => _x( 'Closed', 'post', 'bbpress' ),
  669.                 'label_count'       => _nx_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'post', 'bbpress' ),
  670.                 'public'            => true,
  671.                 'show_in_admin_all' => true
  672.             ) )
  673.         );
  674.  
  675.         // Spam
  676.         register_post_status(
  677.             bbp_get_spam_status_id(),
  678.             apply_filters( 'bbp_register_spam_post_status', array(
  679.                 'label'                     => _x( 'Spam', 'post', 'bbpress' ),
  680.                 'label_count'               => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'post', 'bbpress' ),
  681.                 'protected'                 => true,
  682.                 'exclude_from_search'       => true,
  683.                 'show_in_admin_status_list' => true,
  684.                 'show_in_admin_all_list'    => false
  685.             ) )
  686.          );
  687.  
  688.         // Orphan
  689.         register_post_status(
  690.             bbp_get_orphan_status_id(),
  691.             apply_filters( 'bbp_register_orphan_post_status', array(
  692.                 'label'                     => _x( 'Orphan', 'post', 'bbpress' ),
  693.                 'label_count'               => _nx_noop( 'Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'post', 'bbpress' ),
  694.                 'protected'                 => true,
  695.                 'exclude_from_search'       => true,
  696.                 'show_in_admin_status_list' => true,
  697.                 'show_in_admin_all_list'    => false
  698.             ) )
  699.         );
  700.  
  701.         // Hidden
  702.         register_post_status(
  703.             bbp_get_hidden_status_id(),
  704.             apply_filters( 'bbp_register_hidden_post_status', array(
  705.                 'label'                     => _x( 'Hidden', 'post', 'bbpress' ),
  706.                 'label_count'               => _nx_noop( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'post', 'bbpress' ),
  707.                 'private'                   => true,
  708.                 'exclude_from_search'       => true,
  709.                 'show_in_admin_status_list' => true,
  710.                 'show_in_admin_all_list'    => true
  711.             ) )
  712.         );
  713.  
  714.         /**
  715.          * Trash fix
  716.          *
  717.          * We need to remove the internal arg and change that to
  718.          * protected so that the users with 'view_trash' cap can view
  719.          * single trashed topics/replies in the front-end as wp_query
  720.          * doesn't allow any hack for the trashed topics to be viewed.
  721.          */
  722.         global $wp_post_statuses;
  723.  
  724.         if ( !empty( $wp_post_statuses['trash'] ) ) {
  725.  
  726.             // User can view trash so set internal to false
  727.             if ( current_user_can( 'view_trash' ) ) {
  728.                 $wp_post_statuses['trash']->internal  = false;
  729.                 $wp_post_statuses['trash']->protected = true;
  730.  
  731.             // User cannot view trash so set internal to true
  732.             } else {
  733.                 $wp_post_statuses['trash']->internal = true;
  734.             }
  735.         }
  736.     }
  737.  
  738.     /**
  739.      * Register the topic tag taxonomy
  740.      *
  741.      * @since bbPress (r2464)
  742.      * @uses register_taxonomy() To register the taxonomy
  743.      */
  744.     public static function register_taxonomies() {
  745.  
  746.         // Define local variable(s)
  747.         $topic_tag = array();
  748.  
  749.         // Topic tag labels
  750.         $topic_tag['labels'] = array(
  751.             'name'          => __( 'Topic Tags',     'bbpress' ),
  752.             'singular_name' => __( 'Topic Tag',      'bbpress' ),
  753.             'search_items'  => __( 'Search Tags',    'bbpress' ),
  754.             'popular_items' => __( 'Popular Tags',   'bbpress' ),
  755.             'all_items'     => __( 'All Tags',       'bbpress' ),
  756.             'edit_item'     => __( 'Edit Tag',       'bbpress' ),
  757.             'update_item'   => __( 'Update Tag',     'bbpress' ),
  758.             'add_new_item'  => __( 'Add New Tag',    'bbpress' ),
  759.             'new_item_name' => __( 'New Tag Name',   'bbpress' ),
  760.             'view_item'     => __( 'View Topic Tag', 'bbpress' )
  761.         );
  762.  
  763.         // Topic tag rewrite
  764.         $topic_tag['rewrite'] = array(
  765.             'slug'       => bbp_get_topic_tag_tax_slug(),
  766.             'with_front' => false
  767.         );
  768.  
  769.         // Register the topic tag taxonomy
  770.         register_taxonomy(
  771.             bbp_get_topic_tag_tax_id(),
  772.             bbp_get_topic_post_type(),
  773.             apply_filters( 'bbp_register_topic_taxonomy', array(
  774.                 'labels'                => $topic_tag['labels'],
  775.                 'rewrite'               => $topic_tag['rewrite'],
  776.                 'capabilities'          => bbp_get_topic_tag_caps(),
  777.                 'update_count_callback' => '_update_post_term_count',
  778.                 'query_var'             => true,
  779.                 'show_tagcloud'         => true,
  780.                 'hierarchical'          => false,
  781.                 'show_in_nav_menus'     => false,
  782.                 'public'                => true,
  783.                 'show_ui'               => bbp_allow_topic_tags() && current_user_can( 'bbp_topic_tags_admin' )
  784.             )
  785.         ) );
  786.     }
  787.  
  788.     /**
  789.      * Register the bbPress views
  790.      *
  791.      * @since bbPress (r2789)
  792.      * @uses bbp_register_view() To register the views
  793.      */
  794.     public static function register_views() {
  795.  
  796.         // Popular topics
  797.         bbp_register_view(
  798.             'popular',
  799.             __( 'Most popular topics', 'bbpress' ),
  800.             apply_filters( 'bbp_register_view_popular', array(
  801.                 'meta_key'      => '_bbp_reply_count',
  802.                 'max_num_pages' => 1,
  803.                 'orderby'       => 'meta_value_num',
  804.                 'show_stickies' => false
  805.             )
  806.         ) );
  807.  
  808.         // Topics with no replies
  809.         bbp_register_view(
  810.             'no-replies',
  811.             __( 'Topics with no replies', 'bbpress' ),
  812.             apply_filters( 'bbp_register_view_no_replies', array(
  813.                 'meta_key'      => '_bbp_reply_count',
  814.                 'meta_value'    => 1,
  815.                 'meta_compare'  => '<',
  816.                 'orderby'       => '',
  817.                 'show_stickies' => false
  818.             )
  819.         ) );
  820.     }
  821.  
  822.     /**
  823.      * Register the bbPress shortcodes
  824.      *
  825.      * @since bbPress (r3031)
  826.      *
  827.      * @uses BBP_Shortcodes
  828.      */
  829.     public function register_shortcodes() {
  830.         $this->shortcodes = new BBP_Shortcodes();
  831.     }
  832.  
  833.     /**
  834.      * Setup the currently logged-in user
  835.      *
  836.      * Do not to call this prematurely, I.E. before the 'init' action has
  837.      * started. This function is naturally hooked into 'init' to ensure proper
  838.      * execution. get_currentuserinfo() is used to check for XMLRPC_REQUEST to
  839.      * avoid xmlrpc errors.
  840.      *
  841.      * @since bbPress (r2697)
  842.      * @uses wp_get_current_user()
  843.      */
  844.     public function setup_current_user() {
  845.         $this->current_user = &wp_get_current_user();
  846.     }
  847.  
  848.     /** Custom Rewrite Rules **************************************************/
  849.  
  850.     /**
  851.      * Add the bbPress-specific rewrite tags
  852.      *
  853.      * @since bbPress (r2753)
  854.      * @uses add_rewrite_tag() To add the rewrite tags
  855.      */
  856.     public static function add_rewrite_tags() {
  857.         add_rewrite_tag( '%%' . bbp_get_view_rewrite_id()               . '%%', '([^/]+)'   ); // View Page tag
  858.         add_rewrite_tag( '%%' . bbp_get_edit_rewrite_id()               . '%%', '([1]{1,})' ); // Edit Page tag
  859.         add_rewrite_tag( '%%' . bbp_get_search_rewrite_id()             . '%%', '([^/]+)'   ); // Search Results tag
  860.         add_rewrite_tag( '%%' . bbp_get_user_rewrite_id()               . '%%', '([^/]+)'   ); // User Profile tag
  861.         add_rewrite_tag( '%%' . bbp_get_user_favorites_rewrite_id()     . '%%', '([1]{1,})' ); // User Favorites tag
  862.         add_rewrite_tag( '%%' . bbp_get_user_subscriptions_rewrite_id() . '%%', '([1]{1,})' ); // User Subscriptions tag
  863.         add_rewrite_tag( '%%' . bbp_get_user_topics_rewrite_id()        . '%%', '([1]{1,})' ); // User Topics Tag
  864.         add_rewrite_tag( '%%' . bbp_get_user_replies_rewrite_id()       . '%%', '([1]{1,})' ); // User Replies Tag
  865.     }
  866.  
  867.     /**
  868.      * Register bbPress-specific rewrite rules for uri's that are not
  869.      * setup for us by way of custom post types or taxonomies. This includes:
  870.      * - Front-end editing
  871.      * - Topic views
  872.      * - User profiles
  873.      *
  874.      * @since bbPress (r2688)
  875.      * @param WP_Rewrite $wp_rewrite bbPress-sepecific rules are appended in
  876.      *                                $wp_rewrite->rules
  877.      */
  878.     public static function generate_rewrite_rules( $wp_rewrite ) {
  879.  
  880.         // Slugs
  881.         $view_slug   = bbp_get_view_slug();
  882.         $search_slug = bbp_get_search_slug();
  883.         $user_slug   = bbp_get_user_slug();
  884.  
  885.         // Unique rewrite ID's
  886.         $edit_id     = bbp_get_edit_rewrite_id();
  887.         $view_id     = bbp_get_view_rewrite_id();
  888.         $search_id   = bbp_get_search_rewrite_id();
  889.         $user_id     = bbp_get_user_rewrite_id();
  890.         $favs_id     = bbp_get_user_favorites_rewrite_id();
  891.         $subs_id     = bbp_get_user_subscriptions_rewrite_id();
  892.         $tops_id     = bbp_get_user_topics_rewrite_id();
  893.         $reps_id     = bbp_get_user_replies_rewrite_id();
  894.  
  895.         // Rewrite rule matches used repeatedly below
  896.         $root_rule   = '/([^/]+)/?$';
  897.         $edit_rule   = '/([^/]+)/edit/?$';
  898.         $feed_rule   = '/([^/]+)/feed/?$';
  899.         $page_rule   = '/([^/]+)/page/?([0-9]{1,})/?$';
  900.  
  901.         // Search rules (without slug check)
  902.         $search_root_rule = '/?$';
  903.         $search_page_rule = '/page/?([0-9]{1,})/?$';
  904.  
  905.         // User profile rules
  906.         $tops_rule      = '/([^/]+)/topics/?$';
  907.         $reps_rule      = '/([^/]+)/replies/?$';
  908.         $favs_rule      = '/([^/]+)/' . bbp_get_user_favorites_slug()     . '/?$';
  909.         $subs_rule      = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/?$';
  910.         $tops_page_rule = '/([^/]+)/topics/page/?([0-9]{1,})/?$';
  911.         $reps_page_rule = '/([^/]+)/replies/page/?([0-9]{1,})/?$';
  912.         $favs_page_rule = '/([^/]+)/' . bbp_get_user_favorites_slug()     . '/page/?([0-9]{1,})/?$';
  913.         $subs_page_rule = '/([^/]+)/' . bbp_get_user_subscriptions_slug() . '/page/?([0-9]{1,})/?$';
  914.  
  915.         // New bbPress specific rules to merge with existing that are not
  916.         // handled automatically by custom post types or taxonomy types
  917.         $bbp_rules = array(
  918.  
  919.             // Edit Forum|Topic|Reply|Topic-tag
  920.             bbp_get_forum_slug()         . $edit_rule => 'index.php?' . bbp_get_forum_post_type()  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
  921.             bbp_get_topic_slug()         . $edit_rule => 'index.php?' . bbp_get_topic_post_type()  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
  922.             bbp_get_reply_slug()         . $edit_rule => 'index.php?' . bbp_get_reply_post_type()  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
  923.             bbp_get_topic_tag_tax_slug() . $edit_rule => 'index.php?' . bbp_get_topic_tag_tax_id() . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
  924.  
  925.             // User Pagination|Edit|View
  926.             $user_slug . $tops_page_rule => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $tops_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ),
  927.             $user_slug . $reps_page_rule => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $reps_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ),
  928.             $user_slug . $favs_page_rule => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $favs_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ),
  929.             $user_slug . $subs_page_rule => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $subs_id . '=1&paged=' . $wp_rewrite->preg_index( 2 ),
  930.             $user_slug . $tops_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $tops_id . '=1',
  931.             $user_slug . $reps_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $reps_id . '=1',
  932.             $user_slug . $favs_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $favs_id . '=1',
  933.             $user_slug . $subs_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $subs_id . '=1',
  934.             $user_slug . $edit_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ) . '&' . $edit_id . '=1',
  935.             $user_slug . $root_rule      => 'index.php?' . $user_id  . '=' . $wp_rewrite->preg_index( 1 ),
  936.  
  937.             // Topic-View Pagination|Feed|View
  938.             $view_slug . $page_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
  939.             $view_slug . $feed_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ) . '&feed='  . $wp_rewrite->preg_index( 2 ),
  940.             $view_slug . $root_rule => 'index.php?' . $view_id . '=' . $wp_rewrite->preg_index( 1 ),
  941.  
  942.             // Search All
  943.             $search_slug . $search_page_rule => 'index.php?paged=' . $wp_rewrite->preg_index( 1 ),
  944.             $search_slug . $search_root_rule => 'index.php?' . $search_id,
  945.         );
  946.  
  947.         // Merge bbPress rules with existing
  948.         $wp_rewrite->rules = array_merge( $bbp_rules, $wp_rewrite->rules );
  949.  
  950.         // Return merged rules
  951.         return $wp_rewrite;
  952.     }
  953. }
  954.  
  955. /**
  956.  * The main function responsible for returning the one true bbPress Instance
  957.  * to functions everywhere.
  958.  *
  959.  * Use this function like you would a global variable, except without needing
  960.  * to declare the global.
  961.  *
  962.  * Example: <?php $bbp = bbpress(); ?>
  963.  *
  964.  * @return The one true bbPress Instance
  965.  */
  966. function bbpress() {
  967.     return bbpress::instance();
  968. }
  969.  
  970. /**
  971.  * Hook bbPress early onto the 'plugins_loaded' action.
  972.  *
  973.  * This gives all other plugins the chance to load before bbPress, to get their
  974.  * actions, filters, and overrides setup without bbPress being in the way.
  975.  */
  976. if ( defined( 'BBPRESS_LATE_LOAD' ) ) {
  977.     add_action( 'plugins_loaded', 'bbpress', (int) BBPRESS_LATE_LOAD );
  978.  
  979. // "And now here's something we hope you'll really like!"
  980. } else {
  981.     bbpress();
  982. }
  983.  
  984. endif; // class_exists check
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement