This repository was archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
149 lines (125 loc) · 3.83 KB
/
Copy pathfunctions.php
File metadata and controls
149 lines (125 loc) · 3.83 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
class runcommand {
private static $instance;
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self;
self::$instance->setup_constants();
self::$instance->setup_actions();
self::$instance->setup_filters();
self::$instance->require_files();
self::$instance->setup_controllers();
}
return self::$instance;
}
private function setup_constants() {
define( 'RUNCOMMAND_TWITTER_SHARE_TEXT_MAX_LENGTH', 100 );
}
private function setup_actions() {
add_action( 'init', function(){
if ( ! is_admin() ) {
show_admin_bar( false );
}
});
add_action( 'after_setup_theme', array( $this, 'action_after_setup_theme' ) );
}
private function setup_filters() {
/**
* Set default configuration variables
*/
add_filter( 'pre_option_blogdescription', function(){
return 'the fastest way to do anything with WordPress';
});
/**
* Ensure plugin assets loaded from within the theme are served at a corrected URL
*/
add_filter( 'plugins_url', function( $url = '', $path = '', $plugin = '' ){
if ( empty( $plugin ) ) {
return $url;
}
if ( 0 === strpos( $plugin, get_stylesheet_directory() ) ) {
$url_override = str_replace( get_stylesheet_directory(), get_stylesheet_directory_uri(), dirname( $plugin ) );
$url = trailingslashit( $url_override ) . $path;
}
return $url;
}, 9, 3 );
}
private function require_files() {
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/lib/rest-api/plugin.php';
require_once __DIR__ . '/lib/msm-sitemap/msm-sitemap.php';
require_once __DIR__ . '/lib/fieldmanager/fieldmanager.php';
require_once __DIR__ . '/lib/posts-to-posts/posts-to-posts.php';
require_once __DIR__ . '/lib/wordpress-objects/wordpress-objects.php';
spl_autoload_register( function( $class ) {
$class = ltrim( $class, '\\' );
if ( 0 !== stripos( $class, 'runcommand\\' ) ) {
return;
}
$parts = explode( '\\', $class );
array_shift( $parts ); // Don't need "runcommand"
$last = array_pop( $parts ); // File should be 'class-[...].php'
$last = 'class-' . $last . '.php';
$parts[] = $last;
$file = dirname( __FILE__ ) . '/inc/' . str_replace( '_', '-', strtolower( implode( $parts, '/' ) ) );
if ( file_exists( $file ) ) {
require $file;
}
// Might be a trait
$file = str_replace( '/class-', '/trait-', $file );
if ( file_exists( $file ) ) {
require $file;
}
});
}
private function setup_controllers() {
$controllers = array(
'\runcommand\Assets',
'\runcommand\Content_Model',
'\runcommand\Distribution_Metadata',
'\runcommand\Fields\Command',
'\runcommand\Fields\Distribution_Metadata',
'\runcommand\Integrations\Memberful',
'\runcommand\Query',
'\runcommand\REST\API',
);
foreach( $controllers as $controller ) {
$controller::get_instance();
}
}
public function action_after_setup_theme() {
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_image_size( 'twitter-card', 560, 294, true );
add_image_size( 'facebook-open-graph', 1200, 630, true );
}
/**
* Get a rendered template part
*
* @param string $template
* @param array $vars
* @return string
*/
public static function get_template_part( $template, $vars = array() ) {
$full_path = get_template_directory() . '/parts/' . $template . '.php';
if ( ! file_exists( $full_path ) ) {
return '';
}
ob_start();
// @codingStandardsIgnoreStart
if ( ! empty( $vars ) ) {
extract( $vars );
}
// @codingStandardsIgnoreEnd
include $full_path;
return ob_get_clean();
}
/**
* Get the current request URI
*/
public static function get_request_uri() {
// Accommodate subdirectory installs
return str_replace( parse_url( home_url(), PHP_URL_PATH ), '', $_SERVER['REQUEST_URI'] );
}
}
runcommand::get_instance();