Shifterがサイト上のURLの追加をサポートするようになりました。以下のフィルターをテーマのfunctions.php
に適用することで実現できます。
'ShifterURLS::AppendURLtoAll', 'my_append_urls' ); add_filter(
制限事項
- URLはWordPress内に含まれている必要があります(Shifterは外部URLを取得できません)。
- URLは
home_url("")
に埋め込まれている必要があります。 - URLはスラッシュ(末尾のスラッシュ)で終わるか、許可されたサフィックスのリストに含まれている必要があります。
- URLは
/index.html
で生成されます。 Content-Type
は、ShifterがWordPressから取得したものと同じになります(例:/wp-json/wp/v2/posts/
は/wp-json/wp/v2/posts/index.html
となり、content-type: application/json
として配信されます)。
許可されるファイルサフィックス:
.html .xml .rss .rdf .atom .css .js .json
サンプル
サンプルコードA:
ジェネレーターのターゲットURLに/wp-json/wp/v2/posts/
を追加する
function my_append_urls( $urls ) {
$urls[] = home_url('/wp-json/wp/v2/posts/');
return $urls;
}
'init', function(){
add_action( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );
add_filter( ; } )
結果A:
/wp-json/wp/v2/posts/
が、"link_type": "from_filter_hook"
および"path": "/wp-json/wp/v2/posts/"
としてターゲットURLに追加されます。
$ curl -s https://127.0.0.1:8443/?urls | jq .
{
"datetime": "2020-07-07 02:41:39 UTC",
"page": null,
"start": 0,
"end": 100,
"limit": 100,
"items": [
{
"link_type": "home",
"post_type": "",
"link": "https://127.0.0.1:8443/",
"path": "/"
},
[... cropped ...]
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/wp-json/wp/v2/posts/",
"path": "/wp-json/wp/v2/posts/"
}
],
"request_type": "TOP",
"request_path": "/",
"count": 20,
"finished": true
}
サンプルコードB:
米国の州の統計リストを/states/($slag)/
としてターゲットURLに追加する。
function my_append_urls( $urls ) {
$states = [
'Alabama',
'Arizona',
.]
[...cropped...'Wisconsin',
'Wyoming',
;
]foreach ( $states as $slag ) {
$urls[] = home_url("/states/{$slag}/");
}return $urls;
}
'init', function(){
add_action( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );
add_filter( ; } )
サンプル結果B:
$ curl -s https://127.0.0.1:8443/wp-json/shifter/v1/urls?page=1 | jq .
{
"datetime": "2020-09-04 06:01:58 UTC",
"page": 1,
"start": 100,
"end": 200,
"limit": 100,
"items": [
{
"link_type": "term_feed",
"post_type": "column",
"link": "https://127.0.0.1:8443/column/feed/",
"path": "/column/feed/"
},
:
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/states/Alabama/",
"path": "/states/Alabama/"
},
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/states/Arizona/",
"path": "/states/Arizona/"
},
[..... cropped .......]
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/states/Wisconsin/",
"path": "/states/Wisconsin/"
},
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/states/Wyoming/",
"path": "/states/Wyoming/"
}
],
"request_type": "TOP",
"request_path": "/",
"count": 91,
"finished": true
}