-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpt-maker.php
66 lines (60 loc) · 2.01 KB
/
cpt-maker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Plugin Name: CPT Maker
* Plugin URI: https://github.com/rleeson/cpt-maker.git
* Description: WordPress plugin helps quickly create and initialize custom post types
* Version: 2.0.0
* Author: Ryan Leeson
* Author URI: http://ryanleeson.com
* License: GPLv2
*/
/**
* Auto-loader checks finds classes using current file name format
* - Namespace Based: Search for CPTMaker\Name\Space\Class in /name/space/class.php
*/
spl_autoload_register( function ( $class_name ) {
$root_namespace = 'CPTMaker\\';
if ( false !== strpos( $class_name, $root_namespace ) ) {
$file_name = str_replace( '\\', '/', str_replace( $root_namespace, '\\', $class_name ) );
cpt_maker_require_class_file( sprintf( '%s/%s.php', __DIR__, $file_name ) );
return;
}
} );
/**
* Require a class file
*
* @param string $path Path to file
*/
function cpt_maker_require_class_file( $path ) {
if ( !file_exists( $path ) ) {
return;
}
require_once( $path );
}
use CPTMaker\Registration;
/**
* Associate a new post type of slug $key with the slugs of each key entry in $taxonomies
*
* @param string $key Post type key
* @param array $taxonomies List of taxonomy keys
* @param string $plural Optional plural name for post types
* @return bool
*/
function cpt_register_post_type( string $key, array $taxonomies, string $plural = '' ) {
return Registration::register_post_type( $key, $plural, '-', array(), array(), $taxonomies );
}
/**
* Associate a new taxonomy of slug $key
*
* @param string $key Post type key
* @param string $plural Optional plural name for post types
* @return bool
*/
function cpt_register_taxonomy( string $key, string $plural = '' ) {
return Registration::register_taxonomy( $key, $plural, '-', array(), array(), true );
}
// Action hook used to load custom post types and taxonomies prior to WordPress registration
add_action( 'plugins_loaded', function () {
do_action( 'cpt-registration' );
} );
add_action( 'plugins_loaded', array( Registration::class, 'register' ), 20 );