有人可以协助弃用的 create_function () 吗?

问题描述 投票:0回答:1

我使用 Visual Lightbox 的 Wordpress 插件在我的网站上创建照片画廊。 Wordpress 最近要求我更新到 PHP 8,这导致 Wordpress 出错。我已经联系了开发人员,但他们似乎不再为该插件提供支持。因此,我正在寻求帮助以弄清楚如何更正代码以符合 PHP 8。

这是 admin.php 页面的一个片段,其中存在已弃用的代码。

';
        } else {
            if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) return;
            if (get_user_option('rich_editing') == 'true'){
                add_filter('mce_external_plugins', 'visuallightbox_tinymce_button');
                add_filter('mce_buttons', 'visuallightbox_tinymce_button');
                add_filter('admin_head', create_function('', 'visuallightbox_tinymce_button("admin_head");'));
            }
        }
    }
}

这是错误。

WordPress has a built-in feature that detects when a plugin or theme causes a fatal error on your site, and notifies you with this automated email.

In this case, WordPress caught an error with one of your plugins, Visual LightBox.


When seeking help with this issue, you may be asked for some of the following information:
WordPress version 6.2
Active theme: Amadeus (version 2.1.4)
Current plugin: Visual LightBox (version 2.5.1)
PHP version 8.1.18



Error Details
=============
An error of type E_ERROR was caused in line 46 of the file /x/wp-content/plugins/visuallightbox/admin.php. Error message: Uncaught Error: Call to undefined function create_function() in /x/wp-content/plugins/visuallightbox/admin.php:46
Stack trace:
#0 /x/wp-includes/class-wp-hook.php(308): visuallightbox_tinymce_button()
#1 /x/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#2 /x/wp-includes/plugin.php(517): WP_Hook->do_action()
#3 /x/wp-settings.php(623): do_action()
#4 /x/wp-config.php(60): require_once('/x/d...')
#5 /x/wp-load.php(50): require_once('/x/d...')
#6 /x/wp-admin/admin.php(34): require_once('/x/d...')
#7 /x/wp-admin/plugins.php(10): require_once('/x/d...')
#8 {main}
  thrown

我不是程序员。我对发生的事情有一个大致的了解,但不知道可以使用什么更新代码来使我的网站功能正常。

如能提供任何帮助,我们将不胜感激!

我无法恢复到早期版本的 PHP,因为维护早期版本需要付费。

看了几个论坛,我确定这个问题在新版本的 PHP 中很常见,并且有一些编辑可以解决这个问题。我试图注释掉并替换有问题的代码,但我不是编码员,对语法不够熟悉,无法准确理解需要什么。

php wordpress plugins lightbox create-function
1个回答
0
投票

create_function()
已从 PHP 7.2.0 开始弃用,并从 PHP 8.0.0 开始删除。

您可以尝试使用匿名函数代替。

删除以下行:

add_filter('admin_head', create_function('', 'visuallightbox_tinymce_button("admin_head");'));

用以下内容替换删除的行:

add_filter('admin_head', function () { visuallightbox_tinymce_button("admin_head"); });
© www.soinside.com 2019 - 2024. All rights reserved.