Muffin Cheatsheet

<?php
/*
Plugin Name: Box WDC 10
Plugin URI: http://webdesign.com
Description: Add a simple author box to your blog
Version: 0.1
Author: Bob Bobertson
Author URI: http://bobbobertson.com.com
License: GPL3
*/
/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

register_activation_hook( __FILE__, 'wdc10_author_install' );

function wdc10_author_install() {
   add_option( 'wdc10_author_box_name', '', '', 'yes' );
   add_option( 'wdc10_author_box_bio', '', '', 'yes' );
   add_option( 'wdc10_author_box_image', '', '', 'yes' );
   add_option( 'wdc10_muffins', '', '', 'yes' );
   add_option( 'wdc10_activation_redirect', true );
}

function wdc10_plugin_redirect() {
    if (get_option('wdc10_activation_redirect', false)) {
        delete_option('wdc10_activation_redirect');
$adminUrl = admin_url();
        wp_redirect($adminUrl.'/options-general.php?page=author-box-settings');
    }
}
add_action( 'admin_init', 'wdc10_plugin_redirect' );

register_uninstall_hook( __FILE__, 'wdc10_author_deactivate' );

function wdc10_author_deactivate() {
   delete_option( 'wdc10_author_box_name', '', '', 'yes' );
   delete_option( 'wdc10_author_box_bio', '', '', 'yes' );
   delete_option( 'wdc10_author_box_image', '', '', 'yes' );
   delete_option( 'wdc10_muffins', '', '', 'yes' );
}

add_action( 'admin_menu', 'wdc10_authorbox_menu' );
function wdc10_authorbox_menu() {
add_options_page( 'AuthorBox Options', 'Author Box', 'manage_options', 'author-box-settings', 'wdc10_authorbox_options' );
}

function wdc10_authorbox_options() {
if ( !current_user_can( 'manage_options' ) )  {
wp_die( __( 'You are not allowed to access this page.' ) );
}

$opt_name = 'wdc10_author_box_name';
$opt_bio = 'wdc10_author_box_bio';
$opt_image = 'wdc10_author_box_image';
$opt_muffins = 'wdc10_muffins';

    $hidden_field_name = 'wdc10_mt_submit_hidden';
   
    $data_field_name = 'wdc10_author_box_name';
$data_field_bio = 'wdc10_author_box_bio';
$data_field_image = 'wdc10_author_box_image';
$data_field_muffin = 'wdc10_muffins';

$opt_val_name = get_option( 'wdc10_author_box_name' );
$opt_val_bio = get_option( 'wdc10_author_box_bio' );
$opt_val_image = get_option( 'wdc10_author_box_image' );
$opt_val_muffins = get_option( 'wdc10_muffins' );

if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) {
        $opt_val_name = $_POST[ $data_field_name ];
$opt_val_bio = $_POST[ $data_field_bio ];

$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES[$data_field_image]["name"]));
if ((($_FILES[$data_field_image]["type"] == "image/gif")
|| ($_FILES[$data_field_image]["type"] == "image/jpeg")
|| ($_FILES[$data_field_image]["type"] == "image/png")
|| ($_FILES[$data_field_image]["type"] == "image/jpg"))
&& ($_FILES[$data_field_image]["size"] < 2000000)
&& in_array($extension, $allowedExts))
 {
 if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES[$data_field_image]["error"] . "<br />";
}
 else
{
$upload_dir = wp_upload_dir();
  move_uploaded_file($_FILES[$data_field_image]["tmp_name"], $upload_dir['basedir'] . "/" . $_FILES[$data_field_image]["name"]);
}
 }
else
 {
   echo "Invalid file";
 }

        update_option( $opt_name, $opt_val_name );
update_option( $opt_bio, $opt_val_bio );
update_option( $opt_muffins, $opt_val_muffins );
update_option( $opt_image, $upload_dir['baseurl'] . "/" . $_FILES[$data_field_image]["name"] );
    }

echo '<div class="wrap">';
    echo "<h2>" . __( 'Author Box Plugin Settings', 'wdc10_author-menu' ) . "</h2>";  
?>
<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">

<p><?php _e("Author's Name:", 'wdc10_author-menu' ); ?>
<input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val_name; ?>" size="20">
</p>
<p><?php _e("Author's Bio:", 'wdc10_author-menu' ); ?> <br />
<textarea name="<?php echo $data_field_bio; ?>" cols="80" rows="8"><?php echo $opt_val_bio; ?></textarea>
</p>
<p><?php _e("Author Muffin:", 'wdc10_muffins' ); ?> <br />
<input type="text" name="<?php echo $data_field_muffin; ?>" value="<?php echo $opt_val_muffins; ?>" size="20">
</p>
<p><?php _e("Author's Picture:", 'wdc10_author-menu' ); ?> <br />
<?php if ($opt_val_image != '') { ?>
<img src="<?php echo get_option($opt_image); ?>" />
    <p>Update image
<?php } ?>
<input name="<?php echo $data_field_image; ?>" type="file" />
</p></p>
<hr />

<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
</p>

</form>
</div>

<?php

}

wp_register_sidebar_widget(
    'author_box_widget',      
    'Author Box',        
    'wdc10_widget_display',
    array(                
        'description' => 'Display information about the blog author in your sidebar'
    )
);
function wdc10_widget_display($args){
   extract($args);
   echo $before_widget;
   echo $before_title . 'About the Author' . $after_title;
   echo '<img src="'.get_option('wdc10_author_box_image').'" style="max-width:" /><br />';
   echo '<strong>'.get_option('wdc10_author_box_name').'</strong>';
   echo '<p>'.get_option('wdc10_author_box_bio').'</p>';
   echo '<p>'.get_option('wdc10_muffins').'</p>';
   echo $after_widget;
}

add_shortcode( 'authorbox', 'wdc10_author_shortcode' );

function wdc10_author_shortcode($atts){
return '<strong>About the Author</strong><br /><img src="'.get_option('wdc10_author_box_image').'" style="max-width:150px" /><br /><strong>'.get_option('wdc10_author_box_name').'</strong><p>'.get_option('wdc10_author_box_bio').'</p><p>'.get_option('wdc10_muffins').'</p>';
}



Learn More :