2016-08-09 2 views
0

наш старый веб-мастер сделал этот плагин для wp, но нам он нужен для html-страницы, как «контент», который мы можем интегрировать в наш html для отображения «плагина» i was с просьбой, если вы, ребята, можете помочь мне, я попытался удалить Wp крюки, но он все еще не показывает вверх и я не могу получить, почемуПреобразование wp-плагина в html-php

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

Этот плагин использует WP функции для вызова стилей и файлов сценариев (для front end) и возвращает json с результатами на передний конец (Возможно, с вызовом ajax).

Вам необходимо переписать код в wordpress page template, вы не можете просто «скопировать его».

Направление состоит в том, чтобы создать шаблон страницы, который напечатает результаты - например, функцию plate_search().

Но вместо json напечатайте на страницу и добавьте скрипт/css на страницу.

Смежные вопросы