私は OnlyWire プラグインを使用して、WordPress の投稿をさまざまなネットワークにシンジケートしています。strip_shortcodes
残念ながら、プラグインに機能を追加するのを忘れていました。
投稿のコンテンツに構造を追加するために多くの短いコードを使用する VisualComposer を使用して投稿をフォーマットしています。次に、OnlyWire に投稿すると、すべてのショート コードが含まれてしまいます。
ここや他の場所で見つけたいくつかの例を試しましたがstrip_shortcodes
、削除されたバージョンを再レンダリングする機能を取得できないようです。
ポスト関数は次のとおりです。
function ow_post($postID)
{
global $wpdb;
// Get the correct post ID if revision.
if ($wpdb->get_var("SELECT post_type FROM $wpdb->posts WHERE ID=$postID") == 'revision')
{
$postID = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID=$postID");
}
if (isset($_POST['ow_post']) && $_POST['ow_post'] == 'on')
{
// the checkbox is selected, let's post to onlywire with user credentials
$username = get_option('ow_username');
$password = get_option('ow_password');
if ($username && $password)
{
$post = get_post($postID);
$tagstring = "";
$prefix = '';
if(get_the_tags($post->ID))
{
foreach (get_the_tags($post->ID) as $tag)
{
$tagstring .= $prefix.str_replace(" ","-",trim($tag->name));
$prefix = ',';
}
}
$d = 'm\/d\/Y h\:i\:s T';
$data['url'] = urlencode(get_permalink($postID));
$data['title'] = trim(urlencode($post->post_title));
$data['tags'] = trim($tagstring);
$data['scheduled'] = urlencode(get_post_time($d, true, $post, false));
if (strlen(strip_tags($post->post_content)) > 250)
{
$data['description'] = urlencode(substr(strip_tags($post->post_content), 0, 250) . " ...");
}
else
{
$data['description'] = urlencode(strip_tags($post->post_content));
}
if (get_option('ow_service_logins') != false)
{
$data['networks'] = trim(get_option('ow_service_logins'));
}
createBookmark($data, $username, $password);
}
}
}
コールバックを作成しました:
function ow_strip_shortcodes ( $content ) {
$content = strip_shortcodes( $content );
return $content;
}
次のようにフィルターを追加しようとしました:
$post = get_post($postID);
$tagstring = "";
$prefix = '';
apply_filters('the_content', 'ow_strip_shortcodes');
しかし、それはうまくいかないようです...
単純なことだと思いますが、私はWordpressをあまり扱っていないので、構造がよくわかりません。
- 編集 -
これに加えて、それが機能していることを発見しましstrip_shortcodes
たが、私のコンテンツはショートコード内にネストされていたため、同様に削除されていました.
誰かがブラケットのすべてのインスタンスとその中のコンテンツを置き換える正規表現を手伝ってくれますが、プレーンテキストはそのままにしますか?
部分的な投稿の例を次に示します。
[vc_row][vc_column width="1/1"][vc_column_text] Introductory text goes in this block
[/vc_column_text][/vc_column][/vc_row]
[vc_*]
およびのすべてのインスタンスを[/vc_*]
削除する必要があります。Introductory text goes in this block