未定義函數create_function()的調用
P粉198670603
P粉198670603 2023-11-16 19:00:36
0
1
764

我在網站首頁收到此訊息:

致命錯誤:未捕獲錯誤:呼叫/customers/7/e/7/jovobytes.be/httpd.www/wp-content/themes/inovado/framework/inc/widgets/custommenu 中未定義的函式create_function( )。 php:67 堆疊追蹤: #0 /customers/7/e/7/jovobytes.be/httpd.www/wp-content/themes/inovado/functions.php(39): include_once() #1 /customers/7/ e/7/jovobytes.be/httpd.www/wp-settings.php(566): include('/customers/7/e/...') #2 /customers/7/e/7/jovobytes.be /httpd.www/wp-config.php(96): require_once('/customers/7/e/...') #3 /customers/7/e/7/jovobytes.be/httpd.www/wp- load.php(50): require_once('/customers/7/e/...') #4 /customers/7/e/7/jovobytes.be/httpd.www/wp-blog-header.php(13 ): require_once('/customers/7/e/...') #5 /customers/7/e/7/jovobytes.be/httpd.www/index.php(17): require('/customers/7 /e/...') #6 {main} 拋出在/customers/7/e/7/jovobytes.be/httpd.www/wp-content/themes/inovado/framework/inc/widgets/custommenu.php上第67行

所以我找了主題對應的文件,需要重寫程式碼以便相容php 8.0。任何幫助將不勝感激! ! !

<?php


class WP_Nav_Menu_Widget_Desc extends WP_Widget {

    function __construct() {
        parent::WP_Widget(false, 'minti.SideNav', array('description' => 'Display a Side Navigation'));

    }

    function widget($args, $instance) {
        // Get menu
        $nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );

        if ( !$nav_menu )
            return;

        echo $args['before_widget'];

        //if ( !empty($instance['title']) )
        //  echo $args['before_title'] . $instance['title'] . $args['after_title'];

        wp_nav_menu( array( 'depth' => 1, 'menu' => $nav_menu ) );

        echo $args['after_widget'];
    }

    function update( $new_instance, $old_instance ) {
        $instance['nav_menu'] = (int) $new_instance['nav_menu'];
        return $instance;
    }

    function form( $instance ) {
        $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';

        // Get menus
        $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );

        // If no menus exists, direct the user to go and create some.
        if ( !$menus ) {
            echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
            return;
        }
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
            <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
        <?php
            foreach ( $menus as $menu ) {
                $selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
                echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
            }
        ?>
            </select>
        </p>
        <?php
    }
}
add_action('widgets_init', create_function('', 'return register_widget("WP_Nav_Menu_Widget_Desc");'));
?>


#
P粉198670603
P粉198670603

全部回覆(1)
P粉921130067

這個非常具體的操作可以重寫為:

add_action(
    'widgets_init',
    function() {
        register_widget("WP_Nav_Menu_Widget_Desc");
    }
);

但是,小部件本身使用舊式建構子語法,因此也需要更改。

class WP_Nav_Menu_Widget_Desc extends WP_Widget {

    function __construct() {
        parent::__construct(false, 'minti.SideNav', array('description' => 'Display a Side Navigation'));
    }
}

自從我看到建構函式語法以來已經有一段時間了,所以如果更多的程式碼也被破壞,我不會感到驚訝。您確實應該考慮將主題/外掛程式升級到更新版本,或者升級您的 PHP 版本

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!