convert_existing_username_and_password(); // Setup clockwork try { $options = get_option( 'clockwork_options' ); if( is_array( $options ) && isset( $options['api_key'] ) ) { $this->clockwork = new WordPressClockwork( $options['api_key'] ); } } catch( Exception $e ) { } // Register the activation hook to install register_activation_hook( __FILE__, array( $this, 'install' ) ); add_action( 'admin_head', array( $this, 'setup_admin_head' ) ); add_action( 'admin_menu', array( $this, 'setup_admin_navigation' ) ); 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' ); } /** * Return the username and password from the plugin's existing options * * @return array Array of 'username' and 'password' * @author James Inman */ abstract public function get_existing_username_and_password(); /** * Setup HTML for the admin
* * @return void * @author James Inman */ abstract public function setup_admin_head(); /** * Convert existing username and password to a new API key * * @return void * @author James Inman */ public function convert_existing_username_and_password() { $options = get_option( 'clockwork_options' ); if( !is_array( $options ) || !isset( $options['api_key'] ) ) { $existing_details = $this->get_existing_username_and_password(); if( is_array( $existing_details ) && isset( $existing_details['username'] ) && isset( $existing_details['password'] ) ) { try { // We have a username and password, now go and convert them $this->clockwork = new WordPressClockwork( $existing_details['username'], $existing_details['password'] ); $key = $this->clockwork->createAPIKey( 'WordPress - ' . home_url() ); // Set the Clockwork API key to be the newly created key update_option( 'clockwork_options', array( 'api_key' => $key ) ); } catch( ClockworkException $e ) { return; } } } } /** * Called on plugin activation * * @return void * @author James Inman */ public function install() { } /** * Tell the user to update their Clockwork options on every admin panel page if they haven't already * * @return void * @author James Inman */ 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 . '.'); } } /** * Add the Clockwork balance to the admin bar * * @return void * @author James Inman */ public function setup_admin_bar() { global $wp_admin_bar; if ( !is_super_admin() || !is_admin_bar_showing() ) { return; } $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 } } } /** * Setup admin navigation: callback for 'admin_menu' * * @return void * @author James Inman */ public function setup_admin_navigation() { global $menu; $menu_exists = false; foreach( $menu as $k => $item ) { if( $item[0] == "Clockwork SMS" ) { $menu_exists = true; break; } } // Setup global Clockwork options 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 * * @return void * @author James Inman */ public function setup_admin_init() { register_setting( 'clockwork_options', 'clockwork_options', array( $this, 'clockwork_options_validate' ) ); add_settings_section( 'clockwork_api_keys', 'API Key', array( $this, 'settings_api_key_text' ), 'clockwork' ); 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' Number ", array( $this, 'settings_from_input' ), 'clockwork', 'clockwork_defaults' ); } /** * Introductory text for the API keys part of the form * * @return void * @author James Inman */ public function settings_api_key_text() { echo 'You need an API key to use the Clockwork plugins.
'; } /** * Introductory text for the default part of the form * * @return void * @author James Inman */ public function settings_default_text() { echo 'Default settings apply to every Clockwork plugin you have installed.
'; } /** * Input box for the API key * * @return void * @author James Inman */ public function settings_api_key_input() { $options = get_option( 'clockwork_options' ); if( isset( $options['api_key'] ) ) { try { if( !isset( $this->clockwork ) ) { $this->clockwork = new WordPressClockwork( $options['api_key'] ); } 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 ) { echo ""; echo ''; } return; } else { echo ""; echo ''; } } /** * Input box for the from name * * @return void * @author James Inman */ public function settings_from_input() { $options = get_option( 'clockwork_options' ); if( isset( $options['from'] ) ) { echo ""; } else { echo ""; } 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.
$message