I'm creating a plugin to auto delete post/event. I created a WP settings page to manage the default settings for auto delete.
I followed each step to register_setting
, add_settings_field
and add_settings_section
for the $callback function.
After that I call settings_fields
, do_settings_sections
and `submit_button' inside this $callback
My settings_fields must be a checkbox, so I use the wp checked
function inside input to check data value stored into wp_options.
All display correctly without do_settings_sections
use. As soon as use this function I get this error "memory size exhausted" and the html part replicates itself indefinitely.
Finally, the checked attribute is not registered
I can't find my mistake:
Add to menu :
function stm_addmenu_auto_delete_event() {
add_menu_page(
'Automatic deletion',
'Automatic <br/> deletion',
'manage_options',
'manage-auto-delete-page',
'auto_delete_settings_callback',
'dashicons-fas fa-trash',
21
);
}
add_action( 'admin_menu', 'stm_addmenu_auto_delete_event','manage_options');
add settings to page:
function new_settings_auto_delete() {
add_settings_section(
'default_auto_delete_section',
'Manage the automatic deletion of posts',
'',
'manage-auto-delete-page'
);
register_setting(
'manage-auto-delete-page',
'default_auto_delete_field',
array(
'type' => 'string',
'sanitize_callback' =>'sanitize_text_field',
'default' => ''
)
);
add_settings_field(
'default_auto_delete_field',
'By default activate automatic deletion',
'auto_delete_settings_callback',
'manage-auto-delete-page',
'default_auto_delete_section'
);
}
add_action( 'admin_init', 'new_settings_auto_delete' );
the callback function :
<?php
function auto_delete_settings_callback(){
$option_auto_delete = get_option('default_auto_delete_field');
?>
<stmwrapper>
<form action="options.php" method="post" id="stm_auto_delete_manager_form_style">
<?php
do_settings_sections('manage-auto-delete-page');
?>
<div id="stm_auto_delete_manager_container">
<property class="default_activation">
<!--<span>By default activate automatic deletion</span>-->
<?php settings_fields('manage-auto-delete-page'); ?>
<input class="default_auto_deletion_toggle" type="checkbox" id="default_auto_deletion_toggle" name="default_auto_delete_field" value="" <?php checked( '1', $option_auto_delete); ?>>
<label class="slider-btn" for="default_auto_deletion_toggle">
<span class="off">Non</span>
<span class="on">Oui</span>
</label>
</property>
<?php
submit_button( 'Save' );
?>
</div>
</form>
</stmwrapper>
<?php
}
config.php
with something like this:define( 'WP_MAX_MEMORY_LIMIT', '512M' );
add_option_page()
insteadadd_menu_page()
?. What I would like to know is which function is used to add the option to the wp_options table in the database.