関数 apply_filters()
2014/11/24
apply_filters()
定義ファイル :/blog/wp-includes/plugin.php
呼び出し元 :/blog/wp-includes/version.php
関数リファレンス
apply filters フィルターフックに追加された関数を呼び出します。フィルターフックの一覧は プラグイン API をごらんください。
この関数により、フィルターフック $tag に付加されたコールバック関数が呼び出されます。この関数を、$tag パラメータを使用して新しく指定したフックの名前と一緒に呼び出すことで、フィルターフックを新規作成することができます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | /** * Call the functions added to a filter hook. * * The callback functions attached to filter hook $tag are invoked by calling * this function. This function can be used to create a new filter hook by * simply calling this function with the name of the new hook specified using * the $tag parameter. * * The function allows for additional arguments to be added and passed to hooks. * <code> * // Our filter callback function * function example_callback( $string, $arg1, $arg2 ) { * // (maybe) modify $string * return $string; * } * add_filter( 'example_filter', 'example_callback', 10, 3 ); * * // Apply the filters by calling the 'example_callback' function we * // "hooked" to 'example_filter' using the add_filter() function above. * // - 'example_filter' is the filter hook $tag * // - 'filter me' is the value being filtered * // - $arg1 and $arg2 are the additional arguments passed to the callback. * $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 ); * * * @since 0.71 * * @global array $wp_filter Stores all of the filters. * @global array $merged_filters Merges the filter hooks using this function. * @global array $wp_current_filter Stores the list of current filters with the current one last. * * @param string $tag The name of the filter hook. * @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on. * @param mixed $var Additional variables passed to the functions hooked to <tt>$tag</tt>. * @return mixed The filtered value after all hooked functions are applied to it. */ function apply_filters( $tag, $value ) { global $wp_filter, $merged_filters, $wp_current_filter; $args = array(); // Do 'all' actions first. if ( isset($wp_filter['all']) ) { $wp_current_filter[] = $tag; $args = func_get_args(); _wp_call_all_hook($args); } if ( !isset($wp_filter[$tag]) ) { if ( isset($wp_filter['all']) ) array_pop($wp_current_filter); return $value; } if ( !isset($wp_filter['all']) ) $wp_current_filter[] = $tag; // Sort. if ( !isset( $merged_filters[ $tag ] ) ) { ksort($wp_filter[$tag]); $merged_filters[ $tag ] = true; } reset( $wp_filter[ $tag ] ); if ( empty($args) ) $args = func_get_args(); do { foreach( (array) current($wp_filter[$tag]) as $the_ ) if ( !is_null($the_['function']) ){ $args[1] = $value; $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args'])); } } while ( next($wp_filter[$tag]) !== false ); array_pop( $wp_current_filter ); return $value; } |