forked from yratof/algoliasearch-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
algolia-woocommerce.php
116 lines (100 loc) Β· 3.74 KB
/
algolia-woocommerce.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
/**
* @wordpress-plugin
* Plugin Name: Algolia Search for WooCommerce
* Plugin URI: https://community.algolia.com/woocommerce
* Description: Todo
* Version: 0.10.1
* Author: Algolia
* Author URI: https://www.algolia.com
*
* Text Domain: algolia-woocommerce
* Domain Path: /languages/
*/
// The Algolia Search for WooCommerce plugin version.
define( 'ALGOLIA_WOOCOMMERCE_VERSION', '0.10.1' );
define( 'ALGOLIA_WOOCOMMERCE_PLUGIN_BASENAME', plugin_basename(__FILE__) );
if ( ! defined( 'ALGOLIA_WOOCOMMERCE_PATH' ) ) {
define( 'ALGOLIA_WOOCOMMERCE_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'ALGOLIA_WOOCOMMERCE_URL' ) ) {
define( 'ALGOLIA_WOOCOMMERCE_URL', plugin_dir_url( __FILE__ ) );
}
/**
* @return string
*/
function aw_plugin_path() {
return untrailingslashit( ALGOLIA_WOOCOMMERCE_PATH );
}
add_filter( 'algolia_ua_integration_name', function() {
return 'Woocommerce';
} );
add_filter( 'algolia_ua_integration_version', function() {
return ALGOLIA_WOOCOMMERCE_VERSION;
} );
/**
* Load Localisation files.
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
*
* Locales found in:
* - WP_LANG_DIR/algolia-woocommerce/algolia-woocommerce-LOCALE.mo
* - WP_LANG_DIR/plugins/algolia-woocommerce-LOCALE.mo
*/
function aw_load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'algolia-woocommerce' );
load_textdomain( 'algolia-woocommerce', WP_LANG_DIR . '/algolia-woocommerce/algolia-woocommerce-' . $locale . '.mo' );
load_plugin_textdomain( 'algolia-woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'aw_load_plugin_textdomain' );
// Makes sure the plugin is defined before trying to use it
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
function aw_is_algolia_plugin_active() {
return is_plugin_active( 'search-by-algolia-instant-relevant-results/algolia.php' ) ||
is_plugin_active( 'algoliasearch-wordpress/algolia.php' );
}
/**
* If Algolia is not active, let users know.
**/
if ( ! aw_is_algolia_plugin_active() ) {
add_action( 'admin_notices', function() {
echo '<div class="error notice">
<p>' . __( 'Algolia Search for WooCommerce: <a href="' . admin_url( 'plugin-install.php?s=Search+by+Algolia+β+Instant+%26+Relevant+results&tab=search&type=term' ) . '">Search by Algolia β Instant & Relevant results</a> plugin should be enabled.', 'algolia-woocommerce' ) . '</p>
</div>';
} );
}
/**
* If Algolia version is lower than what is expected invite users to update.
**/
add_action( 'plugins_loaded', function() {
if ( defined( 'ALGOLIA_VERSION' ) && version_compare( ALGOLIA_VERSION, '2.1.0', '<' ) ) {
add_action( 'admin_notices', function () {
echo '<div class="error notice">
<p>' . __(
'Algolia Search for WooCommerce: Search by Algolia β Instant & Relevant should be updated to at least version 2.1.0.',
'algolia-woocommerce'
) . '</p>
</div>';
} );
}
} );
/**
* If WooCommerce is not active, let users know.
**/
if ( ! is_plugin_active('woocommerce/woocommerce.php') ) {
add_action( 'admin_notices', function() {
echo '<div class="error notice">
<p>' . esc_html__( 'Algolia Search for WooCommerce: WooCommerce plugin should be enabled.', 'algolia-woocommerce' ) . '</p>
</div>';
} );
} else {
// Only load the plugin files if the WooCommerce plugin is enabled.
require_once ALGOLIA_WOOCOMMERCE_PATH . '/includes/settings.php';
require_once ALGOLIA_WOOCOMMERCE_PATH . '/includes/frontend.php';
require_once ALGOLIA_WOOCOMMERCE_PATH . '/includes/indexing.php';
if ( is_admin() ) {
require_once dirname( __FILE__ ) . '/includes/admin/admin.php';
}
}