diff --git a/wordpress/class-clockwork-plugin.php b/wordpress/class-clockwork-plugin.php index 53fdcd1..757a318 100755 --- a/wordpress/class-clockwork-plugin.php +++ b/wordpress/class-clockwork-plugin.php @@ -35,7 +35,7 @@ abstract class Clockwork_Plugin { /** * Version of the Clockwork Wordpress wrapper */ - const VERSION = '1.1.0'; + const VERSION = '1.2.1'; /** * URL to signup for a new Clockwork account */ @@ -97,6 +97,7 @@ public function __construct() { add_action( 'admin_notices', array( $this, 'setup_admin_message' ) ); add_action( 'admin_bar_menu', array( $this, 'setup_admin_bar' ), 999 ); add_action( 'admin_init', array( $this, 'setup_admin_init' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'setup_clockwork_js' ) ); $this->plugin_callback = array( $this, 'main' ); } @@ -161,7 +162,7 @@ public function setup_admin_message() { // Don't bother showing the "You need to set your Clockwork options" message if it's that form we're viewing if( !isset( $this->clockwork ) && ( get_current_screen()->base != 'toplevel_page_clockwork_options' ) ) { $this->show_admin_message('You need to set your Clockwork options before you can use ' . $this->plugin_name . '.'); - } + } } /** @@ -175,27 +176,29 @@ public function setup_admin_bar() { if ( !is_super_admin() || !is_admin_bar_showing() ) { return; } - // Display a low credit notification if there's no credit - try { - if( !isset( $this->clockwork ) ) { - $options = get_option( 'clockwork_options' ); - - $clockwork = new WordPressClockwork( $options['api_key'] ); + + $options = get_option( 'clockwork_options' ); + if( isset( $options['api_key'] ) ) { + // Display a low credit notification if there's no credit + try { + if( !isset( $this->clockwork ) ) { + $clockwork = new WordPressClockwork( $options['api_key'] ); + } + $balance = $this->clockwork->checkBalance(); + if( $balance['balance'] <= 0 && $balance['account_type'] == 'PAYG' ) { + $balance_string = '£0. Top up now!'; + } else { + $balance_string = $balance['symbol'] . $balance['balance']; + } + // Add a node to the Admin bar + $wp_admin_bar->add_node( array( + 'id' => 'clockwork_balance', + 'title' => 'Clockwork: ' . $balance_string, + 'href' => self::BUY_URL ) + ); + } catch( Exception $e ) { + // Don't kill the entire admin panel because we can't get the balance } - $balance = $this->clockwork->checkBalance(); - if( $balance <= 0 ) { - $balance_string = '£0. Top up now!'; - } else { - $balance_string = $balance['symbol'] . $balance['balance']; - } - // Add a node to the Admin bar - $wp_admin_bar->add_node( array( - 'id' => 'clockwork_balance', - 'title' => 'Clockwork: ' . $balance_string, - 'href' => self::BUY_URL ) - ); - } catch( Exception $e ) { - // Don't kill the entire admin panel because we can't get the balance } } @@ -220,12 +223,23 @@ public function setup_admin_navigation() { if( !$menu_exists ) { add_menu_page( __( 'Clockwork SMS', $this->language_string ), __( 'Clockwork SMS', $this->language_string ), 'manage_options', 'clockwork_options', array( $this, 'clockwork_options' ), plugins_url( 'images/logo_16px_16px.png', dirname( __FILE__ ) ) ); add_submenu_page( 'clockwork_options', __( 'Clockwork Options', $this->language_string ), __( 'Clockwork Options', $this->language_string ), 'manage_options', 'clockwork_options', array( $this, 'clockwork_options' ) ); + add_submenu_page( NULL, 'Test', 'Test', 'manage_options', 'clockwork_test_message', array( $this, 'clockwork_test_message' ) ); } // Setup options for this plugin add_submenu_page( 'clockwork_options', __( $this->plugin_name, $this->language_string ), __( $this->plugin_name, $this->language_string ), 'manage_options', $this->plugin_callback[1], $this->plugin_callback ); } + /** + * Set up javascript for the Clockwork admin functions + * + * @return void + * @author James Inman + */ + public function setup_clockwork_js() { + wp_enqueue_script( 'clockwork_options', plugins_url( 'js/clockwork_options.js', dirname( __FILE__ ) ), array( 'jquery' ) ); + } + /** * Register global Clockwork settings for API keys * @@ -238,7 +252,7 @@ public function setup_admin_init() { add_settings_field( 'clockwork_api_key', 'Your API Key', array( $this, 'settings_api_key_input' ), 'clockwork', 'clockwork_api_keys' ); add_settings_section( 'clockwork_defaults', 'Default Settings', array( $this, 'settings_default_text' ), 'clockwork' ); - add_settings_field( 'clockwork_from', "'From' Name/Number ", array( $this, 'settings_from_input' ), 'clockwork', 'clockwork_defaults' ); + add_settings_field( 'clockwork_from', "'From' Number ", array( $this, 'settings_from_input' ), 'clockwork', 'clockwork_defaults' ); } /** @@ -268,25 +282,33 @@ public function settings_default_text() { * @author James Inman */ public function settings_api_key_input() { - try { - if( !isset( $this->clockwork ) ) { - $options = get_option( 'clockwork_options' ); - $this->clockwork = new WordPressClockwork( $options['api_key'] ); - } + $options = get_option( 'clockwork_options' ); + + if( isset( $options['api_key'] ) ) { + try { + if( !isset( $this->clockwork ) ) { + $this->clockwork = new WordPressClockwork( $options['api_key'] ); + } - echo ""; + echo ""; - // Show balance - $balance = $this->clockwork->checkBalance(); - if( $balance ) { - echo '
Balance: ' . $balance['symbol'] . $balance['balance'] . ' Buy More
'; - } else { // We can't get the credits for some reason - echo ''; - } + // Show balance + $balance = $this->clockwork->checkBalance(); + if( $balance ) { + echo 'Balance: ' . $balance['symbol'] . $balance['balance'] . ' Buy More
'; + } else { // We can't get the credits for some reason + echo ''; + } - } catch( ClockworkException $e ) { + } catch( ClockworkException $e ) { + echo ""; + echo ''; + } + + return; + } else { echo ""; - echo ''; + echo ''; } } @@ -299,12 +321,12 @@ public function settings_api_key_input() { public function settings_from_input() { $options = get_option( 'clockwork_options' ); if( isset( $options['from'] ) ) { - echo ""; + echo ""; } else { - echo ""; + echo ""; } - echo "You can use an alphabetic string, e.g. the name of your store, which must be 11 characters or less. These are not supported by all international networks. You can also enter any normal mobile phone number, which will allow people to reply to your text messages.
"; + echo "Enter the number your messages will be sent from. We recommend your mobile phone number.
UK customers can use alphanumeric strings up to 11 characters.