PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/flatpress/fp-includes/core/core.wp-plugin-interface.php

https://bitbucket.org/alexandrul/flatpress
PHP | 228 lines | 109 code | 34 blank | 85 comment | 23 complexity | fd60386f61ec66679a19ec70d94642d2 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. // Filters: these are the core of WP's plugin architecture
  6. function merge_filters($tag) {
  7. global $wp_filter;
  8. if (isset($wp_filter['all'])) {
  9. foreach ($wp_filter['all'] as $priority => $functions) {
  10. if (isset($wp_filter[$tag][$priority]))
  11. $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]);
  12. else
  13. $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array());
  14. $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]);
  15. }
  16. }
  17. if ( isset($wp_filter[$tag]) )
  18. ksort( $wp_filter[$tag] );
  19. }
  20. function apply_filters($tag, $string) {
  21. global $wp_filter;
  22. $args = array_slice(func_get_args(), 2);
  23. merge_filters($tag);
  24. if (!isset($wp_filter[$tag])) {
  25. return $string;
  26. }
  27. foreach ($wp_filter[$tag] as $priority => $functions) {
  28. if (!is_null($functions)) {
  29. foreach($functions as $function) {
  30. $all_args = array_merge(array($string), $args);
  31. $function_name = $function['function'];
  32. $accepted_args = $function['accepted_args'];
  33. if($accepted_args == 1) {
  34. $the_args = array($string);
  35. } elseif ($accepted_args > 1) {
  36. $the_args = array_slice($all_args, 0, $accepted_args);
  37. } elseif($accepted_args == 0) {
  38. $the_args = NULL;
  39. } else {
  40. $the_args = $all_args;
  41. }
  42. $string = call_user_func_array($function_name, $the_args);
  43. }
  44. }
  45. }
  46. return $string;
  47. }
  48. function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
  49. global $wp_filter;
  50. // check that we don't already have the same filter at the same priority
  51. if (isset($wp_filter[$tag]["$priority"])) {
  52. foreach($wp_filter[$tag]["$priority"] as $filter) {
  53. // uncomment if we want to match function AND accepted_args
  54. //if ($filter == array($function, $accepted_args)) {
  55. if ($filter['function'] == $function_to_add) {
  56. return true;
  57. }
  58. }
  59. }
  60. // So the format is wp_filter['tag']['array of priorities']['array of ['array (functions, accepted_args)]']
  61. $wp_filter[$tag]["$priority"][] = array('function'=>$function_to_add, 'accepted_args'=>$accepted_args);
  62. //added by NoWhereMan
  63. ksort($wp_filter[$tag]["$priority"]);
  64. return true;
  65. }
  66. function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
  67. global $wp_filter;
  68. $new_function_list = array();
  69. // rebuild the list of filters
  70. if (isset($wp_filter[$tag]["$priority"])) {
  71. foreach($wp_filter[$tag]["$priority"] as $filter) {
  72. if ($filter['function'] != $function_to_remove) {
  73. $new_function_list[] = $filter;
  74. }
  75. }
  76. $wp_filter[$tag]["$priority"] = $new_function_list;
  77. }
  78. return true;
  79. }
  80. // The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content
  81. function do_action($tag, $arg = '') {
  82. global $wp_filter;
  83. $extra_args = array_slice(func_get_args(), 2);
  84. if ( is_array($arg) )
  85. $args = array_merge($arg, $extra_args);
  86. else
  87. $args = array_merge(array($arg), $extra_args);
  88. merge_filters($tag);
  89. if (!isset($wp_filter[$tag])) {
  90. return;
  91. }
  92. foreach ($wp_filter[$tag] as $priority => $functions) {
  93. if (!is_null($functions)) {
  94. foreach($functions as $function) {
  95. $function_name = $function['function'];
  96. $accepted_args = $function['accepted_args'];
  97. if($accepted_args == 1) {
  98. if ( is_array($arg) )
  99. $the_args = $arg;
  100. else
  101. $the_args = array($arg);
  102. } elseif ($accepted_args > 1) {
  103. $the_args = array_slice($args, 0, $accepted_args);
  104. } elseif($accepted_args == 0) {
  105. $the_args = NULL;
  106. } else {
  107. $the_args = $args;
  108. }
  109. $string = call_user_func_array($function_name, $the_args);
  110. }
  111. }
  112. }
  113. }
  114. function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
  115. add_filter($tag, $function_to_add, $priority, $accepted_args);
  116. }
  117. function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
  118. remove_filter($tag, $function_to_remove, $priority, $accepted_args);
  119. }
  120. //----------------------------------------------------------------------------
  121. // WordPress hooks
  122. //----------------------------------------------------------------------------
  123. /*
  124. Current Hooks For Actions
  125. This is a comprehensive list of plugin hooks in the core distribution of WordPress as of version 1.5 beta 1.
  126. 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.
  127. admin_footer
  128. No parameter. Executes at the end of the admin panel inside the body tag. Useful for insertion of additional content.
  129. admin_head
  130. No parameter. Executes in the <head> section of the admin panel. Useful for insertion of additional content.
  131. admin_menu
  132. No parameter. Executes after the basic admin panel menu structure is in place. Useful for adding additional menus to the admin panel.
  133. comment_closed
  134. Receives the comment's post ID as a parameter. Executes when attempting to display the comment form for a post that has closed comments.
  135. comment_form
  136. Receives the comment's post ID as a parameter. Template tag. Executes after displaying the comment form for a post that allows comments.
  137. comment_id_not_found
  138. Receives the comment's post ID as a parameter. Executes when attempting to display the comment form for a post that does not exist.
  139. comment_post
  140. Receives the comment ID as a parameter. Executes when a comment is added through wp-comments.php.
  141. delete_comment
  142. Receives the comment ID as a parameter. Executes when a comment is deleted.
  143. delete_post
  144. Receives the post ID as a parameter. Executes whenever a post is deleted.
  145. edit_comment
  146. Receives the comment ID as a parameter. Executes whenever a comment is edited.
  147. edit_form_advanced
  148. 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.
  149. edit_page_form
  150. No parameter. Executes inside the <form> tag on the page editing form. Useful for inserting additional input fields in the page editing form.
  151. edit_post
  152. Receives the post ID as a parameter. Executes every time a post is edited.
  153. generate_rewrite_rules
  154. No parameter. Executes whenever the rewrite rules are recomputed. To modify the computed rules, use the filter rewrite_rules_array instead.
  155. init
  156. Executes after WordPress has finished loading but before any headers are sent. Useful for intercepting $_GET or $_POST triggers.
  157. pingback_post
  158. Receives the comment ID as a parameter. Executes when a comment is added via XMLRPC.
  159. private_to_published
  160. Receives the post ID as a parameter. Executes when a post is moved from private to published status.
  161. publish_phone
  162. Receives the post ID as a parameter. Executes when a post is added via wp-mail.php.
  163. publish_post
  164. 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.
  165. save_post
  166. Receives the post ID as a parameter. Executes when a post is saved to the database.
  167. shutdown
  168. No parameter. Executes when the page output is complete.
  169. simple_edit_form
  170. 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.
  171. switch_theme
  172. Receives the name of the current theme as a parameter. Executes when the blog theme is changed.
  173. template_redirect
  174. 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.
  175. function all_on_one () {
  176. include(TEMPLATEPATH . '/all.php');
  177. exit;
  178. }
  179. add_action('template_redirect', 'all_on_one');
  180. trackback_post
  181. Receives the comment ID as a parameter. Executes when a comment is added via trackback.php.
  182. wp_footer
  183. No parameter. Template tag. Executes at the end of the <body> tag. Useful for insertion of additional content.
  184. wp_head
  185. No parameter. Executes in the <head> section. Useful for insertion of additional content.
  186. wp_meta
  187. No parameter. Executes in the <li>Meta</li> section of the included Theme's sidebar.php's. Useful for insertion of additional content.
  188. wp_set_comment_status
  189. Receives the comment ID as a parameter. Executes when the comment status changes.
  190. */
  191. ?>