1

我正在处理别人的 Wordpress 安装。他们在主题下添加了许多自定义类/库文件(我猜,他们可能有一些自定义系统,可以在其中为 Wordpress 开发网站)。他们所有的工作看起来都是定制的。我仍然处于初级水平,无法理解一切是如何运作的。

问题: 我无法在任何博客文章中附加特色图片。(即使是自定义帖子类型)

已经尝试过:

  • 禁用所有插件 - 仍然无法正常工作
  • 将主题更改为默认 - 它有效

我不知道如何解决这个问题。

../theme/class/libs/Post.php 文件

namespace lib;
class Posts {
function __construct() {
}

public function create_posts($o = []) {

    // instantiate classes
    $metaBoxesClass = new \lib\MetaBoxes();

    foreach($o['posts'] as $post) {

        // define post type
        $postType = (isset($post['post_type'])) ? $post['post_type'] : 'page';

        // construct post
        $postArray = [
            'post_type' => $postType,
            'slug' => $post['slug'],
            'name' => $post['name'],
            'content' => 'This is the content for the '.$post['name'].' page.'
        ];

        if($o['is_sub_post'] && $o['parent_post']) {

            // define parent post
            $parentPost = get_page_by_path($o['parent_post'], OBJECT, $postType);

            // add child post array items
            $postArray['path'] = $o['parent_post'].'/'.$post['slug'];
            $postArray['parent'] = $parentPost->ID;
        }

        // insert top level post
        $postID = $this->create_post($postArray);

        // update meta boxes
        $metaBoxesClass->update_meta_boxes($post);

        // if post was made taxonomies were included
        if($postID && isset($post['taxonomies'])) {

            // for each taxonomy
            foreach($post['taxonomies'] as $taxonomy => $terms) {

                // add terms to post
                $termIDs = wp_set_object_terms($postID, $terms, $taxonomy);
            }
        }

        // if post has sub posts
        if(isset($post['sub_posts'])) {

            // run function recursively
            $this->create_posts([
                'posts' => $post['sub_posts'],
                'is_sub_post' => true,
                'parent_post' => (isset($o['parent_post'])) ? $o['parent_post'].'/'.$post['slug'] : $post['slug']
            ]);
        }
    }

    return true;
}

public function create_post($postArray = []) {

    // if path, use path as full page slug, otherwise just use the slug itself
    $slug = (isset($postArray['path'])) ? $postArray['path'] : $postArray['slug'];

    // if post doesn't already exist
    if(!get_page_by_path($slug, OBJECT, $postArray['post_type'])) {

        // construct post
        $newPost = [
            'post_type' => $postArray['post_type'],
            'post_name' => $postArray['slug'],
            'post_title' => $postArray['name'],
            'post_content' => $postArray['content'],
            'post_status' => 'publish',
            'post_parent' => ($postArray['parent']) ? $postArray['parent'] : null,
        ];

        // create post
        $postID = wp_insert_post($newPost);

        return $postID;
    }
}
}

这是该类文件夹下的文件结构。我不确定这是否有帮助。

在此处输入图像描述

4

0 回答 0