Go Back    Forum > Digital Publishing / Web Sites > Website and Server Troubleshooting

Reply
 
LinkBack Thread Tools
  #1  
09-23-2012, 04:22 PM
kpmedia's Avatar
kpmedia kpmedia is offline
Site Staff | Web Hosting, Photo
 
Join Date: Feb 2004
Posts: 4,318
Thanked 371 Times in 340 Posts
One of my favorite WordPress themes is an older theme from Revolution Themes (now better known as StudioPress), and came across the following issue while debugging some WP 3.4.2 issues. Since this is a theme from the WordPress 2.x era, it was using a lot of now-deprecated code that needed some tweaking. All of the theme's errors were in the functions.php file, where some theme options had been added to the WordPress admin (wp-admin).

While all WordPress theme upgrades will vary, this is a good example of a common problem.

This is how I fixed the theme:

Debudding is enabled in the wp-config.php file:
Code:
define('WP_DEBUG', true);
These were the errors:
Code:
Notice: Undefined index: action in X:\...\functions.php on line 80
Notice: Undefined index: action in X:\...\functions.php on line 83
Notice: Undefined index: action in X:\...\functions.php on line 109
Notice: Undefined index: saved in X:\...\functions.php on line 135
Notice: Undefined index: reset in X:\...\functions.php on line 136
Notice: Undefined index: options in X:\...\functions.php on line 170
Notice: Undefined index: options in X:\...\functions.php on line 170
Rather than remove old code, I prefer to comment it out -- in case further debugging or troubleshooting is needed later. Wiping out old code is an easy way to make an unrecoverable mess, so always comment it out. It can be removed at a later date, if needed, once the changes have been verified over a longer period of time.

The old code has // marks, which are PHP comment-out lines.
The new code is added underneath it. (Note that this bumps the line numbers in the process. So be aware of this.)

At line 80:
PHP Code:
// if ( $_GET['page'] == basename(__FILE__) ) { //
   
if ( isset($_GET['page']) && $_GET['page'] == basename(__FILE__) ) { 
At line 83:
PHP Code:
// if ( 'save' == $_REQUEST['action'] ) {
   
if ( 'save' == ( isset($_REQUEST['action'] ) && $_REQUEST['action'] ) ) { 
At line 109:
PHP Code:
// } else if( 'reset' == $_REQUEST['action'] ) {
   
} else if ( 'reset' == ( isset($_REQUEST['action'] ) && $_REQUEST['action'] ) ) { 
At line 135-136:
PHP Code:
// if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
// if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
   
if ( isset( $_REQUEST['saved'] ) && $_REQUEST['saved']) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
   if ( isset( 
$_REQUEST['reset'] ) && $_REQUEST['reset']) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>'
At line 170:
PHP Code:
// $ta_options = $value['options'];
   
$ta_options = isset($value['options']); 
Full code block: (Note: Empty lines were removed.)
PHP Code:
function mytheme_add_admin() {
    global $themename, $shortname, $options;
    if ( $_GET['page'] == basename(__FILE__) ) {    
        if ( 'save' == $_REQUEST['action'] ) {
                foreach ($options as $value) {
                    if($value['type'] != 'multicheck'){
                        update_option( $value['id'], $_REQUEST[ $value['id'] ] );
                    }else{
                        foreach($value['options'] as $mc_key => $mc_value){
                            $up_opt = $value['id'].'_'.$mc_key;
                            update_option($up_opt, $_REQUEST[$up_opt] );
                        }
                    }
                }
                foreach ($options as $value) {
                    if($value['type'] != 'multicheck'){
                        if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); }
                    }else{
                        foreach($value['options'] as $mc_key => $mc_value){
                            $up_opt = $value['id'].'_'.$mc_key;                        
                            if( isset( $_REQUEST[ $up_opt ] ) ) { update_option( $up_opt, $_REQUEST[ $up_opt ]  ); } else { delete_option( $up_opt ); }
                        }
                    }
                }
                header("Location: themes.php?page=functions.php&saved=true");
                die;
        } else if( 'reset' == $_REQUEST['action'] ) {
            foreach ($options as $value) {
                if($value['type'] != 'multicheck'){
                    delete_option( $value['id'] );
                }else{
                    foreach($value['options'] as $mc_key => $mc_value){
                        $del_opt = $value['id'].'_'.$mc_key;
                        delete_option($del_opt);
                    }
                }
            }
            header("Location: themes.php?page=functions.php&reset=true");
            die;
        }
    }
    add_theme_page($themename." Options", "$themename Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
}
function mytheme_admin() {
    global $themename, $shortname, $options;
    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';    
?>
<div class="wrap">
<h2><?php echo $themename?> options</h2>
<form method="post">
<table class="optiontable">
<?php foreach ($options as $value) {
    switch ( 
$value['type'] ) {
        case 
'text':
        
option_wrapper_header($value);
        
?>
                <input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings$value['id'] ) != "") { echo get_settings$value['id'] ); } else { echo $value['std']; } ?>" />
        <?php
        option_wrapper_footer
($value);
        break;
        case 
'select':
        
option_wrapper_header($value);
        
?>
                <select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
                    <?php foreach ($value['options'] as $option) { ?>
                    <option<?php if ( get_settings$value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option?></option>
                    <?php ?>
                </select>
        <?php
        option_wrapper_footer
($value);
        break;
        case 
'textarea':
        
$ta_options $value['options'];
        
option_wrapper_header($value);
        
?>
                <textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" style="width:400px;height:100px;"><?php
                
if( get_settings($value['id']) != "") {
                        echo 
stripslashes(get_settings($value['id']));
                    }else{
                        echo 
$value['std'];
                }
?></textarea>
        <?php
        option_wrapper_footer
($value);
        break;
        case 
"radio":
        
option_wrapper_header($value);
         foreach (
$value['options'] as $key=>$option) {
                
$radio_setting get_settings($value['id']);
                if(
$radio_setting != ''){
                    if (
$key == get_settings($value['id']) ) {
                        
$checked "checked=\"checked\"";
                        } else {
                            
$checked "";
                        }
                }else{
                    if(
$key == $value['std']){
                        
$checked "checked=\"checked\"";
                    }else{
                        
$checked "";
                    }
                }
?>
                <input type="radio" name="<?php echo $value['id']; ?>" value="<?php echo $key?><?php echo $checked?> /><?php echo $option?><br />
        <?php
        
}
        
option_wrapper_footer($value);
        break;
        case 
"checkbox":
        
option_wrapper_header($value);
                        if(
get_settings($value['id'])){
                            
$checked "checked=\"checked\"";
                        }else{
                            
$checked "";
                        }
                    
?>
                    <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked?> />
        <?php
        option_wrapper_footer
($value);
        break;
        case 
"multicheck":
        
option_wrapper_header($value);
         foreach (
$value['options'] as $key=>$option) {
                 
$pn_key $value['id'] . '_' $key;
                
$checkbox_setting get_settings($pn_key);
                if(
$checkbox_setting != ''){
                    if (
get_settings($pn_key) ) {
                        
$checked "checked=\"checked\"";
                        } else {
                            
$checked "";
                        }
                }else{
                    if(
$key == $value['std']){
                        
$checked "checked=\"checked\"";
                    }else{
                        
$checked "";
                    }
                }
?>
                <input type="checkbox" name="<?php echo $pn_key?>" id="<?php echo $pn_key?>" value="true" <?php echo $checked?> /><label for="<?php echo $pn_key?>"><?php echo $option?></label><br />
        <?php
        
}        
        
option_wrapper_footer($value);
        break;
        case 
"heading":
        
?>
        <tr valign="top">
            <td colspan="2" style="text-align: center;"><h3><?php echo $value['name']; ?></h3></td>
        </tr>
        <?php
        
break;
        default:
        break;
    }
}
?>
Fixes are important!

While many people would simply opt to turn off the debug errors messages -- which should be done on a live/production site -- the issues still exist, and should NOT just be ignored. These coding deprecations would cause the admin panel options page to malfunction. It also slows down the entire site (including wp-admin), because it's asking for code that doesn't exist, and is wasting resource time, as well as admin and end-user time.

Amongst others things, correcting these errors results in a faster site.

- Did my advice help you? Then become a Premium Member and support this site.
- Please Like Us on Facebook | Follow Us on Twitter

- Need a good web host? Ask me for help! Get the shared, VPS, semi-dedicated, cloud, or reseller you need.
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Ads / Sponsors
 
Join Date: ∞
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
WordPress plugins for better admin and SEO admin Website and Server Troubleshooting 0 04-29-2010 04:58 AM
GetResponse code in WordPress? plugin? admin Website and Server Troubleshooting 0 04-07-2010 10:05 PM
FLV/H.264 in WordPress, hide play bar admin Website and Server Troubleshooting 0 04-07-2010 08:43 PM
More pages per page in WordPress admin kpmedia Website and Server Troubleshooting 0 01-03-2010 10:39 PM

Thread Tools



 
All times are GMT -5. The time now is 03:08 PM