分享笔记:

仪表盘添加快速联系管理员表单

快速联系网站开发

通过这个方法你可以在WordPress网站的桌面上添加一个联系网站开发员的表单,和它沟通任何你遇到的问题。这个方法只适合老外客户,他们大多数交流工作相关的还是喜欢用邮件的。如果是国人就算了,因为遇到任何问题,分分钟微信轰炸你 XD

当然你的网站也得有一个比你懂的人在管理或维护站点,不然你打算发给谁???

wordpress添加联系开发者表单

添加开发者联系表单自定义代码

添加以下一小段代码即可,不需要做其他的任何内容了。另外你得确保你的网站可以发邮件,不然你得连上SMTP服务。否则不管你发多少次,都收不到邮件的。

一定要记得把代码里的接收邮箱换掉!!!

/* 联系开发表单组件 */
// 添加组件到仪表盘
function support_dashboard_widget() {
wp_add_dashboard_widget('support_widget', '任何问题可通过此表单联系', 'render_support_widget');
}
add_action('wp_dashboard_setup', 'support_dashboard_widget');
// Procesamos el widget
function render_support_widget() {
$sitio_actual = get_site_url();
?>
<form method="post" enctype="multipart/form-data">
<p>
<label for="support_subject">事件:</label>
<input type="text" name="support_subject" id="support_subject" class="widefat" required>
</p>
<p>
<label for="support_description">描述:</label>
<textarea name="support_description" id="support_description" class="widefat" rows="4" required></textarea>
</p>
<p>
可上传问题截图
</p>
<p>
<label for="support_archive">上传文件:</label>
<input type="file" name="support_archive" id="support_archive" class="widefat">
</p>
<input type="hidden" name="soporte_sitio" value="<?php echo esc_attr($sitio_actual); ?>">
<p>
<input type="submit" name="soporte_enviar" class="button button-primary" value="发送">
</p>
</form>
<?php
if (isset($_POST['soporte_enviar'])) {
soporte_enviar_email();
}
}
// Envio del correo
function soporte_enviar_email() {
if (!isset($_POST['support_subject']) || !isset($_POST['support_description'])) {
return;
}
$asunto = sanitize_text_field($_POST['support_subject']);
$descripcion = sanitize_textarea_field($_POST['support_description']);
$email_admin = '[email protected]'; //这里写接收求助的邮箱
$sitio = sanitize_text_field($_POST['soporte_sitio']);
$mensaje = "事件: $asunto\n\n描述:\n$descripcion\n\n发送于: $sitio";
$headers = ['Content-Type: text/plain; charset=UTF-8'];
$adjunto = '';
if (!empty($_FILES['support_archive']['tmp_name'])) {
$uploaded_file = wp_handle_upload($_FILES['support_archive'], ['test_form' => false]);
if (isset($uploaded_file['file'])) {
$adjunto = $uploaded_file['file'];
}
}
wp_mail($email_admin, '网站疑问求助: ' . $asunto, $mensaje, $headers, $adjunto ? [$adjunto] : []);
echo '<p style="color: green;">邮件发送成功</p>';
}

添加代码后,你的网站仪表盘就会多一个叫 “任何问题可通过此表单联系” 的组件。没有的话,点击右上角 “显示选项” 打开即可。

wordpress添加联系开发者表单

收到的邮件是下面这样的:

wordpress添加联系开发者表单

为笔记评分

平均评分 5 / 5. 摘星者: 2

有疑问?留个言吧!

更多结果...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
?>

更多结果...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors