Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checkbox to switch to the AI staging api #195

Merged
merged 1 commit into from
Aug 9, 2023
Merged
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
Introduce a checkbox to switch to the AI staging API
  • Loading branch information
enricobattocchi committed Aug 9, 2023
commit 9e9edc62fd2a15388e3b0ffff0d1de4a706724c9
21 changes: 20 additions & 1 deletion src/development-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function add_hooks() {
if ( $this->option->get( 'enable_development_mode' ) ) {
\add_filter( 'yoast_seo_development_mode', '__return_true' );
}
if ( $this->option->get( 'use_ai_staging_api' ) ) {
\add_filter( 'Yoast\WP\SEO\ai_api_url', [ $this, 'use_ai_staging_api' ] );
}

\add_action( 'admin_post_yoast_seo_test_development_mode', [ $this, 'handle_submit' ] );
}
Expand All @@ -48,7 +51,13 @@ public function get_controls() {
$this->option->get( 'enable_development_mode' )
);

return Form_Presenter::get_html( \__( 'Enable development mode', 'yoast-test-helper' ), 'yoast_seo_test_development_mode', $fields );
$fields .= Form_Presenter::create_checkbox(
'use_ai_staging_api',
\esc_html__( 'Switch to AI staging API', 'yoast-test-helper' ),
$this->option->get( 'use_ai_staging_api' )
);

return Form_Presenter::get_html( \__( 'Development settings', 'yoast-test-helper' ), 'yoast_seo_test_development_mode', $fields );
}

/**
Expand All @@ -59,11 +68,21 @@ public function get_controls() {
public function handle_submit() {
if ( \check_admin_referer( 'yoast_seo_test_development_mode' ) !== false ) {
$this->set_bool_option( 'enable_development_mode' );
$this->set_bool_option( 'use_ai_staging_api' );
}

\wp_safe_redirect( \self_admin_url( 'tools.php?page=' . \apply_filters( 'Yoast\WP\Test_Helper\admin_page', '' ) ) );
}

/**
* Uses the AI staging API.
*
* @return string
*/
public function use_ai_staging_api() {
return 'https://ai-staging.yoa.st/api/v1';
}

/**
* Sets a boolean option based on a POST parameter.
*
Expand Down