Skip to content

Commit

Permalink
Synced with Pro plugin
Browse files Browse the repository at this point in the history
Fixes #20
Fixes #58
Fixes #83
Fixes #110
  • Loading branch information
ajaydsouza committed Nov 17, 2024
1 parent c556f24 commit 128805e
Show file tree
Hide file tree
Showing 27 changed files with 1,812 additions and 615 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,24 @@ Here are some of the main features of __Better Search__:
* __Relevance__: Sort the results by relevance or date, and assign different weights to title and content
* __Control the results__: Search within title, content, excerpt, meta fields, authors, tags and other taxonomies and comments
* __Popular searches__: Show a heatmap of the most popular searches on your site, either as a widget or a shortcode
* __AJAX Live Search__: Show search results as you type in any search form on your site
* __Customisation__: Use your own template file and CSS styles for the ultimate look and feel
* __Supports cache plugins__: Works seamlessly with caching plugins like WP-Super-Cache and W3 Total Cache
* __Profanity filter__: Filter out any words that you don't want to appear in search queries
* __Translation ready__: Use the plugin in any language

If you want to take your site search to the next level, download __Better Search__ today and see the difference for yourself.

## Features in Better Search Pro

[__Better Search Pro__](https://webberzone.com/plugins/better-search/pro/) is the premium version of the plugin that offers even more features and functionality. With __Better Search Pro__, you can:

* [__Multisite search__](https://webberzone.com/support/knowledgebase/multisite-search/): Allow network admins to select specific sites for cross-network searches.
* [__Fuzzy search__](https://webberzone.com/support/knowledgebase/fuzzy-matches/): Find results even if the search term is misspelt.
* [__Relevance threshold__](https://webberzone.com/support/knowledgebase/better-search-settings-search/#minimum-relevance-percentage-pro-only): Only show search results above a certain relevance threshold.
* [__Search the post slug__](https://webberzone.com/support/knowledgebase/better-search-settings-search/#search-post-slug-pro-only): Include the post slug in the search results.
* [__REST API__](https://webberzone.com/support/knowledgebase/better-search-rest-api/): Allow the REST API to utilize the Better Search when enabled.

## mySQL FULLTEXT indices

On activation, the plugin creates three mySQL FULLTEXT indices (or indexes) in the `*_posts` table. These are for `post_content`, `post_title` and `(post_title,post_content)`. If you’re running a multisite installation, then this is created for each of the blogs on activation. All these indices occupy space in your mySQL database but are essential for the plugin to run.
Expand Down
5 changes: 4 additions & 1 deletion better-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Plugin Name: Better Search
* Plugin URI: https://webberzone.com/plugins/better-search/
* Description: Replace the default WordPress search with a contextual search. Search results are sorted by relevancy ensuring a better visitor search experience.
* Version: 4.0.0-beta2
* Version: 4.0.0-RC1
* Author: WebberZone
* Author URI: https://webberzone.com/
* Text Domain: better-search
Expand Down Expand Up @@ -64,6 +64,9 @@
*/
define( 'BETTER_SEARCH_DB_VERSION', '2.0' );

// Load Freemius.
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/load-freemius.php';

// Load the autoloader.
require_once BETTER_SEARCH_PLUGIN_DIR . 'includes/autoloader.php';

Expand Down
65 changes: 54 additions & 11 deletions includes/admin/class-tools-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ public function admin_menu() {
public function admin_enqueue_scripts( $hook ) {
if ( $hook === $this->parent_id ) {
wp_enqueue_script( 'better-search-admin-js' );
wp_enqueue_style( 'bsearch-admin-ui-css', );
wp_enqueue_style( 'bsearch-admin-ui-css' );
wp_enqueue_style( 'wp-spinner' );
wp_localize_script(
'better-search-admin-js',
'bsearch_admin_data',
array(
'security' => wp_create_nonce( 'bsearch-admin' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'security' => wp_create_nonce( 'bsearch-admin' ),
'confirm_message' => esc_html__( 'Are you sure you want to clear the cache?', 'better-search' ),
'success_message' => esc_html__( 'Cache cleared successfully!', 'better-search' ),
'fail_message' => esc_html__( 'Failed to clear cache. Please try again.', 'better-search' ),
'request_fail_message' => esc_html__( 'Request failed: ', 'better-search' ),
)
);
}
Expand Down Expand Up @@ -164,7 +170,12 @@ public function render_page() {

<h2 style="padding-left:0px"><?php esc_html_e( 'Clear cache', 'better-search' ); ?></h2>
<p>
<input type="button" name="cache_clear" id="cache_clear" value="<?php esc_attr_e( 'Clear cache', 'better-search' ); ?>" class="button button-secondary" onclick="return clearCache();" />
<?php
printf(
'<button type="button" name="bsearch_cache_clear" class="button button-secondary bsearch_cache_clear" aria-label="%1$s">%1$s</button>',
esc_html__( 'Clear cache', 'better-search' )
);
?>
</p>
<p class="description">
<?php esc_html_e( 'Clear the Better Search cache. This will also be cleared automatically when you save the settings page.', 'better-search' ); ?>
Expand All @@ -176,7 +187,13 @@ public function render_page() {
<form method="post">
<h2 style="padding-left:0px"><?php esc_html_e( 'Recreate FULLTEXT index', 'better-search' ); ?></h2>
<p>
<input name="bsearch_recreate" type="submit" id="bsearch_recreate" value="<?php esc_attr_e( 'Recreate Index', 'better-search' ); ?>" class="button button-secondary" onclick="if ( ! confirm('<?php esc_attr_e( 'Are you sure you want to recreate the index?', 'better-search' ); ?>') ) return false;" />
<?php
printf(
'<button type="submit" name="bsearch_recreate" id="bsearch_recreate" class="button button-secondary" onclick="if ( ! confirm(\'%1$s\') ) return false;">%2$s</button>',
esc_attr__( 'Are you sure you want to recreate the index?', 'better-search' ),
esc_attr__( 'Recreate Index', 'better-search' )
);
?>
</p>
<p class="description">
<?php esc_html_e( 'Recreate the FULLTEXT index that Better Search uses to get the relevant search results. This might take a lot of time to regenerate if you have a lot of posts.', 'better-search' ); ?>
Expand All @@ -200,8 +217,18 @@ public function render_page() {
<?php esc_html_e( 'These buttons will recreate the tables in which Better Search stores its data. This is particularly useful if you are noticing issues with tracking or if there was a problem with the database upgrade', 'better-search' ); ?>
</p>
<p>
<input name="bsearch_recreate_overall" type="submit" id="bsearch_recreate_overall" value="<?php esc_attr_e( 'Recreate overall tables', 'better-search' ); ?>" class="button button-secondary" onclick="if (!confirm('<?php esc_attr_e( 'This will recreate the overall tables. Have you backuped up your database?', 'better-search' ); ?>')) return false;" />
<input name="bsearch_recreate_daily" type="submit" id="bsearch_recreate_daily" value="<?php esc_attr_e( 'Recreate daily tables', 'better-search' ); ?>" class="button button-secondary" onclick="if (!confirm('<?php esc_attr_e( 'This will recreate the daily tables. Have you backed up your database?', 'better-search' ); ?>')) return false;" />
<?php
printf(
'<button type="submit" name="bsearch_recreate_overall" id="bsearch_recreate_overall" class="button button-secondary" onclick="if (!confirm(\'%1$s\')) return false;">%2$s</button>',
esc_attr__( 'This will recreate the overall tables. Have you backed up your database?', 'better-search' ),
esc_attr__( 'Recreate overall tables', 'better-search' )
);
printf(
'<button type="submit" name="bsearch_recreate_daily" id="bsearch_recreate_daily" class="button button-secondary" onclick="if (!confirm(\'%1$s\')) return false;">%2$s</button>',
esc_attr__( 'This will recreate the daily tables. Have you backed up your database?', 'better-search' ),
esc_attr__( 'Recreate daily tables', 'better-search' )
);
?>
</p>

<?php wp_nonce_field( 'bsearch-tools-settings' ); ?>
Expand All @@ -210,8 +237,18 @@ public function render_page() {
<form method="post">
<h2 style="padding-left:0px"><?php esc_html_e( 'Reset database', 'better-search' ); ?></h2>
<p>
<input name="bsearch_trunc_all" type="submit" id="bsearch_trunc_all" value="<?php esc_attr_e( 'Reset Popular searches table', 'better-search' ); ?>" class="button button-secondary" style="color:#f00" onclick="if (!confirm('<?php esc_attr_e( 'Are you sure you want to reset the popular searches?', 'better-search' ); ?>')) return false;" />
<input name="bsearch_trunc_daily" type="submit" id="bsearch_trunc_daily" value="<?php esc_attr_e( 'Reset Daily Popular searches table', 'better-search' ); ?>" class="button button-secondary" style="color:#f00" onclick="if (!confirm('<?php esc_attr_e( 'Are you sure you want to reset the daily popular searches?', 'better-search' ); ?>')) return false;" />
<?php
printf(
'<button type="submit" name="bsearch_trunc_all" id="bsearch_trunc_all" class="button button-secondary" style="color:#f00" onclick="if (!confirm(\'%1$s\')) return false;">%2$s</button>',
esc_attr__( 'Are you sure you want to reset the popular searches?', 'better-search' ),
esc_attr__( 'Reset Popular searches table', 'better-search' )
);
printf(
'<button type="submit" name="bsearch_trunc_daily" id="bsearch_trunc_daily" class="button button-secondary" style="color:#f00" onclick="if (!confirm(\'%1$s\')) return false;">%2$s</button>',
esc_attr__( 'Are you sure you want to reset the daily popular searches?', 'better-search' ),
esc_attr__( 'Reset Daily Popular searches table', 'better-search' )
);
?>
</p>
<p class="description">
<?php esc_html_e( 'This will reset the Better Search tables. If you are running Better Search on multisite then it will delete the popular posts across the entire network. This cannot be reversed. Make sure that your database has been backed up before proceeding', 'better-search' ); ?>
Expand All @@ -232,15 +269,21 @@ public function render_page() {
<strong><?php esc_html_e( 'You will need to restore both tables and delete the backup tables before you can begin the upgrade process.', 'better-search' ); ?></strong>
</p>
<p>
<input name="bsearch_restore_overall" type="submit" id="bsearch_restore_overall" value="<?php esc_attr_e( 'Restore Popular searches table', 'better-search' ); ?>" class="button button-secondary" onclick="if (!confirm('<?php esc_attr_e( 'Are you sure you want to restore the popular searches table from the backup?', 'better-search' ); ?>')) return false;" />
<input name="bsearch_restore_daily" type="submit" id="bsearch_restore_daily" value="<?php esc_attr_e( 'Restore Daily Popular searches table', 'better-search' ); ?>" class="button button-secondary" onclick="if (!confirm('<?php esc_attr_e( 'Are you sure you want to restore the daily popular searches table from the backup?', 'better-search' ); ?>')) return false;" />
<button name="bsearch_restore_overall" type="submit" id="bsearch_restore_overall" class="button button-secondary" onclick="if (!confirm('<?php esc_attr_e( 'Are you sure you want to restore the popular searches table from the backup?', 'better-search' ); ?>')) return false;"><?php esc_attr_e( 'Restore Popular searches table', 'better-search' ); ?></button>
<button name="bsearch_restore_daily" type="submit" id="bsearch_restore_daily" class="button button-secondary" onclick="if (!confirm('<?php esc_attr_e( 'Are you sure you want to restore the daily popular searches table from the backup?', 'better-search' ); ?>')) return false;"><?php esc_attr_e( 'Restore Daily Popular searches table', 'better-search' ); ?></button>
</p>

<p class="description">
<?php esc_html_e( 'If your site has been working fine and populating with new information, then you can delete these backed up tables to save database space.', 'better-search' ); ?>
</p>
<p>
<input name="bsearch_delete_backup_tables" type="submit" id="bsearch_delete_backup_tables" value="<?php esc_attr_e( 'Delete backup tables', 'better-search' ); ?>" class="button button-secondary" style="color:#f00" onclick="if (!confirm('<?php esc_attr_e( 'This will delete the backup tables of Better Search. Have you backed up your database?', 'better-search' ); ?>')) return false;" />
<?php
printf(
'<button type="submit" name="bsearch_delete_backup_tables" id="bsearch_delete_backup_tables" class="button button-secondary" style="color:#f00" onclick="if (!confirm(\'%1$s\')) return false;">%2$s</button>',
esc_attr__( 'This will delete the backup tables of Better Search. Have you backed up your database?', 'better-search' ),
esc_attr__( 'Delete backup tables', 'better-search' )
);
?>
</p>

<?php wp_nonce_field( 'bsearch-tools-settings' ); ?>
Expand Down
Binary file modified includes/admin/images/better-search-pro-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added includes/admin/images/bsearch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed includes/admin/images/paypal_donate_button.webp
Binary file not shown.
Binary file added includes/admin/images/support.webp
Binary file not shown.
Binary file modified includes/admin/images/x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 26 additions & 16 deletions includes/admin/js/admin-scripts.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
// Function to clear the cache.
function clearCache() {
/**** since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php ****/
jQuery.post(
ajaxurl,
{
action: 'bsearch_clear_cache',
security: bsearch_admin_data.security
},
function (response, textStatus, jqXHR) {
alert(response.message);
},
'json'
);
}

jQuery(document).ready(
function ($) {
$('button[name="bsearch_cache_clear"]').on('click', function () {
if (confirm(bsearch_admin_data.confirm_message)) {
var $button = $(this);
$button.prop('disabled', true).append(' <span class="spinner is-active"></span>');
clearCache($button);
}
});

// Function to clear the cache.
function clearCache($button) {
$.post(bsearch_admin_data.ajax_url, {
action: 'bsearch_clear_cache',
security: bsearch_admin_data.security
}, function (response) {
if (response.success) {
alert(response.data.message);
} else {
alert(bsearch_admin_data.fail_message);
}
}).fail(function (jqXHR, textStatus) {
alert(bsearch_admin_data.request_fail_message + textStatus);
}).always(function () {
$button.prop('disabled', false).find('.spinner').remove();
});
}

// Prompt the user when they leave the page without saving the form.
var formmodified = 0;

Expand Down
2 changes: 1 addition & 1 deletion includes/admin/js/admin-scripts.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions includes/admin/network/class-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Register Settings.
*
* @since 4.0.0
*
* @package WebberZone\Better_Search\Admin
*/

namespace WebberZone\Better_Search\Admin\Network;

use WebberZone\Better_Search\Main;

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}

/**
* Class to register the settings.
*
* @since 4.0.0
*/
class Admin {

/**
* Parent ID.
*
* @var string
*/
public $parent_id;

/**
* Main constructor class.
*
* @since 4.0.0
*/
public function __construct() {
$this->hooks();
}

/**
* Run the hooks.
*
* @since 4.0.0
*/
public function hooks() {
add_action( 'network_admin_menu', array( $this, 'network_admin_menu' ) );
}

/**
* Add the network admin menu.
*
* @since 4.0.0
*/
public function network_admin_menu() {
$this->parent_id = add_menu_page(
esc_html__( 'Better Search Multisite Dashboard', 'better-search' ),
esc_html__( 'Better Search', 'better-search' ),
'manage_network_options',
'bsearch_dashboard',
array( $this, 'render_page' ),
'dashicons-search'
);

add_submenu_page(
'bsearch_dashboard',
esc_html__( 'Better Search Multisite Settings', 'better-search' ),
esc_html__( 'Settings', 'better-search' ),
'manage_network_options',
'bsearch_dashboard',
array( $this, 'render_page' )
);
}

/**
* Render the page.
*
* @since 4.0.0
*/
public function render_page() {
?>
<div class="wrap">
<h1><?php esc_html_e( 'Better Search Multisite Settings', 'better-search' ); ?></h1>
<p><?php esc_html_e( 'This page allows you to configure the settings for Better Search on your multisite network.', 'better-search' ); ?></p>

<?php Main::pro_upgrade_banner( false ); ?>

<?php do_action( 'bsearch_multisite_settings' ); ?>
</div>
<?php
}
}
17 changes: 17 additions & 0 deletions includes/admin/settings/class-settings-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ public function hooks() {
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
}

/**
* Filters the CSS classes for the body tag in the admin.
*
* @param string $classes Space-separated list of CSS classes.
* @return string Space-separated list of CSS classes.
*/
public function admin_body_class( $classes ) {
$current_screen = get_current_screen();

if ( in_array( $current_screen->id, $this->menu_pages, true ) ) {
$classes .= ' ' . $this->prefix . '-dashboard-page';
}
return $classes;
}

/**
Expand Down Expand Up @@ -843,6 +859,7 @@ public function plugin_settings() {
ob_start();
?>
<div class="wrap">
<?php do_action( $this->prefix . '_settings_page_header_before' ); ?>
<h1><?php echo esc_html( $this->translation_strings['page_header'] ); ?></h1>
<?php do_action( $this->prefix . '_settings_page_header' ); ?>

Expand Down
Loading

0 comments on commit 128805e

Please sign in to comment.