hooks_searchwp_enabled();
} else {
$this->hooks_searchwp_disabled();
}
}
/**
* Outputs the assets needed for the Settings page.
*
* @since 1.7.0
*
* @return void
*/
public function assets() {
if ( ! Utils::is_settings_page() ) {
return;
}
wp_enqueue_style(
'searchwp-live-search-styles',
SEARCHWP_LIVE_SEARCH_PLUGIN_URL . 'assets/styles/admin/style.css',
[],
SEARCHWP_LIVE_SEARCH_VERSION
);
if ( ! Utils::is_searchwp_active() ) {
// FontAwesome.
wp_enqueue_style(
'searchwp-font-awesome',
SEARCHWP_LIVE_SEARCH_PLUGIN_URL . 'assets/vendor/fontawesome/css/font-awesome.min.css',
null,
'4.7.0'
);
}
}
/**
* Hooks if SearchWP is enabled.
*
* @since 1.7.0
*/
private function hooks_searchwp_enabled() {
if ( ! Utils::is_settings_page() ) {
return;
}
if ( class_exists( '\\SearchWP\\Admin\\NavTab' ) ) {
new \SearchWP\Admin\NavTab( [
'page' => 'searchwp-live-search',
'tab' => 'settings',
'label' => esc_html__( 'Settings', 'searchwp-live-ajax-search' ),
'is_default' => true,
] );
}
add_action( 'searchwp\settings\view', [ $this, 'output' ] );
}
/**
* Hooks if SearchWP is disabled.
*
* @since 1.7.0
*/
private function hooks_searchwp_disabled() {
add_action( 'in_admin_header', [ $this, 'header_searchwp_disabled' ], 100 );
add_filter( 'admin_footer_text', [ $this, 'admin_footer_rate_us_searchwp_disabled' ], 1, 2 );
add_filter( 'update_footer', [ $this, 'admin_footer_hide_wp_version_searchwp_disabled' ], PHP_INT_MAX );
add_action( 'admin_print_scripts', [ $this, 'admin_hide_unrelated_notices' ] );
}
/**
* Return array containing markup for all the appropriate settings fields.
*
* @since 1.7.0
*
* @return array
*/
private function get_settings_fields() {
$fields = [];
$settings = searchwp_live_search()
->get( 'Settings_Api' )
->get_registered_settings();
foreach ( $settings as $slug => $args ) {
$fields[ $slug ] = $this->output_field( $args );
}
return apply_filters( 'searchwp_live_search_settings_fields', $fields );
}
/**
* Settings page output.
*
* @since 1.7.0
*/
public function output() {
?>
get_settings_fields();
?>
true ] ) : '';
// Build standard field markup and return.
$output = '';
if ( ! empty( $args['name'] ) ) {
$output .= '';
$output .= '' . esc_html( $args['name'] ) . ' ';
$output .= ' ';
}
$output .= '';
// Get returned markup from callback.
$output .= call_user_func( $callback, $args );
if ( ! empty( $args['desc_after'] ) ) {
$output .= $args['desc_after'];
}
$output .= ' ';
$output .= '
';
return $output;
}
/**
* Settings checkbox field output.
*
* @since 1.7.0
*
* @param array $args Field config.
*
* @return string
*/
private function output_field_checkbox( $args ) {
$default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
$value = searchwp_live_search()->get( 'Settings_Api' )->get( $args['slug'], $default );
$slug = sanitize_key( $args['slug'] );
$checked = ! empty( $value ) ? checked( 1, $value, false ) : '';
$output = '';
$output .= '
';
if ( ! empty( $args['desc'] ) ) {
$output .= '
' . wp_kses_post( $args['desc'] ) . '
';
}
$output .= '
';
return $output;
}
/**
* Settings select field output.
*
* @since 1.7.0
*
* @param array $args Field config.
*
* @return string
*/
private function output_field_select( $args ) {
$default = isset( $args['default'] ) ? esc_html( $args['default'] ) : '';
$slug = sanitize_key( $args['slug'] );
$value = searchwp_live_search()->get( 'Settings_Api' )->get( $slug, $default );
$data = isset( $args['data'] ) ? (array) $args['data'] : [];
$attr = isset( $args['attr'] ) ? (array) $args['attr'] : [];
foreach ( $data as $name => $val ) {
$data[ $name ] = 'data-' . sanitize_html_class( $name ) . '="' . esc_attr( $val ) . '"';
}
$data = implode( ' ', $data );
$attr = implode( ' ', array_map( 'sanitize_html_class', $attr ) );
$output = '';
foreach ( $args['options'] as $option => $name ) {
if ( empty( $args['selected'] ) ) {
$selected = selected( $value, $option, false );
} else {
$selected = is_array( $args['selected'] ) && in_array( $option, $args['selected'], true ) ? 'selected' : '';
}
$output .= '' . esc_html( $name ) . ' ';
}
$output .= ' ';
if ( ! empty( $args['desc'] ) ) {
$output .= '' . wp_kses_post( $args['desc'] ) . '
';
}
return $output;
}
/**
* Settings content field output.
*
* @since 1.7.0
*
* @param array $args Field config.
*
* @return string
*/
private function output_field_content( $args ) {
return ! empty( $args['content'] ) ? $args['content'] : '';
}
/**
* Renders the header logo.
*
* @since 1.7.3
*
* @return void
*/
private static function header_logo() {
?>
';
do_action( 'searchwp_live_search_settings_header_after' );
}
/**
* Renders the main header.
*
* @since 1.7.3
*
* @return void
*/
private static function header_searchwp_disabled_main() {
?>
get( 'Settings' )->output(); ?>
[
'class' => [],
'aria-hidden' => [],
],
]
),
str_repeat( ' ', 5 ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
?>
»
Bonus: SearchWP Live Ajax Search users get 50% off the regular price , automatically applied at checkout!', 'searchwp-live-ajax-search' ),
[
'strong' => [],
'span' => [
'class' => [],
],
]
);
?>
id ) || strpos( $current_screen->id, 'searchwp-live-search' ) === false ) {
return $text;
}
$url = 'https://wordpress.org/support/plugin/searchwp-live-ajax-search/reviews/?filter=5#new-post';
return sprintf(
wp_kses( /* translators: $1$s - SearchWP plugin name; $2$s - WP.org review link; $3$s - WP.org review link. */
__( 'Please rate %1$s ★★★★★ on WordPress.org to help us spread the word. Thank you from the SearchWP team!', 'searchwp-live-ajax-search' ),
[
'a' => [
'href' => [],
'target' => [],
'rel' => [],
],
]
),
'SearchWP Live Ajax Search ',
$url,
$url
);
}
/**
* Hide the wp-admin area "Version x.x" in footer on SearchWP pages.
*
* @since 1.7.0
*
* @param string $text Default "Version x.x" or "Get Version x.x" text.
*
* @return string
*/
public function admin_footer_hide_wp_version_searchwp_disabled( $text ) {
// Reset text if we're not on a SearchWP screen or page.
if ( Utils::is_settings_page() ) {
return '';
}
return $text;
}
/**
* Output "Did you know" block.
*
* @since 1.7.0
*
* @return string
*/
public static function get_dyk_block_output() {
if ( Utils::is_searchwp_active() ) {
return '';
}
ob_start();
?>
That’s frustrating , because it leaves your visitors unable to find what they are looking for!', 'searchwp-live-ajax-search' ),
[
'strong' => [],
'em' => [],
]
);
?>
»
Bonus: SearchWP Live Ajax Search users get 50% off the regular price , automatically applied at checkout!', 'searchwp-live-ajax-search' ),
[
'strong' => [],
'span' => [
'class' => [],
],
]
);
?>
[], // remove all callbacks.
'admin_notices' => [],
'all_admin_notices' => [],
'admin_footer' => [
'render_delayed_admin_notices', // remove this particular callback.
],
];
$notice_types = array_keys( $rules );
foreach ( $notice_types as $notice_type ) {
if ( empty( $wp_filter[ $notice_type ]->callbacks ) || ! is_array( $wp_filter[ $notice_type ]->callbacks ) ) {
continue;
}
$remove_all_filters = empty( $rules[ $notice_type ] );
foreach ( $wp_filter[ $notice_type ]->callbacks as $priority => $hooks ) {
foreach ( $hooks as $name => $arr ) {
if ( is_object( $arr['function'] ) && is_callable( $arr['function'] ) ) {
if ( $remove_all_filters ) {
unset( $wp_filter[ $notice_type ]->callbacks[ $priority ][ $name ] );
}
continue;
}
$class = '';
if ( ! empty( $arr['function'][0] ) && is_object( $arr['function'][0] ) ) {
$class = strtolower( get_class( $arr['function'][0] ) );
}
if ( ! empty( $arr['function'][0] ) && is_string( $arr['function'][0] ) ) {
$class = strtolower( $arr['function'][0] );
}
// Remove all callbacks except SearchWP notices.
if ( $remove_all_filters && strpos( $class, 'searchwp' ) === false ) {
unset( $wp_filter[ $notice_type ]->callbacks[ $priority ][ $name ] );
continue;
}
$cb = is_array( $arr['function'] ) ? $arr['function'][1] : $arr['function'];
// Remove a specific callback.
if ( ! $remove_all_filters && in_array( $cb, $rules[ $notice_type ], true ) ) {
unset( $wp_filter[ $notice_type ]->callbacks[ $priority ][ $name ] );
}
}
}
}
}
}