0

我收到一个插件的开箱即用错误,我想知道是否有快速修复。

我已经用谷歌搜索了这个问题并检查了插件网站的创建者。没有帮助。

该插件需要:

<?php do_shortcode('[print_wp_footer]'); ?>

为主题添加到 Footer.php。

WordPress然后给出一个错误:

Warning: Invalid argument supplied for foreach() in /.../wp-content/plugins/wp-footer-menu/main.php on line 192

这是自己的行

foreach ($values as $attr=>$val) {

这是带有箭头的“192”行的代码部分。

<?php


}

function wp_footer_menu_confirm_delete ($delete) {

$base_uri = wp_footer_menu_base_uri();

// Find out about this menu item.
$menu_items = get_option ( 'footer_menu_links' );
$item_to_delete = explode( ',', $menu_items[$delete] );
$item_title = $item_to_delete[0];
$item_address = $item_to_delete[1];

// Create form for user to confirm option.
echo '<h3>Confirm Delete</h3>';
echo '<p>Are you sure you want to delete this menu item?</p>';
echo '<p>Title: ' . $item_title . '</p>' ;
echo '<p>Address: ' . $item_address . '</p>';
echo '<form method="post" action="' . $base_uri . '">';
echo '<input type="hidden" name="delete_key" value="' . $delete . '" />';
echo wp_nonce_field( 'confirm_delete', 'delete' );
echo '<input type="submit" class="button-primary" value="Delete item" />';
echo '</form>';

}

function wp_footer_menu_process() {

if ( isset( $_GET[ 'delete' ] ) ) {
    $nonce = $_GET ['nonce'];
    if ( wp_verify_nonce( $nonce, 'footer_delete' ) ) {
        wp_footer_menu_confirm_delete ( $_GET[ 'delete' ] );
    }
    return 0;
} else if ( isset( $_POST[ 'delete_key' ] ) && check_admin_referer ( 'confirm_delete', 'delete' ) ) {

    $menu_items = get_option ( 'footer_menu_links' );
    $key = $_POST['delete_key'];
    unset ( $menu_items[$key] );
    update_option ( 'footer_menu_links', $menu_items );

}

if ( isset( $_POST[ 'link_title' ] ) && check_admin_referer( 'footer_menu', 'add' ) ) {

    $link_title = $_POST ['link_title'];
    $link_address = $_POST ['link_address'];
    $link_order = $_POST ['link_order'];
    $new_link = $link_title . ',' . $link_address . ',' . $link_order;

    $footer_links = get_option( 'footer_menu_links' );
    if ($footer_links == '') {
        $footer_links = array();
    }
    $new_links = array_push( $footer_links, $new_link );
    update_option ( 'footer_menu_links', $footer_links );
}

if ( isset( $_POST[ 'font-size' ] ) && check_admin_referer( 'footer_menu', 'save' ) ) {
    if (empty($_POST['auto-footer'])) {
        $_POST['auto-footer'] = 'no';
    }
    if (empty($_POST['auto-sticky'])) {
        $_POST['auto-sticky'] = 'no';
    }
    update_option('wp_footer_values', $_POST);
    echo '<div class="wp_footer_info" style="margin:0 auto;margin-top:5px;text-align:center;">Customizations Saved</div>';
}

return 1;

}

function wp_footer_print_menu() {
$menu = wp_footer_get_menu();
$values = get_option('wp_footer_values');
--192-->    foreach ($values as $attr=>$val) {
    $menu = str_replace('%' . $attr . '%', stripslashes($val), $menu);
}
echo $menu;
if ($values['auto-sticky'] == 'yes') {
    ?>
    <style type="text/css">
        .wp_footer_sticky {
            position:fixed;
            bottom: 0;
            width: 100%;
        }
    </style>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            $('#wp_footer_menu').addClass('wp_footer_sticky');
        });
    </script>
    <?php
4

1 回答 1

0

它似乎取决于以下代码的返回值:

$values = get_option('wp_footer_values');

根据 WordPress 代码,如果该选项不存在,则返回布尔值 FALSE。您需要验证该$values变量是否为空。检查以下代码。

function wp_footer_print_menu() {
$menu = wp_footer_get_menu();
$values = get_option('wp_footer_values');
if (!empty($values)) { // <-- verify it's not empty
  foreach ($values as $attr=>$val) {
    $menu = str_replace('%' . $attr . '%', stripslashes($val), $menu);
  }
  echo $menu;
  // [...}
} // <-- don't forget to close the if statement just after the end of the foreach statement

希望有所帮助。

来源:get_option()

于 2013-03-22T21:42:44.923 回答