I've created the following plugin which requires a js library, however attempts to load the plugin with the line add_action( 'wp_enqueue_scripts', 'calc_script' );
in place fail with the error unexpected T_STRING
any help appreciated.
<?php
/**
* Plugin Name: NME Savings Calculator
* Description: A widget that displays the potential savings from installing solar panels.
* Version: 0.1
* Author: NME
* Author URI: http://nme.com.au
*/
add_action( 'widgets_init', 'NME_solar_widget' );
function NME_solar_widget() {
register_widget( 'NME_solar_widget' );
}
class NME_solar_widget extends WP_Widget {
function NME_solar_widget() {
$widget_ops = array( 'classname' => 'example', 'description' => __('A widget that displays the potential savings from installing solar panels.', 'example') );
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'example-widget' );
$this->WP_Widget( 'example-widget', __('Solar Calculator Widget', 'example'), $widget_ops, $control_ops );
}
function widget( $args, $instance ) {
extract( $args );
//Our variables from the widget settings.
$title = apply_filters('widget_title', $instance['title'] );
$name = $instance['name'];
$daily_kwh = $instance['daily_kwh'];
$contact_text = $instance['contact_text'];
$cost_label = $instance['cost_label'];
$provide_label = $instance['provide_label'];
echo $before_widget;
// Display the widget title
if ( $title )
echo $before_title . $title . $after_title;
//Display the name
echo '<div>';
printf( '<p>' . __('%1$s', 'example') . '</p>', $name );
printf( '<p>' . __('%1$s', 'example') . ' <input type="text" id="daily-average" size="8"/> <span id="quote-system-size-daily"> 0 kw </p>', $daily_kwh );
printf( '<p>' . __('%1$s', 'example') . ' <input type="text" id="quarter-average" size="8"/> <span id="quote-system-size-quarter"> 0 kw </p>', $cost_label );
printf( '<p><input type="text" id="system-size" size="26"/> ' . __('%1$s', 'example') . '<br/><span class="amount" id="quote-savings">'.'$0 per year!!'.'</p>', $provide_label );
echo '</div>';
if ( $contact_text )
printf( '<p>' . __('%1$s', 'example') . '</p>', $contact_text );
echo $after_widget;
}
//Update the widget
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
//Strip tags from title and name to remove HTML
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['name'] = strip_tags( $new_instance['name'] );
$instance['daily_kwh'] = strip_tags( $new_instance['daily_kwh'] );
$instance['contact_text'] = strip_tags( $new_instance['contact_text'] );
$instance['cost_label'] = strip_tags( $new_instance['cost_label'] );
$instance['provide_label'] = strip_tags( $new_instance['provide_label'] );
return $instance;
}
function calc_script()
{
wp_register_script( 'calc', plugins_url( '/solar/calc.js', __FILE__ ), array( 'jquery' ) );
wp_enqueue_script( 'calc' );
}
add_action( 'wp_enqueue_scripts', 'calc_script' );
function form( $instance ) {
//Set up some default widget settings.
$defaults = array( 'title' => __('Type text here', 'example'), 'name' => __('Type text here', 'example'), 'show_info' => true );
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Headline:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Introduction Text:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'daily_kwh' ); ?>"><?php _e('Daily KWH Text:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'daily_kwh' ); ?>" name="<?php echo $this->get_field_name( 'daily_kwh' ); ?>" value="<?php echo $instance['daily_kwh']; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'cost_label' ); ?>"><?php _e('Cost Text:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'cost_label' ); ?>" name="<?php echo $this->get_field_name( 'cost_label' ); ?>" value="<?php echo $instance['cost_label']; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'contact_text' ); ?>"><?php _e('Contact Text:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'contact_text' ); ?>" name="<?php echo $this->get_field_name( 'contact_text' ); ?>" value="<?php echo $instance['contact_text']; ?>" style="width:100%;" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'provide_label' ); ?>"><?php _e('Provide Text:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'provide_label' ); ?>" name="<?php echo $this->get_field_name( 'provide_label' ); ?>" value="<?php echo $instance['provide_label']; ?>" style="width:100%;" />
</p>
<?php
}
}
?>