-
Notifications
You must be signed in to change notification settings - Fork 6
/
enable-mastodon-apps.php
74 lines (63 loc) · 2.09 KB
/
enable-mastodon-apps.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
<?php
/**
* Plugin name: Enable Mastodon Apps
* Plugin author: Alex Kirk
* Plugin URI: https://github.com/akirk/enable-mastodon-apps
* Version: 0.9.9
*
* Description: Allow accessing your WordPress with Mastodon clients. Just enter your own blog URL as your instance.
*
* License: GPL2
* Text Domain: enable-mastodon-apps
*
* @package Enable_Mastodon_Apps
*/
namespace Enable_Mastodon_Apps;
use OAuth2;
defined( 'ABSPATH' ) || exit;
define( 'ENABLE_MASTODON_APPS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ENABLE_MASTODON_APPS_VERSION', '0.9.9' );
require __DIR__ . '/vendor/bshaffer/oauth2-server-php/src/OAuth2/Autoloader.php';
OAuth2\Autoloader::register();
/**
* Class Autoloader
*/
\spl_autoload_register(
function ( $full_class ) {
$base_dir = __DIR__ . '/includes/';
$base = 'Enable_Mastodon_Apps\\';
if ( strncmp( $full_class, $base, strlen( $base ) ) === 0 ) {
$maybe_uppercase = str_replace( $base, '', $full_class );
$class = strtolower( $maybe_uppercase );
// All classes should be capitalized. If this is instead looking for a lowercase method, we ignore that.
if ( $maybe_uppercase === $class ) {
return;
}
if ( false !== strpos( $class, '\\' ) ) {
$parts = explode( '\\', $class );
$class = array_pop( $parts );
$sub_dir = strtolower( strtr( implode( '/', $parts ), '_', '-' ) );
$base_dir = $base_dir . $sub_dir . '/';
}
$filename = 'class-' . strtr( $class, '_', '-' );
$file = $base_dir . $filename . '.php';
if ( file_exists( $file ) && is_readable( $file ) ) {
require_once $file;
} else {
// translators: %s is the class name.
\wp_die( sprintf( esc_html__( 'Required class not found or not readable: %s', 'enable-mastodon-apps' ), esc_html( $file ) ) );
}
}
}
);
add_action(
'init',
function () {
new Mastodon_API();
new Integration\Pixelfed();
new Comment_CPT();
}
);
if ( is_admin() && version_compare( get_option( 'ema_plugin_version', ENABLE_MASTODON_APPS_VERSION ), '<' ) ) {
add_action( 'admin_init', array( __NAMESPACE__ . '\Mastodon_Admin', 'upgrade_plugin' ) );
}