我们的旧网站管理员为wp做了这个插件,但我们需要它用于html页面,例如"内容"我们可以在我们的html中集成以显示"插件" 我问你们是否可以帮助我,我试图删除wp钩子,但它仍然没有出现,我不知道为什么
<?php
/*
Plugin Name: Plate Search
Description: A simple plate fetcher
Domain Path: /languages
*/
add_action( 'wp_ajax_plate_search', 'plate_search' );
add_action( 'wp_ajax_nopriv_plate_search', 'plate_search' );
add_action( 'wp_enqueue_scripts', 'plate_search_enqueue' );
function plate_search_enqueue($hook) {
wp_enqueue_script( 'script-name', plugins_url( '/script.js', __FILE__ ), array('jquery') );
wp_enqueue_style( 'style-name', plugins_url( '/style.css', __FILE__ ));
// in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
wp_localize_script( 'script-name', 'ajax_object',
array( 'ajax_url' => admin_url( 'admin-ajax.php' )));
}
function plate_search() {
if (isset($_GET['plate'])) {
$url = 'http://www.mister-auto.it/it/ajax/select-immatriculation.php';
$params = array(
'immatriculation' => $_GET['plate'],
'titulaire' => 'none',
'id_categorie' => 'undefined',
'id_famille' => 'undefined',
'id_generique' => 'undefined',
'id_stage' => 'accueil',
'req_uri' => '/it/',
'force_ktypenr_session' => 'undefined',
'immat_s' => substr(md5(rand(1,10000)),0,13)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$json = array('matches' => array(), 'success' => false);
if (strpos($result,'infobulle')) {
/*
Results Found
*/
$start = "<div class='immatriculation_vehicule_thickbox_bloc'>";
$end = "</div>";
$pos = 0;
while (1) {
$pos1 = strpos($result, $start, $pos);
if ($pos1 > $pos) {
/*
There is another result
*/
$pos2 = strpos($result, $end, $pos1);
$data = substr($result, $pos1, $pos2 - $pos1);
$json['matches'][] = explode('|',strip_tags(str_replace('<br/>','|',$data)));
$pos = $pos2;
$json['success'] = true;
} else {
break;
}
}
}
curl_close($ch);
echo json_encode($json);
exit;
}
}
?>
那是我正在尝试的那个
<?php
/*
Plugin Name: Plate Search
Description: A simple plate fetcher
Domain Path: /languages
*/
add_action( 'plate_search' );
add_action( 'plate_search' );
add_action( 'plate_search_enqueue' );
function plate_search_enqueue($hook) {
wp_enqueue_script( 'script-name', plugins_url( '/script.js', __FILE__ ), array('jquery') );
wp_enqueue_style( 'style-name', plugins_url( '/style.css', __FILE__ ));
// in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
wp_localize_script( 'script-name', 'ajax_object',
array( 'ajax_url' => admin_url( 'admin-ajax.php' )));
}
function plate_search() {
if (isset($_GET['plate'])) {
$url = 'http://www.mister-auto.it/it/ajax/select-immatriculation.php';
$params = array(
'immatriculation' => $_GET['plate'],
'titulaire' => 'none',
'id_categorie' => 'undefined',
'id_famille' => 'undefined',
'id_generique' => 'undefined',
'id_stage' => 'accueil',
'req_uri' => '/it/',
'force_ktypenr_session' => 'undefined',
'immat_s' => substr(md5(rand(1,10000)),0,13)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$json = array('matches' => array(), 'success' => false);
if (strpos($result,'infobulle')) {
/*
Results Found
*/
$start = "<div class='immatriculation_vehicule_thickbox_bloc'>";
$end = "</div>";
$pos = 0;
while (1) {
$pos1 = strpos($result, $start, $pos);
if ($pos1 > $pos) {
/*
There is another result
*/
$pos2 = strpos($result, $end, $pos1);
$data = substr($result, $pos1, $pos2 - $pos1);
$json['matches'][] = explode('|',strip_tags(str_replace('<br/>','|',$data)));
$pos = $pos2;
$json['success'] = true;
} else {
break;
}
}
}
curl_close($ch);
echo json_encode($json);
exit;
}
}
?>
答案 0 :(得分:0)
此插件使用WP函数调用样式和脚本文件(用于前端),并返回带有结果的json到前端(可能带有ajax调用)。
您需要在wordpress page template中重新编写代码,而不能只是&#34;复制粘贴&#34;它
方向是创建一个打印结果的页面模板 - 如函数plate_search()。
但不是json,而是打印到页面,并将脚本/ css添加到页面。