douyiqi9640 2016-08-09 17:36
浏览 85

在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条回答 默认 最新

  • douzi9430 2016-08-09 18:29
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大