Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@
require_once ALGOLIA_PATH . 'includes/admin/class-algolia-admin-page-premium-support.php';
require_once ALGOLIA_PATH . 'includes/admin/class-algolia-admin-page-seo.php';
require_once ALGOLIA_PATH . 'includes/admin/class-algolia-admin-template-notices.php';
require_once ALGOLIA_PATH . 'includes/admin/class-algolia-admin-page-debug.php';
}
4 changes: 2 additions & 2 deletions includes/admin/class-algolia-admin-page-autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public function autocomplete_enabled_callback() {
* @since 2.10.0
*/
public function autocomplete_debounce_callback() {
$value = $this->settings->get_autocomplete_debounce();
$indices = $this->autocomplete_config->get_form_data();
$value = $this->settings->get_autocomplete_debounce();
$indices = $this->autocomplete_config->get_form_data();
?>
<input type="number" name="algolia_autocomplete_debounce" class="small-text" min="0" value="<?php echo esc_attr( $value ); ?>" <?php disabled( empty( $indices ) ); ?>/>
<p class="description" id="home-description">
Expand Down
132 changes: 132 additions & 0 deletions includes/admin/class-algolia-admin-page-debug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
/**
* Algolia_Admin_Page_Debug class file.
*
* @author WebDevStudios <[email protected]>
* @since 2.10.1
* @package WebDevStudios\WPSWA
*/

/**
* Algolia_Admin_Page_Debug class.
*
* @since 2.10.1
*/
class Algolia_Admin_Page_Debug {

/**
* Admin page slug.
*
* @author WebDevStudios <[email protected]>
* @since 2.10.1
*
* @var string
*/
private $slug = 'algolia-debug';

/**
* Admin page capabilities.
*
* @author WebDevStudios <[email protected]>
* @since 2.10.1
*
* @var string
*/
private $capability = 'manage_options';

/**
* Admin page section.
*
* @author WebDevStudios <[email protected]>
* @since 2.10.1
*
* @var string
*/
private $section = 'algolia_section_debug';

/**
* Admin page option group.
*
* @author WebDevStudios <[email protected]>
* @since 2.10.1
*
* @var string
*/
private $option_group = 'algolia_settings';

/**
* Plugin instance.
*
* @author WebDevStudios <[email protected]>
* @since 2.10.1
*
* @var Algolia_Plugin
*/
private $plugin;

/**
* Constructor.
*
* @param Algolia_Plugin $plugin The plugin instance.
*/
public function __construct( Algolia_Plugin $plugin ) {
$this->plugin = $plugin;

add_action( 'admin_menu', [ $this, 'add_page' ] );
add_action( 'network_admin_menu', [ $this, 'add_network_page' ] );
add_action( 'admin_init', [ $this, 'add_settings' ] );
}

/**
* Add the page to the admin menu (single site).
*/
public function add_page() {
add_submenu_page(
'algolia',
esc_html__( 'Debug', 'wp-search-with-algolia' ),
esc_html__( 'Debug', 'wp-search-with-algolia' ),
$this->capability,
$this->slug,
[ $this, 'display_page' ]
);
}

/**
* Add the page to the network admin menu (multisite).
*/
public function add_network_page() {
add_submenu_page(
'wpswa_pro_network',
esc_html__( 'Debug', 'wp-search-with-algolia' ),
esc_html__( 'Debug', 'wp-search-with-algolia' ),
'manage_network_options',
$this->slug,
[ $this, 'display_page' ]
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has me going "hmm" because from a plugin standpoint, should free/"base" plugins be intentionally aware of addons that extend it? or should they be "dumb" but built in ways that allow for extending unbeknownst to it's own code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tw2113 The current setup is intentionally “dumb” in the best-practice sense—it doesn’t have any logic that’s aware of addons. It just registers its own admin pages and handles its own debug view.

Long-term, the idea is to keep the base plugin clean and maintainable, while making it easy to extend via hooks or filters. So yeah, it’s not trying to be smart—just flexible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to assume it'd just silently fail, but the reference to wpswa_pro_network is the spot where we're "smartening it up" with one line of code.


/**
* Add the settings section.
*/
public function add_settings() {
add_settings_section(
$this->section,
null,
[ $this, 'print_section_settings' ],
$this->slug
);
}

/**
* Display the page.
*/
public function display_page() {
require_once dirname( __FILE__ ) . '/partials/form-options-debug.php';
}

/**
* Print the section settings.
*/
public function print_section_settings() {
}
}
14 changes: 9 additions & 5 deletions includes/admin/class-algolia-admin-page-native-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ public function add_settings() {

register_setting( $this->option_group, 'algolia_override_native_search', array( $this, 'sanitize_override_native_search' ) );

register_setting( $this->option_group, 'algolia_instantsearch_template_version', [
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => 'legacy'
] );
register_setting(
$this->option_group,
'algolia_instantsearch_template_version',
[
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => 'legacy',
]
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct( Algolia_Plugin $plugin ) {
* @return string|void The resulting page's hook_suffix.
*/
public function add_page() {
$api = $this->plugin->get_api();
$api = $this->plugin->get_api();
$parent_slug = ! $api->is_reachable() ? 'algolia-account-settings' : 'algolia';
add_submenu_page(
$parent_slug,
Expand Down
11 changes: 7 additions & 4 deletions includes/admin/class-algolia-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @package WebDevStudios\WPSWA
*/

// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- We're using RuntimeException.

/**
* Class Algolia_Admin
*
Expand Down Expand Up @@ -60,6 +62,7 @@ public function __construct( Algolia_Plugin $plugin ) {
new Algolia_Admin_Page_WooCommerce( $plugin );
new Algolia_Admin_Page_SEO( $plugin );
new Algolia_Admin_Page_Premium_Support( $plugin );
new Algolia_Admin_Page_Debug( $plugin );

add_action( 'admin_notices', array( $this, 'display_unmet_requirements_notices' ) );

Expand Down Expand Up @@ -272,8 +275,7 @@ public function re_index() {

wp_send_json( $response );
} catch ( Exception $exception ) {
echo esc_html( $exception->getMessage() );
throw $exception;
wp_send_json_error( array( 'message' => $exception->getMessage() ) );
}
}

Expand Down Expand Up @@ -307,8 +309,7 @@ public function push_settings() {
);
wp_send_json( $response );
} catch ( Exception $exception ) {
echo esc_html( $exception->getMessage() );
throw $exception;
wp_send_json_error( array( 'message' => $exception->getMessage() ) );
}
}

Expand Down Expand Up @@ -399,3 +400,5 @@ public function handle_pro_redirect() {
}
}
}

// phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- We're using RuntimeException.
14 changes: 14 additions & 0 deletions includes/admin/css/algolia-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,17 @@ form .radio-info {
.algolia-pro-features li {
list-style: disc;
}

/* debug page */
.algolia-search_page_algolia-debug h2 {
margin-top: 30px;
}

.debug-log-output {
background: #f5f5fa;
border: 1px solid #ccc;
max-height: 400px;
overflow: auto;
padding: 10px;
white-space: pre-wrap;
}
Loading