Answer the question
In order to leave comments, you need to log in
Why is the new post type not being added?
I am writing a small plugin, registering a new post type and a fee for it, however, after activation, there is no new post type in the admin panel.
Where is the mistake?
class EC24_Simple_Youtube_Video_Gallery
{
public $data = array();
function __construct()
{
DEFINE('EC24_SIMPLE_YOUTUBE_VIDEO_GALLERY', true);
$this->plugin_name = plugin_basename(__FILE__);
$this->plugin_url = trailingslashit(WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__)));
// Функция которая исполняется при активации плагина
register_activation_hook($this->plugin_name, array(&$this, 'sytvg_activate'));
}
public function sytvg_activate()
{
add_action('init', array(&$this, 'sytvg_register_post_type'));
add_action('init', array(&$this, 'sytvg_register_taxonomy'));
}
function sytvg_register_post_type()
{
register_post_type(
'sytvg_videos',
array(
'labels' => array(
'name' => 'YouTube видео',
'singular_name' => 'YouTube видео',
'add_new' => 'Добавить YouTube видео',
'add_new_item' => 'Добавление YouTube видео',
'edit_item' => 'Редактирование YouTube видео',
'new_item' => 'Новое YouTube видео',
'view_item' => 'Смотреть YouTube видео',
'search_items' => 'Искать YouTube видео',
'parent_item_colon' => '',
'menu_name' => 'YouTube видео',
),
'public' => false,
'show_ui' => true,
'has_archive' => false,
'menu_position' => 10,
'menu_icon' => 'dashicons-video-alt3',
'supports' => array(
'title',
'excerpt',
'thumbnail',
'custom-fields',
),
'taxonomies' => array('sytvg-video-category'),
)
);
}
function sytvg_register_taxonomy()
{
register_taxonomy(
'sytvg-video-category',
'sytvg_videos',
array(
'labels' => array(
'name' => 'Видеокатегории',
'singular_name' => 'Видеокатегория',
'search_items' => 'Поиск видеокатегорий',
'all_items' => 'Все Видеокатегории',
'parent_item' => 'Родительская видеокатегория',
'parent_item_colon' => 'Родительская видеокатегория:',
'edit_item' => 'Редактировать видеокатегорию',
'update_item' => 'Обновить видеокатегорию',
'add_new_item' => 'Добавить новую видеокатегорию',
'new_item_name' => 'Имя новой видеокатегории',
'menu_name' => 'Видеокатегории',
),
'hierarchical' => true,
'query_var' => 'true',
'rewrite' => 'true',
'show_admin_column' => 'true',
)
);
}
}
global $sytvg;
$sytvg = new EC24_Simple_Youtube_Video_Gallery();
Answer the question
In order to leave comments, you need to log in
The registration of post types is essentially suspended on the plugin activation hook, and this code works once - when the plugin is activated, so that the post type is always there, this code must work every time the kernel and plugins are loaded.
It is necessary to take out the code where add_action('init'...) from the class, or call these functions inside the constructor.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question