我第一次添加了wordpress仪表板小部件。我正在创建一个简单的表单,让用户能够直接从wp仪表板发送支持请求。我不确定所有代码是否都正常工作,在测试期间,我注意到表单不会提交邮件消息。有人能帮我吗?
function uptheme_support_dashboard_widgets()
{
global $wp_meta_boxes;
wp_add_dashboard_widget(\'custom_help_widget\', \'Premium Ticket System\', \'custom_dashboard_help\');
}
function custom_dashboard_help()
{
$current_theme = wp_get_theme( \'uptheme-panel\' );
?>
<p><?php _e(\'Hi! you are using the custom theme \'. esc_html($current_theme) ); ?></p>
<p><?php _e(\'Use the form to request support for your theme.\'); ?></p>
<form method="POST">
<p><?php _e(\'Email\'); ?></p>
<input type="text" class="widefat" name="email" id="email" placeholder="" />
<p><?php _e(\'Request type\'); ?></p>
<select name="support_ticket_type">
<option value=""><?php _e(\'Support request\'); ?></option>
<option value=""><?php _e(\'Modification request\'); ?></option>
</select>
<p><?php _e(\'Message\'); ?></p>
<textarea class="widefat" name="support_message"></textarea>
<input type="hidden" name="action" value="submit_support_ticket">
<?php wp_nonce_field( \'submit_support_ticket\', \'support_ticket_hash\' ); ?>
<button class="btn-primary" type="submit" class=""><?php _e(\'Invia\'); ?></button>
</form>
<small><?php _e(\'Theme powered by\'); ?><a href="#"><?php _e(\'theme author\'); ?></a></small>
<?php
}
add_action(\'wp_dashboard_setup\', \'uptheme_support_dashboard_widgets\');
function _submit_support_ticket()
{
if( isset($_POST[\'support_ticket_hash\']) || ! wp_verify_nonce( $_POST[\'support_ticket_hash\'], \'submit_support_ticket\' ) ){
//echo \'\';
exit;
}
$email = $_POST[\'email\'];
$subject = $_POST[\'support_ticket_type\'];
$message = $_POST[\'support_message\'];
$to = \'mymail@provider.com\';
$headers[] = "From: <$email>";
wp_mail( $to, $subject, $message, $headers );
}
add_action( \'admin_post_submit_support_ticket\', \'_submit_support_ticket\' );