这里的解决方案并没有解决我们的问题。我已经有了一个解决方案来更改我们主题中字段表单中的所有链接。我为每个网络使用不同的数组,例如$example_network_1 $example_network_2为每个附属网络使用 PHP foreach。
现在我需要一个解决方案来将相同的数组用于 WordPress 帖子的内容。
此解决方案适用于一个网络,但它会导致 YouTube 视频出现 404e 错误。我们从 YouTube 视频中输入 URL,WordPress 会自动生成一个嵌入视频。使用以下代码,我们会得到一个404 错误 iframe或类似的东西。
我们需要针对多个网络的解决方案。
我非常感谢您的每一次帮助!
$example_network_1 = array(
array('shop'=>'shop1.com','id'=>'11111'),
array('shop'=>'shop2.co.uk','id'=>'11112'),
);
$example_network_2 = array(
array('shop'=>'shop-x1.com','id'=>'11413'),
array('shop'=>'shop-x2.net','id'=>'11212'),
);
add_filter( 'the_content', 'wpso_change_urls' ) ;
function wpso_found_urls( $matches ) {
global $example_network_1,$example_network_2;
foreach( $example_network_1 as $rule ) {
if (strpos($matches[0], $rule['shop']) !== false) {
$raw_url = trim( $matches[0], '"' ) ;
return '"https://www.network-x.com/click/'. $rule['id'].'lorem_lorem='.rawurlencode($raw_url ) . '"';
}
/*
foreach( $example_network_2 as $rule ) {
if (strpos($matches[0], $rule['shop']) !== false) {
$raw_url = trim( $matches[0], '"' ) ;
return '"https://www.network-y.com/click/'. $rule['id'].'lorem='.rawurlencode($raw_url ) . '"';
}
*/
}
}
function wpso_change_urls( $content ) {
global $example_network_1,example_network_2;
return preg_replace_callback( '/"+(http|https)(\:\/\/\S*'. $example_network_1 ['shop'] .'\S*")/', 'wpso_found_urls', $content ) ;
// return preg_replace_callback( '/"+(http|https)(\:\/\/\S*'. $example_network_2 ['shop'] .'\S*")/', 'wpso_found_urls', $content ) ;
}
www说
蓝山帝景
红颜莎娜
12345678_0001
随时随地看视频慕课网APP