bouncebackdata1
Forum Replies Created
-
Forum: Plugins
In reply to: [METAR plugin] [Plugin: metar-widget] BROKENHere’s a similar NOAA widget code, in case it might help:
<?php
/**
Plugin Name: NOAA Weather
Plugin URI: https://www.berneman.com/noaa-weather
Description: Display the current NOAA weather in the sidebar. Be sure to set your NOAA Code!
Version: 1.1.0
Author: Tim Berneman
Author URI: https://www.berneman.com
License: GPL2Copyright 2010-2011 Tim Berneman (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
*//**
Credits:
Thanks to Justin Tadlock and his article “The complete guide to creating widgets in WordPress 2.8”
and to the WordPress codex which helped me to write this, my first widget. Justins’ article can
be found here: https://justintadlock.com/archives/2009/05/26/the-complete-guide-to-creating-widgets-in-wordpress-28
*//**
Load our widget and css file and register our hooks.
*/
register_activation_hook( __FILE__ , ‘activate_NOAA_Weather_widget’ );
register_deactivation_hook( __FILE__ , ‘deactivate_NOAA_Weather_widget’ );
add_action( ‘widgets_init’ , ‘init_NOAA_Weather_widget’ );
add_action( ‘widgets_init’ , ‘load_NOAA_Weather_widget’ );
add_action( ‘Get_NOAA_Weather’ , ‘Get_NOAA_Weather_File’ );function activate_NOAA_Weather_widget() {
// Schedule cron entry to download the weather file
wp_schedule_event( time() , ‘twicehourly’ , ‘Get_NOAA_Weather’ );
// Get files for any codes currently used
Get_NOAA_Weather_File();
}function deactivate_NOAA_Weather_widget() {
// Remove cron entry that downloads the weather file
wp_clear_scheduled_hook( ‘Get_NOAA_Weather’ );
}function init_NOAA_Weather_widget() {
// Register our stylesheet
wp_enqueue_style( ‘NOAA_Weather_Widget_Stylesheet’ , WP_PLUGIN_URL . ‘/noaa-weather/noaa-weather.css’ );
}function load_NOAA_Weather_widget() {
register_widget( ‘NOAA_Weather_Widget’ );
}/**
* Get weather file from NOAA for each weather code
*/
function Get_NOAA_Weather_File() {
//Look in options for all codes to retrieve weather for, disregarding duplicates
$options = get_option( “widget_noaa_weather” );
$codes = array(); // holder for codes to check for duplicates
foreach ( $options as $key => $value ) {
if ( is_array($value) ) {
$code = $options[$key][“noaa_code”];
if ( $code <> null ) {
if ( !in_array($code,$codes) ) {
$codes[] = $code;
Get_NOAA_Weather_File_With_HTTP( $code );
}
}
}
}
}/**
* Use WP HTTP to get weather file according to the code
*/
function Get_NOAA_Weather_File_With_HTTP( $code ) {
// Get current conditions
$result = wp_remote_get ( “https://www.weather.gov/xml/current_obs/{$code}.xml” );
$fp = fopen(dirname( __FILE__) . “/weather-current-{$code}.xml”, “w” );
fwrite($fp, $result[“body”]);
fclose($fp);
}/**
* Set up the cron to get the weather every so often
*/
function NOAA_Weather_Define_Cron_Schedule( $schedules ) {
// add a ‘twicehourly’ schedule to the existing set
$schedules[‘twicehourly’] = array(
‘interval’ => 1800,
‘display’ => __(‘Twice Hourly’)
);
return $schedules;
}
add_filter( ‘cron_schedules’, ‘NOAA_Weather_Define_Cron_Schedule’ );/**
* Create our widget.
*/
class=’noaa_humidity’><span>Humidity: </span>”.$xml->relative_humidity.”%</p>”);
if ( isset($xml->windchill_f) ) {
echo(“<p class=’noaa_windchill’><span>Windchill: </span>”.$xml->windchill_f.”°F</p>”);
}elseif ( isset($xml->heat_index_f) ) {
echo(“<p class=’noaa_heatindex’><span>Heat Index: </span>”.$xml->heat_index_f.”°F</p>”);
}elseif ( isset($xml->dewpoint_f) ) {
echo(“<p class=’noaa_dewpoint’><span>Dewpoint: </span>”.$xml->dewpoint_f.”°F</p>”);
}
echo(“<p class=’noaa_forecast’>latitude.”&lon=”.$xml->longitude.”‘ title=’Click for your 5-day forecast.’ target=’_blank’>Your 5-Day Forecast at a Glance</p>”);
echo(“</div>”);
}
}else{
echo ‘<p>No NOAA Code Found.</p>’;
}/* After widget (defined by themes). */
echo $after_widget;
}class NOAA_Weather_Widget extends WP_Widget {/**
* Widget setup.
*/
function NOAA_Weather_Widget() {
$widget_ops = array( ‘classname’ => ‘noaa_weather’, ‘description’ => __(‘Display the current NOAA weather in the sidebar.’ ));
$control_ops = array( ‘width’ => 400, ‘height’ => 350, ‘id_base’ => ‘noaa_weather’ );
$this->WP_Widget( ‘noaa_weather’ , __(‘NOAA Weather’) , $widget_ops , $control_ops );
}/**
* How to display the widget on the screen.
*/
function widget( $args, $instance ) {
extract( $args );/* User-selected settings. */
$noaa_title = apply_filters( ‘widget_title’ , $instance[‘noaa_title’] );
$noaa_code = $instance[‘noaa_code’];/* Before widget (defined by themes). */
echo $before_widget;/* Title of widget (before and after defined by themes). */
if ( $noaa_title )
echo $before_title . $noaa_title . $after_title;/* Display name from widget settings. */
if ( $noaa_code ) {
$xml = @simplexml_load_file(dirname(__FILE__) . “/weather-current-“.$noaa_code.”.xml”);
if ( $xml === false )
echo(“Weather Unavailable or invalid NOAA code.”);
else {
$wind_full = array( “Northeast” , “Northwest” , “Southeast” , “Southwest” );
$wind_abbr = array( “NE” , “NW” , “SE” , “SW” );
echo(“<div id=’noaa-weather’>”);
echo(“<p class=’noaa_loc’>”.$xml->location.”</p>”);
echo(“<p class=’noaa_update’>”.$xml->observation_time.”</p>”);
echo(“<p class=’noaa_link’>Weather by credit_URL.”‘ title='”.htmlentities($xml->credit,ENT_QUOTES).”‘ target=’_blank’>NOAA“.”</p>”);
echo(“<p class=’noaa_current’>Current Conditions: “.$xml->weather.”</p>”);
echo(“<p class=’noaa_icon’>latitude.”&lon=”.$xml->longitude.”‘ title=’Click for your 5-day forecast.’ target=’_blank’><img src='”.$xml->icon_url_base.$xml->icon_url_name.”‘ alt=’NOAA Icon’/>“.”</p>”);
echo(“<p class=’noaa_temp’><span>Temp: </span>”.round($xml->temp_f).”°F</p>”);
echo(“<p class=’noaa_wind’><span>Wind: </span>”.str_ireplace($wind_full,$wind_abbr,$xml->wind_dir).” at “.round($xml->wind_mph).”mph</p>”);
echo(“<pfunction update( $new_instance, $old_instance ) {
$instance = $old_instance;/* Trim and strip tags for user provided data */
$newtitle = trim(strip_tags($new_instance[‘noaa_title’]));
$newcode = strtoupper(trim(strip_tags($new_instance[‘noaa_code’])));/* Update the widget settings. */
$instance[‘noaa_title’] = $newtitle;
$instance[‘noaa_code’] = $newcode;/* Update the options table */
//update_option(“widget_noaa_weather”, $newvalue);/* Call the function to get the weather file immediately for this code if not blank*/
if ( strlen($newcode) > 0 )
Get_NOAA_Weather_File_With_HTTP( $newcode );return $instance;
}function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( ‘noaa_title’ => ‘NOAA Weather’, ‘noaa_code’ => ” );
$instance = wp_parse_args( (array) $instance, $defaults ); ?><p>
<label for=”<?php echo $this->get_field_id( ‘noaa_title’ ); ?>”>Title:</label>
<input id=”<?php echo $this->get_field_id( ‘noaa_title’ ); ?>” name=”<?php echo $this->get_field_name( ‘noaa_title’ ); ?>” value=”<?php echo $instance[‘noaa_title’]; ?>” style=”width:100%;” />
</p><p>
<label for=”<?php echo $this->get_field_id( ‘noaa_code’ ); ?>”>NOAA Code:</label>
<input id=”<?php echo $this->get_field_id( ‘noaa_code’ ); ?>” name=”<?php echo $this->get_field_name( ‘noaa_code’ ); ?>” value=”<?php echo $instance[‘noaa_code’]; ?>” style=”width:100%;” />
</p>
<p class=’description’>
Find your code here by selecting your state from the dropdown list and then click the ‘Find’ button. On the next screen find your ‘Observation Location’ and the code you need is in parenthesis after your location name.
</p><?php
}Forum: Plugins
In reply to: [METAR plugin] [Plugin: metar-widget] BROKENI found some basic instructions that deal with widget formatting:
https://www.makeuseof.com/tag/how-to-create-wordpress-widgets/
But I don’t know how to incorporate it with the METAR plugin. Maybe you could easily update the plugin by using this?
Forum: Plugins
In reply to: [METAR plugin] [Plugin: metar-widget] Can't activate pluginyes, I fixed it by changing the last line to:
add_action( ‘widgets_init’, create_function( ”, ‘register_widget( “MetarWidget” );’ ) );
I’m trying to format the function so it looks like other widgets with a title, etc. now.
Forum: Plugins
In reply to: [METAR plugin] [Plugin: metar-widget] BROKENI got it working by changing the last line of code so the function wasn’t anonymous:
add_action( ‘widgets_init’, create_function( ”, ‘register_widget( “MetarWidget” );’ ) );
It worked for all themes but the Karma theme until I made that change.
Is it possible that you could make the widget look like other widgets with a title and white text?
Thanks,
MikeForum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionFinally! it works! Thank you very much for the help.
Forum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionCan anyone tell me how to “ditch the anonymous function”?
Forum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionI’m sorry, I don’t know a lot about programming, but I can usually figure things out with some direction.
Forum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionHow do I do that?
Forum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionI just tried activating it on another karma theme site and I get the same error. I tried activating it on an avada theme site and it worked. I’m not sure how to hunt down the problem.
Forum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionI was running 5.2, but I upgraded to 5.3 and I get the same error. I’m using the Karma theme, I’m guessing there must be some conflict with something in there. Anyone have any troubleshooting tips?
Forum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionI gave you [mod redacted password] so you can take a look if you don’t mind. I tried changing line 62 a few times, it broke my site once and I had to go into the SQL database and disable all the plugins for the site to work again.
Forum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionThe site is https://www.midwestrotor.com
Forum: Fixing WordPress
In reply to: Broken Plugin, unexpected T_functionHey, I’m running 3.4.2 as well. Is in conflicting with Jquery or something like that?
Forum: Plugins
In reply to: [METAR plugin] [Plugin: metar-widget] Can't activate pluginI just discovered it’s the pgi inventory plugin that’s doing it. It works again once I deactivate it. Any idea what could be causing it or how I can fix it?
Forum: Themes and Templates
In reply to: Change font color for a SINGLE menu itemI tried your code. am I supposed to put “#nav #item-54 a span strong …”? I just started with the #item.
What else can I try?