Support

Account

Home Forums Add-ons Options Page Add custom message to option page Reply To: Add custom message to option page

  • Actually, it’s still more complicated than all that. It changes based on the parent page’s “redirect” setting. If that parameter is “true”, it treats the first subpage as the top-level page, so then the first subpage’s hook name will be “toplevel_page_acf-options-{$subpage_slug_built_from_sanitized_title}”, where “toplevel” is the actual literal value. Subsequent subpages’ hook names will be “{$parent_slug}_page_acf-options-{$subpage_slug_built_from_sanitized_title}”.

    So for example, using this code:

    if ( function_exists( 'acf_add_options_page' ) ) {
    	
    	acf_add_options_page( [
    		'page_title' 	=> 'Permalink Manager Transfer',
    		'menu_title'	=> 'Permalink Manager Transfer',
    		'menu_slug' 	=> 'permalink-manager-transfer',
    		'redirect'      => true
    	] );
    	
    	acf_add_options_sub_page( [
    		'page_title' 	=> 'Permalink Manager Transfer - Import',
    		'menu_title'	=> 'Import',
    		'parent_slug'	=> 'permalink-manager-transfer',
    	] );
    	
    	acf_add_options_sub_page( [
    		'page_title' 	=> 'Permalink Manager Transfer - Export',
    		'menu_title'	=> 'Export',
    		'parent_slug'	=> 'permalink-manager-transfer',
    	] );
    	
    }
    
    add_action( 'toplevel_page_permalink-manager-transfer', function() { 
    	echo "<br>toplevel_page_permalink-manager-transfer<br>"; 
    } );
    
    add_action( 'toplevel_page_acf-options-import', function() { 
    	echo "<br>toplevel_page_acf-options-import<br>"; 
    } );
    
    add_action( 'toplevel_page_acf-options-export', function() { 
    	echo "<br>toplevel_page_acf-options-export<br>"; 
    } );
    
    add_action( 'permalink-manager-transfer_page_acf-options-import', function() { 
    	echo "<br>permalink-manager-transfer_page_acf-options-import<br>"; 
    } );
    
    add_action( 'permalink-manager-transfer_page_acf-options-export', function() { 
    	echo "<br>permalink-manager-transfer_page_acf-options-export<br>"; 
    } );

    …with the parent menu’s “redirect” setting = true, you will see this output when clicking on the parent, import, and export options:

    toplevel_page_acf-options-import
    toplevel_page_acf-options-import
    permalink-manager-transfer_page_acf-options-export

    …and with the parent menu’s “redirect” setting = false, you will see this:

    permalink-manager-transfer_page_acf-options-import
    permalink-manager-transfer_page_acf-options-import
    permalink-manager-transfer_page_acf-options-export

    Also, as of Pro version 5.12.2, if the redirect setting is false, it replicates the top level menu selection and adds it as the first submenu item, so that you are able to use both of them to get to the parent page. For this example, that means that even though you only created two submenus, three are displayed.

    All in all, it’s not a very good way to run a railroad.