php - 从非常旧的更新到 PHP 7.4 后插件 preg_match_all 错误
问题描述
我们的网站打开错误(插件激活):
有错误的示例 URL: https ://www.live-karikaturen.ch/downloads/1-august-fahnen-schwingen-nationalfeiertag-schweiz/ https://www.live-karikaturen.ch/webshop-gratisbilder-free-cartoon -comic-images/ https://www.live-karikaturen.ch/downloads/auto-suv-autofan-abgase-umweltverschmutzung/
更新不兼容:我从一个非常旧的 PHP 版本更新到 7.4
我使用这个非常重要的插件,它已经过时了(最近更新 4 年): https ://wordpress.org/support/plugin/creative-commons-configurator-1/
现在我收到这个错误,我认为它可能很容易解决,但我对 PHP 几乎一无所知,但我尝试学习一下,所以提前非常感谢你。
错误: *
警告:preg_match_all():编译失败:转义序列在 /home/clients/f9abb707fe4ac1215fe0f0a9c0b0ae21/www.live-karikaturen-ch/wp-content/plugins/creative-commons-configurator-1/creative 中偏移 18 处的字符类中无效-commons-configurator-1.php 在第 821 行
我在这里从 .php 文件中复制代码
代码:这是第 821 行:
if ( ! preg_match_all( $pattern_images_no_caption, $post_content, $matches ) ) {
return $post_content;
}
代码从第 803 - 828 行(不知道复制行号的人):
function bccl_separate_licensing_on_images_without_caption( $post_content ) {
// Plugin options
$options = get_option('cc_settings');
if ( $options === false || $options['cc_enable_individual_media_licensing'] == '0' ) {
return $post_content;
}
$post = get_queried_object();
if ( apply_filters('bccl_exclude_license', false, $post) ) {
return $post_content;
}
// Pattern that matches images without caption
//$pattern_images_no_caption = '#<p>[\s\R]*(<img [^>]+>)#';
$pattern_images_no_caption = '#<(?:p|h[\d]+)>[\s\R]*(<img [^>]+>)#';
$pattern_images_no_caption = apply_filters('bccl_pattern_match_images_without_caption' , $pattern_images_no_caption);
**if ( ! preg_match_all( $pattern_images_no_caption, $post_content, $matches ) ) {
return $post_content;
}**
//var_dump($matches[1]);
// Iterate over the found images and add licensing metadata
foreach ( $matches[1] as $image_html ) {
有没有一种简单的方法来解决这个错误?
非常感谢您的回答和帮助!
解决方案
非常感谢你,你太棒了!:) 我试过了,它可以工作,至少没有错误了。
首先 ,我只是不确定我应该采用哪个版本的更正代码。我猜Nr。1 没问题,没有 []。这意味着,正如上面 Toto 所写,我将 [\s\R] 替换为简单的 \s。
编号。1.)没有[]
//$pattern_images_no_caption = '#
\s*(<img [^>]+>)#'; $pattern_images_no_caption = '#<(?:p|h[\d]+)>\s*(<img [^>]+>)#';
编号。2.) 带有 []
//$pattern_images_no_caption = '#<p>[\s]*(<img [^>]+>)#';
$pattern_images_no_caption = '#<(?:p|h[\d]+)>[\s]*(<img [^>]+>)#';
第二 ,我在整个 creative-commons-configurator.php 插件代码中搜索了 \R 并在第 979 行进一步发现:
$parts = preg_split('#\R#u', $attach`enter code here`ment_data);
这部分的所有行都是这样的:
// Attachment ID
// Unfortunately, WP does not provide enough information in order to determine the attachment ID
// So, first collect all the audio/video media file URLs in $attachments_urls
$attachments_data = get_post_meta( $post->ID, 'enclosure', false );
//var_dump($attachments_data);
$attachments_urls = array();
foreach ( $attachments_data as $attachment_data ) {
$parts = preg_split('#\R#u', $attachment_data);
$attachments_urls[] = $parts[0];
}
//var_dump($attachments_urls);
// Then check which media file URL exists in the $atts array so as to
// determine which attachment we are processing currently.
$atts_values = array_values($atts);
//var_dump($atts_values);
// Find the URL of the attachment we are processing
$current_attachment_url = '';
foreach ( $attachments_urls as $attachment_url) {
if ( in_array($attachment_url, $atts_values) ) {
$current_attachment_url = $attachment_url;
break;
}
}
问题:目前我没有收到任何错误,但我想知道这是否会产生一个并且我必须删除或替换“邪恶”\R?
推荐阅读
- math - 如何将四元数与向量相乘?
- javascript - 如何创建数组对象并将相同的对象值推入数组
- python - Pandas 使用多行计数
- java - 隐藏按钮返回、主页、Android 应用程序
- python - 如何修改 model.fit 设置?
- google-cloud-platform - Cloud Functions - 从 StackDriver 中删除默认日志记录?
- android - Android Studio 和 Jax-rs 中的登录和 Oauth
- c++ - 如何使用linux接受多个输入进行操作
- twitter-bootstrap - 为 Bootstrap 4 重新排序移动设备中的列
- c++ - Apache Ignite C++ 瘦客户端:如何放置/获取字节数组?