我創建了一個畫廊崗位類型(作爲一個插件的一部分),包含除了標題和一些元信息也wp_list_table
,查詢那些具有當前崗位作爲post_parent
附件。當我的發佈按鈕突然停止工作時,我遇到了一個問題。無論我是否創建一個新的畫廊,或者如果我正在編輯一箇舊的畫廊,一旦我點擊更新/發佈,我的更改就會丟失,最終我會在edit.php
。
有人知道這是什麼意思?WordPress的自定義文章類型 - 打破發布按鈕
我在哪裏可以找出問題的癥結所在。它在我的list_table類中,它繼承自wp_list_table
。在評論出一些不重要的功能後,我最終得到了一個不同的錯誤,但仍然沒有新的或更新的圖庫。現在我得到are you sure you want to do this
頁面。
即使是最基本的類將無法正常工作......
if(! class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class Yard_Attachment_Table extends WP_List_Table {
function __construct() {
global $status, $page;
parent::__construct(array(
'singular' => 'yard Attachment',
'plural' => 'yard Attachments',
'ajax' => false
));
}
function column_default($item, $column_name) {
return 'default';
}
function get_columns(){
$columns = array(
'checkbox' => '<input type="checkbox" />', //for simplicity its not 'cb'
'thumb' => 'Thumbnail',
'title' => 'Titel',
'pos' => 'Position'
);
return $columns;
}
function prepare_items() {
global $wpdb;
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
if (isset($_REQUEST['post'])) {
$query = " SELECT *
FROM $wpdb->posts
WHERE post_type = 'attachment'
AND post_parent = {$_REQUEST['post']}";
$data = $wpdb->get_results($query, ARRAY_A);
} else {
$data = array();
}
$this->items = $data;
}
}
在插件類的構造函數我用
add_action('add_meta_boxes_yard_gallery', array($this, 'yard_metaboxes'));
。
在yard_metaboxes
我使用add_meta_box
和功能我有一個回調我創建我的表類的實例new
,我打電話prepare_items()
和display()
轉向使用error_reporting我的網頁上有這些消息去世:
Strict Standards: Only variables should be passed by reference in /Applications/MAMP/htdocs/Web/ChristophRokitta/wp v.1.0/wp-includes/pomo/mo.php on line 210
Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/Web/ChristophRokitta/wp v.1.0/wp-includes/pomo/mo.php:210) in /Applications/MAMP/htdocs/Web/ChristophRokitta/wp v.1.0/wp-includes/pluggable.php on line 876
BTW我沒有本地化。
請幫忙!如果我有更多的聲譽,我會提供。
加元框代碼
在我的插件文件:
require_once(plugin_dir_path(__FILE__) . 'class-yard.php');
Yard::get_instance();
在我的課碼文件
元框的方法是在底部:
class Yard {
protected static $instance = null;
private function __construct() {
include_once('class-yard-attachments.php');
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles'));
add_action('after_setup_theme', array($this, 'yard_thumbnails'));
add_action('init', array($this, 'yard_post_type'));
add_action('init', array($this, 'yard_taxonomies'));
add_filter('manage_yard_gallery_posts_columns', array($this, 'yard_add_columns'));
add_action('manage_posts_custom_column', array($this, 'yard_fill_columns'));
add_action('add_meta_boxes_yard_gallery', array($this, 'yard_metaboxes'));
}
public static function get_instance() {// If the single instance hasn't been set, set it now.
if (null == self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
public function enqueue_admin_styles() {
$screen = get_current_screen();
if ($screen->post_type == 'yard_gallery') {
wp_register_style('yard-gallery-style', plugins_url('css/yard-gallery-style.css', __FILE__));
wp_enqueue_style('yard-gallery-style');
}
}
public function yard_thumbnails() {
//add_image_size('yard-thumbnail', 100, 100, true);
}
public function yard_post_type() {
$gallery_labels = array(
'name' => 'Galerien',
'singular_name' => 'Galerie',
'all_items' => 'Alle Galerien',
'add_new' => 'Erstellen',
'add_new_item' => 'Neue Galerie erstellen',
'edit_item' => 'Galerie bearbeiten',
'new_item' => 'Neue Galerie',
'view' => 'Galerie anzeigen',
'view_item' => 'Gallerie anzeigen',
'search_items' => 'Galerie durchsuchen',
'not_found' => 'Keine Galerien gefunden',
'not_found_in_trash' => 'Es befinden sich keine Galerien im Papierkorb',
'parent_item_colon' => ''
);
$gallery_args = array(
'labels' => $gallery_labels,
'public' => true,
// 'publicly_queryable' => true,
// 'show_ui' => true,
// 'show_in_menu' => true,
// 'query_var' => true,
'rewrite' => true,
// 'capability_type' => 'post',
// 'hierarchical' => false,
'menu_position' => 12,
'supports' => array(
'title'
)
// 'menu_icon' => plugin_dir_url(__FILE__) . '/assets/icon_16_grey.png'//16x16 png if you want an icon
);
register_post_type('yard_gallery', $gallery_args);
}
public function yard_taxonomies() {
register_taxonomy(
'yard_work_type',
'yard_gallery',
array(
'hierarchical' => true,
'label' => 'Art der Arbeit'
)
);
register_taxonomy(
'yard_subject',
'yard_gallery',
array(
'hierarchical' => true,
'label' => 'Motiv'
)
);
}
public function yard_add_columns($columns){
$columns = array(
'cb' => '<input type="checkbox">',
'yard_post_thumb' => 'Thumbnail',
'title' => 'Bezeichnung',
'yard_pos' => 'Position',
'date' => 'Datum'
);
return $columns;
}
public function yard_fill_columns($column) {
global $post;
switch ($column) {
case 'yard_post_thumb' :
echo the_post_thumbnail('admin-list-thumb');
break;
}
}
public function yard_metaboxes($post) {
global $wp_meta_boxes;
add_meta_box(
'yard-attachments',
'Bilder',
array($this, 'get_yard_attachment_table'),
'yard_gallery'
);
}
public function get_yard_attachment_table() {
$yard_list_table = new Yard_Attachment_Table();
$yard_list_table->prepare_items();
$yard_list_table->display();
}
}
您的問題出在您的Meta Box代碼中,但是您顯示的Table類代碼似乎與發佈操作無關...... – brasofilo
@brasofilo幾乎是整個代碼。我希望你能找到一分鐘來看看 – yardarrat
有點不可告人,因爲你發佈的代碼不是[SSCCE](http://sscce.org/)。檢查[this](https://github.com/brasofilo/Internal-Link-Check)以獲得擴展'WP_List_Table'並將其用作元框回調的示例。 – brasofilo