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