在将代码添加到函数后无法登录WordPress wp-admin。php

时间:2021-10-29 作者:Alex P

我在函数末尾添加以下代码。php文件,用于根据自定义帖子的帖子标题填充分类法。问题是,当我添加代码时,尝试登录wp admin时会出现以下错误。非常感谢您能帮助我们弄清楚为什么会发生这种情况。

Error:

错误:由于意外输出,Cookie被阻止。有关帮助,请参阅此文档或尝试支持论坛。

Code:




<?php

function update_custom_terms($post_id) {

  // only update terms if it\'s a \'artist\' post
  if ( \'artist\' != get_post_type($post_id)) {
    return;
  
  // don\'t create or update terms for system generated posts
  if (get_post_status($post_id) == \'auto-draft\') {
    return;
  }
    
 
  $term_title = get_the_title($post_id);
  $term_slug = get_post( $post_id )->post_name;

  /*
  * Check if a corresponding term already exists by comparing 
  * the post ID to all existing term descriptions.
    \'artists\' is the taxonomy getting populated
  */
  $existing_terms = get_terms(\'artists\', array(\'hide_empty\' => false));

  foreach($existing_terms as $term) {
    if ($term->description == $post_id) {
      //term already exists, so update it and we\'re done
      wp_update_term($term->term_id, \'artists\', array(
        \'name\' => $term_title,
        \'slug\' => $term_slug
        )
      );
      return;
    }
  }

  /* 
  * If we didn\'t find a match above, this is a new post, 
  * so create a new term.
  */
  wp_insert_term($term_title, \'artists\', array(
    \'slug\' => $term_slug,
    \'description\' => $post_id
    )
  );
}

//run the update function whenever a post is created or edited
add_action(\'save_post\', \'update_custom_terms\');

function delete_term( $post_id ) {

  $post = get_post( $post_id );

  if ( term exists( $post->post_title, \'artists\' ) ) {
    $term = get_term_by( \'name\', $post->post_title, \'artists\' );
    wp_delete_term( $term->term_id, \'artists\' );
  }

}
add_action( \'before_delete_post\', \'delete_term\' );
?>

1 个回复
SO网友:Alex P

似乎问题不在于代码本身,而在于?php和&燃气轮机;整个functions.php 文件我将所有内容复制到记事本++中,删除了除顶部标记以外的所有标记,代码工作正常,现在可以再次登录。