forked from 10up/distributor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distributor.php
181 lines (161 loc) · 4.94 KB
/
distributor.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
* Plugin Name: Distributor
* Description: Makes it easy to syndicate and reuse content across your websites, whether inside of a multisite or across the web.
* Version: 1.3.3
* Author: 10up Inc.
* Author URI: https://distributorplugin.com
* License: GPLv2 or later
* Text Domain: distributor
* Domain Path: /lang/
* GitHub Plugin URI: https://github.com/10up/distributor
*
* @package distributor
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
define( 'DT_VERSION', '1.3.3-dev' );
define( 'DT_PLUGIN_FILE', preg_replace( '#^.*plugins/(.*)$#i', '$1', __FILE__ ) );
// Define a constant if we're network activated to allow plugin to respond accordingly.
$active_plugins = get_site_option( 'active_sitewide_plugins' );
if ( is_multisite() && isset( $active_plugins[ plugin_basename( __FILE__ ) ] ) ) {
define( 'DT_IS_NETWORK', true );
} else {
define( 'DT_IS_NETWORK', false );
}
/**
* PSR-4 autoloading
*/
spl_autoload_register(
function( $class ) {
// Project-specific namespace prefix.
$prefix = 'Distributor\\';
// Base directory for the namespace prefix.
$base_dir = __DIR__ . '/includes/classes/';
// Does the class use the namespace prefix?
$len = strlen( $prefix );
if ( strncmp( $prefix, $class, $len ) !== 0 ) {
return;
}
$relative_class = substr( $class, $len );
$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
// If the file exists, require it.
if ( file_exists( $file ) ) {
require $file;
}
}
);
/**
* Require PHP version 5.6 - throw an error if the plugin is activated on an older version.
*/
register_activation_hook(
__FILE__,
function() {
if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) {
wp_die(
esc_html__( 'Distributor requires PHP version 5.6.', 'distributor' ),
esc_html__( 'Error Activating', 'distributor' )
);
}
}
);
/**
* Tell the world this site supports Distributor. We need this for external connections.
*/
add_action(
'send_headers',
function() {
if ( ! headers_sent() ) {
header( 'X-Distributor: yes' );
}
}
);
/**
* Set Distributor header in all API responses.
*/
add_filter(
'rest_post_dispatch',
function( $response ) {
$response->header( 'X-Distributor', 'yes' );
return $response;
}
);
\Distributor\Connections::factory();
// Include in case we have composer issues.
require_once __DIR__ . '/vendor/yahnis-elsts/plugin-update-checker/plugin-update-checker.php';
require_once __DIR__ . '/includes/utils.php';
require_once __DIR__ . '/includes/external-connection-cpt.php';
require_once __DIR__ . '/includes/push-ui.php';
require_once __DIR__ . '/includes/pull-ui.php';
require_once __DIR__ . '/includes/rest-api.php';
require_once __DIR__ . '/includes/subscriptions.php';
require_once __DIR__ . '/includes/syndicated-post-ui.php';
require_once __DIR__ . '/includes/distributed-post-ui.php';
require_once __DIR__ . '/includes/settings.php';
require_once __DIR__ . '/includes/template-tags.php';
if ( \Distributor\Utils\is_vip_com() ) {
add_filter( 'dt_network_site_connection_enabled', '__return_false', 9 );
}
if ( class_exists( 'Puc_v4_Factory' ) ) {
/**
* Enable updates if we have a valid license
*/
$valid_license = false;
if ( ! DT_IS_NETWORK ) {
$valid_license = \Distributor\Utils\get_settings()['valid_license'];
} else {
$valid_license = \Distributor\Utils\get_network_settings()['valid_license'];
}
if ( $valid_license ) {
// @codingStandardsIgnoreStart
$updateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/10up/distributor/',
__FILE__,
'distributor'
);
$updateChecker->addResultFilter(
function( $plugin_info, $http_response = null ) {
$plugin_info->icons = array(
'svg' => plugins_url( '/assets/img/icon.svg', __FILE__ ),
);
return $plugin_info;
}
);
// @codingStandardsIgnoreEnd
}
}
/**
* Register connections
*/
add_action(
'init',
function() {
\Distributor\Connections::factory()->register( '\Distributor\ExternalConnections\WordPressExternalConnection' );
\Distributor\Connections::factory()->register( '\Distributor\ExternalConnections\WordPressDotcomExternalConnection' );
if (
/**
* Filter whether the network connection type is enabled. Enabled by default, return false to disable.
*
* @since 1.0.0
*
* @param bool true Whether the network connection should be enabled.
*/
apply_filters( 'dt_network_site_connection_enabled', true )
) {
\Distributor\Connections::factory()->register( '\Distributor\InternalConnections\NetworkSiteConnection' );
}
},
1
);
/**
* We use setup functions to avoid unit testing WP_Mock strict mode errors.
*/
\Distributor\ExternalConnectionCPT\setup();
\Distributor\PushUI\setup();
\Distributor\PullUI\setup();
\Distributor\RestApi\setup();
\Distributor\Subscriptions\setup();
\Distributor\SyndicatedPostUI\setup();
\Distributor\DistributedPostUI\setup();
\Distributor\Settings\setup();