PluginProbe
Better Search – Relevant search results for WordPress / trunk
Better Search – Relevant search results for WordPress vtrunk
4.4.3 4.4.2 4.4.1 4.4.0 4.3.2 4.3.1 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 All 68 releases
better-search / better-search.php

better-search.php in Better Search – Relevant search results for WordPress trunk, at better-search.php

214 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Better Search is a plugin that will replace the default WordPress search page
4 * with highly relevant search results improving your visitors search experience.
5 *
6 * @package Better_Search
7 * @author Ajay D'Souza
8 * @license GPL-2.0+
9 * @link https://webberzone.com
10 * @copyright 2009-2026 Ajay D'Souza
11 *
12 * @wordpress-plugin
13 * Plugin Name: Better Search
14 * Plugin URI: https://webberzone.com/plugins/better-search/
15 * Description: Replace the default WordPress search with a contextual search. Search results are sorted by relevancy ensuring a better visitor search experience.
16 * Version: 4.4.3
17 * Author: WebberZone
18 * Author URI: https://webberzone.com/
19 * Text Domain: better-search
20 * License: GPL-2.0+
21 * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
22 * Domain Path: /languages
23 */
24
25 namespace WebberZone\Better_Search;
26
27 if ( ! defined( 'WPINC' ) ) {
28 die;
29 }
30
31 if ( ! defined( 'BETTER_SEARCH_VERSION' ) ) {
32 /**
33 * Holds the version of Better Search.
34 *
35 * @since 2.9.3
36 */
37 define( 'BETTER_SEARCH_VERSION', '4.4.3' );
38 }
39
40 if ( ! defined( 'BETTER_SEARCH_PLUGIN_DIR' ) ) {
41 /**
42 * Holds the filesystem directory path (with trailing slash) for Better Search
43 *
44 * @since 2.2.0
45 */
46 define( 'BETTER_SEARCH_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
47 }
48
49 if ( ! defined( 'BETTER_SEARCH_PLUGIN_URL' ) ) {
50 /**
51 * Holds the filesystem directory path (with trailing slash) for Better Search
52 *
53 * @since 2.2.0
54 */
55 define( 'BETTER_SEARCH_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
56 }
57
58 if ( ! defined( 'BETTER_SEARCH_PLUGIN_FILE' ) ) {
59 /**
60 * Holds the filesystem directory path (with trailing slash) for Better Search
61 *
62 * @since 2.2.0
63 */
64 define( 'BETTER_SEARCH_PLUGIN_FILE', __FILE__ );
65 }
66
67 if ( ! defined( 'BETTER_SEARCH_DB_VERSION' ) ) {
68 /**
69 * Holds the version of Better Search.
70 *
71 * @since 3.3.0
72 */
73 define( 'BETTER_SEARCH_DB_VERSION', '2.0' );
74 }
75
76 /**
77 * Holds the default thumbnail URL for Better Search.
78 *
79 * @since 4.2.2
80 */
81 if ( ! defined( 'BETTER_SEARCH_DEFAULT_THUMBNAIL_URL' ) ) {
82 define( 'BETTER_SEARCH_DEFAULT_THUMBNAIL_URL', BETTER_SEARCH_PLUGIN_URL . 'includes/images/default-thumb.png' );
83 }
84
85 if ( ! function_exists( __NAMESPACE__ . '\bsearch_deactivate_other_instances' ) ) {
86 /**
87 * Deactivate other instances of Better Search when this plugin is activated.
88 *
89 * @param string $plugin The plugin being activated.
90 * @param bool $network_wide Whether the plugin is being activated network-wide.
91 */
92 function bsearch_deactivate_other_instances( $plugin, $network_wide = false ) {
93 $free_plugin = 'better-search/better-search.php';
94 $pro_plugin = 'better-search-pro/better-search.php';
95
96 // Only proceed if one of our plugins is being activated.
97 if ( ! in_array( $plugin, array( $free_plugin, $pro_plugin ), true ) ) {
98 return;
99 }
100
101 $plugins_to_deactivate = array();
102 $deactivated_plugin = '';
103
104 // If pro is being activated, deactivate free.
105 if ( $pro_plugin === $plugin ) {
106 if ( is_plugin_active( $free_plugin ) || ( $network_wide && is_plugin_active_for_network( $free_plugin ) ) ) {
107 $plugins_to_deactivate[] = $free_plugin;
108 $deactivated_plugin = 'Better Search';
109 }
110 }
111
112 // If free is being activated, deactivate pro.
113 if ( $free_plugin === $plugin ) {
114 if ( is_plugin_active( $pro_plugin ) || ( $network_wide && is_plugin_active_for_network( $pro_plugin ) ) ) {
115 $plugins_to_deactivate[] = $pro_plugin;
116 $deactivated_plugin = 'Better Search Pro';
117 }
118 }
119
120 if ( ! empty( $plugins_to_deactivate ) ) {
121 deactivate_plugins( $plugins_to_deactivate, false, $network_wide );
122 set_transient( 'bsearch_deactivated_notice', $deactivated_plugin, 1 * HOUR_IN_SECONDS );
123 }
124 }
125 add_action( 'activated_plugin', __NAMESPACE__ . '\bsearch_deactivate_other_instances', 10, 2 );
126 }
127
128 // Show admin notice about automatic deactivation.
129 if ( ! has_action( 'admin_notices', __NAMESPACE__ . '\bsearch_show_deactivation_notice' ) ) {
130 add_action(
131 'admin_notices',
132 function () {
133 $deactivated_plugin = get_transient( 'bsearch_deactivated_notice' );
134 if ( $deactivated_plugin ) {
135 /* translators: %s: Name of the deactivated plugin */
136 $message = sprintf( __( "Better Search and Better Search PRO should not be active at the same time. We've automatically deactivated %s.", 'better-search' ), $deactivated_plugin );
137 ?>
138 <div class="updated" style="border-left: 4px solid #ffba00;">
139 <p><?php echo esc_html( $message ); ?></p>
140 </div>
141 <?php
142 delete_transient( 'bsearch_deactivated_notice' );
143 }
144 }
145 );
146 }
147
148 // Load the Composer autoloader (includes the Freemius SDK).
149 $composer_autoload = plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
150 if ( file_exists( $composer_autoload ) ) {
151 require_once $composer_autoload;
152 }
153
154 if ( ! function_exists( __NAMESPACE__ . '\bsearch_freemius' ) ) {
155 // Finally load Freemius integration.
156 require_once BETTER_SEARCH_PLUGIN_DIR . 'load-freemius.php';
157 }
158
159 // Load custom autoloader.
160 if ( ! function_exists( __NAMESPACE__ . '\autoload' ) ) {
161 require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/autoloader.php';
162 }
163
164 if ( ! function_exists( __NAMESPACE__ . '\better_search' ) ) {
165 /**
166 * Returns the main instance of Better_Search to prevent the need to use globals.
167 *
168 * @since 4.0.6
169 *
170 * @return Main Main instance of the plugin.
171 */
172 function better_search() {
173 return Main::get_instance();
174 }
175 }
176
177 if ( ! function_exists( __NAMESPACE__ . '\load' ) ) {
178 /**
179 * The main function responsible for returning the one true WebberZone Better Search instance to functions everywhere.
180 *
181 * @since 3.3.0
182 */
183 function load(): void {
184 better_search();
185 }
186 add_action( 'plugins_loaded', __NAMESPACE__ . '\load' );
187 }
188
189 /*
190 *----------------------------------------------------------------------------
191 * Include files
192 *----------------------------------------------------------------------------
193 */
194 if ( ! function_exists( 'bsearch_get_settings' ) ) {
195 require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/options-api.php';
196 require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/class-better-search-core-query.php';
197 require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/class-better-search-query.php';
198 require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/functions.php';
199 require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/general-template.php';
200 require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/heatmap.php';
201 }
202
203 // Register activation hook.
204 register_activation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::activation_hook' );
205 register_deactivation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::deactivation_hook' );
206
207 /**
208 * Declare $bsearch_settings global so that it can be accessed in every function
209 *
210 * @since 1.3
211 */
212 global $bsearch_settings;
213 $bsearch_settings = bsearch_get_settings();
214