在html-php中转换wp插件

our old webmaster did this plugin for wp, but we need it for html page, like a "content" that we can integrate in our html for show up the "plugin" i was asking if you guys can help me out, i tried to remove the wp hooks but it still doesnt show up and i cant get why

<?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;
        }
    }

?>

that's the one i am trying

<?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;
        }
    }

?>

1个回答



此插件使用WP函数调用样式和脚本文件(用于前端),并返回带有结果的json到前端(可能) 使用ajax调用)。</ p>

您需要在 wordpress页面模板,你不能只是”复制粘贴“它。</ p>

方向是 创建一个将打印结果的页面模板 - 如函数plate_search()。 </ p>

但是不是json,而是打印到页面,并将脚本/ css添加到页面。</ p>
</ div>

展开原文

原文

This plugin uses WP functions to call style and script files (for front end), and returns a json with results to front end (Probably with ajax call).

You need to re-write the code in a wordpress page template, you can't just "copy paste" it.

The direction is to create a page template that will print the results - like function plate_search().

But instead of to json, print to page, and add the script/css to page too.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐