admin管理员组文章数量:1323684
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');
}
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
edited Sep 4, 2020 at 6:19
omukiguy
2221 silver badge6 bronze badges
asked Feb 15, 2013 at 22:44
user1609391user1609391
4776 silver badges10 bronze badges
0
1 Answer
Reset to default 1Try
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();
}
}
本文标签: pluginsTheme Functions run a function upon activation or preview
版权声明:本文标题:plugins - Theme Functions run a function upon activation or preview 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742137987a2422454.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论