{"id":1413,"date":"2012-01-10T01:05:13","date_gmt":"2012-01-09T16:05:13","guid":{"rendered":"http:\/\/codaholic.org\/?p=1413"},"modified":"2012-01-10T01:05:13","modified_gmt":"2012-01-09T16:05:13","slug":"wordpress%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%a8%e3%81%97%e3%81%a6%e8%bf%bd%e5%8a%a0%e3%81%a7%e3%81%8d%e3%82%8b%e3%83%95%e3%82%a3%e3%83%ab%e3%82%bf%e3%83%bc%e6%a9%9f%e8%83%bd%e3%81%af","status":"publish","type":"post","link":"https:\/\/codaholic.org\/?p=1413","title":{"rendered":"[WordPress]\u30d7\u30e9\u30b0\u30a4\u30f3\u3068\u3057\u3066\u8ffd\u52a0\u3067\u304d\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\u6a5f\u80fd\u306f\u3069\u306e\u3088\u3046\u306b\u5b9f\u73fe\u3055\u308c\u3066\u3044\u308b\u306e\u304b"},"content":{"rendered":"<p>add_filter\u95a2\u6570\u306f\u30aa\u30ea\u30b8\u30ca\u30eb\u306e\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u3092\u767b\u9332\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\u3067\u3001\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u3092\u767b\u9332\u3059\u308b\u3068WordPress\u304c\u51fa\u529b\u3059\u308b\u3042\u3089\u3086\u308b\u30c7\u30fc\u30bf\u3092\u52a0\u5de5\u3057\u3066\u51fa\u529b\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002apply_filters\u95a2\u6570\u306f\u767b\u9332\u3055\u308c\u305f\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\u3067\u3059\u3002\u3069\u306e\u3088\u3046\u306a\u4ed5\u7d44\u307f\u3067\u5b9f\u73fe\u3055\u308c\u3066\u3044\u308b\u306e\u304b\u6c17\u306b\u306a\u3063\u305f\u306e\u3067\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u78ba\u8a8d\u3057\u307e\u3057\u305f\u3002\u5b8c\u5168\u306b\u30c8\u30ec\u30fc\u30b9\u3067\u304d\u305f\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30e1\u30e2\u3092\u517c\u306d\u3066\u8a18\u4e8b\u3068\u3057\u3066\u516c\u958b\u3057\u307e\u3059\u3002\u30d0\u30fc\u30b8\u30e7\u30f33.1.3\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u4f8b\u3048\u3070\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u30d7\u30e9\u30b0\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u8ff0\u3057\u3066plugin\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u3068\u3001\u5168\u3066\u306e\u8a18\u4e8b\u30bf\u30a4\u30c8\u30eb\u306b(\u3053\u3093\u306b\u3061\u306f)\u3068\u3044\u3046\u6587\u5b57\u5217\u304c\u9023\u7d50\u3055\u308c\u3066\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306fadd_filter\u95a2\u6570\u306b\u3088\u3063\u3066\u767b\u9332\u3055\u308c\u305f\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u304capply_filters\u95a2\u6570\u306b\u3088\u3063\u3066\u3001\u753b\u9762\u306b\u51fa\u529b\u3055\u308c\u308b\u524d\u306b(\u3053\u3093\u306b\u3061\u306f)\u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u9023\u7d50\u3055\u305b\u308b\u51e6\u7406\u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>[php]<br \/>\nfunction addHello($title){<br \/>\n\treturn $title . &#8216;(\u3053\u3093\u306b\u3061\u306f)&#8217;;<br \/>\n}<br \/>\nadd_filter(&#8216;the_title&#8217;, &#8216;addHello&#8217;);<br \/>\n[\/php]<br \/>\n<\/p>\n<p>add_filter\u95a2\u6570\u306f wp-include\/plugin.php \u3067\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>[php]<br \/>\nfunction add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {<br \/>\n\tglobal $wp_filter, $merged_filters;<\/p>\n<p>\t\/\/ \u8ffd\u52a0\u3059\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u306bid\u3092\u30e6\u30cb\u30fc\u30af\u306a\u632f\u308a\u307e\u3059\u3002<br \/>\n\t$idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);<\/p>\n<p>\t\/\/ \u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u304b\u3051\u308b\u30bf\u30b0\u3001\u512a\u5148\u5ea6\u3001id\u3067\u69cb\u6210\u3055\u308c\u305f\u9023\u60f3\u914d\u5217\u306b\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u540d\u3068\u305d\u306e\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u304c\u53d7\u3051\u53d6\u308b\u5f15\u6570\u306e\u6570\u3092\u66f8\u304d\u8fbc\u307f\u307e\u3059\u3002<br \/>\n\t$wp_filter[$tag][$priority][$idx] = array(&#8216;function&#8217; => $function_to_add, &#8216;accepted_args&#8217; => $accepted_args);<\/p>\n<p>\t\/\/ \u8abf\u67fb\u4e2d(\u512a\u5148\u5ea6\u3067\u4e26\u3073\u66ff\u3048\u308b\u305f\u3081\u306e\u30d5\u30e9\u30b0\u304b\u306a\uff1f)<br \/>\n\tunset( $merged_filters[ $tag ] );<br \/>\n\treturn true;<br \/>\n}<br \/>\n[\/php]<br \/>\n<\/p>\n<p>\u7d9a\u3044\u3066apply_filters\u95a2\u6570\u3067\u3059\u3002apply_filters\u95a2\u6570\u306f wp-include\/plugin.php \u3067\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>[php]<br \/>\nfunction apply_filters($tag, $value) {<br \/>\n\tglobal $wp_filter, $merged_filters, $wp_current_filter;<\/p>\n<p>\t$args = array();<br \/>\n\t$wp_current_filter[] = $tag;<\/p>\n<p>\t\/\/ \u30d5\u30a3\u30eb\u30bf\u30fc\u30bf\u30b0 all \u306b\u5bfe\u3057\u3066\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u304c\u767b\u9332\u3055\u308c\u3066\u3044\u305f\u3089\u5b9f\u884c\u3057\u307e\u3059\u3002<br \/>\n\t\/\/ Do &#8216;all&#8217; actions first<br \/>\n\tif ( isset($wp_filter[&#8216;all&#8217;]) ) {<br \/>\n\t\t$args = func_get_args();<br \/>\n\t\t_wp_call_all_hook($args);<br \/>\n\t}<\/p>\n<p>\t\/\/ \u30d5\u30a3\u30eb\u30bf\u30fc\u3092\u304b\u3051\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\u30bf\u30b0\u306b\u5bfe\u3057\u3066\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u304c\u767b\u9332\u3055\u308c\u3066\u3044\u306a\u3051\u308c\u3070\u51fa\u529b\u3092\u305d\u306e\u307e\u307e\u8fd4\u3057\u3066\u51e6\u7406\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002<br \/>\n\tif ( !isset($wp_filter[$tag]) ) {<br \/>\n\t\tarray_pop($wp_current_filter);<br \/>\n\t\treturn $value;<br \/>\n\t}<\/p>\n<p>\t\/\/ \u512a\u5148\u5ea6\u9806\u306b\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u3092\u4e26\u3079\u66ff\u3048\u307e\u3059\u3002<br \/>\n\t\/\/ Sort<br \/>\n\tif ( !isset( $merged_filters[ $tag ] ) ) {<br \/>\n\t\tksort($wp_filter[$tag]);<br \/>\n\t\t$merged_filters[ $tag ] = true;<br \/>\n\t}<\/p>\n<p>\t\/\/ \u914d\u5217\u306e\u30dd\u30a4\u30f3\u30bf\u3092\u5143\u306b\u623b\u3057\u307e\u3059\u3002<br \/>\n\treset( $wp_filter[ $tag ] );<\/p>\n<p>\t\/\/ $args\u306b\u307e\u3060\u5f15\u6570\u3092\u66f8\u304d\u8fbc\u3093\u3067\u3044\u306a\u3051\u308c\u3070\u3053\u3053\u3067\u5f15\u6570\u3092\u5168\u3066\u53d6\u5f97\u3057\u307e\u3059\u3002<br \/>\n\tif ( empty($args) )<br \/>\n\t\t$args = func_get_args();<\/p>\n<p>\tdo {<br \/>\n\t\t\/\/ \u4eca\u3001\u5b9f\u884c\u3057\u3066\u3044\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\u30bf\u30b0\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u3092\u9806\u756a\u306b\u5b9f\u884c\u3057\u307e\u3059\u3002<br \/>\n\t\tforeach( (array) current($wp_filter[$tag]) as $the_ )<br \/>\n\t\t\tif ( !is_null($the_[&#8216;function&#8217;]) ){<br \/>\n\t\t\t\t$args[1] = $value;<br \/>\n\t\t\t\t$value = call_user_func_array($the_[&#8216;function&#8217;], array_slice($args, 1, (int) $the_[&#8216;accepted_args&#8217;]));<br \/>\n\t\t\t}<\/p>\n<p>\t\/\/ next\u95a2\u6570\u306b\u3088\u3063\u3066\u914d\u5217\u306e\u30dd\u30a4\u30f3\u30bf\u30921\u3064\u5148\u306b\u9032\u3081\u307e\u3059\u3002\u6b21\u306e\u512a\u5148\u5ea6\u306e\u914d\u5217\u304c\u53c2\u7167\u3055\u308c\u307e\u3059\u3002<br \/>\n\t} while ( next($wp_filter[$tag]) !== false );<\/p>\n<p>\t\/\/ \u8abf\u67fb\u4e2d<br \/>\n\tarray_pop( $wp_current_filter );<\/p>\n<p>\t\/\/ \u30d5\u30a3\u30eb\u30bf\u30fc\u9069\u7528\u5f8c\u306e\u7d50\u679c\u3092\u8fd4\u3057\u307e\u3059\u3002<br \/>\n\treturn $value;<br \/>\n}<br \/>\n[\/php]<\/p>\n<p><strong>36\u884c\u76ee\u306e\u88dc\u8db3<\/strong><br \/>\nadd_filter\u95a2\u6570\u306b\u3088\u3063\u3066\u66f8\u304d\u8fbc\u3093\u3060\u306e\u306f $wp_filter[$tag][$priority][$idx] \u3068\u3044\u3046\u914d\u5217\u3067\u3042\u308a\u3001[&#8216;function&#8217;]\u3068\u3044\u3046\u30e9\u30d9\u30eb\u3068[&#8216;accepted_args&#8217;]\u3068\u3044\u3046\u30e9\u30d9\u30eb\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002current($wp_filter[$tag]) \u3068foreach\u69cb\u6587\u306b\u3088\u308a\u73fe\u5728\u306e$priority\u914d\u5217\u3092$the_\u3068\u3057\u3066\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p><strong>39\u884c\u76ee\u306e\u88dc\u8db3<\/strong><br \/>\napply_filters\u95a2\u6570\u306b\u6e21\u3055\u308c\u305f\u5f15\u6570\u3092\u3001accepted_args\u3067\u6307\u5b9a\u3057\u305f\u6570\u3060\u3051\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u306b\u6e21\u3057\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002apply_filters\u95a2\u6570\u306e\u7b2c1\u5f15\u6570\u306f\u30d5\u30a3\u30eb\u30bf\u30fc\u30bf\u30b0\u306a\u306e\u3067\u3001\u7b2c2\u5f15\u6570\u4ee5\u964d\u304c\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u306b\u6e21\u3055\u308c\u308b\u5f15\u6570\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u306e\u305f\u3081array_slice\u95a2\u6570\u30670\u756a\u76ee\u306e\u8981\u7d20\u306f\u5bfe\u8c61\u306b\u306a\u3063\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\n$wp_current_filter\u3068$merged_filters\u306b\u3064\u3044\u3066\u306f\u8abf\u67fb\u4e2d\u3068\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u3089\u306e\u51e6\u7406\u306e\u4e2d\u3060\u3051\u3067\u306f\u3042\u307e\u308a\u610f\u5473\u3092\u6301\u3063\u3066\u3044\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u3001\u4ed6\u306e\u51e6\u7406\u3068\u306e\u517c\u306d\u5408\u3044\u3092\u898b\u308b\u5fc5\u8981\u304c\u3042\u308a\u305d\u3046\u3067\u3059\u3002\u50d5\u306e\u30ec\u30d9\u30eb\u3067WordPress\u306e\u30bd\u30fc\u30b9\u3092\u8aad\u3080\u3068\u975e\u5e38\u306b\u9aa8\u304c\u6298\u308c\u307e\u3059\u304c\u52c9\u5f37\u306b\u306a\u308b\u7b87\u6240\u304c\u591a\u3044\u3067\u3059&#8230;\u5f15\u304d\u7d9a\u304dWordPress\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u89e3\u6790\u3092\u7d9a\u3051\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>add_filter\u95a2\u6570\u306f\u30aa\u30ea\u30b8\u30ca\u30eb\u306e\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u3092\u767b\u9332\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\u3067\u3001\u30d5\u30a3\u30eb\u30bf\u30fc\u95a2\u6570\u3092\u767b\u9332\u3059\u308b\u3068WordPress\u304c\u51fa\u529b\u3059\u308b\u3042\u3089\u3086\u308b\u30c7\u30fc\u30bf\u3092\u52a0\u5de5\u3057\u3066\u51fa\u529b\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002apply_filters\u95a2\u6570\u306f\u767b\u9332\u3055\u308c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[191,192,242],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8gd1W-mN","_links":{"self":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1413"}],"collection":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1413"}],"version-history":[{"count":14,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1413\/revisions"}],"predecessor-version":[{"id":1427,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/1413\/revisions\/1427"}],"wp:attachment":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}