| 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.3.2 |
| 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.3.2' ); |
| 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 |
if ( ! function_exists( __NAMESPACE__ . '\bsearch_freemius' ) ) { |
| 149 |
// Finally load Freemius integration. |
| 150 |
require_once BETTER_SEARCH_PLUGIN_DIR . 'load-freemius.php'; |
| 151 |
} |
| 152 |
|
| 153 |
// Load custom autoloader. |
| 154 |
if ( ! function_exists( __NAMESPACE__ . '\autoload' ) ) { |
| 155 |
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/autoloader.php'; |
| 156 |
} |
| 157 |
|
| 158 |
if ( ! function_exists( __NAMESPACE__ . '\better_search' ) ) { |
| 159 |
/** |
| 160 |
* Returns the main instance of Better_Search to prevent the need to use globals. |
| 161 |
* |
| 162 |
* @since 4.0.6 |
| 163 |
* |
| 164 |
* @return Main Main instance of the plugin. |
| 165 |
*/ |
| 166 |
function better_search() { |
| 167 |
return Main::get_instance(); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
if ( ! function_exists( __NAMESPACE__ . '\load' ) ) { |
| 172 |
/** |
| 173 |
* The main function responsible for returning the one true WebberZone Better Search instance to functions everywhere. |
| 174 |
* |
| 175 |
* @since 3.3.0 |
| 176 |
*/ |
| 177 |
function load(): void { |
| 178 |
better_search(); |
| 179 |
} |
| 180 |
add_action( 'plugins_loaded', __NAMESPACE__ . '\load' ); |
| 181 |
} |
| 182 |
|
| 183 |
/* |
| 184 |
*---------------------------------------------------------------------------- |
| 185 |
* Include files |
| 186 |
*---------------------------------------------------------------------------- |
| 187 |
*/ |
| 188 |
if ( ! function_exists( 'bsearch_get_settings' ) ) { |
| 189 |
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/options-api.php'; |
| 190 |
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/class-better-search-core-query.php'; |
| 191 |
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/class-better-search-query.php'; |
| 192 |
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/functions.php'; |
| 193 |
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/general-template.php'; |
| 194 |
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/heatmap.php'; |
| 195 |
} |
| 196 |
|
| 197 |
// Register activation hook. |
| 198 |
register_activation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::activation_hook' ); |
| 199 |
|
| 200 |
/** |
| 201 |
* Declare $bsearch_settings global so that it can be accessed in every function |
| 202 |
* |
| 203 |
* @since 1.3 |
| 204 |
*/ |
| 205 |
global $bsearch_settings; |
| 206 |
$bsearch_settings = bsearch_get_settings(); |
| 207 |
|