Navigation Menu

Skip to content

Commit

Permalink
Conversion to WP coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertDD committed Dec 17, 2012
1 parent 2485953 commit ef66bf3
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions tinymce-email-button.php
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: TinyMCE Email Button
Plugin URI: https://github.com/GeertDD/tinymce-email-button
Plugin URI: https://github.com/GeertDD/wp-plugin-tinymce-email-button
Description: Adds a button for creating email links to the TinyMCE editor
Version: 1.0
Author: Geert De Deckere
Expand All @@ -17,20 +17,18 @@ class TinyMCE_Email_Button {
*
* @return void
*/
public function __construct()
{
add_action('init', array($this, 'init'));
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}

/**
* Initialize the plugin
*
* @return void
*/
public function init()
{
public function init() {
// This plugin only applies to Wysiwyg areas in the admin
if ( ! is_admin() || get_user_option('rich_editing') !== 'true')
if ( ! is_admin() || 'true' !== get_user_option( 'rich_editing' ) )
return;

// Setup internationalisation first
Expand All @@ -39,30 +37,29 @@ public function init()
// Note: the TinyMCE Advanced plugin also uses these hooks and uses priority 999.
// We need a higher priority in order for the button to be added succesfully.
// See: http://wordpress.org/extend/plugins/tinymce-advanced/
add_filter('mce_buttons', array($this, 'mce_buttons'), 1000);
add_filter('mce_external_plugins', array($this, 'mce_external_plugins'), 1000);
add_filter( 'mce_buttons', array( $this, 'mce_buttons' ), 1000 );
add_filter( 'mce_external_plugins', array( $this, 'mce_external_plugins' ), 1000 );
}

/**
* Internationalization setup
*
* @return void
*/
public function i18n()
{
public function i18n() {
// Load language files
// See: http://www.geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
$domain = 'tinymce-email-button';
$locale = apply_filters('plugin_locale', get_locale(), $domain);
load_textdomain($domain, WP_LANG_DIR.'/tinymce-email-button/'.$domain.'-'.$locale.'.mo');
load_plugin_textdomain($domain, FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
load_textdomain( $domain, WP_LANG_DIR."/tinymce-email-button/$domain-$locale.mo" );
load_plugin_textdomain( $domain, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

// Localization for the tinymce-email-button.js file
wp_localize_script('editor', 'tinymce_email_button', array(
'url' => plugin_dir_url(__FILE__),
'title' => __('Insert e-mail link', 'tinymce-email-button'),
'prompt' => __('Enter the email address to link to:', 'tinymce-email-button'),
));
wp_localize_script( 'editor', 'tinymce_email_button', array(
'url' => plugin_dir_url( __FILE__ ),
'title' => __( 'Insert e-mail link', 'tinymce-email-button' ),
'prompt' => __( 'Enter the email address to link to:', 'tinymce-email-button' ),
) );
}

/**
Expand All @@ -71,20 +68,17 @@ public function i18n()
* @param array $buttons ordered button list
* @return array $buttons
*/
public function mce_buttons($buttons)
{
public function mce_buttons( $buttons ) {
// Look for the regular link button
if (FALSE === ($key = array_search('link', $buttons)))
{
$key = array_search( 'link', $buttons );
if ( false === $key ) {
// Append the button to the end of the row if no link button was found
$buttons[] = 'email';
}
else
{
} else {
// Insert the email button before the link button
$before = array_slice($buttons, 0, $key);
$after = array_slice($buttons, $key);
$buttons = array_merge($before, array('email'), $after);
$before = array_slice( $buttons, 0, $key );
$after = array_slice( $buttons, $key );
$buttons = array_merge( $before, array( 'email' ), $after );
}

return $buttons;
Expand All @@ -96,10 +90,9 @@ public function mce_buttons($buttons)
* @param array $plugins TinyMCE plugin files
* @return array $plugins
*/
public function mce_external_plugins($plugins)
{
$suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
$plugins['email'] = plugin_dir_url(__FILE__).'javascript/tinymce-email-button'.$suffix.'.js';
public function mce_external_plugins( $plugins ) {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
$plugins['email'] = plugin_dir_url( __FILE__ ) . "javascript/tinymce-email-button$suffix.js";
return $plugins;
}

Expand Down

0 comments on commit ef66bf3

Please sign in to comment.