我在wordpress主题的function.php文件中进行了更改。当我尝试更新funtion.php文件时,它会出错:
致命错误:在第45行的/hermes/waloraweb088/b1248/moo.armaan815/Voga/fp/wp-content/themes/enterweb/functions.php中调用未定义的函数add_action()。
我不确定如何修复它。我真的很感激反馈/帮助。感谢。
这是function.php文件代码。行号“45”表示侧栏功能后的第一个呼叫。
<?php
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Sidebar Widget Area',
'id' => 'sidebar-widget-area',
'before_widget' => '<div id="%1$s" class="box widget %2$s">',
'before_title' => '<div class="wtitle"><h2>',
'after_title' => '</h2></div><!--/wtitle --><div class="content">',
'after_widget' => '</div><!--/content --></div><!--/box -->',
));
register_sidebar(array(
'name' => 'Single Sidebar Widget',
'id' => 'single-widget-area',
'before_widget' => '<div id="%1$s" class="cols %2$s">',
'before_title' => '<h2>',
'after_title' => '</h2>',
'after_widget' => '</div><!--/box -->',
));
register_sidebar(array(
'name' => 'Post Sidebar Widget',
'id' => 'post-widget-area',
'before_widget' => '<div class="boxx"><div id="%1$s" class="box
widget_posts %2$s">',
'before_title' => '<div class="wtitle"><h2>',
'after_title' => '</h2></div><!--/wtitle --><div class="content">',
'after_widget' => '</div><!--/content --></div></div><!--/box -->',
));
register_sidebar(array(
'name' => 'Widget Ad Manager Small',
'id' => 'widget-ad-minister-small',
'before_widget' => '<div id="%1$s" class="box ads %2$s">',
'before_title' => '<div class="wtitle"><h2>',
'after_title' => '</h2></div><!--/wtitle --><div class="content">',
'after_widget' => '</div><!--/content --></div><!--/box -->',
));
register_sidebar(array(
'name' => 'Widget Ad Manager Big',
'id' => 'widget-ad-minister-big',
'before_widget' => '<div id="%1$s" class="box ads %2$s">',
'before_title' => '<div class="wtitle"><h2>',
'after_title' => '</h2></div><!--/wtitle --><div class="content">',
'after_widget' => '</div><!--/content --></div><!--/box -->',
));
}
add_action('admin_menu', 'taccess_theme_page');
function taccess_theme_page ()
{
if ( count($_POST) > 0 && isset($_POST['taccess_settings']) )
{
$options = array ( 'feedburner_id', 'advertise_page', 'flickr_group_id' );
foreach ( $options as $opt )
{
delete_option ( 'taccess_'.$opt, $_POST[$opt] );
add_option ( 'taccess_'.$opt, $_POST[$opt] );
}
wp_redirect("themes.php?page=functions.php&saved=true");
die;
}
add_theme_page(__('wpTheme Settings'), __('wpTheme Settings'), 'edit_themes', basename(__FILE__), 'taccess_settings');
}
function taccess_settings ()
{
if ( isset( $_REQUEST['saved'] ) ) echo '<div id="message" class="updated fade"><p>
<strong>'.__('Options saved.').'</strong></p></div>';
echo <<<TT
<div class="wrap">
<h2>wp Theme Settings</h2>
<form method="post" action="">
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="feedburner_id">FeedBurner ID</label>
</th>
<td><input name="feedburner_id" type="text" id="feedburner_id"
value="<?php echo htmlspecialchars(stripslashes(get_option('taccess_feedburner_id')));
?>" class="regular-text" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="advertise_page">Advertise Page</label>
</th>
<td>
<?php
wp_dropdown_pages("name=advertise_page&show_option_none=".__('- Select -')."&selected="
.get_option('taccess_advertise_page')); ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="flickr_group_id">Flickr Group
ID</label></th>
<td>
<input name="flickr_group_id" type="text"
id="flickr_group_id" value="<?php echo
htmlspecialchars(stripslashes(get_option('taccess_flickr_group_id'))); ?>"
class="regular-text" />
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="Save
Changes" />
<input type="hidden" name="taccess_settings" value="save"
style="display:none;" />
</p>
</form>
</div>
TT;
}
?>
<?php
/**
* add a default-gravatar to options
*/
if ( !function_exists('fb_addgravatar') ) {
function fb_addgravatar( $avatar_defaults ) {
$myavatar = get_bloginfo('template_directory') . '/images/avatar.gif';
$avatar_defaults[$myavatar] = 'people';
$myavatar2 = get_bloginfo('template_directory') . '/images/myavatar.png';
$avatar_defaults[$myavatar2] = 'wpengineer.com';
return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'fb_addgravatar' );
}
?>
答案 0 :(得分:0)
我已将这个functions.php代码复制到测试环境中,并且无法产生相同的错误(唯一的问题是在开始时缺少打开的php标记。
作为一个稍微单独的注释,我会使用'widgets_init'钩子将侧边栏注册添加到他们自己的函数中。像
这样的东西add_action('widgets_init','register_my_sidebars');
您不需要测试register_sidebar是否存在。关于该主题的This is a good article。