Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Speak Pirate plugin for WordPress
* Plugin Name: Speak Pirate
* Plugin URI:
* Description: translates text in a shortcode into the equivalent text spoken as a pirate
* Author: ericjuden
* Author URI:
* Version: 1.0
class Speak_Pirate {
function __construct(){
// Constructor...actions and filters go here
add_shortcode('speak_pirate', array($this, 'speak_pirate'), 10, 2);
function speak_pirate($args, $content = null){
// Check if there is any content
if($content == null){
// URL encode our "pirate" text
$text = urlencode($content);
// Set the url for our web service. Found API from
$url = sprintf('', $text);
// Retrieve response from web service
$response = wp_remote_get($url);
// Return translated string. If nothing found, returns empty string
return wp_remote_retrieve_body($response);
// Create an instance of the class so it will run
$speak_pirate = new Speak_Pirate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment