2012-10-16 136 views
2

我做了這個插件來顯示從我的業務yelp的評論,這是我的第一次嘗試,它的工作原理,但我想分享給大家。 當我在代碼上添加我的設置時,它的工作方式應該是這樣。但是,當我創建管理界面以便人們可以使用他們自己的API密鑰並將其外觀改爲最佳配置時,它不會「保存」設置並且不起作用。 我希望有人可以擺脫一些光線,幫助我,讓我可以分享代碼/插件。 (順便說一下,這是我第一次嘗試編碼)WordPress的Yelp評論代碼插件

yelprt.php

<?php 
/* 
Plugin Name: Yelp Reviews Ticker 
Plugin URI: http://www.google.com/ 
Description: Yelp Reviews Ticker 
Version:  0.1 
Author:  Flavio 
Author URI: http://www.google.com/  
*/ 
    function yelp_rt_widget($args, $widget_args = 1) { 

     extract($args, EXTR_SKIP); 
     if (is_numeric($widget_args)) 
      $widget_args = array('number' => $widget_args); 
     $widget_args = wp_parse_args($widget_args, array('number' => -1)); 
     extract($widget_args, EXTR_SKIP); 

     $options = get_option('yelprt_widget'); 
     if (!isset($options[$number])) 
     return; 

     $title = $options[$number]['title'];  // single value 
     $speed = $options[$number]['speed']; 
     $pause = $options[$number]['pause']; 
     $showitems = $options[$number]['showitems']; 
     $animation = $options[$number]['animation']; 
     $mousepause = $options[$number]['mousepause']; 
     //$height = $options[$number]['height']; 
     $direction = $options[$number]['direction']; 
     $yrtunsigned_url = $options[$number]['unsigned_url']; 
     $yrtconsumer_key = $options[$number]['consumer_key']; 
     $yrtconsumer_secret = $options[$number]['consumer_secret']; 
     $yrttoken = $options[$number]['token']; 
     $yrttoken_secret = $options[$number]['token_secret']; 

     echo $before_widget; // start widget display code 
?><h2><?=$title?></h2><?php 
//print $yrtunsigned_url; 
//echo $options[$number]['unsigned_url']; 

//******MY ADDITION  
// From http://non-diligent.com/articles/yelp-apiv2-php-example/ 
// 

// Enter the path that the oauth library is in relation to the php file 
//require_once ('lib/OAuth.php'); 
$unsigned_url = $options[$number]['unsigned_url']; 
$consumer_key = $options[$number]['consumer_key']; 
$consumer_secret = $options[$number]['consumer_secret']; 
$token = $options[$number]['token']; 
$token_secret = $options[$number]['token_secret']; 


require_once ('lib/OAuth.php'); 
// Token object built using the OAuth library 
$token = new OAuthToken($token, $token_secret); 
//$token = new OAuthToken($yrttoken, $yrttoken_secret); 

// Consumer object built using the OAuth library 
$consumer = new OAuthConsumer($consumer_key, $consumer_secret); 
//$consumer = new OAuthConsumer($yrtconsumer_key, $yrtconsumer_secret); 

// Yelp uses HMAC SHA1 encoding 
$signature_method = new OAuthSignatureMethod_HMAC_SHA1(); 

// Build OAuth Request using the OAuth PHP library. Uses the consumer and token object created above. 
$oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url); 
//$oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $yrtunsigned_url); 

// Sign the request 
$oauthrequest->sign_request($signature_method, $consumer, $token); 
//$oauthrequest->sign_request($signature_method, $yrtconsumer, $yrttoken); 

// Get the signed URL 
$signed_url = $oauthrequest->to_url(); 

// Send Yelp API Call 
$ch = curl_init($signed_url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
$data = curl_exec($ch); // Yelp response 
curl_close($ch); 

// Handle Yelp response data 
$response = json_decode($data); 

$arr = (array) $response; 

if(is_array($arr['reviews'])){ 
    echo "<div id='yelprt'>"; 
    echo "<ul id='list'>"; 
    foreach($arr['reviews'] as $review){ 
     echo "<li><div id='yelprt_table'>\n"; 
     echo " <div class='row'>\n"; 
     echo " <span class='yelprt_cell2'>\n"; 
     echo "  <img src='" . $review->user->image_url . "' width='60px'/>\n"; 
     echo "  <br />" . $review->user->name . "\n"; 
     echo "  <br /><img src='" . $review->rating_image_small_url . "'/>\n"; 
     echo " </span>\n"; 
     echo " <span class='yelprt_cell1'>\n"; 
     echo "  " . $review->excerpt . "\n"; 
     echo "  <br />\n"; 
     echo "   <span class='yelprt_smalltxt'>" . gmdate("m/d/Y", $review->time_created) . " more at <a href='".$yrtunsigned_url."'><img src='http://s3-media1.ak.yelpcdn.com/assets/2/www/img/14f29ad24935/map/miniMapLogo.png'/></a></span>\n"; 
     echo " </span>\n"; 
     echo " </div>\n"; 
     echo " </div></li>\n"; 
    } 
    echo "</div>"; 
} 

    echo $after_widget; // end widget display code 

} 


    function yelp_rt_widget_control($widget_args) { 

     global $wp_registered_widgets; 
     static $updated = false; 

     if (is_numeric($widget_args)) 
      $widget_args = array('number' => $widget_args);   
     $widget_args = wp_parse_args($widget_args, array('number' => -1)); 
     extract($widget_args, EXTR_SKIP); 

     $options = get_option('yelprt_widget'); 

     if (!is_array($options)) 
      $options = array(); 

     if (!$updated && !empty($_POST['sidebar'])) { 

      $sidebar = (string) $_POST['sidebar']; 
      $sidebars_widgets = wp_get_sidebars_widgets(); 

      if (isset($sidebars_widgets[$sidebar])) 
       $this_sidebar =& $sidebars_widgets[$sidebar]; 
      else 
       $this_sidebar = array(); 

      foreach ((array) $this_sidebar as $_widget_id) { 
       if ('yelp_rt_widget' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) { 
        $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number']; 
        if (!in_array("yelp-rt-$widget_number", $_POST['widget-id'])) // the widget has been removed. 
         unset($options[$widget_number]); 
       } 
      } 

      foreach ((array) $_POST['yelp-rt'] as $widget_number => $yelprt_widget) { 
       if (!isset($yelprt_widget['title']) && isset($options[$widget_number])) // user clicked cancel 
        continue; 

       $title = strip_tags(stripslashes($yelprt_widget['title'])); 
       $speed = $yelprt_widget['speed_value']; 
       $pause = $yelprt_widget['pause_value']; 
       $showitems = $yelprt_widget['showitems_value']; 
       $animation = $yelprt_widget['animation_value']; 
       $mousepause = $yelprt_widget['mousepause_value']; 
       //$height = $yelprt_widget['height_value']; 
       $direction = $yelprt_widget['direction_value']; 
       $yrtunsigned_url = $yelprt_widget['unsigned_url_value']; 
       $yrtconsumer_key = $yelprt_widget['consumer_key_value']; 
       $yrtconsumer_secret = $yelprt_widget['consumer_secret_value']; 
       $yrttoken = $yelprt_widget['token_value']; 
       $yrttoken_secret = $yelprt_widget['token_secret_value']; 
       // Pact the values into an array 
       $options[$widget_number] = compact('title', 'speed', 'pause', 'showitems', 'animation', 'mousepause', 'direction', 'unsigned_url', 'consumer_key', 'consumer_secret', 'token', 'token_secret'); 
      } 

      update_option('yelprt_widget', $options); 
      $updated = true; 
     } 

     if (-1 == $number) { // if it's the first time and there are no existing values 

      $title = 'Reviews'; 
      $speed = '2500'; 
      $pause = '6000'; 
      $showitems = '2'; 
      $animation = 'fade'; 
      $mousepause = 'true'; 
      //$height = ''; 
      $direction = 'up'; 
      $yrtunsigned_url = ''; 
      $yrtconsumer_key = ''; 
      $yrtconsumer_secret = ''; 
      $yrttoken = ''; 
      $yrttoken_secret = ''; 
      $yrtnumber = '%i%'; 

     } else { // otherwise get the existing values 

      $title = $options[$number]['title']; 
      $speed = $options[$number]['speed']; 
      $pause = $options[$number]['pause']; 
      $showitems = $options[$number]['showitems']; 
      $animation = $options[$number]['animation']; 
      $mousepause = $options[$number]['mousepause']; 
      //$height = $options[$number]['height']; 
      $direction = $options[$number]['direction']; 
      $yrtunsigned_url = $options[$number]['unsigned_url']; 
      $yrtconsumer_key = $options[$number]['consumer_key']; 
      $yrtconsumer_secret = $options[$number]['consumer_secret']; 
      $yrttoken = $options[$number]['token']; 
      $yrttoken_secret = $options[$number]['token_secret']; 
     } 

     print_r($options[$number]); 

    ?> 
    <p><label>Widget Title</label><br /><input id="title_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][title]" type="text" value="<?=$title?>" /></p> 
    <p><label>Speed</label><br /><input id="speed_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][speed_value]" type="text" value="<?=$speed?>" /></p> 
    <p><label>Pause</label><br /><input id="pause_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][pause_value]" type="text" value="<?=$pause?>" /></p> 
    <p><label>Show Items</label><br /><input id="showitems_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][showitems_value]" type="text" value="<?=$showitems?>" /></p> 

    <p> 
     <label>Fade</label><br /> 
     Yes <input id="animation_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][animation_value]" type="radio" <?php if($animation == 'fade') echo 'checked="checked"'; ?> value="fade" /> 
     No <input id="animation_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][animation_value]" type="radio" <?php if($animation == '') echo 'checked="checked"'; ?> value="" /> 
    </p> 
    <p> 
     <label>Mousepause</label><br /> 
     Yes <input id="mousepause_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][mousepause_value]" type="radio" <?php if($mousepause == 'true') echo 'checked="checked"'; ?> value="true" /> 
     No <input id="mousepause_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][mousepause_value]" type="radio" <?php if($mousepause == 'false') echo 'checked="checked"'; ?> value="false" /> 
    </p> 
    <p> 
     <label>Direction</label><br /> 
     Up <input id="direction_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][direction_value]" type="radio" <?php if($direction == 'up') echo 'checked="checked"'; ?> value="up" /> 
     Down <input id="direction_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][direction_value]" type="radio" <?php if($direction == 'down') echo 'checked="checked"'; ?> value="down" /> 
    </p> 
    <p><label>Business URL</label><br /><input id="unsigned_url_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][unsigned_url_value]" type="text" value="<?=$yrtunsigned_url?>" /></p> 
    <p><label>Consumer Key</label><br /><input id="consumer_key_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][consumer_key_value]" type="text" value="<?=$yrtconsumer_key?>" /></p> 
    <p><label>Consumer Secret</label><br /><input id="consumer_secret_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][consumer_secret_value]" type="text" value="<?=$yrtconsumer_secret?>" /></p> 
    <p><label>Token</label><br /><input id="token_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][token_value]" type="text" value="<?=$yrttoken?>" /></p> 
    <p><label>Token Secret</label><br /><input id="token_secret_value_<?php echo $number; ?>" name="yelp-rt[<?php echo $number; ?>][token_secret_value]" type="text" value="<?=$yrttoken_secret?>" /></p> 

    <input type="hidden" name="yelp-rt[<?php echo $number; ?>][submit]" value="1" /> 

    <?php 
    } 


    function yelp_rt_widget_register() { 
     if (!$options = get_option('yelprt_widget')) 
      $options = array(); 
     $widget_ops = array('classname' => 'yelprt_widget', 'description' => __('Yelp Reviews Ticker')); 
     $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'yelp-rt'); 
     $name = __('Yelp Reviews Ticker Widget'); 

     $id = false; 
     foreach ((array) array_keys($options) as $o) { 

      if (!isset($options[$o]['title'])) 
       continue; 

      $id = "yelp-rt-$o"; 
      wp_register_sidebar_widget($id, $name, 'yelp_rt_widget', $widget_ops, array('number' => $o)); 
      wp_register_widget_control($id, $name, 'yelp_rt_widget_control', $control_ops, array('number' => $o)); 
     } 

     if (!$id) { 
      wp_register_sidebar_widget('yelp-rt-1', $name, 'yelp_rt_widget', $widget_ops, array('number' => -1)); 
      wp_register_widget_control('yelp-rt-1', $name, 'yelp_rt_widget_control', $control_ops, array('number' => -1)); 
     } 
    } 

add_action('init', yelp_rt_widget_register, 1); 
//add_action('widgets_init', create_function('', 'return register_widget("yelprt_widget");')); 
add_action('wp_head', 'yelprt_head'); 
    function yelprt_head($widget_args) { 

     global $wp_registered_widgets; 
     static $updated = false; 

     if (is_numeric($widget_args)) 
      $widget_args = array('number' => $widget_args);   
     $widget_args = wp_parse_args($widget_args, array('number' => -1)); 
     extract($widget_args, EXTR_SKIP); 

     $options = get_option('yelprt_widget'); 
      $title = $options[$number]['title']; 
      $speed = $options[$number]['speed']; 
      $pause = $options[$number]['pause']; 
      $showitems = $options[$number]['showitems']; 
      $animation = $options[$number]['animation']; 
      $mousepause = $options[$number]['mousepause']; 
      //$height = $options[$number]['height']; 
      $direction = $options[$number]['direction']; 
      $yrtunsigned_url = $options[$number]['unsigned_url']; 
      $yrtconsumer_key = $options[$number]['consumer_key']; 
      $yrtconsumer_secret = $options[$number]['consumer_secret']; 
      $yrttoken = $options[$number]['token']; 
      $yrttoken_secret = $options[$number]['token_secret']; 
      echo "<!-- Start Yelp Reviews Ticker -->\n"; 
      echo "<link type='text/css' href='" . plugins_url('css/yelprt.css' , __FILE__) . "' rel='stylesheet'/>\n"; 
      echo "<script type='text/javascript' src='" . plugins_url('lib/jquery.js' , __FILE__) . "'></script>\n"; 
      echo "<script type='text/javascript' src='" . plugins_url('lib/jquery.vticker-min.js' , __FILE__) . "'></script>\n"; 
      echo "<script type='text/javascript'>\n"; 
      echo " $(function(){\n"; 
      echo " $('#yelprt').vTicker({ \n"; 
      echo "  speed: ".$speed.",\n"; 
      echo "  pause: ".$pause.",\n"; 
      echo "  animation: '".$animation."',\n"; 
      echo "  mousePause: ".$mousepause.",\n"; 
      echo "  direction: '".$direction."',\n"; 
      echo "  showItems: ".$showitems."\n"; 
      echo " });\n"; 
      echo "});\n"; 
      echo "</script>\n"; 
      echo "<!-- End Yelp Reviews Ticker -->\n"; 
    } 
?> 

我知道我還有很多的代碼清潔

+0

事實上,你確實有一些代碼清理做。 :) 這是很多的代碼來閱讀。請儘量縮小範圍。 'update_options'之前你的值是否正確?您是否檢查過數據庫以驗證該值是否已保存?也許問題在於檢索。另外,你真的應該使用[Widget API](http://codex.wordpress.org/Widgets_API)。我很驚訝那些舊式的小部件註冊函數不被棄用(還)。 –

+0

值在_options - > yelprt_widget下被保存到db中,對不起,由於我在wordpress上缺乏經驗,我複製並粘貼了部分示例代碼,可能它並不是最新的。問題是,當'code'//在該行後面發送Yelp API Call'code'時,當我調用密鑰和設置時,它不使用這些值。我可以讓它打印這些值,但由於某種原因,當它使用代碼時,它看起來像是空白的值 –

+0

好的。所以問題不是你說的那樣。該選項確實保存。你的問題是檢索。其實,我不確定你是否回答了這個問題。 API密鑰是否專門保存? –

回答

0

事實上,我在wordpress進行$實例調用之前使用了一個非常古老的「插件模板」。所以人們習慣於自己創造實例,這正是我所做的。 我已經清理了我的代碼並使其工作。 我遇到的唯一問題是,一旦jQuery接管,我的css將無法在插件中工作。 但這是一個不同的問題。 這裏是我的固定

<?php 
/* 
Plugin Name: Yelp Reviews Ticker 
Plugin URI: http://wordpress.org/extend/plugins/ 
Description: This reviews ticker allows you to show your yelp reviews and also customize its display to your taste in a easy manner 
Version:  0.5 
Author:  Flavio Domeneck Jr 
Author URI: http://www.flaviotreeservice.com/ 
License: GPL2 

Copyright 2013 FDJ (email : [email protected]) 

    This program is free software; you can redistribute it and/or modify 
    it under the terms of the GNU General Public License, version 2, as 
    published by the Free Software Foundation. 

    This program is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    GNU General Public License for more details. 

    You should have received a copy of the GNU General Public License 
    along with this program; if not, write to the Free Software 
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
*/ 


class yrtWidget extends WP_Widget { 
    function yrtWidget() { 
     parent::__construct( 
      false, 
      'Yelp Reviews Ticker', 
      array('description' => "Yelp Reviews Ticker shows your yelp reviews cleanly and pain free") 
     ); 

    } 

    function widget($args, $instance) { 
     extract($args); 
     echo $before_widget; 
     echo $before_title.$instance['title'].$after_title; 

// 
// Partially from 
// http://non-diligent.com/articles/yelp-apiv2-php-example/ 
// https://github.com/Yelp/yelp-api/blob/master/v2/php/example.php 
// 

// Enter the path that the oauth library is in relation to the php file 
require_once ('lib/OAuth.php'); 

// Set instance values 
$speed = $instance['speed']; 
$pause = $instance['pause']; 
$showitems = $instance['showitems']; 
$animation = $instance['animation']; 
$mousepause = $instance['mousepause']; 
$direction = $instance['direction']; 
$yelp_url = $instance['yelp_url']; 
$unsigned_url = $instance['unsigned_url']; 
$consumer_key = $instance['consumer_key']; 
$consumer_secret = $instance['consumer_secret']; 
$token = $instance['token']; 
$token_secret = $instance['token_secret']; 

// Token object built using the OAuth library 
$token = new OAuthToken($token, $token_secret); 

// Consumer object built using the OAuth library 
$consumer = new OAuthConsumer($consumer_key, $consumer_secret); 

// Yelp uses HMAC SHA1 encoding 
$signature_method = new OAuthSignatureMethod_HMAC_SHA1(); 

// Build OAuth Request using the OAuth PHP library. Uses the consumer and token object created above. 
$oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url); 

// Sign the request 
$oauthrequest->sign_request($signature_method, $consumer, $token); 

// Get the signed URL 
$signed_url = $oauthrequest->to_url(); 

// Send Yelp API Call 
$ch = curl_init($signed_url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
$data = curl_exec($ch); // Yelp response 
curl_close($ch); 

// Handle Yelp response data 
$response = json_decode($data); 

$arr = (array) $response; 



if(is_array($arr['reviews'])){ 
    ?> 

<!-- Start Yelp Reviews Ticker --> 
<script type="text/javascript"> 
$(function(){ 
    $('#yelp-review-ticker').vTicker({ 
    <? 
    echo " speed: " . $instance['speed'] . ",\n"; 
    echo " pause: " . $instance['pause'] . ",\n"; 
    echo " animation: '" . $instance['animation'] . "',\n"; 
    echo " mousePause: " . $instance['mousepause'] . ",\n"; 
    echo " direction: '" . $instance['direction'] . "',\n"; 
    echo " showItems: " . $instance['showitems'] . "\n"; 
    ?> 
    }); 
}); 
</script> 
<!-- End Yelp Reviews Ticker --> 
<div id="yelp-review-ticker"><ul> 
<? foreach($arr['reviews'] as $review){ ?> 
     <li> 
      <table> 
       <tr> 
        <td style="text-align:center; padding:5px; font-size:90%"> 
<? echo "    <img src=\"" . $review->user->image_url . "\" width=\"60px\"/>\n"; 
echo "     <br />" . $review->user->name . "\n"; 
echo "     <br /><img src=\"" . $review->rating_image_small_url . "\" />\n"; 
?> 
        </td> 
        <td> 
<? echo "    <p>" . $review->excerpt . "</p>\n"; 
echo "     <div style=\"text-align:right; font-size:80%;\"><a href=\"" . $instance['yelp_url'] . "\" target=\"_blank\"> " . gmdate("m/d/Y", $review->time_created) . " more at \n"; 
echo "      <img src=\"http://s3-media1.ak.yelpcdn.com/assets/2/www/img/14f29ad24935/map/miniMapLogo.png\"/></a>\n"; 
?> 
        </div> 
        </td> 
       </tr> 
      </table> 
     </li> 
<? } ?> 
    </ul> 
</div> 
<? } 


echo $after_widget; 

} // End function widget. 


    function yrtWidget_header(){ 
// jQuery vTicker from 
// http://www.jugbit.com/jquery-vticker-vertical-news-ticker/ 
     echo ' 
     <script type="text/javascript" src="' . plugins_url('lib/jquery-1.8.3.min.js' , __FILE__) . '"></script> 
     <script type="text/javascript" src="' . plugins_url('lib/jquery.vticker-min.js' , __FILE__) . '"></script> 
     <style type="text/css" media="all" src="' . plugins_url('css/yelprt.css' , __FILE__) . '"></style> 
     '; 

    } 

// Updates the settings. 

    function update($new_instance, $old_instance) { 
     return $new_instance; 
    } 
    function form($instance) { //<- set default parameters of widget 
     if($instance){ 
      $title = $instance['title']; 
      $speed = $instance['speed']; 
      $pause = $instance['pause']; 
      $showitems = $instance['showitems']; 
      $animation = $instance['animation']; 
      $mousepause = $instance['mousepause']; 
      $direction = $instance['direction']; 
      $yelp_url = $instance['yelp_url']; 
      $unsigned_url = $instance['unsigned_url']; 
      $consumer_key = $instance['consumer_key']; 
      $consumer_secret = $instance['consumer_secret']; 
      $token = $instance['token']; 
      $token_secret = $instance['token_secret']; 
     } 
     else{ 
      $title = 'Reviews'; 
      $speed = '2500'; 
      $pause = '6000'; 
      $showitems = '2'; 
      $animation = 'fade'; 
      $mousepause = 'true'; 
      $direction = 'up'; 
      $yelp_url = 'http://www.yelp.com/biz/'; 
      $unsigned_url = 'http://api.yelp.com/v2/business/'; 
      $consumer_key = ''; 
      $consumer_secret = ''; 
      $token = ''; 
      $token_secret = ''; 
     } 
    ?> 
     <p> 
      <label for="<?php echo $this->get_field_id('title');?>">Widget Title</label><br /> 
      <input id="<?php echo $this->get_field_id('title');?>" name="<?php echo $this->get_field_name('title');?>" type="text" value="<?php echo $title; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('speed');?>">Speed</label><br /> 
      <input id="<?php echo $this->get_field_id('speed');?>" name="<?php echo $this->get_field_name('speed');?>" type="text" value="<?php echo $speed; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('pause');?>">Pause</label><br /> 
      <input id="<?php echo $this->get_field_id('pause');?>" name="<?php echo $this->get_field_name('pause');?>" type="text" value="<?php echo $pause; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('showitems');?>"># of reviews</label><br /> 
      <input id="<?php echo $this->get_field_id('showitems');?>" name="<?php echo $this->get_field_name('showitems');?>" type="text" value="<?php echo $showitems; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('animation');?>">Fade</label><br /> 
      Yes <input id="<?php echo $this->get_field_id('animation');?>" name="<?php echo $this->get_field_name('animation');?>" type="radio" <?php if($animation == 'fade') echo 'checked="checked"'; ?> value="fade"/> 
      No <input id="<?php echo $this->get_field_id('animation');?>" name="<?php echo $this->get_field_name('animation');?>" type="radio" <?php if($animation == '') echo 'checked="checked"'; ?> value=""/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('mousepause');?>">Mouse Pause</label><br /> 
      Yes <input id="<?php echo $this->get_field_id('mousepause');?>" name="<?php echo $this->get_field_name('mousepause');?>" type="radio" <?php if($mousepause == 'true') echo 'checked="checked"'; ?> value="true"/> 
      No <input id="<?php echo $this->get_field_id('mousepause');?>" name="<?php echo $this->get_field_name('mousepause');?>" type="radio" <?php if($mousepause == 'false') echo 'checked="checked"'; ?> value="false"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('direction');?>">Direction</label><br /> 
      Up <input id="<?php echo $this->get_field_id('direction');?>" name="<?php echo $this->get_field_name('direction');?>" type="radio" <?php if($direction == 'up') echo 'checked="checked"'; ?> value="up"/> 
      Down <input id="<?php echo $this->get_field_id('direction');?>" name="<?php echo $this->get_field_name('direction');?>" type="radio" <?php if($direction == 'down') echo 'checked="checked"'; ?> value="down"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('yelp_url');?>">Yelp Business URL</label><br /> 
      http://www.yelp.com/biz/...<br /> 
      <input id="<?php echo $this->get_field_id('yelp_url');?>" name="<?php echo $this->get_field_name('yelp_url');?>" type="text" value="<?php echo $yelp_url; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('unsigned_url');?>">API Business URL</label><br /> 
      http://api.yelp.com/v2/business/...<br /> 
      <input id="<?php echo $this->get_field_id('unsigned_url');?>" name="<?php echo $this->get_field_name('unsigned_url');?>" type="text" value="<?php echo $unsigned_url; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('consumer_key');?>">Consumer Key</label><br /> 
      <input id="<?php echo $this->get_field_id('consumer_key');?>" name="<?php echo $this->get_field_name('consumer_key');?>" type="text" value="<?php echo $consumer_key; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('consumer_secret');?>">Consumer Secret</label><br /> 
      <input id="<?php echo $this->get_field_id('consumer_secret');?>" name="<?php echo $this->get_field_name('consumer_secret');?>" type="text" value="<?php echo $consumer_secret; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('token');?>">Token</label><br /> 
      <input id="<?php echo $this->get_field_id('token');?>" name="<?php echo $this->get_field_name('token');?>" type="text" value="<?php echo $token; ?>"/> 
     </p> 
     <p> 
      <label for="<?php echo $this->get_field_id('token_secret');?>">Token Secret</label><br /> 
      <input id="<?php echo $this->get_field_id('token_secret');?>" name="<?php echo $this->get_field_name('token_secret');?>" type="text" value="<?php echo $token_secret; ?>"/> 
     </p> 


    <?php 
    } // end function form 



} // end class 

// Register the widget. 
function yrtw_register() { 
    register_widget('yrtWidget'); 
} 

add_action('wp_head', 'add_yrt_header'); 
    function add_yrt_header(){ 

     echo ' 
     <script type="text/javascript" src="' . plugins_url('lib/jquery-1.8.3.min.js' , __FILE__) . '"></script> 
     <script type="text/javascript" src="' . plugins_url('lib/jquery.vticker-min.js' , __FILE__) . '"></script> 
     <style type="text/css" media="all" src="' . plugins_url('css/yelprt.css' , __FILE__) . '"></style> 
     '; 

    } 

add_action('widgets_init', 'yrtw_register'); 


?> 

我希望它可以幫助別人

0

var_dump($options);有權根據本line-- $options = get_option('yelprt_widget');和告訴我$unsigned_url是否有。

+0

是的,'[「unsigned_url」] =>字符串(65)「http://google.com」' –

+0

我是假設它已經通過這一行正確填充:'$ unsigned_url = $ options [$ number] ['unsigned_url'];'如果是這樣,'var_dump($ oauthrequest)' –

+0

我無法'var_dump($ oauthrequest)因爲它導致了一個錯誤,但'echo $ oauthrequest;'給了我預期的URL –