option_name, [ $this, 'sanitize_settings' ] );
add_settings_section(
'agentmark_main_section',
__( 'General Settings', 'agentmark' ),
null,
'agentmark'
);
add_settings_field(
'enabled_post_types',
__( 'Enabled Post Types', 'agentmark' ),
[ $this, 'render_post_types_field' ],
'agentmark',
'agentmark_main_section'
);
add_settings_field(
'enable_front_matter',
__( 'Enable YAML Front Matter', 'agentmark' ),
[ $this, 'render_checkbox_field' ],
'agentmark',
'agentmark_main_section',
[ 'label_for' => 'enable_front_matter' ]
);
add_settings_field(
'enable_llms_txt',
__( 'Enable llms.txt', 'agentmark' ),
[ $this, 'render_checkbox_field' ],
'agentmark',
'agentmark_main_section',
[ 'label_for' => 'enable_llms_txt' ]
);
add_settings_field(
'site_description',
__( 'Site Description (for llms.txt)', 'agentmark' ),
[ $this, 'render_text_field' ],
'agentmark',
'agentmark_main_section',
[ 'label_for' => 'site_description' ]
);
add_settings_field(
'ai_guidelines',
__( 'AI Guidelines (for llms.txt)', 'agentmark' ),
[ $this, 'render_text_field' ],
'agentmark',
'agentmark_main_section',
[ 'label_for' => 'ai_guidelines' ]
);
}
public function render_post_types_field() {
$options = $this->get_options();
$enabled = isset( $options['enabled_post_types'] ) ? $options['enabled_post_types'] : [ 'post', 'page' ];
$post_types = get_post_types( [ 'public' => true ], 'objects' );
foreach ( $post_types as $type ) {
if ( in_array( $type->name, [ 'attachment' ] ) ) continue;
printf(
'
',
esc_attr( $this->option_name ),
esc_attr( $type->name ),
checked( in_array( $type->name, $enabled ), true, false ),
esc_html( $type->label )
);
}
}
public function render_checkbox_field( $args ) {
$options = $this->get_options();
$id = $args['label_for'];
$value = isset( $options[$id] ) ? $options[$id] : false;
printf(
'',
esc_attr( $id ),
esc_attr( $this->option_name ),
esc_attr( $id ),
checked( $value, 1, false )
);
}
public function render_text_field( $args ) {
$options = $this->get_options();
$id = $args['label_for'];
$value = isset( $options[$id] ) ? $options[$id] : '';
printf(
'',
esc_attr( $id ),
esc_attr( $this->option_name ),
esc_attr( $id ),
esc_textarea( $value )
);
}
public function render_main_page() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'agentmark' ) );
}
$active_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'settings'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading tab for UI display only.
?>