/** * Generates and returns the ThinkUp options array. Caches the result after the first call to the function to speed * up future calls. * * If the $force_update (first argument) is set to 'force-update', the function will update the cached options * array and return it. * * @return Array options array */ public static function getOptionsArray($force_update = null) { if (!is_array(self::$options) || $force_update == 'force-update') { self::$options = array('thinkup_twitter_username' => array('key' => 'thinkup_twitter_username', 'label' => __('Default Twitter username:'******'thinkup-wp-plugin'), 'description' => __('(Required) Override this by using the "username" parameter in the shortcodes.', 'thinkup-wp-plugin'), 'type' => 'text', 'value' => get_option('thinkup_twitter_username')), 'thinkup_table_prefix' => array('key' => 'thinkup_table_prefix', 'label' => __('ThinkUp table prefix:', 'thinkup-wp-plugin'), 'description' => __('(Optional) The prefix on your ThinkUp database tables, e.g. <i>tu_</i>', 'thinkup-wp-plugin'), 'type' => 'text', 'value' => get_option('thinkup_table_prefix')), 'thinkup_server' => array('key' => 'thinkup_server', 'label' => __('ThinkUp database server:', 'thinkup-wp-plugin'), 'description' => __('Required only if the ThinkUp database tables are located in a different ' . 'databasethan the WordPress tables.', 'thinkup-wp-plugin'), 'type' => 'text', 'value' => get_option('thinkup_server')), 'thinkup_db' => array('key' => 'thinkup_db', 'label' => __('ThinkUp database name:', 'thinkup-wp-plugin'), 'description' => __('Required only if the ThinkUp database tables are located in a different ' . 'database than the WordPress tables.', 'thinkup-wp-plugin'), 'type' => 'text', 'value' => get_option('thinkup_db')), 'thinkup_dbusername' => array('key' => 'thinkup_dbusername', 'label' => __('ThinkUp database username:'******'thinkup-wp-plugin'), 'description' => __('Required only if the ThinkUp database tables are located in a different ' . 'database than the WordPress tables.', 'thinkup-wp-plugin'), 'type' => 'text', 'value' => get_option('thinkup_dbusername')), 'thinkup_dbpw' => array('key' => 'thinkup_dbpw', 'label' => __('ThinkUp database password:'******'thinkup-wp-plugin'), 'description' => __('Required only if the ThinkUp database tables are located in a different ' . 'database than the WordPress tables.', 'thinkup-wp-plugin'), 'type' => 'password', 'value' => ThinkUpWordPressPlugin::unscramblePassword(get_option('thinkup_dbpw')))); } return self::$options; }
/** * The default landing page for the plugin's admin pages. * * PHP + HTML = Messy :( */ public static function settings() { //fetch the options array $options_array = ThinkUpWordPressPlugin::getOptionsArray(); //check to see if the form was submitted if (isset($_POST['Submit'])) { //make sure the user submitting the form is an admin check_admin_referer('thinkup_settings_submit', ThinkUpWordPressPlugin::nonceName()); foreach ($options_array as $opt) { // read posted values $opt['value'] = $_POST[$opt['key']]; // save the posted value in the database if ($opt['key'] == 'thinkup_dbpw') { // scramble the password update_option($opt['key'], ThinkUpWordPressPlugin::scramblePassword($opt['value'])); } else { // store non-passwords normally update_option($opt['key'], $opt['value']); } } // print "updated!" message to screen ?> <div class="updated"> <p><strong> <?php _e('Options saved.', ThinkUpWordPressPlugin::uniqueIdentifier()); ?> </strong></p> </div> <?php //force an update to the options array for display purposes $options_array = ThinkUpWordPressPlugin::getOptionsArray('force-update'); } ?> <div id="poststuff" class="ui-sortable meta-box-sortable"> <div class="postbox" id="thinkup_settings"> <h3><?php _e('ThinkUp Plugin Settings', ThinkUpWordPressPlugin::uniqueIdentifier()); ?></h3> <div class="inside" style="line-height: 2;"> <form name="thinkup_settings_form" method="post" action=""><?php //Add the nonce field for added security. wp_nonce_field('thinkup_settings_submit', ThinkUpWordPressPlugin::nonceName()); ?> <table> <?php foreach ($options_array as $opt) { if ($opt['key'] == 'thinkup_dbpw') { $field_value = ThinkUpWordPressPlugin::unscramblePassword( get_option($opt['key'])); } else { $field_value = get_option($opt['key']); } ?> <tr> <td align="right" valign="top"><?php _e($opt['label'], ThinkUpWordPressPlugin::uniqueIdentifier()); ?></td> <td><input type="<?php echo $opt['type']; ?>" name="<?php echo $opt['key'] ?>" value="<?php echo $field_value ?>" size="20"> <br /> <small> <?php echo $opt['description']; ?> </small></td> </tr> <?php } ?> </table> <p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options', ThinkUpWordPressPlugin::uniqueIdentifier()); ?>" /> </p> </form> </div> </div> </div> <?php }