forked from the-events-calendar/ql-events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ql-events.php
115 lines (105 loc) · 2.46 KB
/
ql-events.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
<?php
/**
* Plugin Name: QL Events
* Description: Adds The Events Calendar Functionality to WPGraphQL schema.
* Version: 0.1.0
* Author: kidunot89
* Author URI: https://axistaylor.com
* Text Domain: ql-events
* Domain Path: /languages
*
* @package WPGraphQL\QL_Events
* @author kidunot89
*/
namespace WPGraphQL\QL_Events;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Setups QL Events constants
*/
function constants() {
// Plugin version.
if ( ! defined( 'QL_EVENTS_VERSION' ) ) {
define( 'QL_EVENTS_VERSION', '0.0.1' );
}
// Plugin Folder Path.
if ( ! defined( 'QL_EVENTS_PLUGIN_DIR' ) ) {
define( 'QL_EVENTS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'QL_EVENTS_PLUGIN_URL' ) ) {
define( 'QL_EVENTS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File.
if ( ! defined( 'QL_EVENTS_PLUGIN_FILE' ) ) {
define( 'QL_EVENTS_PLUGIN_FILE', __FILE__ );
}
// Whether to autoload the files or not.
if ( ! defined( 'QL_EVENTS_AUTOLOAD' ) ) {
define( 'QL_EVENTS_AUTOLOAD', true );
}
}
/**
* Returns path to plugin "includes" directory.
*
* @return string
*/
function get_includes_directory() {
return trailingslashit( QL_EVENTS_PLUGIN_DIR ) . 'includes/';
}
/**
* Returns path to plugin "vendor" directory.
*
* @return string
*/
function get_vendor_directory() {
return trailingslashit( QL_EVENTS_PLUGIN_DIR ) . 'vendor/';
}
/**
* Checks if QL Events required plugins are installed and activated
*
* @param array $deps Unloaded dependencies list.
*
* @return bool
*/
function dependencies_not_ready( &$deps = [] ) {
if ( ! class_exists( 'WPGraphQL' ) ) {
$deps[] = 'WPGraphQL';
}
if ( ! class_exists( 'Tribe__Events__Main' ) ) {
$deps[] = 'The Events Calendar';
}
return empty( $deps );
}
/**
* Initializes QL Events
*/
function init() {
constants();
if ( dependencies_not_ready( $not_ready ) ) {
require get_includes_directory() . 'class-ql-events.php';
return QL_Events::instance();
}
foreach ( $not_ready as $dep ) {
add_action(
'admin_notices',
function() use ( $dep ) {
?>
<div class="error notice">
<p>
<?php
printf(
/* translators: dependency not ready error message */
esc_html__( '%1$s must be active for QL Events to work', 'ql-events' ),
esc_html( $dep )
);
?>
</p>
</div>
<?php
}
);
}
return false;
}
add_action( 'graphql_init', 'WPGraphQL\QL_Events\init' );