I have created dashboard widget fields for the admin and editor role to add tracking code to the website from the dashboard. This works for the admin, but the editor can see the fields but cannot submit them, as I have removed their access to visit the options.php page.
How can I apply the below code to the editor user, without having to reinstate their access to the options.php page.
// Custom Dashboard Widget
add_action('wp_dashboard_setup', 'custom_dashboard_widget_contact_details');
function custom_dashboard_widget_contact_details(){
if( current_user_can('editor') || current_user_can('administrator') )
{
wp_add_dashboard_widget('custom_contact_widget', 'Contact Details', 'custom_dashboard_contact');
}
}
// Display Form
if(!function_exists('custom_dashboard_contact')) {
function custom_dashboard_contact() { ?>
<div class="wrap">
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<table>
<tr>
<th scope="row" width="120" align="left" valign="top">Google Analytics</th>
<td>
<input type="text" name="analytics" size="500" value='<?php echo get_option('analytics');?>' style="width:100%" />
</td>
</tr>
<tr>
<th scope="row" width="120" align="left" valign="top">Facebook Pixel</th>
<td>
<input type="text" name="faceb" size="500" value='<?php echo get_option('faceb');?>' style="width:100%" />
</td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="analytics" value="faceb, email_address" />
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php }
}
Aucun commentaire:
Enregistrer un commentaire