• Hello

    I am a bit new with WordPress but I am very new in developpement.
    I followed a tutorial in order to add a panel in the Dashboard.
    (I installed a new instence of Word press)

    I added a menu name “My Panel” because of the following code.
    I created a file name “wp-content/themes/twentyseventeen/my_panel.php” and I pasted the following code

    <?php
    add_action('admin_menu', 'my_pannel');
    
    function my_pannel(){
    	//add_menu_page('My Profile','My profile', 'author', 'my-profile','render_profile', NULL, 81);
    	add_menu_page('My pannel','My pannel', 'activate_plugins', 'my-pannel','render_pannel', NULL, 6);
    }
    
    function render_pannel(){
    	if(!empty($_POST)){
    		var_dump($_POST);
    	}
    	?>
    	<div class="wrap theme-options-page">
    		<div id="icon-options-general" class="icon32"><br></div>
    		<h2>Welcome to your profile</h2>
    		<quote>To update your profile, go to Profile</quote>
    
    		<form action="" method="post">
    			<div class="theme-options-group">
    
    				<table cellspacing="0" class="widefat options-table">
    					<thead>
    						<tr>
    							<th colspan="2">
    								Education
    							</th>
    						</tr>
    					</thead>
    					<tbody>
    						<tr>
    							<th>
    								From
    							</th>
    							<td>
    								<input type="text" name="from">
    							</td>
    						</tr>
    						<tr>
    							<th>
    								Util
    							</th>
    							<td>
    								<input type="text" name="until">
    							</td>
    						</tr>
    						<tr>
    							<th>
    								Institut
    							</th>
    							<td>
    								<input type="text" name="institut">
    							</td>
    						</tr>
    					</tbody>
    				</table>
    			</div>
    			<p class="submit">
    				<input type="submit" name="send_education" class="button-primary autowidth" value="save">
    			</p>
    		</form>
    
    	</div>
    	<?php
    }

    That work fine, because now I have a men My Panel below Posts.

    My question is hjwo to create now a submenu ‘education’. For exemple

    My Panel
    — education
    — researches
    — projects

    That means that the above code will move to education section and not My Panel section as it is now.

    many thank

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter pierrot10

    (@pierrot10)

    The answer is here
    add_submenu_page('my-panel', 'Education','Education','activate_plugins', 'my-education','render_education');

    Moderator bcworkz

    (@bcworkz)

    I’m glad you were able to answer your own question!

    I wanted to add for general information that you shouldn’t add custom code to twentyseventeen theme or any other theme or plugin that is subject to updates. Updates will remove any changes you made. To keep your work safe, either create a child theme or custom plugin. Child themes tend to be preferred for some reason, but then your code is tied to a specific parent plugin.

    A custom plugin will allow your code to persist regardless of which theme you might decide to use in the future.

    Thread Starter pierrot10

    (@pierrot10)

    Hello, thank for your advise.
    I duplicated the theme twentyseventeen theme and I am using the duplicated one.
    But what do you means by child theme?
    I would prefere to work with a child than a duplicated them, but it’s also fine if I continue with the duplicated…. :).

    May I ask you a short different question? I would like to get the ID of the authentifed user. Is there a short cut for that? Later I will need it to get the profile from a separate table. I was used to use CakePHP but now I want to migrate to WP keeping the same DB.

    Thank, Cheers
    Pierre

    Moderator bcworkz

    (@bcworkz)

    Child Themes
    I think you realize that duplicating a theme is sub-optimal because you can miss out on important theme updates, or at least updates can be difficult to port over to your copy, depending on how extensive your changes are.

    Current user ID is available as wp_get_current_user()->ID.

    Other than the fact you need custom code to access a foreign table, I don’t see any problems with a profile table that supplements the usual WP tables.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to have submenu in admin panel’ is closed to new replies.