Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin for the custom post type for Projects #131

Merged
merged 7 commits into from
May 20, 2020
Merged
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 @@ -119,3 +119,4 @@ wp-content/debug.log
# add a line here that looks like this:
# !/wp-content/themes/currentorg
!/wp-content/themes/currentorg
!/wp-content/plugins/current-ltw-projects
41 changes: 41 additions & 0 deletions wp-content/plugins/current-ltw-projects/.distignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# A set of files you probably don't want in your WordPress.org distribution
.babelrc
.deployignore
.distignore
.editorconfig
.eslintignore
.eslintrc
.git
.gitignore
.gitlab-ci.yml
.travis.yml
.DS_Store
Thumbs.db
behat.yml
bitbucket-pipelines.yml
bin
.circleci/config.yml
composer.json
composer.lock
dependencies.yml
Gruntfile.js
package.json
package-lock.json
phpunit.xml
phpunit.xml.dist
multisite.xml
multisite.xml.dist
.phpcs.xml
phpcs.xml
.phpcs.xml.dist
phpcs.xml.dist
README.md
webpack.config.js
wp-cli.local.yml
yarn.lock
tests
vendor
node_modules
*.sql
*.tar.gz
*.zip
22 changes: 22 additions & 0 deletions wp-content/plugins/current-ltw-projects/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4

[{.jshintrc,*.json,*.yml}]
indent_style = space
indent_size = 2

[{*.txt,wp-config-sample.php}]
end_of_line = crlf
10 changes: 10 additions & 0 deletions wp-content/plugins/current-ltw-projects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
phpcs.xml
phpunit.xml
Thumbs.db
wp-cli.local.yml
package-lock.json
node_modules/
*.sql
*.tar.gz
*.zip
56 changes: 56 additions & 0 deletions wp-content/plugins/current-ltw-projects/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = function( grunt ) {

'use strict';

// Project configuration
grunt.initConfig( {

pkg: grunt.file.readJSON( 'package.json' ),

addtextdomain: {
options: {
textdomain: 'current-ltw-projects',
},
update_all_domains: {
options: {
updateDomains: true
},
src: [ '*.php', '**/*.php', '!\.git/**/*', '!bin/**/*', '!node_modules/**/*', '!tests/**/*' ]
}
},

wp_readme_to_markdown: {
your_target: {
files: {
'README.md': 'readme.txt'
}
},
},

makepot: {
target: {
options: {
domainPath: '/languages',
exclude: [ '\.git/*', 'bin/*', 'node_modules/*', 'tests/*' ],
mainFile: 'current-ltw-projects.php',
potFilename: 'current-ltw-projects.pot',
potHeaders: {
poedit: true,
'x-poedit-keywordslist': true
},
type: 'wp-plugin',
updateTimestamp: true
}
}
},
} );

grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );
grunt.registerTask( 'default', [ 'i18n','readme' ] );
grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] );
grunt.registerTask( 'readme', ['wp_readme_to_markdown'] );

grunt.util.linefeed = '\n';

};
25 changes: 25 additions & 0 deletions wp-content/plugins/current-ltw-projects/current-ltw-projects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Plugin Name: Current.org Local That Works Projects
* Plugin URI: https://github.com/INN/umbrella-currentorg/tree/master/wp-content/plugins
* Description: Creates the 'projects' post type powering the Local That Works database
* Author: INN Labs
* Author URI: https://labs.inn.org
* Text Domain: current-ltw-projects
* Domain Path: /languages
* Version: 0.1.0
*
* @package Current_Ltw_Projects
*/

$includes = array(
'/post-types/projects.php',
'/taxonomies/project-status.php',
'/taxonomies/project-org-type.php',
'/taxonomies/project-category.php',
);
foreach ( $includes as $include ) {
if ( 0 === validate_file( $include ) ) {
require_once( dirname( __FILE__ ) . $include );
}
}
11 changes: 11 additions & 0 deletions wp-content/plugins/current-ltw-projects/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "current-ltw-projects",
"version": "0.1.0",
"main": "Gruntfile.js",
"author": "INN Labs",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-wp-i18n": "~0.5.0",
"grunt-wp-readme-to-markdown": "~1.0.0"
}
}
199 changes: 199 additions & 0 deletions wp-content/plugins/current-ltw-projects/post-types/projects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php
/**
* Regster the projects post type and associated metadata
*/

/**
* Registers the `projects` post type.
*/
function projects_init() {
register_post_type( 'projects', array(
'labels' => array(
'name' => __( 'Local That Works Projects', 'current-ltw-projects' ),
'singular_name' => __( 'Project', 'current-ltw-projects' ),
'all_items' => __( 'All LTW Projects', 'current-ltw-projects' ),
'archives' => __( 'LTW Project Archives', 'current-ltw-projects' ),
'attributes' => __( 'LTW Project Attributes', 'current-ltw-projects' ),
'insert_into_item' => __( 'Insert into Project', 'current-ltw-projects' ),
'uploaded_to_this_item' => __( 'Uploaded to this Project', 'current-ltw-projects' ),
'featured_image' => _x( 'Project Featured Image', 'projects', 'current-ltw-projects' ),
'set_featured_image' => _x( 'Set featured image', 'projects', 'current-ltw-projects' ),
'remove_featured_image' => _x( 'Remove featured image', 'projects', 'current-ltw-projects' ),
'use_featured_image' => _x( 'Use as featured image', 'projects', 'current-ltw-projects' ),
'filter_items_list' => __( 'Filter Projects list', 'current-ltw-projects' ),
'items_list_navigation' => __( 'Projects list navigation', 'current-ltw-projects' ),
'items_list' => __( 'Projects list', 'current-ltw-projects' ),
'new_item' => __( 'New Project', 'current-ltw-projects' ),
'add_new' => __( 'Add New', 'current-ltw-projects' ),
'add_new_item' => __( 'Add New Project', 'current-ltw-projects' ),
'edit_item' => __( 'Edit Project', 'current-ltw-projects' ),
'view_item' => __( 'View Project', 'current-ltw-projects' ),
'view_items' => __( 'View LTW Projects', 'current-ltw-projects' ),
'search_items' => __( 'Search LTW Projects', 'current-ltw-projects' ),
'not_found' => __( 'No Projects found', 'current-ltw-projects' ),
'not_found_in_trash' => __( 'No Projects found in trash', 'current-ltw-projects' ),
'parent_item_colon' => __( 'Parent Project:', 'current-ltw-projects' ),
'menu_name' => __( 'Projects', 'current-ltw-projects' ),
),
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_nav_menus' => true,
'supports' => array( 'title', 'editor' ),
'has_archive' => true,
'rewrite' => array( 'slug' => 'local-that-works' ),
'query_var' => true,
'menu_position' => null,
'menu_icon' => 'dashicons-awards',
'show_in_rest' => true,
'rest_base' => 'projects',
'rest_controller_class' => 'WP_REST_Posts_Controller',
'supports' => array(
'title',
'editor',
// 'author',
'thumbnail',
// 'excerpt',
'custom-fields',
// 'comments',
// 'revisions',
// 'page-attributes',
// 'post-formats',
),
) );

}
add_action( 'init', 'projects_init' );

/**
* Sets the post updated messages for the `projects` post type.
*
* @param array $messages Post updated messages.
* @return array Messages for the `projects` post type.
*/
function projects_updated_messages( $messages ) {
global $post;

$permalink = get_permalink( $post );

$messages['projects'] = array(
0 => '', // Unused. Messages start at index 1.
/* translators: %s: post permalink */
1 => sprintf( __( 'Project updated. <a target="_blank" href="%s">View Project</a>', 'current-ltw-projects' ), esc_url( $permalink ) ),
2 => __( 'Custom field updated.', 'current-ltw-projects' ),
3 => __( 'Custom field deleted.', 'current-ltw-projects' ),
4 => __( 'Project updated.', 'current-ltw-projects' ),
/* translators: %s: date and time of the revision */
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Project restored to revision from %s', 'current-ltw-projects' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
/* translators: %s: post permalink */
6 => sprintf( __( 'Project published. <a href="%s">View Project</a>', 'current-ltw-projects' ), esc_url( $permalink ) ),
7 => __( 'Project saved.', 'current-ltw-projects' ),
/* translators: %s: post permalink */
8 => sprintf( __( 'Project submitted. <a target="_blank" href="%s">Preview Project</a>', 'current-ltw-projects' ), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
/* translators: 1: Publish box date format, see https://secure.php.net/date 2: Post permalink */
9 => sprintf( __( 'Project scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Project</a>', 'current-ltw-projects' ),
date_i18n( __( 'M j, Y @ G:i', 'current-ltw-projects' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ),
/* translators: %s: post permalink */
10 => sprintf( __( 'Project draft updated. <a target="_blank" href="%s">Preview Project</a>', 'current-ltw-projects' ), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
);

return $messages;
}
add_filter( 'post_updated_messages', 'projects_updated_messages' );

/**
* Register the custom post meta for Local That Works projects
*
* @link https://developer.wordpress.org/reference/functions/register_meta/
* @link https://developer.wordpress.org/block-editor/tutorials/plugin-sidebar-0/
*/
function projects_register_post_meta() {
register_post_meta(
'projects',
'project-contact-name',
array(
'object_subtype' => 'post',
'type' => 'string',
'description' => 'The contact human for this project.',
'single' => true,
'sanitize_callback' => 'sanitize_text_field',
// 'auth_callback' => .... I don't know the answer to this question.
'show_in_rest' => true,
)
);
register_post_meta(
'projects',
'project-contact-email',
array(
'object_subtype' => 'post',
'type' => 'string',
'description' => 'The contact email for this project.',
'single' => true,
'sanitize_callback' => 'sanitize_text_field',
// 'auth_callback' => .... I don't know the answer to this question.
'show_in_rest' => true,
)
);
register_post_meta(
'projects',
'project-organization',
array(
'object_subtype' => 'post',
'type' => 'string',
'description' => 'The organization responsible for this project.',
'single' => true,
'sanitize_callback' => 'sanitize_text_field',
// 'auth_callback' => .... I don't know the answer to this question.
'show_in_rest' => true,
)
);
register_post_meta(
'projects',
'project-video',
array(
'object_subtype' => 'post',
'type' => 'string',
'description' => 'Link to video URL for this project',
'single' => true,
'sanitize_callback' => 'esc_url_raw',
// 'auth_callback' => .... I don't know the answer to this question.
'show_in_rest' => true,
)
);
}
add_action( 'init', 'projects_register_post_meta' );

/**
* Add the meta boxes for the projects meta fields
*
*/
function projects_add_meta_box() {
add_meta_box(
'current-ltw-project',
__( 'Project Metadata', 'current-ltw-projects' ),
'projects_meta_box',
'projects', // post type
'advanced',
'high',
array(
'__block_editor_compatible_meta_box' => true,
'__back_compat_meta_box' => false,
)
);
}
add_action( 'add_meta_boxes', 'projects_add_meta_box' );

/*
* Save callback for the project meta fields
*/


/**
* The meta box for the project meta fields
*/
function projects_meta_box( $post ) {
// project-contact-name - text
// project-contact-email - email
// project-organization - text
// project-video - url
}
Loading