Alexander James Ehwalt Ryan
Testing Features Wordpress Plugin:
A wordpress plugin I've been working on mainly to get more experience with php. Since php on this server tries to run automatically, I've posted it within a <pre> tag.
<?php /** * @package Newer Plugin * @version 0.1 */ /* Plugin Name: Testbed Plugin Plugin URI: N/A Description: This is not just a plugin, it is a testing plugin. Read newplugin.php to figure out what it does. Author: Alexander The 1st Version: 0.1 Author URI: http://alexanderthe1st.com/ */ /* Intended to allow us to apply some type of style change to some text. */ function variable_instancing_newPlugin(){ add_option('newPlugin_Modify_Activation', False, 'To activate Modify Text Style'); add_option('newPlugin_CoreActivation', False, 'To activate new Plugin Core'); add_option('newPlugin_MainActivation', True, 'To activate new Plugin Core'); } function variable_deinstancing_newPlugin(){ delete_option('newPlugin_Modify_Activation'); delete_option('newPlugin_CoreActivation'); delete_option('newPlugin_MainActivation'); } function modifyTextStyle($sometext){ if(get_option('newPlugin_Modify_Activation')){ $newString = '<span style = \'font-style: italic; font-family: "Arial";\'>$sometext</span>'; return $newString; }else{ return $sometext; } } function newPluginCSS(){ echo ' <style type=\'text/css\'> #newPluginMain { float: right; margin-right: 50%; margin-bottom: 10px; //margin: 2px; font-size: 12px; background-color: #010101; font-color: #FFFFFF; } </style> '; } function newPluginCore(){ if(get_option('newPlugin_CoreActivation')){ return wptexturize('Lorem ipsum dolor sit amet, consectetur adipiscing elit.'); } return \'\'; } function newPluginMain(){ if(get_option(\'newPlugin_MainActivation\')){ $value = newPluginCore(); echo '<div id = \'newPluginMain\'>$value</div>'; }else{ } } /* Mostly splitting the options page generation code from the functionality atm so that we can split this off in the future. */ function newPlugin_options_page_generator(){ ?><div class='wrap'><h2>Customization for New Plugin:</h2> <?php //Now we determine if we're updating or not. if($_REQUEST\['submit'\]){ newPlugin_form_update(); } newPlugin_form_data(); ?></div><?php } function newPlugin_form_update(){ try{ $moA = $_REQUEST\['np_MoA'\]; $cA = $_REQUEST\['np_cA'\]; $maA = $_REQUEST\['np_mAA'\]; update_option('newPlugin_Modify_Activation', $moA); update_option('newPlugin_CoreActivation', $cA); update_option('newPlugin_MainActivation', $maA); ?><div id = 'message' class = 'updated fade'> <p>Options updated</p> </div><?php }catch(Exception $e){ ?><div id='message' class='error fade'> <p>There was an error when saving values - please try again. </p> </div> <?php } return; } function newPlugin_form_data(){ ?> <form method='post'> <label for='np_MoA'>Activate the modification for the content? <input type='checkbox' name='np_MoA' <?php if(get_option('newPlugin_Modify_Activation')){ echo 'checked';} ?> /> </label> <br /> <label for='np_cA'>Activate Lorem Ipsum text? <input type='checkbox' name='np_cA' <?php if(get_option('newPlugin_CoreActivation')){ echo 'checked';} ?> /> </label> <br /> <label for='np_mAA'>Activate main Plugin routine (Needed for Lorem Ipsum text to display)? <input type='checkbox' name='np_mAA' <?php if(get_option('newPlugin_MainActivation')){ echo 'checked';} ?> /> </label> <br /> <input type = 'submit' name='submit' value'Submit' /> </form> <?php } function newPlugin_Menu_opener(){ add_options_page('New Plugin options', 'New Plugin customizations', 'manage_options', __FILE__, 'newPlugin_options_page_generator'); } add_action( 'admin_footer', 'newPluginMain' ); add_action( 'admin_footer', 'newPluginCSS' ); add_action( 'wp_footer', 'newPluginMain' ); add_action( 'wp_footer', 'newPluginCSS' ); add_filter( 'the_content', 'modifyTextStyle', 10); register_activation_hook(__FILE__, variable_instancing_newPlugin); register_deactivation_hook(__FILE__, variable_deinstancing_newPlugin); add_action('admin_menu', 'newPlugin_Menu_opener'); ?>