为什么这个PHP代码以这种方式工作

时间:2016-11-29 22:38:16

标签: php wordpress

我意识到这是一个wordpress插件,但我希望有人可以帮助我解决我的代码的整体php结构。

<?php    
  add_filter( 'wprss_auto_create_terms', 'filter_categories', 10, 3 );
  /**
  * Filter categories to only allow "Plugin Reviews".
  * Change "Plugin Reviews" into "Plugins" if found.
  */
  function filter_categories( $categories, $taxonomy, $source_id ) {
  // Check for feed source 3878
    if ( $source_id == '3878' ) {
      // Loop all categories
      foreach( $categories as $i => $category ) {
        // If "Plugin Reviews" is found, change it to "Plugins"
        if ( $category['name'] == 'Plugin Reviews' )
          $categories[$i]['name'] = 'Plugins';
          // If not "Plugin Reviews", remove it
        else unset( $categories[$i] );
      }
    }
    // Return the categories
    return $categories;
  }

我可以使用名称&#34;插件评论&#34;更改任何Feed类别名称到&#34;插件&#34;因为Feed中的所有当前帖子目前都包含类别&#34;插件评论&#34;。如果我尝试一个所有帖子都没有的类别,那么无论是否有某个类别名称,都会调用未分类。我错过了什么以及如何解决这个问题?

0 个答案:

没有答案
相关问题