replacement text key/value pairs // Contructor function AnyVar() { // Load current vars $this->vars = get_option('anyvar_vars'); if(is_admin()) { add_action('admin_menu',array(&$this,'anyvar_menu')); add_action('activate_'.basename (dirname (__FILE__)).'/'.basename (__FILE__), array(&$this,'activate')); } else { add_action('template_redirect',array(&$this,'anyvar_ob_start')); } } /* Admin Display Functions */ // Adds the AnyVar menu item function anyvar_menu() { $page = add_management_page('AnyVar Admin', 'AnyVar', $this->min_level, __FILE__, array(&$this,'anyvar_admin')); add_action("admin_print_styles-$page", array(&$this,'anyvar_css')); // Add required css file(s) add_action("admin_print_scripts-$page", array(&$this,'anyvar_head')); // Add required JS file(s) } // Loads the Wordpress forms.js script function anyvar_head() { wp_enqueue_script('admin-forms'); if ( user_can_richedit() ) { wp_enqueue_script('media-upload'); add_action('admin_head', 'wp_tiny_mce'); wp_enqueue_script('editor'); } } function anyvar_css() { wp_enqueue_style('thickbox'); } // Displays the admin pages function anyvar_admin() { $action = ''; if(isset($_REQUEST['action'])) $action = $_REQUEST['action']; if ( isset($_POST['deleteit']) && isset($_POST['delete']) ) $action = 'delete'; $this->display_heading(); // Strip the magic / wordpress added quotes $_POST['var_name'] = stripslashes(strtolower($_POST['var_name'])); $_POST['content'] = stripslashes($_POST['content']); switch ($action) { case 'add': // The add variable form has been submitted $error = $this->validate($_POST['var_name']); if($error == '') { $this->vars[$_POST['var_name']] = $_POST['content']; update_option('anyvar_vars',$this->vars); $this->display_message("[{$_POST['var_name']}] successfully added."); $this->display_list(); $this->display_form(); } else // There's an error. Display the error and the form again { $this->display_message($error); $this->display_form('add',$_POST['var_name'],$_POST['content']); } break; case 'edit': // Load the variable to be edited, display it in a form if(isset($this->vars[$_GET['var']])) { $this->display_form('edit',$_GET['var'],$this->vars[$_GET['var']]); } else { $this->display_message("Cannot edit variable because it doesn't exist."); $this->display_list(); $this->display_form(); } break; case 'edited': // The edit variable form has been submitted $error = $this->validate($_POST['var_name']); if($error == '') { // Update the exiting key instead of unsetting and replacing it. This preserves the array order $temp_array = $this->update_array_key($this->vars,$_POST['old_var_name'],$_POST['var_name']); $temp_array[$_POST['var_name']] = $_POST['content']; $this->vars = $temp_array; update_option('anyvar_vars',$this->vars); unset($temp_array); $this->display_message("[{$_POST['var_name']}] successfully edited."); $this->display_list(); $this->display_form(); } else // There's an error. Display the error and the form again { $this->display_message($error); $this->display_form('edit',$_POST['var_name'],$_POST['content']); } break; case 'delete': // Variable deletion form has been submitted if(is_array($_POST['delete']) && count($_POST['delete'])) // There are variables selected to be delete { $count = 0; foreach($_POST['delete'] as $unlucky_var) { if(isset($this->vars[$unlucky_var])) { $count++; unset($this->vars[$unlucky_var]); } } update_option('anyvar_vars',$this->vars); $this->display_message("$count variables deleted"); $this->display_list(); $this->display_form(); } else // No variables were selected for deletion { $this->display_list(); $this->display_form(); } break; default: // The standard page $this->display_list(); $this->display_form(); break; } } // Displays a message function display_message($message) { echo "
The most effective way to invoke your variables is with tags.
Simply put a [var_name] tag anywhere in your HTML.
Please Note: tags must be lowercase.