hook ) !== false ) { wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'thickbox' ); wp_enqueue_script( 'media-upload' ); } } /** * Register admin css styles (only for plugin admin page) * **/ function config_page_styles() { //make sure we're on the appropriate page if ( isset( $_GET['page'] ) && strpos( $_GET['page'], $this->hook ) !== false ) { wp_enqueue_style( 'dashboard' ); wp_enqueue_style( 'thickbox' ); wp_enqueue_style( 'global' ); wp_enqueue_style( 'wp-admin' ); wp_enqueue_style( 'bit51-css', plugin_dir_url( __FILE__ ). 'bit51.css' ); } } /** * Register all settings groups * * Registers all settings groups defined in main plugin file * **/ function register_settings() { foreach ( $this->settings as $group => $settings ) { //look at each main group foreach ( $settings as $setting => $option ) { //look at each option set if ( isset( $option['callback'] ) ) { //if callback is defined register with callback register_setting( $group, $setting, array( $this, $option['callback'] ) ); } else { //register without callback register_setting( $group, $setting ); } } } } /** * Add action link to plugin page * * Adds plugin settings link to plugin page in WordPress admin area. * * @param object $links Array of WordPress links * @param string $file String name of current file * @return object Array of WordPress links * **/ function add_action_link( $links, $file ) { static $this_plugin; if ( empty( $this_plugin ) ) { $this_plugin = $this->pluginbase; } if ( $file == $this_plugin ) { $settings_link = '' . __( 'Settings', $this->hook ) . ''; array_unshift( $links, $settings_link ); } return $links; } /** * Return URL of options page * * @return object WordPress admin URL * **/ function plugin_options_url() { return admin_url('options-general.php?page=' . $this->hook); } /** * Setup and call admin messages * * Sets up messages and registers actions for WordPress admin messages * * @param object $errors WordPress error object or string of message to display * **/ function showmessages( $errors ) { global $savemessages; //use global to transfer to add_action callback $savemessages = ''; //initialize so we can get multiple error messages (if needed) if ( function_exists( 'apc_store' ) ) { apc_clear_cache(); //Let's clear APC (if it exists) when big stuff is saved. } if ( is_wp_error( $errors ) ) { //see if object is even an error $errors = $errors->get_error_messages(); //get all errors if it is foreach ( $errors as $error => $string ) { $savemessages .= '

' . $string . '

'; } } else { //no errors so display settings saved message $savemessages .= '

' . $errors . '

'; } //register appropriate message actions add_action('admin_notices', array(&$this, 'dispmessage')); add_action('network_admin_notices', array(&$this, 'dispmessage')); } /** * Set all default settings * * Takes default settings defined in main plugin file and saves them as a WordPress option * **/ function default_settings() { foreach ( $this->settings as $settings ) { foreach ( $settings as $setting => $defaults ) { $options = get_option( $setting ); //Get the option if it already exists //set missing options foreach ( $defaults as $option => $value ) { if ( $option != 'callback' && !isset( $options[$option] ) ) { $options[$option] = $value; } } //remove obsolete options foreach ( $options as $option => $value ) { if ( ! isset( $defaults[$option] ) && $option != 'version' ) { unset( $options[$option] ); } } update_option( $setting, $options ); //save new options } } return $options; } /** * Echos admin messages * * Takes care of echoing admin message when appropriate action is called * **/ function dispmessage() { global $savemessages; echo $savemessages; unset($savemessages); //delete any saved messages } /** * Setup postbox * * Echos postbox for settings screen * * @param string $id css ID for postbox * @param string $title title to display to user * @param string $content postbox content **/ function postbox( $id, $title, $content ) { ?>

$content(); } else { echo $content; } ?>


hook ) ?>

postbox( 'adminform', $content[0], $content[1] ); } ?>
donate(); $this->support(); $this->news(); $this->social(); ?>
supportpage . '" target="_blank">support forums.', $this->hook); $this->postbox( 'bit51support', __( 'Need Help?', $this->hook ), $content ); //execute as postbox } /** * Display Bit51's latest posts * * Displays latest posts from Bit51 in admin page sidebar * **/ function news() { include_once( ABSPATH . WPINC . '/feed.php' ); //load WordPress feed info $feed = fetch_feed( $this->feed ); //get the feed $feeditems = $feed->get_items( 0, $feed->get_item_quantity( 5 ) ); //narrow feed to last 5 items $content = ''; //end list $this->postbox( 'bit51posts' , __( 'The Latest from Bit51', $this->hook ), $content ); //set up postbox } /** * Display donate box * * Displays bit51 donate box in sidebar of admin pages * **/ function donate() { $content = __( 'Have you found this plugin useful? Please help support it\'s continued development with a donation of $20, $50, or $100!', $this->hook ); $content .= '
'; $content .= '

' . __( 'Short on funds?', $this->hook ) . '

'; $content .= ''; $this->postbox( 'donate', __( 'Support This Plugin' , $this->hook ), $content ); //setup the postbox } /** * Display social links * * Displays Bit51's social links on admin sidebar * **/ function social() { $content = ''; $this->postbox( 'bit51social', __( 'Bit51 on the Web', $this->hook ), $content ); //setup the postbox } /** * Display (and hide) donation reminder * * Adds reminder to donate or otherwise support on dashboard * **/ function ask() { global $blog_id; //get the current blog id if ( is_multisite() && ( $blog_id != 1 || ! current_user_can( 'manage_network_options' ) ) ) { //only display to network admin if in multisite return; } $options = get_option( $this->plugindata ); //this is called at a strange point in WP so we need to bring in some data global $plugname; global $plughook; global $plugopts; $plugname = $this->pluginname; $plughook = $this->hook; $plugopts = $this->plugin_options_url(); //display the notifcation if they haven't turned it off and they've been using the plugin at least 30 days if ( ! isset( $options['no-nag'] ) && $options['activatestamp'] < ( time() - 2952000 ) ) { if ( ! function_exists( 'bit51_plugin_donate_notice' ) ) { function bit51_plugin_donate_notice(){ global $plugname; global $plughook; global $plugopts; echo '

' . __( 'It looks like you\'ve been enjoying', $plughook ) . ' ' . $plugname . ' ' . __( 'for at least 30 days. Would you consider a small donation to help support continued development of the plugin?', $plughook ) . '

'; } } add_action( 'admin_notices', 'bit51_plugin_donate_notice' ); //register notification } //if they've clicked a button hide the notice if ( ( isset( $_GET['bit51_donate_nag'] ) || isset( $_GET['bit51_lets_rate'] ) || isset( $_GET['bit51_lets_tweet'] ) || isset( $_GET['bit51_lets_donate'] ) ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'bit51-nag' ) ) { $options = get_option( $this->plugindata ); $options['no-nag'] = 1; update_option( $this->plugindata,$options ); remove_action( 'admin_notices', 'bit51_plugin_donate_notice' ); //take the user to paypal if they've clicked donate if ( isset( $_GET['bit51_lets_donate'] ) ) { wp_redirect( 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=' . $this->paypalcode, '302' ); } //Go to the WordPress page to let them rate it. if ( isset( $_GET['bit51_lets_rate'] ) ) { wp_redirect( $this->wppage, '302' ); } //Compose a Tweet if ( isset( $_GET['bit51_lets_tweet'] ) ) { wp_redirect( 'http://twitter.com/home?status=' . urlencode( 'I use ' . $this->pluginname . ' for WordPress by @bit51 and you should too - ' . $this->homepage ) , '302' ); } } } } }