BP_Docs

Main plugin class.

Defined (1)

The class is defined in the following location(s).

/bp-docs.php  
  1. class BP_Docs { 
  2. var $post_type_name; 
  3. var $associated_item_tax_name; 
  4.  
  5. /** 
  6. * Folders add-on. 
  7. * @var BP_Docs_Folders 
  8. * @since 1.8 
  9. */ 
  10. var $folders; 
  11.  
  12. /** 
  13. * PHP 5 constructor 
  14. * @since 1.0-beta 
  15. */ 
  16. function __construct() { 
  17.  
  18. // Define post type and taxonomy names for use in the register functions 
  19. $this->post_type_name = apply_filters( 'bp_docs_post_type_name', 'bp_doc' ); 
  20. $this->associated_item_tax_name = apply_filters( 'bp_docs_associated_item_tax_name', 'bp_docs_associated_item' ); 
  21. $this->access_tax_name = apply_filters( 'bp_docs_access_tax_name', 'bp_docs_access' ); 
  22.  
  23. // :'( 
  24. wp_cache_add_non_persistent_groups( array( 'bp_docs_nonpersistent' ) ); 
  25.  
  26. // Let plugins know that BP Docs has started loading 
  27. add_action( 'plugins_loaded', array( $this, 'load_hook' ), 20 ); 
  28.  
  29. // Load predefined constants first thing 
  30. add_action( 'bp_docs_load', array( $this, 'load_constants' ), 2 ); 
  31.  
  32. // Includes necessary files 
  33. add_action( 'bp_docs_load', array( $this, 'includes' ), 4 ); 
  34.  
  35. // Load the BP Component extension 
  36. add_action( 'bp_docs_load', array( $this, 'do_integration' ), 6 ); 
  37.  
  38. // Load textdomain 
  39. add_action( 'bp_docs_load', array( $this, 'load_plugin_textdomain' ) ); 
  40.  
  41. // Let other plugins know that BP Docs has finished initializing 
  42. add_action( 'bp_init', array( $this, 'init_hook' ) ); 
  43.  
  44. // Hooks into the 'init' action to register our WP custom post type and tax 
  45. add_action( 'bp_docs_init', array( $this, 'register_post_type' ), 2 ); 
  46. add_action( 'bp_docs_init', array( &$this, 'add_rewrite_tags' ), 4 ); 
  47.  
  48. // Set up doc taxonomy, etc 
  49. add_action( 'bp_docs_init', array( $this, 'load_doc_extras' ), 8 ); 
  50.  
  51. // Add rewrite rules 
  52. add_action( 'generate_rewrite_rules', array( &$this, 'generate_rewrite_rules' ) ); 
  53.  
  54. // parse_query 
  55. add_action( 'parse_query', array( $this, 'parse_query' ) ); 
  56.  
  57. // Protect doc access 
  58. add_action( 'template_redirect', array( $this, 'protect_doc_access' ) ); 
  59.  
  60. add_action( 'admin_init', array( $this, 'flush_rewrite_rules' ) ); 
  61.  
  62. /** 
  63. * PHP 4 constructor 
  64. * @since 1.0-beta 
  65. */ 
  66. function bp_docs() { 
  67. $this->__construct(); 
  68.  
  69. /** 
  70. * Loads the textdomain for the plugin 
  71. * @since 1.0.2 
  72. */ 
  73. function load_plugin_textdomain() { 
  74. load_plugin_textdomain( 'bp-docs', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
  75.  
  76. /** 
  77. * Includes files needed by BuddyPress Docs 
  78. * @since 1.0-beta 
  79. */ 
  80. function includes() { 
  81.  
  82. // functions.php includes miscellaneous utility functions used throughout 
  83. require( BP_DOCS_INCLUDES_PATH . 'functions.php' ); 
  84.  
  85. // component.php extends BP_Component, and does most of the basic setup for BP Docs 
  86. require( BP_DOCS_INCLUDES_PATH . 'component.php' ); 
  87.  
  88. // caps.php handles capabilities and roles 
  89. require( BP_DOCS_INCLUDES_PATH . 'caps.php' ); 
  90.  
  91. // access-query.php is a helper for determining access to docs 
  92. require( BP_DOCS_INCLUDES_PATH . 'access-query.php' ); 
  93.  
  94. // query-builder.php contains the class that fetches the content for each view 
  95. require( BP_DOCS_INCLUDES_PATH . 'query-builder.php' ); 
  96.  
  97. // templatetags.php has all functions in the global space available to templates 
  98. require( BP_DOCS_INCLUDES_PATH . 'templatetags.php' ); 
  99.  
  100. require( BP_DOCS_INCLUDES_PATH . 'templatetags-edit.php' ); 
  101.  
  102. require( BP_DOCS_INCLUDES_PATH . 'attachments.php' ); 
  103.  
  104. require( BP_DOCS_INCLUDES_PATH . 'ajax-validation.php' ); 
  105.  
  106. require( BP_DOCS_INCLUDES_PATH . 'theme-bridge.php' ); 
  107.  
  108. require( BP_DOCS_INCLUDES_PATH . 'edit-lock.php' ); 
  109.  
  110. // formatting.php contains filters and functions used to modify appearance only 
  111. require( BP_DOCS_INCLUDES_PATH . 'formatting.php' ); 
  112.  
  113. // class-wp-widget-recent-docs.php adds a widget to show recently created docs. 
  114. require( BP_DOCS_INCLUDES_PATH . 'class-wp-widget-recent-docs.php' ); 
  115.  
  116. // Dashboard-specific functions 
  117. if ( is_admin() ) { 
  118. require( BP_DOCS_INCLUDES_PATH . 'admin.php' ); 
  119. require( BP_DOCS_INCLUDES_PATH . 'upgrade.php' ); 
  120.  
  121. /** 
  122. * Defines bp_docs_load action 
  123. * This action fires on WP's plugins_loaded action and provides a way for the rest of 
  124. * BuddyPress Docs, as well as other dependent plugins, to hook into the loading process in 
  125. * an orderly fashion. 
  126. * @since 1.2 
  127. */ 
  128. function load_hook() { 
  129. do_action( 'bp_docs_load' ); 
  130.  
  131. /** 
  132. * Defines bp_docs_init action 
  133. * This action fires on WP's init action and provides a way for the rest of BuddyPress 
  134. * Docs, as well as other dependent plugins, to hook into the loading process in an 
  135. * orderly fashion. 
  136. * @since 1.0-beta 
  137. */ 
  138. function init_hook() { 
  139. do_action( 'bp_docs_init' ); 
  140.  
  141. /** 
  142. * Defines bp_docs_loaded action 
  143. * This action tells BP Docs and other plugins that the main initialization process has 
  144. * finished. 
  145. * @since 1.0-beta 
  146. */ 
  147. function loaded() { 
  148. do_action( 'bp_docs_loaded' ); 
  149.  
  150. /** 
  151. * Defines constants needed throughout the plugin. 
  152. * These constants can be overridden in bp-custom.php or wp-config.php. 
  153. * @since 1.0-beta 
  154. */ 
  155. function load_constants() { 
  156. if ( ! defined( 'BP_DOCS_PLUGIN_SLUG' ) ) { 
  157. define( 'BP_DOCS_PLUGIN_SLUG', 'buddypress-docs' ); 
  158.  
  159. // You should never really need to override this bad boy 
  160. if ( !defined( 'BP_DOCS_INSTALL_PATH' ) ) { 
  161. define( 'BP_DOCS_INSTALL_PATH', plugin_dir_path( __FILE__ ) ); 
  162.  
  163. // Ditto 
  164. if ( !defined( 'BP_DOCS_INCLUDES_PATH' ) ) 
  165. define( 'BP_DOCS_INCLUDES_PATH', BP_DOCS_INSTALL_PATH . 'includes/' ); 
  166.  
  167. // Ditto^2. For deprecated files, we need a non-system path. Note: doesn't work 
  168. // right with symlinks 
  169. if ( !defined( 'BP_DOCS_INCLUDES_PATH_ABS' ) ) 
  170. define( 'BP_DOCS_INCLUDES_PATH_ABS', str_replace( ABSPATH, '', BP_DOCS_INCLUDES_PATH ) ); 
  171.  
  172. // The slug used when viewing a doc category 
  173. if ( !defined( 'BP_DOCS_CATEGORY_SLUG' ) ) 
  174. define( 'BP_DOCS_CATEGORY_SLUG', 'category' ); 
  175.  
  176. // The slug used when editing a doc 
  177. if ( !defined( 'BP_DOCS_EDIT_SLUG' ) ) 
  178. define( 'BP_DOCS_EDIT_SLUG', 'edit' ); 
  179.  
  180. // The slug used when viewing doc histor 
  181. if ( !defined( 'BP_DOCS_HISTORY_SLUG' ) ) 
  182. define( 'BP_DOCS_HISTORY_SLUG', 'history' ); 
  183.  
  184. // The slug used when viewing a single doc 
  185. if ( !defined( 'BP_DOCS_SINGLE_SLUG' ) ) 
  186. define( 'BP_DOCS_SINGLE_SLUG', 'single' ); 
  187.  
  188. // The slug used when creating a new doc 
  189. if ( !defined( 'BP_DOCS_CREATE_SLUG' ) ) 
  190. define( 'BP_DOCS_CREATE_SLUG', 'create' ); 
  191.  
  192. // The slug used when deleting a doc 
  193. if ( !defined( 'BP_DOCS_DELETE_SLUG' ) ) 
  194. define( 'BP_DOCS_DELETE_SLUG', 'delete' ); 
  195.  
  196. // The slug used when deleting a doc 
  197. if ( !defined( 'BP_DOCS_UNTRASH_SLUG' ) ) 
  198. define( 'BP_DOCS_UNTRASH_SLUG', 'untrash' ); 
  199.  
  200. // The slug used when removing a doc from a group 
  201. if ( ! defined( 'BP_DOCS_UNLINK_FROM_GROUP_SLUG' ) ) 
  202. define( 'BP_DOCS_UNLINK_FROM_GROUP_SLUG', 'unlink-from-group' ); 
  203.  
  204. // The slug used for the Started section of My Docs 
  205. if ( !defined( 'BP_DOCS_STARTED_SLUG' ) ) 
  206. define( 'BP_DOCS_STARTED_SLUG', 'started' ); 
  207.  
  208. // The slug used for the Edited section of My Docs 
  209. if ( !defined( 'BP_DOCS_EDITED_SLUG' ) ) 
  210. define( 'BP_DOCS_EDITED_SLUG', 'edited' ); 
  211.  
  212. // The slug used for 'my-docs' 
  213. if ( !defined( 'BP_DOCS_MY_DOCS_SLUG' ) ) 
  214. define( 'BP_DOCS_MY_DOCS_SLUG', 'my-docs' ); 
  215.  
  216. // The slug used for 'my-groups' 
  217. if ( !defined( 'BP_DOCS_MY_GROUPS_SLUG' ) ) 
  218. define( 'BP_DOCS_MY_GROUPS_SLUG', 'my-groups' ); 
  219.  
  220. // By default, BP Docs will replace the Recent Comments WP Dashboard Widget 
  221. if ( !defined( 'BP_DOCS_REPLACE_RECENT_COMMENTS_DASHBOARD_WIDGET' ) ) 
  222. define( 'BP_DOCS_REPLACE_RECENT_COMMENTS_DASHBOARD_WIDGET', true ); 
  223.  
  224. /** 
  225. * Registers BuddyPress Docs's post types and taxonomies 
  226. * The post type bp_doc corresponds to individual doc page, which in turn corresponds to 
  227. * individual WP posts (plus their revisions). 
  228. * The taxonomy bp_docs_associated_item is a hierarchical taxonomy that connects bp_doc 
  229. * items to groups. The parent terms 'groups' and 'users' are created automatically when 
  230. * first doc corresponding to that item type is created. Individual item ids, like 
  231. * group_ids or user_ids, have taxonomy item created for them (if necessary) when a doc 
  232. * needs to be associated with them. So a bp_doc post associated with group 6 will have 
  233. * the taxonomy bp_docs_associated_item '6', where '6' is a sub-tax of 'groups'. 
  234. * @since 1.0-beta 
  235. */ 
  236. function register_post_type() { 
  237. // Only register on the root blog 
  238. if ( !bp_is_root_blog() ) 
  239. switch_to_blog( BP_ROOT_BLOG ); 
  240.  
  241. // Define the labels to be used by the post type bp_doc 
  242. $post_type_labels = array( 
  243. 'name' => _x( 'Docs', 'post type general name', 'bp-docs' ),  
  244. 'singular_name' => _x( 'Doc', 'post type singular name', 'bp-docs' ),  
  245. 'add_new' => _x( 'Add New', 'add new', 'bp-docs' ),  
  246. 'add_new_item' => __( 'Add New Doc', 'bp-docs' ),  
  247. 'edit_item' => __( 'Edit Doc', 'bp-docs' ),  
  248. 'new_item' => __( 'New Doc', 'bp-docs' ),  
  249. 'view_item' => __( 'View Doc', 'bp-docs' ),  
  250. 'search_items' => __( 'Search Docs', 'bp-docs' ),  
  251. 'not_found' => __( 'No Docs found', 'bp-docs' ),  
  252. 'not_found_in_trash' => __( 'No Docs found in Trash', 'bp-docs' ),  
  253. 'parent_item_colon' => '' 
  254. ); 
  255.  
  256. // Set up the arguments to be used when the post type is registered 
  257. // Only filter this if you are hella smart and/or know what you're doing 
  258. $bp_docs_post_type_args = apply_filters( 'bp_docs_post_type_args', array( 
  259. 'label' => __( 'Docs', 'bp-docs' ),  
  260. 'labels' => $post_type_labels,  
  261. 'public' => true,  
  262. 'show_ui' => $this->show_cpt_ui(),  
  263. 'hierarchical' => true,  
  264. 'supports' => array( 'title', 'editor', 'revisions', 'excerpt', 'comments', 'author' ),  
  265. 'query_var' => true,  
  266. 'has_archive' => true,  
  267. 'rewrite' => array( 
  268. 'slug' => bp_docs_get_docs_slug(),  
  269. 'with_front' => false 
  270. ) ); 
  271.  
  272. // Register the bp_doc post type 
  273. register_post_type( $this->post_type_name, $bp_docs_post_type_args ); 
  274.  
  275. // Define the labels to be used by the taxonomy bp_docs_associated_item 
  276. $associated_item_labels = array( 
  277. 'name' => __( 'Associated Items', 'bp-docs' ),  
  278. 'singular_name' => __( 'Associated Item', 'bp-docs' ) 
  279. ); 
  280.  
  281. // Register the bp_docs_associated_item taxonomy 
  282. register_taxonomy( $this->associated_item_tax_name, array( $this->post_type_name ), array( 
  283. 'labels' => $associated_item_labels,  
  284. 'hierarchical' => true,  
  285. 'show_ui' => true,  
  286. 'query_var' => true,  
  287. 'rewrite' => array( 'slug' => 'item' ),  
  288. ) ); 
  289.  
  290. // Register the bp_docs_access taxonomy 
  291. register_taxonomy( $this->access_tax_name, array( $this->post_type_name ), array( 
  292. 'hierarchical' => false,  
  293. 'show_ui' => false,  
  294. 'query_var' => false,  
  295. ) ); 
  296.  
  297. do_action( 'bp_docs_registered_post_type' ); 
  298.  
  299. // Only register on the root blog 
  300. if ( !bp_is_root_blog() ) 
  301. restore_current_blog(); 
  302.  
  303.  
  304. /** 
  305. * Loads the file that enables the use of extras (doc taxonomy, hierarchy, etc) 
  306. * This is loaded conditionally, so that the use of extras can be disabled by the 
  307. * administrator. It is loaded before the bp_docs post type is registered so that we have 
  308. * access to the 'taxonomy' argument of register_post_type. 
  309. * @since 1.0-beta 
  310. */ 
  311. function load_doc_extras() { 
  312. // Todo: make this conditional with a filter or a constant 
  313. require_once( BP_DOCS_INCLUDES_PATH . 'addon-taxonomy.php' ); 
  314. $this->taxonomy = new BP_Docs_Taxonomy; 
  315.  
  316. require_once( BP_DOCS_INCLUDES_PATH . 'addon-hierarchy.php' ); 
  317. $this->hierarchy = new BP_Docs_Hierarchy; 
  318.  
  319. // Don't load the History component if post revisions are disabled 
  320. $wp_post_revisions = defined( 'WP_POST_REVISIONS' ) && WP_POST_REVISIONS; 
  321. $bp_docs_revisions = defined( 'BP_DOCS_REVISIONS' ) && BP_DOCS_REVISIONS; 
  322. if ( $wp_post_revisions || $bp_docs_revisions ) { 
  323. require_once( BP_DOCS_INCLUDES_PATH . 'addon-history.php' ); 
  324. $this->history = new BP_Docs_History; 
  325.  
  326. // Load the wikitext addon 
  327. require_once( BP_DOCS_INCLUDES_PATH . 'addon-wikitext.php' ); 
  328. $this->wikitext = new BP_Docs_Wikitext; 
  329.  
  330. // Load the Folders addon 
  331. require_once( BP_DOCS_INCLUDES_PATH . 'addon-folders.php' ); 
  332. $this->folders = new BP_Docs_Folders(); 
  333.  
  334. do_action( 'bp_docs_load_doc_extras' ); 
  335.  
  336. /** 
  337. * Add rewrite tags 
  338. * @since 1.2 
  339. */ 
  340. function add_rewrite_tags() { 
  341. add_rewrite_tag( '%%' . BP_DOCS_EDIT_SLUG . '%%', '([1]{1, })' ); 
  342. add_rewrite_tag( '%%' . BP_DOCS_HISTORY_SLUG . '%%', '([1]{1, })' ); 
  343. add_rewrite_tag( '%%' . BP_DOCS_DELETE_SLUG . '%%', '([1]{1, })' ); 
  344. add_rewrite_tag( '%%' . BP_DOCS_UNTRASH_SLUG . '%%', '([1]{1, })' ); 
  345. add_rewrite_tag( '%%' . BP_DOCS_CREATE_SLUG . '%%', '([1]{1, })' ); 
  346. add_rewrite_tag( '%%' . BP_DOCS_MY_GROUPS_SLUG . '%%', '([1]{1, })' ); 
  347. add_rewrite_tag( '%%' . BP_DOCS_UNLINK_FROM_GROUP_SLUG . '%%', '([1]{1, })' ); 
  348.  
  349.  
  350. /** 
  351. * Generates custom rewrite rules 
  352. * @since 1.2 
  353. */ 
  354. function generate_rewrite_rules( $wp_rewrite ) { 
  355. $bp_docs_rules = array( 
  356. /** 
  357. * Top level 
  358. */ 
  359.  
  360. // Create 
  361. bp_docs_get_docs_slug() . '/' . BP_DOCS_CREATE_SLUG . '/?$' => 
  362. 'index.php?post_type=' . $this->post_type_name . '&name=' . $wp_rewrite->preg_index( 1 ) . '&' . BP_DOCS_CREATE_SLUG . '=1',  
  363.  
  364. // My Groups 
  365. bp_docs_get_docs_slug() . '/' . BP_DOCS_MY_GROUPS_SLUG . "/{$wp_rewrite->pagination_base}/([0-9]{1, })/?$" => 
  366. 'index.php?post_type=' . $this->post_type_name . '&' . BP_DOCS_MY_GROUPS_SLUG . '=1' . '&paged=' . $wp_rewrite->preg_index( 1 ),  
  367. bp_docs_get_docs_slug() . '/' . BP_DOCS_MY_GROUPS_SLUG . '/?$' => 
  368. 'index.php?post_type=' . $this->post_type_name . '&name=' . $wp_rewrite->preg_index( 1 ) . '&' . BP_DOCS_MY_GROUPS_SLUG . '=1',  
  369.  
  370. /** 
  371. * Single Docs 
  372. */ 
  373.  
  374. // Edit 
  375. bp_docs_get_docs_slug() . '/([^/]+)/' . BP_DOCS_EDIT_SLUG . '/?$' => 
  376. 'index.php?post_type=' . $this->post_type_name . '&name=' . $wp_rewrite->preg_index( 1 ) . '&' . BP_DOCS_EDIT_SLUG . '=1',  
  377.  
  378. // History 
  379. bp_docs_get_docs_slug() . '/([^/]+)/' . BP_DOCS_HISTORY_SLUG . '/?$' => 
  380. 'index.php?post_type=' . $this->post_type_name . '&name=' . $wp_rewrite->preg_index( 1 ) . '&' . BP_DOCS_HISTORY_SLUG . '=1',  
  381.  
  382. // Delete 
  383. bp_docs_get_docs_slug() . '/([^/]+)/' . BP_DOCS_DELETE_SLUG . '/?$' => 
  384. 'index.php?post_type=' . $this->post_type_name . '&name=' . $wp_rewrite->preg_index( 1 ) . '&' . BP_DOCS_HISTORY_SLUG . '=1',  
  385.  
  386. // Untrash 
  387. bp_docs_get_docs_slug() . '/([^/]+)/' . BP_DOCS_UNTRASH_SLUG . '/?$' => 
  388. 'index.php?post_type=' . $this->post_type_name . '&name=' . $wp_rewrite->preg_index( 1 ) . '&' . BP_DOCS_UNTRASH_SLUG . '=1',  
  389.  
  390. // Unlink from group 
  391. bp_docs_get_docs_slug() . '/([^/]+)/' . BP_DOCS_UNLINK_FROM_GROUP_SLUG . '/?$' => 
  392. 'index.php?post_type=' . $this->post_type_name . '&name=' . $wp_rewrite->preg_index( 1 ) . '&' . BP_DOCS_UNLINK_FROM_GROUP_SLUG . '=1',  
  393.  
  394. ); 
  395.  
  396. // Merge Docs rules with existing 
  397. $wp_rewrite->rules = array_merge( $bp_docs_rules, $wp_rewrite->rules ); 
  398.  
  399. return $wp_rewrite; 
  400.  
  401. /** 
  402. * Show the CPT Dashboard UI to the current user? 
  403. * Defaults to is_super_admin(), but is filterable 
  404. * @since 1.0.8 
  405. * @return bool $show_ui 
  406. */ 
  407. function show_cpt_ui() { 
  408. $show_ui = is_super_admin(); 
  409.  
  410. return apply_filters( 'bp_docs_show_cpt_ui', $show_ui ); 
  411.  
  412. /** 
  413. * Handles stuff that needs to be done at 'parse_query' 
  414. * - Ensures that no post is loaded on the creation screen 
  415. * - Ensures that an archive template is loaded in /docs/my-groups/ 
  416. */ 
  417. function parse_query( $posts_query ) { 
  418.  
  419. // Bail if $posts_query is not the main loop 
  420. if ( ! $posts_query->is_main_query() ) 
  421. return; 
  422.  
  423. // Bail if filters are suppressed on this query 
  424. if ( true == $posts_query->get( 'suppress_filters' ) ) 
  425. return; 
  426.  
  427. // Bail if in admin 
  428. if ( is_admin() ) 
  429. return; 
  430.  
  431. // Don't query for any posts on /docs/create/ 
  432. if ( $posts_query->get( BP_DOCS_CREATE_SLUG ) ) { 
  433. $posts_query->is_404 = false; 
  434. $posts_query->set( 'p', -1 ); 
  435.  
  436. // Fall back on archive template on /docs/my-groups/ 
  437. if ( $posts_query->get( BP_DOCS_MY_GROUPS_SLUG ) ) { 
  438. $posts_query->is_404 = false; 
  439.  
  440. // For single Doc views, allow access to 'deleted' items 
  441. // that the current user is the admin of 
  442. if ( $posts_query->is_single && bp_docs_get_post_type_name() === $posts_query->get( 'post_type' ) ) { 
  443.  
  444. $doc_slug = $posts_query->get( 'name' ); 
  445.  
  446. // Direct query, because barf 
  447. global $wpdb; 
  448. $author_id = $wpdb->get_var( $wpdb->prepare( 
  449. "SELECT post_author FROM {$wpdb->posts} WHERE post_type = %s AND post_name = %s",  
  450. bp_docs_get_post_type_name(),  
  451. $doc_slug 
  452. ) ); 
  453.  
  454. // Post author or mod can visit it 
  455. if ( $author_id && ( $author_id == get_current_user_id() || current_user_can( 'bp_moderate' ) ) ) { 
  456. $posts_query->set( 'post_status', array( 'publish', 'trash' ) ); 
  457.  
  458. // Make the 'trash' post status public 
  459. add_filter( 'posts_request', array( $this, 'make_trash_public' ) ); 
  460.  
  461. // ... and undo that when we're done 
  462. add_filter( 'the_posts', array( $this, 'remove_make_trash_public' ) ); 
  463.  
  464. /** 
  465. * Make the 'trash' post status public. 
  466. * This is an unavoidable hack for cases where we want a trashed doc 
  467. * to be visitable by the post author or by an admin. 
  468. * Access is public because it needs to be accessible by 
  469. * call_user_func(), but should *not* be called directly. 
  470. * @since BuddyPress 1.5.5 
  471. * @param $request Passthrough. 
  472. */ 
  473. public function make_trash_public( $request ) { 
  474. global $wp_post_statuses; 
  475. $wp_post_statuses['trash']->public = true; 
  476. return $request; 
  477.  
  478. /** 
  479. * Reverse the public-trash hack applied in self::make_trash_public() 
  480. * @since BuddyPress 1.5.5 
  481. * @param $posts Passthrough. 
  482. */ 
  483. public function remove_make_trash_public( $posts ) { 
  484. global $wp_post_statuses; 
  485. $wp_post_statuses['trash']->public = false; 
  486. return $posts; 
  487.  
  488. /** 
  489. * Protects group docs from unauthorized access 
  490. * @since 1.2 
  491. */ 
  492. function protect_doc_access() { 
  493. // What is the user trying to do? 
  494. if ( bp_docs_is_doc_read() ) { 
  495. $action = 'bp_docs_read'; 
  496. } else if ( bp_docs_is_doc_create() ) { 
  497. $action = 'bp_docs_create'; 
  498. } else if ( bp_docs_is_doc_edit() ) { 
  499. $action = 'bp_docs_edit'; 
  500. } else if ( bp_docs_is_doc_history() ) { 
  501. $action = 'bp_docs_view_history'; 
  502.  
  503. if ( ! isset( $action ) ) { 
  504. return; 
  505.  
  506. if ( ! current_user_can( $action ) ) { 
  507. $redirect_to = bp_docs_get_doc_link(); 
  508.  
  509. bp_core_no_access( array( 
  510. 'mode' => 2,  
  511. 'redirect' => $redirect_to,  
  512. ) ); 
  513.  
  514. function flush_rewrite_rules() { 
  515. if ( ! is_admin() ) { 
  516. return; 
  517.  
  518. if ( ! is_super_admin() ) { 
  519. return; 
  520.  
  521. global $wp_rewrite; 
  522.  
  523. // Check to see whether our rules have been registered yet, by 
  524. // finding a Docs rule and then comparing it to the registered rules 
  525. $test_rewrite = null; 
  526. foreach ( $wp_rewrite->extra_rules_top as $rewrite => $rule ) { 
  527. if ( 0 === strpos( $rewrite, bp_docs_get_docs_slug() ) ) { 
  528. $test_rewrite = $rewrite; 
  529. $test_rule = $rule; 
  530. break; 
  531. $registered_rules = get_option( 'rewrite_rules' ); 
  532.  
  533. if ( $test_rewrite && is_array( $registered_rules ) && ( ! isset( $registered_rules[ $test_rewrite ] ) || $test_rule !== $registered_rules[ $test_rewrite ] ) ) { 
  534. flush_rewrite_rules(); 
  535.  
  536. /** 
  537. * Initiates the BP Component extension 
  538. * @since 1.0-beta 
  539. */ 
  540. function do_integration() { 
  541. global $bp; 
  542.  
  543. $bp->bp_docs = new BP_Docs_Component;