Plugin Directory

Changeset 1418872


Ignore:
Timestamp:
05/17/2016 03:19:13 PM (10 years ago)
Author:
ericjuden
Message:

Updated to filter all site content on Speak like a Pirate Day (September 19)...kudos to joemcgill. Also updated code to better adhere to WordPress coding standards.

Location:
speak-pirate/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • speak-pirate/trunk/readme.txt

    r1234394 r1418872  
    33Tags: pirate, language, shortcode, translate, translation
    44Requires at least: 3.0
    5 Tested up to: 4.3
    6 Stable tag: trunk
     5Tested up to: 4.5.2
     6Stable tag: master
    77License: GPLv2 or later
    88
     
    2222
    2323== Changelog ==
     24= 1.1 =
     25* Updated to filter all site content on Speak like a Pirate Day (September 19)...kudos to joemcgill
     26* Updated code to better adhere to WordPress coding standards
     27
    2428= 1.0 =
    2529* Initial release
  • speak-pirate/trunk/speak-pirate.php

    r654703 r1418872  
    22/**
    33 * Plugin Name: Speak Pirate
    4  * Plugin URI: 
    5  * Description: Translates text in a shortcode into the equivalent text spoken as a pirate
     4 * Plugin URI:
     5 * Description: translates text in a shortcode into the equivalent text spoken as a pirate
    66 * Author: ericjuden
    77 * Author URI: http://ericjuden.com
    8  * Version: 1.0
     8 * Version: 1.1
    99 */
    10  
     10
    1111class Speak_Pirate {
    1212    function __construct(){
    1313        // Constructor...actions and filters go here
    14         add_shortcode('speak_pirate', array($this, 'speak_pirate'), 10, 2);
     14        add_shortcode( 'speak_pirate' , array( $this , 'speak_pirate_shortcode' ), 10 , 2 );
     15
     16        /**
     17         * Add filter to all content on Speak like a Pirate Day (Sept. 19)
     18         */
     19        if ( 'Sep 19' === date( 'M j' ) )  {
     20            add_filter( 'the_content' , array( $this , 'speak_pirate') );
     21        }
    1522    }
    16  
    17     function speak_pirate($args, $content = null){
     23
     24    function speak_pirate( $content = null ){
    1825        // Check if there is any content
    19         if($content == null){
     26        if( $content == null ) {
    2027            return;
    2128        }
    22        
     29
    2330        // URL encode our "pirate" text
    24         $text = urlencode($content);
    25        
     31        $text = urlencode( $content );
     32
    2633        // Set the url for our web service. Found API from apihub.com
    27         $url = sprintf('http://isithackday.com/arrpi.php?text=%s', $text);
    28        
     34        $url = sprintf( 'http://isithackday.com/arrpi.php?text=%s' , $text );
     35
    2936        // Retrieve response from web service
    30         $response = wp_remote_get($url);
    31        
     37        $response = wp_remote_get( $url );
     38
    3239        // Return translated string. If nothing found, returns empty string
    33         return wp_remote_retrieve_body($response);
     40        return wp_remote_retrieve_body( $response );
     41    }
     42
     43    function speak_pirate_shortcode( $args, $content = null ) {
     44      return $this->speak_pirate( $content );
    3445    }
    3546}
    36  
     47
    3748// Create an instance of the class so it will run
    3849$speak_pirate = new Speak_Pirate();
Note: See TracChangeset for help on using the changeset viewer.