AI Site Editor: "Connect Claude" setup (class-setup.php),
* publishing mode, pre-publish checks, connected apps and recent agent
* activity.
*
* Uses the Settings API (options.php handles the nonce and capability check;
* Agent_Publisher_Policy::sanitize() cleans the input).
*
* @package Acadium_Agent_Publisher
*/
defined( 'ABSPATH' ) || exit;
final class Agent_Publisher_Settings_Page {
const SLUG = 'acadium-agent-publisher';
const GROUP = 'agent_publisher';
public static function init() {
add_action( 'admin_init', array( __CLASS__, 'register' ) );
add_action( 'admin_menu', array( __CLASS__, 'menu' ) );
add_filter( 'plugin_action_links_' . plugin_basename( AGENT_PUBLISHER_FILE ), array( __CLASS__, 'action_links' ) );
add_action( 'admin_notices', array( __CLASS__, 'permalinks_notice' ) );
add_action( 'admin_post_agent_publisher_enable_permalinks', array( __CLASS__, 'enable_permalinks' ) );
}
/** The connection URL and OAuth discovery (/.well-known/…) need pretty permalinks. */
public static function has_pretty_permalinks() {
return '' !== (string) get_option( 'permalink_structure' );
}
/** On the Plugins screen and this plugin's settings page only: offer to turn on pretty permalinks. */
public static function permalinks_notice() {
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( self::has_pretty_permalinks() || ! current_user_can( 'manage_options' ) || ! $screen || ! in_array( $screen->id, array( 'plugins', 'settings_page_' . self::SLUG ), true ) ) {
return;
}
?>
Permalinks would. */
public static function enable_permalinks() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'acadium-agent-publisher' ), 403 );
}
check_admin_referer( 'agent_publisher_enable_permalinks' );
global $wp_rewrite;
$wp_rewrite->set_permalink_structure( '/%postname%/' );
flush_rewrite_rules();
wp_safe_redirect( add_query_arg( 'agent-publisher-permalinks', '1', admin_url( 'options-general.php?page=' . self::SLUG ) ) );
exit;
}
public static function register() {
register_setting(
self::GROUP,
Agent_Publisher_Policy::OPTION,
array(
'type' => 'array',
'sanitize_callback' => array( 'Agent_Publisher_Policy', 'sanitize' ),
'default' => Agent_Publisher_Policy::defaults(),
)
);
}
public static function menu() {
add_options_page(
__( 'AI Site Editor', 'acadium-agent-publisher' ),
__( 'AI Site Editor', 'acadium-agent-publisher' ),
'manage_options',
self::SLUG,
array( __CLASS__, 'render' )
);
}
public static function action_links( $links ) {
array_unshift(
$links,
sprintf( '%s', esc_url( admin_url( 'options-general.php?page=' . self::SLUG ) ), esc_html__( 'Settings', 'acadium-agent-publisher' ) )
);
return $links;
}
public static function render() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$s = Agent_Publisher_Policy::settings();
$name = Agent_Publisher_Policy::OPTION;
$labels = Agent_Publisher_Policy::mode_labels();
$help = array(
'drafts' => __( 'Agents create and edit their own drafts. A person reviews and publishes them.', 'acadium-agent-publisher' ),
'review' => __( 'Agents can also move their drafts to "Pending review" for an editor to publish.', 'acadium-agent-publisher' ),
'publish' => __( 'Agents can also publish and schedule their own posts after the checks below, and unpublish them again.', 'acadium-agent-publisher' ),
'publish_edit' => __( 'Agents can also change their own posts after they are live.', 'acadium-agent-publisher' ),
);
?>
' . esc_html__( 'Pretty permalinks are on. If the connection URL below returns "Not Found", your web server does not apply WordPress rewrite rules yet: see Settings > Permalinks.', 'acadium-agent-publisher' ) . '
';
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display-only flag after a nonce-checked redirect.
if ( isset( $_GET['agent-publisher-revoked'] ) ) {
echo '
' . esc_html__( 'Connection removed. The app can no longer access this site.', 'acadium-agent-publisher' ) . '