我正在 Wordpress 中构建一个过滤器插件,并用一些 html 替换一些插件特定的标签。
示例:[VIDEO ID=12]
将通过此函数中的 preg_replaced 替换
function display_video($text){
$pattern = '/\[VIDEO ID\=\d+\]/';
$text=preg_replace($pattern,get_video_block($id),$text);
return $text;
}
我不确定如何确保为每次替换事件提供正确的 ( $id
) 参数给我的函数。get_video_block()
除了函数内部之外,没有真正的循环在进行preg_replace()
,那么我将如何提供该值?
有关更多上下文,请get_video_block()
使用以下功能:
function get_video_block($id){
global $wpdb;
$wpdb->show_errors();
$table_name = $wpdb->prefix . "video_manager";
$query = "SELECT * FROM " . $table_name . " WHERE `index` = '$id'";
$results = $wpdb->get_results($query, ARRAY_A);
$results = $results[0];
$returnString = '<div class="vidBlock">';
$returnString .= $results['embed_code'];
$returnString .= '<div class="voteBar">';
$returnString .= $results['vote_text'];
$returnString .= '<input type="button" value="YES" class="voteButton">';
$returnString .= '<input type="button" value="NO" class="voteButton">';
$returnString .= '</div>';
$returnString .= $results['title'] . '<br>';
$returnString .= $results['description'] . '<br>';
$returnString .= '</div>';
return $returnString;
}