PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/coding-style/fp-includes/core/core.wp-plugin-interface.php

https://bitbucket.org/alexandrul/flatpress
PHP | 271 lines | 116 code | 12 blank | 143 comment | 26 complexity | 4635b0a427fa89c8149e38682416a0f9 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MIT
  1. <?php
  2. // plugins.php
  3. // plugin interface
  4. // This is EXACTLY a copy & paste from wordpress
  5. // DMKE: Erm... not more. It is formatted ;-)
  6. // Filters: these are the core of WP's plugin architecture
  7. /**
  8. * Enter description here...
  9. *
  10. * @global $wp_filter
  11. * @param string $tag
  12. */
  13. function merge_filters($tag) {
  14. global $wp_filter;
  15. if (isset($wp_filter['all'])) {
  16. foreach ($wp_filter['all'] as $priority => $functions) {
  17. if (isset($wp_filter[$tag][$priority])) {
  18. $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
  19. } else {
  20. $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
  21. }
  22. $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
  23. }
  24. }
  25. if (isset($wp_filter[$tag])) {
  26. ksort($wp_filter[$tag]);
  27. }
  28. }
  29. /**
  30. * Applies all $tag related filters.
  31. *
  32. * @global $wp_filter
  33. * @param string $tag
  34. * @param string $string
  35. * @return mixed
  36. */
  37. function apply_filters($tag, $string) {
  38. global $wp_filter;
  39. $args = array_slice(func_get_args(), 2);
  40. merge_filters($tag);
  41. if (!isset($wp_filter[$tag])) {
  42. return $string;
  43. }
  44. foreach ($wp_filter[$tag] as $priority => $functions) {
  45. if (!is_null($functions)) {
  46. foreach($functions as $function) {
  47. $all_args = array_merge(array($string), $args);
  48. $function_name = $function['function'];
  49. $accepted_args = $function['accepted_args'];
  50. if($accepted_args == 1) {
  51. $the_args = array($string);
  52. } elseif ($accepted_args > 1) {
  53. $the_args = array_slice($all_args, 0, $accepted_args);
  54. } elseif($accepted_args == 0) {
  55. $the_args = NULL;
  56. } else {
  57. $the_args = $all_args;
  58. }
  59. $string = call_user_func_array($function_name, $the_args);
  60. }
  61. }
  62. }
  63. return $string;
  64. }
  65. /**
  66. * Adds a filter.
  67. *
  68. * @global $wp_filter
  69. * @param string $tag
  70. * @param string $function_to_add
  71. * @param int $priority
  72. * @param int $accepted_args
  73. * @return boolean
  74. */
  75. function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
  76. global $wp_filter;
  77. // check that we don't already have the same filter at the same priority
  78. if (isset($wp_filter[$tag]["$priority"])) {
  79. foreach($wp_filter[$tag]["$priority"] as $filter) {
  80. // uncomment if we want to match function AND accepted_args
  81. //if ($filter == array($function, $accepted_args)) {
  82. if ($filter['function'] == $function_to_add) {
  83. return true;
  84. }
  85. }
  86. }
  87. // So the format is wp_filter['tag']['array of priorities']['array of ['array (functions, accepted_args)]']
  88. $wp_filter[$tag]["$priority"][] = array(
  89. 'function' => $function_to_add,
  90. 'accepted_args' => $accepted_args
  91. );
  92. //added by NoWhereMan
  93. ksort($wp_filter[$tag]["$priority"]);
  94. return true;
  95. }
  96. /**
  97. * Deletes a filter.
  98. *
  99. * @global $wp_filter
  100. * @param string $tag
  101. * @param string $function_to_remove
  102. * @param inr $priority
  103. * @param int $accepted_args
  104. * @return boolean
  105. */
  106. function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
  107. global $wp_filter;
  108. $new_function_list = array();
  109. // rebuild the list of filters
  110. if (isset($wp_filter[$tag]["$priority"])) {
  111. foreach($wp_filter[$tag]["$priority"] as $filter) {
  112. if ($filter['function'] != $function_to_remove) {
  113. $new_function_list[] = $filter;
  114. }
  115. }
  116. $wp_filter[$tag]["$priority"] = $new_function_list;
  117. }
  118. return true;
  119. }
  120. // The *_action functions are just aliases for the *_filter functions,
  121. // they take special strings instead of generic content
  122. /**
  123. * Applies an action.
  124. *
  125. * @param string $tag
  126. * @param mixed $arg
  127. */
  128. function do_action($tag, $arg = '') {
  129. global $wp_filter;
  130. $extra_args = array_slice(func_get_args(), 2);
  131. if (is_array($arg)) {
  132. $args = array_merge($arg, $extra_args);
  133. } else {
  134. $args = array_merge(array($arg), $extra_args);
  135. }
  136. merge_filters($tag);
  137. if (!isset($wp_filter[$tag])) {
  138. return;
  139. }
  140. foreach ($wp_filter[$tag] as $priority => $functions) {
  141. if (!is_null($functions)) {
  142. foreach($functions as $function) {
  143. $function_name = $function['function'];
  144. $accepted_args = $function['accepted_args'];
  145. if ($accepted_args == 1) {
  146. if (is_array($arg)) {
  147. $the_args = $arg;
  148. } else {
  149. $the_args = array($arg);
  150. }
  151. } elseif ($accepted_args > 1) {
  152. $the_args = array_slice($args, 0, $accepted_args);
  153. } elseif($accepted_args == 0) {
  154. $the_args = NULL;
  155. } else {
  156. $the_args = $args;
  157. }
  158. $string = call_user_func_array($function_name, $the_args);
  159. }
  160. }
  161. }
  162. }
  163. /**
  164. * Add an action.
  165. *
  166. * @param string $tag
  167. * @param string $function_to_add
  168. * @param int $priority
  169. * @param int $accepted_args
  170. */
  171. function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
  172. add_filter($tag, $function_to_add, $priority, $accepted_args);
  173. }
  174. /**
  175. * Removes an action.
  176. *
  177. * @param string $tag
  178. * @param string $function_to_remove
  179. * @param int $priority
  180. * @param int $accepted_args
  181. */
  182. function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
  183. remove_filter($tag, $function_to_remove, $priority, $accepted_args);
  184. }
  185. //----------------------------------------------------------------------------
  186. // WordPress hooks
  187. //----------------------------------------------------------------------------
  188. /*
  189. Current Hooks For Actions
  190. This is a comprehensive list of plugin hooks in the core distribution of WordPress as of version 1.5 beta 1.
  191. NOTE: the following list is not a comprehensive listing of hooks available in 1.5 final. See Skippy's list (http://codex.wordpress.org/User:Skippy) for a more comprehensive, if less descriptive, listing of actions and filters.
  192. admin_footer
  193. No parameter. Executes at the end of the admin panel inside the body tag. Useful for insertion of additional content.
  194. admin_head
  195. No parameter. Executes in the <head> section of the admin panel. Useful for insertion of additional content.
  196. admin_menu
  197. No parameter. Executes after the basic admin panel menu structure is in place. Useful for adding additional menus to the admin panel.
  198. comment_closed
  199. Receives the comment's post ID as a parameter. Executes when attempting to display the comment form for a post that has closed comments.
  200. comment_form
  201. Receives the comment's post ID as a parameter. Template tag. Executes after displaying the comment form for a post that allows comments.
  202. comment_id_not_found
  203. Receives the comment's post ID as a parameter. Executes when attempting to display the comment form for a post that does not exist.
  204. comment_post
  205. Receives the comment ID as a parameter. Executes when a comment is added through wp-comments.php.
  206. delete_comment
  207. Receives the comment ID as a parameter. Executes when a comment is deleted.
  208. delete_post
  209. Receives the post ID as a parameter. Executes whenever a post is deleted.
  210. edit_comment
  211. Receives the comment ID as a parameter. Executes whenever a comment is edited.
  212. edit_form_advanced
  213. No parameter. Executes during the display of the admin panel's advanced editing page, just before the <div> is closed that contains the post content textarea. Useful for inserting additional input fields into the advanced editing form.
  214. edit_page_form
  215. No parameter. Executes inside the <form> tag on the page editing form. Useful for inserting additional input fields in the page editing form.
  216. edit_post
  217. Receives the post ID as a parameter. Executes every time a post is edited.
  218. generate_rewrite_rules
  219. No parameter. Executes whenever the rewrite rules are recomputed. To modify the computed rules, use the filter rewrite_rules_array instead.
  220. init
  221. Executes after WordPress has finished loading but before any headers are sent. Useful for intercepting $_GET or $_POST triggers.
  222. pingback_post
  223. Receives the comment ID as a parameter. Executes when a comment is added via XMLRPC.
  224. private_to_published
  225. Receives the post ID as a parameter. Executes when a post is moved from private to published status.
  226. publish_phone
  227. Receives the post ID as a parameter. Executes when a post is added via wp-mail.php.
  228. publish_post
  229. Receives the post ID as a parameter. Executes when a post is saved and its status is set to "publish", regardless of its prior setting. NOTE: to add a hook to this action in 1.2, be sure to specify a priority between 0 and 9. The generic_ping hook is buggy and prevents any lesser priority hooks from working.
  230. save_post
  231. Receives the post ID as a parameter. Executes when a post is saved to the database.
  232. shutdown
  233. No parameter. Executes when the page output is complete.
  234. simple_edit_form
  235. No parameter. Executes during the display of the admin panel's simple editing page, just before the <div> is closed that contains the post content textarea. Useful for inserting additional input fields into the simple editing form.
  236. switch_theme
  237. Receives the name of the current theme as a parameter. Executes when the blog theme is changed.
  238. template_redirect
  239. No parameter. Executes before the determination of the template file to be used to display the requested page. Useful for providing additional templates based on request criteria. Example (pedagogical, not useful): Redirect all requests to the all.php template file in the current themes' directory.
  240. function all_on_one () {
  241. include(TEMPLATEPATH . '/all.php');
  242. exit;
  243. }
  244. add_action('template_redirect', 'all_on_one');
  245. trackback_post
  246. Receives the comment ID as a parameter. Executes when a comment is added via trackback.php.
  247. wp_footer
  248. No parameter. Template tag. Executes at the end of the <body> tag. Useful for insertion of additional content.
  249. wp_head
  250. No parameter. Executes in the <head> section. Useful for insertion of additional content.
  251. wp_meta
  252. No parameter. Executes in the <li>Meta</li> section of the included Theme's sidebar.php's. Useful for insertion of additional content.
  253. wp_set_comment_status
  254. Receives the comment ID as a parameter. Executes when the comment status changes.
  255. */
  256. ?>