2

我制作了这个插件来显示来自我业务的 yelp 的评论,这是我的第一次尝试并且它有效,但我想与大家分享。当我在代码上添加我的设置时,它会按照预期的方式工作。但是当我制作管理界面以便人们可以使用他们自己的 API 密钥并将外观更改为最合适的时,它不会“保存”设置并且不会工作。我希望有人可以阐明并帮助我,以便我可以共享代码/插件。(顺便说一下,这是我第一次尝试编码)

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

我知道我还有很多代码清理工作

4

2 回答 2

0

var_dump($options);就在这条线下面$options = get_option('yelprt_widget');——告诉我是否$unsigned_url在那里。

于 2012-10-16T15:14:32.933 回答
0

事实上,在 wordpress 调用 $instance 之前,我使用的是一个非常古老的“插件模板”。所以人们过去常常制作自己的实例,这就是我正在做的事情。我已经清理了我的代码并让它工作了。我遇到的唯一问题是,一旦 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 : contactflavio@gmail.com )

    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' );


?>

我希望它可以帮助别人

于 2013-02-12T15:09:07.937 回答