PageRenderTime 37ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/bbpress/includes/core/actions.php

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 313 lines | 152 code | 42 blank | 119 comment | 1 complexity | 00e25443fd798b0b72bfd5299b68d07c MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. * bbPress Actions
  4. *
  5. * @package bbPress
  6. * @subpackage Core
  7. *
  8. * This file contains the actions that are used through-out bbPress. They are
  9. * consolidated here to make searching for them easier, and to help developers
  10. * understand at a glance the order in which things occur.
  11. *
  12. * There are a few common places that additional actions can currently be found
  13. *
  14. * - bbPress: In {@link bbPress::setup_actions()} in bbpress.php
  15. * - Admin: More in {@link BBP_Admin::setup_actions()} in admin.php
  16. *
  17. * @see /core/filters.php
  18. */
  19. // Exit if accessed directly
  20. if ( !defined( 'ABSPATH' ) ) exit;
  21. /**
  22. * Attach bbPress to WordPress
  23. *
  24. * bbPress uses its own internal actions to help aid in third-party plugin
  25. * development, and to limit the amount of potential future code changes when
  26. * updates to WordPress core occur.
  27. *
  28. * These actions exist to create the concept of 'plugin dependencies'. They
  29. * provide a safe way for plugins to execute code *only* when bbPress is
  30. * installed and activated, without needing to do complicated guesswork.
  31. *
  32. * For more information on how this works, see the 'Plugin Dependency' section
  33. * near the bottom of this file.
  34. *
  35. * v--WordPress Actions v--bbPress Sub-actions
  36. */
  37. add_action( 'plugins_loaded', 'bbp_loaded', 10 );
  38. add_action( 'init', 'bbp_init', 0 ); // Early for bbp_register
  39. add_action( 'parse_query', 'bbp_parse_query', 2 ); // Early for overrides
  40. add_action( 'widgets_init', 'bbp_widgets_init', 10 );
  41. add_action( 'generate_rewrite_rules', 'bbp_generate_rewrite_rules', 10 );
  42. add_action( 'wp_enqueue_scripts', 'bbp_enqueue_scripts', 10 );
  43. add_action( 'wp_head', 'bbp_head', 10 );
  44. add_action( 'wp_footer', 'bbp_footer', 10 );
  45. add_action( 'set_current_user', 'bbp_setup_current_user', 10 );
  46. add_action( 'setup_theme', 'bbp_setup_theme', 10 );
  47. add_action( 'after_setup_theme', 'bbp_after_setup_theme', 10 );
  48. add_action( 'template_redirect', 'bbp_template_redirect', 8 ); // Before BuddyPress's 10 [BB2225]
  49. add_action( 'login_form_login', 'bbp_login_form_login', 10 );
  50. add_action( 'profile_update', 'bbp_profile_update', 10, 2 ); // user_id and old_user_data
  51. add_action( 'user_register', 'bbp_user_register', 10 );
  52. /**
  53. * bbp_loaded - Attached to 'plugins_loaded' above
  54. *
  55. * Attach various loader actions to the bbp_loaded action.
  56. * The load order helps to execute code at the correct time.
  57. * v---Load order
  58. */
  59. add_action( 'bbp_loaded', 'bbp_constants', 2 );
  60. add_action( 'bbp_loaded', 'bbp_boot_strap_globals', 4 );
  61. add_action( 'bbp_loaded', 'bbp_includes', 6 );
  62. add_action( 'bbp_loaded', 'bbp_setup_globals', 8 );
  63. add_action( 'bbp_loaded', 'bbp_setup_option_filters', 10 );
  64. add_action( 'bbp_loaded', 'bbp_setup_user_option_filters', 12 );
  65. add_action( 'bbp_loaded', 'bbp_register_theme_packages', 14 );
  66. add_action( 'bbp_loaded', 'bbp_filter_user_roles_option', 16 );
  67. /**
  68. * bbp_init - Attached to 'init' above
  69. *
  70. * Attach various initialization actions to the init action.
  71. * The load order helps to execute code at the correct time.
  72. * v---Load order
  73. */
  74. add_action( 'bbp_init', 'bbp_load_textdomain', 0 );
  75. add_action( 'bbp_init', 'bbp_register', 0 );
  76. add_action( 'bbp_init', 'bbp_add_rewrite_tags', 20 );
  77. add_action( 'bbp_init', 'bbp_add_rewrite_rules', 30 );
  78. add_action( 'bbp_init', 'bbp_add_permastructs', 40 );
  79. add_action( 'bbp_init', 'bbp_ready', 999 );
  80. /**
  81. * There is no action API for roles to use, so hook in immediately after
  82. * everything is included (including the theme's functions.php. This is after
  83. * the $wp_roles global is set but before $wp->init().
  84. *
  85. * If it's hooked in any sooner, role names may not be translated correctly.
  86. *
  87. * @link http://bbpress.trac.wordpress.org/ticket/2219
  88. *
  89. * This is kind of lame, but is all we have for now.
  90. */
  91. add_action( 'bbp_after_setup_theme', 'bbp_add_forums_roles', 1 );
  92. /**
  93. * When setting up the current user, make sure they have a role for the forums.
  94. *
  95. * This is multisite aware, thanks to bbp_filter_user_roles_option(), hooked to
  96. * the 'bbp_loaded' action above.
  97. */
  98. add_action( 'bbp_setup_current_user', 'bbp_set_current_user_default_role' );
  99. /**
  100. * bbp_register - Attached to 'init' above on 0 priority
  101. *
  102. * Attach various initialization actions early to the init action.
  103. * The load order helps to execute code at the correct time.
  104. * v---Load order
  105. */
  106. add_action( 'bbp_register', 'bbp_register_post_types', 2 );
  107. add_action( 'bbp_register', 'bbp_register_post_statuses', 4 );
  108. add_action( 'bbp_register', 'bbp_register_taxonomies', 6 );
  109. add_action( 'bbp_register', 'bbp_register_views', 8 );
  110. add_action( 'bbp_register', 'bbp_register_shortcodes', 10 );
  111. // Autoembeds
  112. add_action( 'bbp_init', 'bbp_reply_content_autoembed', 8 );
  113. add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8 );
  114. /**
  115. * bbp_ready - attached to end 'bbp_init' above
  116. *
  117. * Attach actions to the ready action after bbPress has fully initialized.
  118. * The load order helps to execute code at the correct time.
  119. * v---Load order
  120. */
  121. add_action( 'bbp_ready', 'bbp_setup_akismet', 2 ); // Spam prevention for topics and replies
  122. add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration
  123. // Try to load the bbpress-functions.php file from the active themes
  124. add_action( 'bbp_after_setup_theme', 'bbp_load_theme_functions', 10 );
  125. // Widgets
  126. add_action( 'bbp_widgets_init', array( 'BBP_Login_Widget', 'register_widget' ), 10 );
  127. add_action( 'bbp_widgets_init', array( 'BBP_Views_Widget', 'register_widget' ), 10 );
  128. add_action( 'bbp_widgets_init', array( 'BBP_Search_Widget', 'register_widget' ), 10 );
  129. add_action( 'bbp_widgets_init', array( 'BBP_Forums_Widget', 'register_widget' ), 10 );
  130. add_action( 'bbp_widgets_init', array( 'BBP_Topics_Widget', 'register_widget' ), 10 );
  131. add_action( 'bbp_widgets_init', array( 'BBP_Replies_Widget', 'register_widget' ), 10 );
  132. add_action( 'bbp_widgets_init', array( 'BBP_Stats_Widget', 'register_widget' ), 10 );
  133. // Notices (loaded after bbp_init for translations)
  134. add_action( 'bbp_head', 'bbp_login_notices' );
  135. add_action( 'bbp_head', 'bbp_topic_notices' );
  136. add_action( 'bbp_template_notices', 'bbp_template_notices' );
  137. // Always exclude private/hidden forums if needed
  138. add_action( 'pre_get_posts', 'bbp_pre_get_posts_normalize_forum_visibility', 4 );
  139. // Profile Page Messages
  140. add_action( 'bbp_template_notices', 'bbp_notice_edit_user_success' );
  141. add_action( 'bbp_template_notices', 'bbp_notice_edit_user_is_super_admin', 2 );
  142. // Before Delete/Trash/Untrash Topic
  143. add_action( 'wp_trash_post', 'bbp_trash_forum' );
  144. add_action( 'trash_post', 'bbp_trash_forum' );
  145. add_action( 'untrash_post', 'bbp_untrash_forum' );
  146. add_action( 'delete_post', 'bbp_delete_forum' );
  147. // After Deleted/Trashed/Untrashed Topic
  148. add_action( 'trashed_post', 'bbp_trashed_forum' );
  149. add_action( 'untrashed_post', 'bbp_untrashed_forum' );
  150. add_action( 'deleted_post', 'bbp_deleted_forum' );
  151. // Auto trash/untrash/delete a forums topics
  152. add_action( 'bbp_delete_forum', 'bbp_delete_forum_topics', 10 );
  153. add_action( 'bbp_trash_forum', 'bbp_trash_forum_topics', 10 );
  154. add_action( 'bbp_untrash_forum', 'bbp_untrash_forum_topics', 10 );
  155. // New/Edit Forum
  156. add_action( 'bbp_new_forum', 'bbp_update_forum', 10 );
  157. add_action( 'bbp_edit_forum', 'bbp_update_forum', 10 );
  158. // Save forum extra metadata
  159. add_action( 'bbp_new_forum_post_extras', 'bbp_save_forum_extras', 2 );
  160. add_action( 'bbp_edit_forum_post_extras', 'bbp_save_forum_extras', 2 );
  161. add_action( 'bbp_forum_attributes_metabox_save', 'bbp_save_forum_extras', 2 );
  162. // New/Edit Reply
  163. add_action( 'bbp_new_reply', 'bbp_update_reply', 10, 7 );
  164. add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 7 );
  165. // Before Delete/Trash/Untrash Reply
  166. add_action( 'wp_trash_post', 'bbp_trash_reply' );
  167. add_action( 'trash_post', 'bbp_trash_reply' );
  168. add_action( 'untrash_post', 'bbp_untrash_reply' );
  169. add_action( 'delete_post', 'bbp_delete_reply' );
  170. // After Deleted/Trashed/Untrashed Reply
  171. add_action( 'trashed_post', 'bbp_trashed_reply' );
  172. add_action( 'untrashed_post', 'bbp_untrashed_reply' );
  173. add_action( 'deleted_post', 'bbp_deleted_reply' );
  174. // New/Edit Topic
  175. add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 );
  176. add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
  177. // Split/Merge Topic
  178. add_action( 'bbp_merged_topic', 'bbp_merge_topic_count', 1, 3 );
  179. add_action( 'bbp_post_split_topic', 'bbp_split_topic_count', 1, 3 );
  180. // Move Reply
  181. add_action( 'bbp_post_move_reply', 'bbp_move_reply_count', 1, 3 );
  182. // Before Delete/Trash/Untrash Topic
  183. add_action( 'wp_trash_post', 'bbp_trash_topic' );
  184. add_action( 'trash_post', 'bbp_trash_topic' );
  185. add_action( 'untrash_post', 'bbp_untrash_topic' );
  186. add_action( 'delete_post', 'bbp_delete_topic' );
  187. // After Deleted/Trashed/Untrashed Topic
  188. add_action( 'trashed_post', 'bbp_trashed_topic' );
  189. add_action( 'untrashed_post', 'bbp_untrashed_topic' );
  190. add_action( 'deleted_post', 'bbp_deleted_topic' );
  191. // Favorites
  192. add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_favorites' );
  193. add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' );
  194. // Subscriptions
  195. add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' );
  196. add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' );
  197. add_action( 'bbp_trash_forum', 'bbp_remove_forum_from_all_subscriptions' );
  198. add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' );
  199. add_action( 'bbp_new_reply', 'bbp_notify_subscribers', 11, 5 );
  200. add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 );
  201. // Sticky
  202. add_action( 'bbp_trash_topic', 'bbp_unstick_topic' );
  203. add_action( 'bbp_delete_topic', 'bbp_unstick_topic' );
  204. // Update topic branch
  205. add_action( 'bbp_trashed_topic', 'bbp_update_topic_walker' );
  206. add_action( 'bbp_untrashed_topic', 'bbp_update_topic_walker' );
  207. add_action( 'bbp_deleted_topic', 'bbp_update_topic_walker' );
  208. add_action( 'bbp_spammed_topic', 'bbp_update_topic_walker' );
  209. add_action( 'bbp_unspammed_topic', 'bbp_update_topic_walker' );
  210. // Update reply branch
  211. add_action( 'bbp_trashed_reply', 'bbp_update_reply_walker' );
  212. add_action( 'bbp_untrashed_reply', 'bbp_update_reply_walker' );
  213. add_action( 'bbp_deleted_reply', 'bbp_update_reply_walker' );
  214. add_action( 'bbp_spammed_reply', 'bbp_update_reply_walker' );
  215. add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
  216. // User status
  217. // @todo make these sub-actions
  218. add_action( 'make_ham_user', 'bbp_make_ham_user' );
  219. add_action( 'make_spam_user', 'bbp_make_spam_user' );
  220. // User role
  221. add_action( 'bbp_profile_update', 'bbp_profile_update_role' );
  222. // Hook WordPress admin actions to bbPress profiles on save
  223. add_action( 'bbp_user_edit_after', 'bbp_user_edit_after' );
  224. // Caches
  225. add_action( 'bbp_new_forum_pre_extras', 'bbp_clean_post_cache' );
  226. add_action( 'bbp_new_forum_post_extras', 'bbp_clean_post_cache' );
  227. add_action( 'bbp_new_topic_pre_extras', 'bbp_clean_post_cache' );
  228. add_action( 'bbp_new_topic_post_extras', 'bbp_clean_post_cache' );
  229. add_action( 'bbp_new_reply_pre_extras', 'bbp_clean_post_cache' );
  230. add_action( 'bbp_new_reply_post_extras', 'bbp_clean_post_cache' );
  231. /**
  232. * bbPress needs to redirect the user around in a few different circumstances:
  233. *
  234. * 1. POST and GET requests
  235. * 2. Accessing private or hidden content (forums/topics/replies)
  236. * 3. Editing forums, topics, replies, users, and tags
  237. * 4. bbPress specific AJAX requests
  238. */
  239. add_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked', 1 );
  240. add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden', 1 );
  241. add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private', 1 );
  242. add_action( 'bbp_template_redirect', 'bbp_post_request', 10 );
  243. add_action( 'bbp_template_redirect', 'bbp_get_request', 10 );
  244. add_action( 'bbp_template_redirect', 'bbp_check_user_edit', 10 );
  245. add_action( 'bbp_template_redirect', 'bbp_check_forum_edit', 10 );
  246. add_action( 'bbp_template_redirect', 'bbp_check_topic_edit', 10 );
  247. add_action( 'bbp_template_redirect', 'bbp_check_reply_edit', 10 );
  248. add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit', 10 );
  249. // Theme-side POST requests
  250. add_action( 'bbp_post_request', 'bbp_do_ajax', 1 );
  251. add_action( 'bbp_post_request', 'bbp_edit_topic_tag_handler', 1 );
  252. add_action( 'bbp_post_request', 'bbp_edit_user_handler', 1 );
  253. add_action( 'bbp_post_request', 'bbp_edit_forum_handler', 1 );
  254. add_action( 'bbp_post_request', 'bbp_edit_reply_handler', 1 );
  255. add_action( 'bbp_post_request', 'bbp_edit_topic_handler', 1 );
  256. add_action( 'bbp_post_request', 'bbp_merge_topic_handler', 1 );
  257. add_action( 'bbp_post_request', 'bbp_split_topic_handler', 1 );
  258. add_action( 'bbp_post_request', 'bbp_move_reply_handler', 1 );
  259. add_action( 'bbp_post_request', 'bbp_new_forum_handler', 10 );
  260. add_action( 'bbp_post_request', 'bbp_new_reply_handler', 10 );
  261. add_action( 'bbp_post_request', 'bbp_new_topic_handler', 10 );
  262. // Theme-side GET requests
  263. add_action( 'bbp_get_request', 'bbp_toggle_topic_handler', 1 );
  264. add_action( 'bbp_get_request', 'bbp_toggle_reply_handler', 1 );
  265. add_action( 'bbp_get_request', 'bbp_favorites_handler', 1 );
  266. add_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 );
  267. add_action( 'bbp_get_request', 'bbp_forum_subscriptions_handler', 1 );
  268. add_action( 'bbp_get_request', 'bbp_search_results_redirect', 10 );
  269. // Maybe convert the users password
  270. add_action( 'bbp_login_form_login', 'bbp_user_maybe_convert_pass' );
  271. add_action( 'bbp_activation', 'bbp_add_activation_redirect' );