Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My theme currently has the following line in the function.php file: if ( $_GET['activated'] == 'true' || $_GET['preview'] == 1 ) If this statement is true the code runs a function.

I am getting a php error that says Notice: Undefined index: activated in and Notice: Undefined index: preview in.

I am sure in wordrpess there is another way to do this "if statement" to prevent the Undefined index: error I am getting.

Any suggestions?

Thank you!

Here is the full code:


   //ADD OPTION PAGE

add_action('admin_menu', 'ddthemes_admin');

 //UPON ACTIVATION OR PREVIEWED

 if ( $_GET['activated'] == 'true'  || $_GET['preview'] == 1 )

{ ddthemes_setup(); } function ddthemes_admin() { /* PROCESS OPTION SAVING HERE */ if ( 'save' == $_REQUEST['action'] ) { if ( $_REQUEST['savetype'] == 'header' ) { update_option( 'ddthemes_header', $_REQUEST['ddthemes_header']); } } /* SHOW THEME CUSTOMIZE PAGE HERE */

add_theme_page(__('Logo Options'), __('Logo Options'), 'edit_themes', basename(__FILE__), 'ddthemes_headeropt_page');}

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Try

if ( isset($_GET['activated']) && $_GET['activated'] == 'true' || isset($_GET['preview']) && $_GET['preview'] == 1 )

instead of

if ( $_GET['activated'] == 'true' || $_GET['preview'] == 1 )

Edit:

You should wrap the if-sentence in the functions.php file into a function and a relevant hook. Here is an example using the after_theme_setup hook:

add_action('after_theme_setup','my_theme_setup');
function my_theme_setup(){
    if ( isset($_GET['activated']) && $_GET['activated'] == 'true' || isset($_GET['preview']) && $_GET['preview'] == 1 ){
        ddthemes_setup();
    }
}
share|improve this answer
    
Thank your for the reply. I used your code and got this error Warning: Cannot modify header information - headers already sent by (output started at /home3/an/public_html/wp-content/themes/tipztheme/functions.php:1) in /home3/answerun/public_html/wp-includes/pluggable.php on line 876 I updated the full code above, perhaps that is causing the error with isset. Any ideas? –  user1609391 Feb 15 '13 at 23:09
    
the if-code you are using is not within a function and most likely ddthemes_setup() is printing out some stuff. you should consider to hook it into init or some relevant hook. –  birgire Feb 15 '13 at 23:23
    
it looks like the hook after_setup_theme could be relevant - I updated the code example above. –  birgire Feb 15 '13 at 23:35
    
thank you so much. That worked to solve the issue. One minor error in your code { at opening of the if statement. Thank you again! –  user1609391 Feb 16 '13 at 0:45
    
ok great, I updated the code with the missing { - thanks –  birgire Feb 16 '13 at 0:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.