I would like to initiate class setting_management to inside class ckasBlog h1 heading and submit button showing. But settings_fields(‘custom-settings-group’); and do_settings_sections(‘custom-settings’); are not showing. various way i was try fix this but this is not showing, how to fix this issue. please help me.
class ckasBlog {
private $setting_instance;
public function __construct() {
add_action('admin_menu', [$this, 'custom_settings_menu']);
}
public function custom_settings_menu() {
add_options_page(
'Custom Settings', // Page title
'Custom', // Menu title
'manage_options', // Capability required to access
'custom-settings', // Menu slug
[$this, 'custom_settings_page'] // Callback function to render the page
);
}
public function custom_settings_page() {
$this->setting_instance = new setting_management();
$this->setting_instance->render_settings_page();
}
}
new ckasBlog();
class setting_management {
public function __construct() {
add_action('admin_init', [$this, 'custom_settings_init']);
}
// Register settings and fields
public function custom_settings_init() {
register_setting(
'custom-settings-group', // Option group
'custom_option_name', // Option name
[$this, 'sanitize_callback'] // Sanitization callback function
);
add_settings_section(
'custom-settings-section', // ID
'Custom Settings Section', // Title
[$this, 'section_callback'], // Callback function to render the section
'custom-settings' // Page slug
);
add_settings_field(
'custom-field-id', // ID
'Custom Field', // Title
[$this, 'field_callback'], // Callback function to render the field
'custom-settings', // Page slug
'custom-settings-section' // Section ID
);
}
// Render the settings page
public function render_settings_page() {
?>
<div class="wrap">
<h2>Custom Settings</h2>
<form method="post" action="options.php">
<?php
// Output security fields
settings_fields('custom-settings-group');
// Output setting sections
do_settings_sections('custom-settings');
// Submit button
submit_button();
?>
</form>
</div>
<?php
}
// Sanitization callback
public function sanitize_callback($input) {
// Sanitize input here as needed
return $input;
}
// Section callback
public function section_callback() {
// Optional: Section description or instructions
echo '<p>Section description goes here.</p>';
}
// Field callback
public function field_callback() {
// Render field HTML here
$value = get_option('custom_option_name');
echo '<input type="text" id="custom_field_id" name="custom_option_name" value="' . esc_attr($value) . '" />';
}
}
I would like to display setting_management class functionality inside into ckasBlog class. How to do it?