post_status || metadata_exists( 'post', $post_id, '_docsstation_order_initialized' ) ) { return; } $running = true; $documents = get_posts( array( 'post_type' => 'docsstation_doc', 'post_status' => array( 'publish', 'draft', 'pending', 'private', 'future' ), 'posts_per_page' => 1, 'orderby' => 'menu_order', 'order' => 'DESC', 'fields' => 'ids', 'exclude' => array( $post_id ), ) ); $last_order = $documents ? (int) get_post_field( 'menu_order', $documents[0] ) : -1; remove_action( 'save_post_docsstation_doc', array( __CLASS__, 'initialize_document_order' ), 20 ); wp_update_post( array( 'ID' => $post_id, 'menu_order' => $last_order + 1, ) ); add_action( 'save_post_docsstation_doc', array( __CLASS__, 'initialize_document_order' ), 20, 3 ); update_post_meta( $post_id, '_docsstation_order_initialized', '1' ); $running = false; } public static function register() { register_post_type( 'docsstation_doc', array( 'labels' => array( 'name' => __( 'Documents', 'docsstation' ), 'singular_name' => __( 'Document', 'docsstation' ), 'add_new' => __( 'Add Document', 'docsstation' ), 'add_new_item' => __( 'Add New Document', 'docsstation' ), 'edit_item' => __( 'Edit Document', 'docsstation' ), 'new_item' => __( 'New Document', 'docsstation' ), 'view_item' => __( 'View Document', 'docsstation' ), 'search_items' => __( 'Search Documents', 'docsstation' ), 'not_found' => __( 'No documents found.', 'docsstation' ), 'not_found_in_trash' => __( 'No documents found in Trash.', 'docsstation' ), 'menu_name' => __( 'DocsStation', 'docsstation' ), ), 'public' => true, 'show_in_nav_menus' => false, 'show_in_rest' => true, 'menu_icon' => 'dashicons-book-alt', 'has_archive' => 'docs', 'rewrite' => array( 'slug' => 'docs', 'with_front' => false ), 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'author', 'revisions', 'page-attributes' ), 'taxonomies' => array( 'docsstation_category' ), 'map_meta_cap' => true, 'capability_type' => 'post', ) ); register_taxonomy( 'docsstation_category', 'docsstation_doc', array( 'labels' => self::taxonomy_labels( __( 'Categories', 'docsstation' ), __( 'Category', 'docsstation' ) ), 'public' => true, 'show_in_nav_menus' => false, 'hierarchical' => true, 'show_in_rest' => true, 'show_admin_column' => true, 'rewrite' => array( 'slug' => 'docs-category', 'with_front' => false ), ) ); } private static function taxonomy_labels( $plural, $singular ) { return array( 'name' => $plural, 'singular_name' => $singular, /* translators: %s: taxonomy plural name */ 'search_items' => sprintf( __( 'Search %s', 'docsstation' ), $plural ), /* translators: %s: taxonomy plural name */ 'all_items' => sprintf( __( 'All %s', 'docsstation' ), $plural ), /* translators: %s: taxonomy singular name */ 'edit_item' => sprintf( __( 'Edit %s', 'docsstation' ), $singular ), /* translators: %s: taxonomy singular name */ 'update_item' => sprintf( __( 'Update %s', 'docsstation' ), $singular ), /* translators: %s: taxonomy singular name */ 'add_new_item' => sprintf( __( 'Add New %s', 'docsstation' ), $singular ), 'menu_name' => $plural, ); } public static function title_placeholder( $title, $post ) { if ( $post && 'docsstation_doc' === $post->post_type ) { return __( 'Add document title', 'docsstation' ); } return $title; } }