当前位置:万花网 > Wordpress建站 > 正文

wordpress前端会员投稿需要用到的变量!

摘要:我收集了一些大家在制作前端投稿需要用到的资源,需要的童鞋拿走吧!
本文最后更新于【 2019-05-08 12:34:05 】,某些文章具有时效性,若有错误或已失效,请在下方 留言 或联系 小P君

投稿时间需要间隔100秒

//可自行修改100秒的时间间隔
 if ( current_time('timestamp') - strtotime($last_post) < 100 )
{
wp_die('需要间隔100s才能继续投稿哦!');
}

表单变量初始化

$name = isset( $_POST['tougao_authorname'] ) ? trim(htmlspecialchars($_POST['tougao_authorname'], ENT_QUOTES)) : '';
$email = isset( $_POST['tougao_authoremail'] ) ? trim(htmlspecialchars($_POST['tougao_authoremail'], ENT_QUOTES)) : '';
$blog = isset( $_POST['tougao_authorblog'] ) ? trim(htmlspecialchars($_POST['tougao_authorblog'], ENT_QUOTES)) : '';
$title = isset( $_POST['tougao_title'] ) ? trim(htmlspecialchars($_POST['tougao_title'], ENT_QUOTES)) : '';
$category = isset( $_POST['cat'] ) ? (int)$_POST['cat'] : 0;
$content = isset( $_POST['tougao_content'] ) ? trim(htmlspecialchars($_POST['tougao_content'], ENT_QUOTES)) : '';

假如需要加入表单验证

昵称必须填写,E-mail必须填写;并限制长度

if ( empty($name) || mb_strlen($name) > 20 )
{
wp_die('昵称必须填写,长度不得超过20字');
}
if ( empty($email) || strlen($email) > 60 || !preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email))
{
wp_die('Email必须填写,长度不得超过60字,必须符合Email格式');
}

标题和内容,同理,并限制长度

 if ( empty($title) || mb_strlen($title) > 50 )
{
wp_die('标题必须填写,且长度不得超过50字');
}

if ( empty($content) || mb_strlen($content) > 3500 || mb_strlen($content) < 100)
{
wp_die('内容必须填写,且长度不得超过3500字,不得少于100字');
}

将文章插入数据库

$status = wp_insert_post( $tougao );

 

 

wxgzhewm

扫码关注万花网公众号

汇集全网优质电商资源,薅羊毛资源,PS,AI资源,应有尽有。

作者保留所有权,侵删请联系,转载请注明: » 万花网 » wordpress前端会员投稿需要用到的变量!

感觉很棒!可以赞赏支持我哟~

赞(0) 打赏

低至¥89元/年限时抢

抢阿里云服务器1折起代金券

立即抢购

评论1

  1. #1

    个人博客很少用到投稿,真要投稿可以考虑邮件投稿或者开放注册。

    奶爸de笔记5年前 (2019-05-08)