[oik] plugins.com

WordPress plugins and themes

  • Home
  • About
    • lazy shortcodes
    • smart shortcodes
    • oik base plugin
      • oik – donate
      • oik PayPal buttons
      • oik installation
      • oik Button Shortcode button
      • oik changelog
      • oik FAQ
      • oik plugins on SVN
      • oik plugins on GitHub
  • Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins
    • Bespoke oik plugins
  • Shortcodes
    • Shortcode examples
  • Blocks
    • Block examples
  • APIs
    • ALL action and filter hooks
  • Blog

bw_tides() – Implement [bw_tides] shortcode for UK-tides

Description

Implement [bw_tides] shortcode for UK-tides

Display information about high and low tides obtained from www.tidetimes.org.uk or www.tidetimes.co.uk The data is stored as transient data until midnight, after which we expect new figures for the next day. If the site is going to display more than one set of tide information then you will need to indicate a special code for storing the information. I would have liked to have extracted the location from the tideurl but got distracted with set_transient crashing when passed a SimpleXML object.

Usage

$string = bw_tides( $atts, $content, $tag );

Parameters

$atts
( array ) optional – shortcode parameters
$content
( string ) optional – not expected
$tag
( string ) optional – the shortcode

Returns

string the generated HTML

Source

File name: uk-tides/shortcodes/uk-tides.php
Lines:
1 to 64 of 64
function bw_tides( $atts=null, $content=null, $tag=null ) {

  $tideurl = bw_array_get( $atts, "tideurl", "http://www.tidetimes.org.uk/chichester-harbour-entrance-tide-times.rss" );
  $tideurl = bw_tideurl_namify( $tideurl );
  $store = bw_array_get( $atts, "store", "1" );
  $force = bw_array_get( $atts, "force", null );

  bw_trace2( $tideurl, 'tideurl', true, BW_TRACE_DEBUG );
  bw_trace2( $store, 'store', false, BW_TRACE_VERBOSE );

  $desc = get_transient( 'bw_tides_desc_'. $store );
  $title = get_transient( 'bw_tides_title_'. $store );
  $link = get_transient( 'bw_tides_link_'. $store );

  if ( $desc === FALSE || $title === FALSE || $link === FALSE || $force   ) {
    $tideinfo = bw_get_tide_info( $tideurl );

    if ( is_wp_error( $tideinfo ) || !$tideinfo ||  !$tideinfo->channel ) {
      p( "Tide times and heights not available for $tideurl" );
    } else {

      $channel = $tideinfo->channel;
      bw_trace2( (string) $channel, 'channel', false, BW_TRACE_DEBUG );
      $link = (string) $channel->link;

      /* cast to a string since otherwise there can be a problem with attempting to serialise a simpleXML element */
      $desc = (string) $channel->item->description;

      bw_trace2( $desc, 'desc', false, BW_TRACE_DEBUG );
      /* We may need to strip some unwanted advertising which appears in an anchor tag <a */
      /*
      $desc = preg_replace('/<a (.*?)<\/a>/', "\\2", $desc);
      $allowed = array( 'b' => array(),
                        'br' =>  array()
                      );
      $desc = wp_kses( $desc, $allowed );
      */
      $title = (string) $channel->item->title;
      // $title = $channel->item->title;   uncomment this to cause set_transient to fail

      $secs = bw_time_of_day_secs();
      $secs = 86400 - $secs;
      set_transient( "bw_tides_desc_" . $store, $desc, $secs);
      set_transient( "bw_tides_title_" . $store, $title, $secs);
      set_transient( "bw_tides_link_" . $store, $link, $secs);
    }
  }
  else {
     // We got all the data from the transient store
  }

  bw_trace2( $desc, 'desc', false, BW_TRACE_DEBUG );
  bw_trace2( $title, 'title', false, BW_TRACE_DEBUG );
  bw_trace2( $link, 'link', false, BW_TRACE_DEBUG );

  // Now that tidetimes.org.uk creates the links itself we only need to display the informaton in span
  // with class tides, to allow for custom CSS styling
  //alink( "tides", $link , $desc , $title );
  $css_class = bw_get_css_classname( $store );
  span( "bw_tides $css_class" );
  bw_tides_format_desc( $desc );
  epan( "bw_tides" );
  return( bw_ret());
}
 
 View on GitHub View on Trac

Called by

1 to 1 of 1
  • bw_tides__example() –

Invoked by

    Calls

    1 to 10 of 10
    • bw_array_get() – Return the array[index] or array->index (for an object) or a default value if not set
    • bw_get_css_classname() – Return a CSS class name for the given value
    • bw_get_tide_info() – Gets tide information from the $tide_url
    • bw_ret() – Use bw_ret() to return the contents of $bwecho, leaving the global value as NULL
    • bw_tides_format_desc() – Format the description
    • bw_tideurl_namify() – Form an URL for the given location assuming UK based
    • bw_time_of_day_secs() – Return the time of day in seconds
    • bw_trace2() – Trace $value to the trace log file if tracing is active
    • epan() –
    • span() –

    Call hooks

    Function name: bw_tides
    Plugin ref: UK tides – times and heights
    Version: 3.3.2
    Sourcefile: shortcodes/uk-tides.php
    File ref: shortcodes/uk-tides.php
    API type: shortcode
    Deprecated?: No
    API Letters: B,T

    Published: April 10, 2017 | Last updated: April 10, 2017

    Information

    Function name: bw_tides
    Plugin ref: UK tides – times and heights
    Version: 3.3.2
    Sourcefile: shortcodes/uk-tides.php
    File ref: shortcodes/uk-tides.php
    API type: shortcode
    Deprecated?: No
    API Letters: B,T

    Recent plugin updates

    oik-weight-zone-shipping v0.2.13 oik-weight-zone-shipping v0.2.13 has been tested with WooCommerce 10.1.2 and WordPress 6.8.2 ...
    SB Children Block v1.3.0 Upgrade to SB Children Block v1.3.0 for support for PHP 8.3 and PHP 8.4  ...
    oik v4.15.3 Update to oik v4.15.3 for a couple of security fixes. Tested with WordPress 6.8.2 ...
    oik-privacy-policy v1.4.9 Update to oik-privacy-policy v1.4.9 for a security fix. Tested with WordPress 6.8.2 and PHP 8.3 and PHP 8.4 ...
    oik-nivo-slider v1.17.0 oik-nivo-slider v1.17.0 introduces the Nivo slider block - oik-nivo-slider/nivo. ...

    Plugins

    • All Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins

    Themes

    • FREE themes
    • Bespoke themes
    • Premium themes

    Blocks

    • All Blocks
    • Block examples
    • About Blocks

    Shortcodes

    • All Shortcodes
    • Shortcode examples
    • About Shortcodes

    Reference

    • About APIs
    • All APIs
    • All Classes
    • All Files
    • All Hooks

    Support

    • Contact
    • Cookies policy
    • Get API key
    • Privacy
    • Request support
    • Sitemap
    • Stay informed
    • Terms and Conditions
    oik-plugins
    Email: herb@bobbingwide.com

    Weight shipping plugins

    Find out which cart weight shipping plugin you need for your WooCommerce site.
    Which cart weight based plugin do I need?

    Site:  www.oik-plugins.com
    © Copyright oik-plugins 2011-2025. All rights reserved.


    Website designed and developed by Herb Miller of Bobbing Wide
    Proudly powered by WordPress and oik-plugins

    WordPress version: 6.8.3

    Gutenberg version: 21.7.0

    PHP version: 8.2.29