Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ web/app/plugins/*
!web/app/plugins/mitlib-post-exhibits
!web/app/plugins/mitlib-post-experts
!web/app/plugins/mitlib-post-locations
!web/app/plugins/mitlib-post-notebooks
!web/app/plugins/mitlib-pull-events
!web/app/plugins/mitlib-pull-hours

Expand Down
45 changes: 45 additions & 0 deletions web/app/mu-plugins/mitlib-post/src/class-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,51 @@
* Defines the Base class for custom post types.
*/
class Base {
/**
* Generic define function that relies on constants defined in descendant
* classes.
*/
public static function generic() {
$labels = array(
'name' => _x( static::PLURAL, 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( static::SINGULAR, 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( static::PLURAL, 'text_domain' ),
'name_admin_bar' => __( static::SINGULAR, 'text_domain' ),
'parent_item_colon' => __( static::SINGULAR, 'text_domain' ),
'all_items' => __( 'All ' . static::PLURAL, 'text_domain' ),
'add_new_item' => __( 'Add New ' . static::SINGULAR, 'text_domain' ),
'add_new' => __( 'New ' . static::SINGULAR, 'text_domain' ),
'new_item' => __( 'New ' . static::SINGULAR, 'text_domain' ),
'edit_item' => __( 'Edit ' . static::SINGULAR, 'text_domain' ),
'update_item' => __( 'Update ' . static::SINGULAR, 'text_domain' ),
'view_item' => __( 'View ' . static::SINGULAR, 'text_domain' ),
'search_items' => __( 'Search ' . static::PLURAL, 'text_domain' ),
'not_found' => __( 'No ' . static::PLURAL . ' found', 'text_domain' ),
'not_found_in_trash' => __( 'No ' . static::PLURAL . ' found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( static::SINGULAR, 'text_domain' ),
'description' => __( static::SINGULAR, 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'page-attributes', 'thumbnail' ),
'taxonomies' => array( 'category', 'post_tag', 'event' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-calendar-alt',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( strtolower( static::SINGULAR ), $args );
}

/**
* Called during acf/settings/load_json
*
Expand Down
26 changes: 26 additions & 0 deletions web/app/plugins/mitlib-post-notebooks/mitlib-post-notebooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Plugin Name: MITlib Post Notebooks
* Description: Defines the custom Notebooks post type
* Version: 1.0.0
* Author: MIT Libraries
* License: GPL2
*
* @package MITlib Post Notebooks
* @author MIT Libraries
*/

namespace Mitlib\PostTypes;

// Don't call the file directly!
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Require the necessary classes.
require_once( plugin_dir_path( __FILE__ ) . 'src/class-notebook.php' );

// Register class methods with the WordPress hooks which will call them.
add_action( 'init', array( 'Mitlib\PostTypes\Notebook', 'generic' ) );
add_filter( 'acf/settings/load_json', array( 'Mitlib\PostTypes\Notebook', 'load_point' ) );
add_filter( 'acf/settings/save_json', array( 'Mitlib\PostTypes\Notebook', 'save_point' ) );
24 changes: 24 additions & 0 deletions web/app/plugins/mitlib-post-notebooks/src/class-notebook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Class that defines the Notebooks custom post type, including fields.
*
* @package MITlib Post Notebooks
* @since 1.0.0
*/

namespace Mitlib\PostTypes;

/**
* Defines the Notebook post type, used for richer, long-form blobs of text.
*/
class Notebook extends Base {
/**
* The singular name of this post type.
*/
const SINGULAR = 'Notebook';

/**
* The plural name of this post type.
*/
const PLURAL = 'Notebooks';
}