在html-php中转换一个wp插件


Convert a wp plugin in html-php

我们的老站长做了这个插件为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;
        }
    }
?>

这个插件使用WP函数来调用样式和脚本文件(用于前端),并返回带有结果的json到前端(可能与ajax调用)。

你需要重新编写wordpress页面模板中的代码,你不能只是"复制粘贴"它。

方向是创建一个页面模板,它将打印类似于函数plate_search()的结果。

但不是到json,打印到页面,并添加脚本/css到页面。