1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plugin Name: Test Content Generator |
4
|
|
|
* Plugin URI: https://github.com/oldtownmedia/test-content-suite |
5
|
|
|
* Description: Spin up test posts, pages, CPTs, and terms from an easy-to-use admin page. |
6
|
|
|
* Version: 1.0 |
7
|
|
|
* Author: Old Town Media |
8
|
|
|
* Author URI: https://github.com/oldtownmedia/ |
9
|
|
|
* Text Domain: otm-test-content |
10
|
|
|
* Domain Path: /languages |
11
|
|
|
* License: GPL2 |
12
|
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace testContent; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Autoloader callback. |
19
|
|
|
* |
20
|
|
|
* Converts a class name to a file path and requires it if it exists. |
21
|
|
|
* |
22
|
|
|
* @param string $class Class name. |
23
|
|
|
*/ |
24
|
|
|
function test_content_autoloader( $class ) { |
25
|
|
|
$namespace = explode( '\\', $class ); |
26
|
|
|
|
27
|
|
|
if ( __NAMESPACE__ !== $namespace[0] ){ |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$class = str_replace( __NAMESPACE__ . '\\', '', $class ); |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
if ( 'Views' === $namespace[1] ){ |
35
|
|
|
$class = strtolower( preg_replace( '/(?<!^)([A-Z])/', '/\1', $class ) ); |
36
|
|
|
$class = str_replace( '\\', '', $class ); |
37
|
|
|
$file = dirname( __FILE__ ) . '/' . $class . '.php'; |
38
|
|
|
} else { |
39
|
|
|
$class = strtolower( preg_replace( '/(?<!^)([A-Z])/', '-\\1', $class ) ); |
40
|
|
|
$file = dirname( __FILE__ ) . '/includes/class-' . $class . '.php'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ( file_exists( $file ) ) { |
44
|
|
|
require_once( $file ); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
spl_autoload_register( __NAMESPACE__ . '\test_content_autoloader' ); |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Retrieve the plugin instance. |
53
|
|
|
* |
54
|
|
|
* @return object Plugin |
55
|
|
|
*/ |
56
|
|
|
function plugin() { |
57
|
|
|
static $instance; |
58
|
|
|
|
59
|
|
|
if ( null === $instance ) { |
60
|
|
|
$instance = new Plugin(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $instance; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Set our definitions for later use |
67
|
|
|
plugin()->set_definitions( |
68
|
|
|
(object) array( |
69
|
|
|
'basename' => plugin_basename( __FILE__ ), |
70
|
|
|
'directory' => plugin_dir_path( __FILE__ ), |
71
|
|
|
'file' => __FILE__, |
72
|
|
|
'slug' => 'structure', |
73
|
|
|
'url' => plugin_dir_url( __FILE__ ) |
74
|
|
|
) |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
// Register hook providers and views. |
78
|
|
|
plugin()->register_hooks( new AdminPage() ) |
79
|
|
|
->register_views( new Views\Posts() ) |
80
|
|
|
->register_views( new Views\Terms() ) |
81
|
|
|
->register_views( new Views\Various() ); |
82
|
|
|
|
83
|
|
|
// Load textdomain hook |
84
|
|
|
add_action( 'plugins_loaded', array( plugin(), 'load_textdomain' ) ); |
85
|
|
|
|