the function do_settings_section($page) generate error “Allowed memory size of … bytes exhausted”

You seem to be creating a recursive loop.

In stm_addmenu_auto_delete_event(), you register an admin page via add_menu_page() that has a callback of auto_delete_settings_callback:

function stm_addmenu_auto_delete_event() {
  add_menu_page(
    'Automatic deletion',
    'Automatic <br/> deletion',
    'manage_options',
    'manage-auto-delete-page',
    'auto_delete_settings_callback',

In new_settings_auto_delete you register a settings field with a callback of auto_delete_settings_callback:

function new_settings_auto_delete() {
  // …

  add_settings_field(  
    'default_auto_delete_field',
    'By default activate automatic deletion',
    'auto_delete_settings_callback',
    'manage-auto-delete-page',

Thus, when you navigate to the Automatic deletion page you registered in stm_addmenu_auto_delete_event():

  1. auto_delete_settings_callback() is called.
  2. In auto_delete_settings_callback(), do_settings_sections('manage-auto-delete-page'); is executed.
  3. WordPress finds settings fields registered to 'manage-auto-delete-page'.
  4. default_auto_delete_field is found, with a registered callback of auto_delete_settings_callback.
  5. We loop back to step 1 recursively, until the server runs out of memory.

It seems you may have meant to register a different callback for either the add_menu_page() call or the add_settings_field() call.

tech