首页 > 解决方案 > acf 循环中的自定义 slug 函数导致严重错误,define('WP_DEBUG', true); 不显示调试信息

问题描述

我有一个自定义的 slug 函数,我需要在其中获取 URL,将其作为参数传递给函数并“对其进行 slugify”,但它使我的网站崩溃。

下面是代码:

<?php if (have_rows('agenda_section_events')): ?>
  <?php while (have_rows('agenda_section_events')) : the_row(); ?>
  <?php
  function createUrlSlug($urlString) {
    $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $urlString);
    return strtolower($slug);
  }
  $titleToSlug = the_sub_field('agenda_event_title');
  $titleSlugged = createUrlSlug($titleToSlug);
  ?>
  <div data-event-box="<?php echo $titleSlugged ?>" class="tc__overlay">
  <div style="color: red; display: block !important">$titleToSlug: <?php $titleToSlug ?> $titleSlugged: <?php echo $titleSlugged ?> the_sub_field('agenda_event_title'): <?php the_sub_field('agenda_event_title') ?> createUrlString: <?php echo createUrlSlug('Test string to slug'); ?></div>
<?php endwhile ?>
          <?php endif ?>

由于某种原因,这段代码完全使我的网站崩溃 - 我无法调试,因为我无法显示错误日志

它说的是:

本网站出现严重错误。

了解有关 WordPress 故障排除的更多信息。

定义('WP_DEBUG',真);不显示错误

我试过了:

define('WP_DEBUG', true);

error_reporting(E_ALL);
ini_set('display_errors', 1);

不工作

// Enable WP_DEBUG mode
define('WP_DEBUG', true);

// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);

// Disable display of errors and warnings 
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define('SCRIPT_DEBUG', true);

也不起作用。

为什么 slugify 代码会破坏我的 wordpress 网站?如何在调试模式下显示错误?

标签: phpwordpress

解决方案


推荐阅读