Skip to content

Commit

Permalink
Merge pull request #142 from 10up/fix/admin-menu-notice
Browse files Browse the repository at this point in the history
Show admin menu notice (!) for lack of registration instead of specific service setup
  • Loading branch information
helen authored Sep 26, 2019
2 parents 1258d8b + 69b00fd commit 8b144fd
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions includes/Classifai/Services/ServicesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,22 @@ public function register_settings() {
*/
public function sanitize_settings( $settings ) {
$new_settings = [];
if ( isset( $settings['email'] ) && isset( $settings['license_key'] ) ) {
if ( $this->check_license_key( $settings['email'], $settings['license_key'] ) ) {
$new_settings['valid_license'] = true;
$new_settings['email'] = sanitize_text_field( $settings['email'] );
$new_settings['license_key'] = sanitize_text_field( $settings['license_key'] );
} else {
$new_settings['valid_license'] = false;
$new_settings['email'] = '';
$new_settings['license_key'] = '';
add_settings_error(
'registration',
'classifai-registration',
esc_html__( 'Invalid ClassifAI registration info. Please check and try again.', 'classifai' ),
'error'
);
}
if ( isset( $settings['email'] )
&& isset( $settings['license_key'] )
&& $this->check_license_key( $settings['email'], $settings['license_key'] ) ) {
$new_settings['valid_license'] = true;
$new_settings['email'] = sanitize_text_field( $settings['email'] );
$new_settings['license_key'] = sanitize_text_field( $settings['license_key'] );
} else {
$new_settings['valid_license'] = false;
$new_settings['email'] = isset( $settings['email'] ) ? sanitize_text_field( $settings['email'] ) : '';
$new_settings['license_key'] = isset( $settings['license_key'] ) ? sanitize_text_field( $settings['license_key'] ) : '';
add_settings_error(
'registration',
'classifai-registration',
esc_html__( 'Invalid ClassifAI registration info. Please check and try again.', 'classifai' ),
'error'
);
}

return $new_settings;
Expand Down Expand Up @@ -218,11 +218,11 @@ protected function register_services() {
* Helper to return the $menu title
*/
protected function get_menu_title() {
$is_setup = get_option( 'classifai_configured' );
$this->title = esc_html__( 'ClassifAI', 'classifai' );
$this->menu_title = $this->title;
$registration_settings = get_option( 'classifai_settings' );
$this->title = esc_html__( 'ClassifAI', 'classifai' );
$this->menu_title = $this->title;

if ( ! $is_setup ) {
if ( ! isset( $registration_settings['valid_license'] ) || ! $registration_settings['valid_license'] ) {
/*
* Translators: Main title.
*/
Expand Down

0 comments on commit 8b144fd

Please sign in to comment.