-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummybot.php
94 lines (79 loc) · 2.29 KB
/
dummybot.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Plugin Name: DummyBody
* Plugin URI: https://dummybot.com
* Description: Spin up test posts, pages, CPTs, and terms from an easy-to-use admin page.
* Version: 1.0
* Author: Mike Selander
* Author URI: https://github.com/mikeselander/
* Text Domain: dummybot
* Domain Path: /languages
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
namespace DummyPress;
/**
* Autoloader callback.
*
* Converts a class name to a file path and requires it if it exists.
*
* @param string $class Class name.
*/
function dummypress_autoloader( $class ) {
$namespace = explode( '\\', $class );
if ( __NAMESPACE__ !== $namespace[0] ) {
return;
}
$class = str_replace( __NAMESPACE__ . '\\', '', $class );
$nss = array(
'Abstracts',
'Types',
'Views'
);
if ( in_array( $namespace[1], $nss ) ) {
$class = strtolower( preg_replace( '/(?<!^)([A-Z])/', '/\1', $class ) );
$class = str_replace( '\\', '', $class );
$file = dirname( __FILE__ ) . '/' . $class . '.php';
} else {
$class = strtolower( preg_replace( '/(?<!^)([A-Z])/', '-\\1', $class ) );
$file = dirname( __FILE__ ) . '/includes/class-' . $class . '.php';
}
if ( is_readable( $file ) ) {
require_once( $file );
}
}
spl_autoload_register( __NAMESPACE__ . '\dummypress_autoloader' );
/**
* Retrieve the plugin instance.
*
* @return object Plugin
*/
function plugin() {
static $instance;
if ( null === $instance ) {
$instance = new Plugin();
}
return $instance;
}
// Set our definitions for later use
plugin()->set_definitions(
(object) array(
'basename' => plugin_basename( __FILE__ ),
'directory' => plugin_dir_path( __FILE__ ),
'file' => __FILE__,
'slug' => 'test-content',
'url' => plugin_dir_url( __FILE__ )
)
);
// Register hook providers and views.
plugin()->register_hooks( new AdminPage() )
->register_hooks( new Ajax() )
->register_view( new Views\Posts() )
->register_view( new Views\Terms() )
->register_view( new Views\Users() )
->register_view( new Views\Various() )
->register_type( new Types\Post() )
->register_type( new Types\Term() )
->register_type( new Types\User() );
// Load textdomain hook
add_action( 'plugins_loaded', array( plugin(), 'load_textdomain' ) );