'sanitize_text_field',
'default' => '',
]
);
register_setting(
'aisp_global_settings',
'aisp_autocomplete_here_limit',
[
'sanitize_callback' => 'absint',
'default' => 5,
]
);
}
/**
* Enqueue admin JS and CSS.
* Uses WordPress AJAX endpoint — key is never sent to the browser directly.
*/
public function enqueue_admin_scripts( $hook ) {
if ( 'toplevel_page_aisp-autocomplete' !== $hook ) {
return;
}
wp_enqueue_style(
'aisp-admin-style',
plugin_dir_url( AISP_SMART_AUTOCOMPLETE_ADDRESS_FILE ) . 'assets/css/admin.css',
[],
AISP_SMART_AUTOCOMPLETE_ADDRESS_VERSION
);
wp_enqueue_script(
'aisp-check-key',
plugin_dir_url( AISP_SMART_AUTOCOMPLETE_ADDRESS_FILE ) . 'assets/js/admin-check-key.js',
[ 'jquery' ],
AISP_SMART_AUTOCOMPLETE_ADDRESS_VERSION,
true
);
wp_localize_script(
'aisp-check-key',
'aispCheckKey',
[
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'action' => 'aisp_check_api_key',
'nonce' => wp_create_nonce( 'aisp_check_api_key' ),
'checking' => __( 'Checking…', 'aisp-smart-autocomplete-address' ),
'empty' => __( 'Please enter an API key first.', 'aisp-smart-autocomplete-address' ),
'error' => __( 'Network error while checking key.', 'aisp-smart-autocomplete-address' ),
]
);
}
/** Render settings page with tabs. */
public function render_settings_page() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- safe read for tab navigation.
$active_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'settings';
echo '
';
echo '
' . esc_html__( 'Smart Autocomplete Address', 'aisp-smart-autocomplete-address' ) . '
';
echo '';
echo wp_kses_post( $this->render_tab_link( 'settings', __( 'Settings', 'aisp-smart-autocomplete-address' ), $active_tab ) );
echo wp_kses_post( $this->render_tab_link( 'custom-field', __( 'Custom Field', 'aisp-smart-autocomplete-address' ), $active_tab ) );
$this->render_conditional_tab( 'WooCommerce', 'woocommerce', __( 'WooCommerce', 'aisp-smart-autocomplete-address' ), $active_tab );
$this->render_conditional_tab( 'FluentForm\App\Modules\Form\Form', 'fluent-forms', __( 'Fluent Forms', 'aisp-smart-autocomplete-address' ), $active_tab, __( 'requires Fluent Forms', 'aisp-smart-autocomplete-address' ) );
$this->render_conditional_tab( 'SRFM\\Plugin_Loader', 'sureforms', __( 'SureForms', 'aisp-smart-autocomplete-address' ), $active_tab );
$this->render_conditional_tab( 'WPCF7', 'contact-form-7', __( 'Contact Form 7', 'aisp-smart-autocomplete-address' ), $active_tab, __( 'requires Contact Form 7', 'aisp-smart-autocomplete-address' ) );
$this->render_conditional_tab( 'WPForms', 'wpforms', __( 'WPForms', 'aisp-smart-autocomplete-address' ), $active_tab, __( 'requires WPForms', 'aisp-smart-autocomplete-address' ) );
echo wp_kses_post( $this->render_tab_link( 'help', __( 'Help & API Key', 'aisp-smart-autocomplete-address' ), $active_tab ) );
echo '
';
switch ( $active_tab ) {
case 'settings':
$this->render_global_tab();
break;
case 'custom-field':
if ( class_exists( 'AISP_Autocomplete_Custom_Field_Integration' ) ) {
AISP_Autocomplete_Custom_Field_Integration::render_settings_tab();
}
break;
case 'woocommerce':
if ( class_exists( 'AISP_Autocomplete_WC_Integration' ) ) {
AISP_Autocomplete_WC_Integration::render_woocommerce_tab();
}
break;
case 'fluent-forms':
if ( class_exists( 'AISP_Autocomplete_Fluent_Forms_Integration' ) ) {
AISP_Autocomplete_Fluent_Forms_Integration::render_settings_tab();
}
break;
case 'sureforms':
if ( class_exists( 'AISP_Autocomplete_SureForms_Integration' ) ) {
AISP_Autocomplete_SureForms_Integration::render_settings_tab();
}
break;
case 'contact-form-7':
if ( class_exists( 'AISP_Autocomplete_CF7_Integration' ) ) {
AISP_Autocomplete_CF7_Integration::render_settings_tab();
}
break;
case 'wpforms':
if ( class_exists( 'AISP_Autocomplete_WPForms_Integration' ) ) {
AISP_Autocomplete_WPForms_Integration::render_settings_tab();
}
break;
case 'help':
$this->render_help_tab();
break;
default:
$this->render_global_tab();
break;
}
echo '';
}
/** Render a nav tab link. */
private function render_tab_link( $slug, $label, $active_tab ) {
$url = esc_url( add_query_arg( 'tab', $slug ) );
$active = $active_tab === $slug ? 'nav-tab-active' : '';
return sprintf(
'%3$s',
$url,
esc_attr( $active ),
esc_html( $label )
);
}
/** Render a conditional tab (dimmed if required plugin not active). */
private function render_conditional_tab( $class, $slug, $label, $active_tab, $req = '' ) {
if ( class_exists( $class ) ) {
printf(
'%3$s',
esc_url( add_query_arg( 'tab', $slug ) ),
esc_attr( $active_tab === $slug ? 'nav-tab-active' : '' ),
esc_html( $label )
);
} else {
echo '' . esc_html( $label );
if ( $req ) {
echo ' (' . esc_html( $req ) . ')';
}
echo '';
}
}
/** Render global settings tab. */
private function render_global_tab() {
?>
-
[ 'href' => [], 'target' => [], 'rel' => [] ] ]
),
'',
''
);
?>
-
https://yoursite.com
https://www.yoursite.com
, %2$s closes it. */
__( 'The free plan includes %1$s1,000 autocomplete requests per day%2$s — enough for most small to medium WooCommerce stores.', 'aisp-smart-autocomplete-address' ),
[ 'strong' => [] ]
),
'',
''
);
?>
[ 'href' => [], 'target' => [], 'rel' => [] ] ]
),
'',
''
);
?>