This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ql-search.php
98 lines (90 loc) · 2.24 KB
/
ql-search.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
<?php
/**
* Plugin Name: QL Search
* Plugin URI: https://github.com/funkhaus/ql-search
* Description: Allows you to executes search using SearchWP in WPGraphQL.
* Version: 1.0.0
* Author: kidunot89, Funkhaus LLC
* Author URI: https://funkhaus.us
* Text Domain: ql-search
* Domain Path: /languages
* License: GPL-3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*
* @package WPGraphQL\SearchWP
* @author kidunot89
* @license GPL-3
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Setups WPGraphQL WooCommerce constants
*/
function ql_search_constants() {
// Plugin version.
if ( ! defined( 'QL_SEARCH_VERSION' ) ) {
define( 'QL_SEARCH_VERSION', '1.0.0' );
}
// Plugin Folder Path.
if ( ! defined( 'QL_SEARCH_PLUGIN_DIR' ) ) {
define( 'QL_SEARCH_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL.
if ( ! defined( 'QL_SEARCH_PLUGIN_URL' ) ) {
define( 'QL_SEARCH_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin Root File.
if ( ! defined( 'QL_SEARCH_PLUGIN_FILE' ) ) {
define( 'QL_SEARCH_PLUGIN_FILE', __FILE__ );
}
// Whether to autoload the files or not.
if ( ! defined( 'QL_SEARCH_AUTOLOAD' ) ) {
define( 'QL_SEARCH_AUTOLOAD', true );
}
}
/**
* Checks if WPGraphQL WooCommerce required plugins are installed and activated
*/
function ql_search_dependencies_not_ready() {
$deps = array();
if ( ! class_exists( '\WPGraphQL' ) ) {
$deps[] = 'WPGraphQL';
}
if ( ! class_exists( '\SWP_Query' ) ) {
$deps[] = 'SearchWP';
}
return $deps;
}
/**
* Initializes QL Search
*/
function ql_search_init() {
ql_search_constants();
$not_ready = ql_search_dependencies_not_ready();
if ( empty( $not_ready ) ) {
require_once QL_SEARCH_PLUGIN_DIR . 'includes/class-ql-search.php';
return QL_Search::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 Search" to work', 'ql-search' ),
esc_html( $dep )
);
?>
</p>
</div>
<?php
}
);
}
return false;
}
add_action( 'graphql_init', 'ql_search_init' );