前端注册/登录和发布/更新1个定制帖子

时间:2012-07-03 作者:Rob

我希望能够允许用户register/login via a front end form 并且能够create 1 custom post 只有他们才能做到edit and update via a front end form.

这将是“仪表板”的一部分。

It\'s very important that this works with the http://www.advancedcustomfield.com plugin.

通过使用ACF的前端表单,我成功地实现了一些目标。这允许编辑和更新自定义帖子。

问题在于:

没有前端注册/登录

If anyone could point me in the right direction with those issues or has any creative ways to get around them then that would be great. I need to do this without using lot\'s of other plugins.

UPDATE:

我发现这将允许我通过前端表单创建新帖子。使用action 我想我可以将用户重定向到他们刚刚创建的自定义帖子。因此,这将允许他们通过下面的第二个代码框更新/编辑帖子。

So all that I need to do is the user registration/login!

<?php $postTitle = $_POST[\'post_title\'];
$post = $_POST[\'post\'];
$submit = $_POST[\'submit\'];

if(isset($submit)){

    global $user_ID;

    $new_post = array(
        \'post_title\' => $postTitle,
        \'post_content\' => $post,
        \'post_status\' => \'publish\',
        \'post_date\' => date(\'Y-m-d H:i:s\'),
        \'post_author\' => $user_ID,
        \'post_type\' => \'post\',
        \'post_category\' => array(0)
    );

    wp_insert_post($new_post);

}

?>
<!DOCTYPE HTML SYSTEM>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled Document</title>
</head>

<body>
<div id="wrap">
<form action="" method="post">
<table border="1" width="200">
  <tr>
    <td><label for="post_title">Post Title</label></td>
    <td><input name="post_title" type="text" /></td>
  </tr>
  <tr>
    <td><label for="post">Post</label></td>
    <td><input name="post" type="text" /></td>
  </tr>
</table>

<input name="submit" type="submit" value="submit" />
</form>
</div>

</body>
</html>
下面的代码允许用户编辑/更新他们刚刚创建的帖子。

<?php
/**
 * @package WordPress
 * @subpackage Default_Theme
 * Template Name: Login
 */
acf_form_head();
get_header(); ?>

    <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>

<div style="width:719px;">
<?php global $current_user;
get_currentuserinfo();
$page_name = $current_user->user_login; ?>
Logged in as: <?php echo $page_name; ?> (<?php echo $current_user->ID; ?>)
<br />
List posts by <?php echo $page_name; ?>:

<?php               
$loop = new WP_Query( array(
    \'post_type\' => \'page\',
    \'author\' => $current_user->ID
));

while ( $loop->have_posts() ) : $loop->the_post(); 
the_title();
echo "<br>";
endwhile;

//Reset Query
wp_reset_query();

?>

<?php $defaults = array(
    \'post_id\' => $post->ID, // post id to get field groups from and save data to
    \'field_groups\' => array(), // this will find the field groups for this post (post ID\'s of the acf post objects)
    \'form_attributes\' => array( // attributes will be added to the form element
        \'class\' => \'\'
    ),
    \'return\' => add_query_arg( \'updated\', \'true\', get_permalink() ), // return url
    \'html_field_open\' => \'<div class="field">\', // field wrapper open
    \'html_field_close\' => \'</div>\', // field wrapper close
    \'html_before_fields\' => \'\', // html inside form before fields
    \'html_after_fields\' => \'\', // html inside form after fields
    \'submit_value\' => \'Update\', // value for submit field
    \'updated_message\' => \'Post updated.\', // default updated message. Can be false to show no message
);

acf_form(); ?>
</div>

        <?php endwhile; ?>
    <?php endif; ?>

<?php get_footer(); ?>

4 个回复
SO网友:Aleks

WP用户前端插件将满足您的所有需求。您可以在此处找到插件:https://wordpress.org/extend/plugins/wp-user-frontend/.该插件允许用户从站点前端创建新帖子、编辑帖子、编辑个人资料。因此,用户无需进入管理面板。他们需要做的一切都可以从前端完成。

如果你在谷歌上做一个小搜索,你会遇到许多其他类似功能的插件。我相信WP用户前端将最能满足您的需求。

SO网友:Logen

由于您已经解决了编辑问题,因此要解决您的前端登录和注册使用s2member plugin. 我在我的网站上使用它来处理成员身份,并阻止成员访问Wordpress的后端。

SO网友:brasofilo

仅用于在前端管理用户注册和登录,Theme My Login 做得很好。

该插件根据您当前的主题设置WordPress登录、注册和忘记密码页面的主题。它创建一个页面来代替wp登录。php,使用主题中的页面模板。还包括用于侧栏登录的小部件。

插件页面没有屏幕截图,所以它们在这里:
enter image description here

在这里,您可以将用户重定向到使用Template Name: Login:
enter image description here

SO网友:Adj

我正在使用wp members插件进行用户注册和登录,无需访问Wordpress后端。不过,您需要一些自定义代码来重置密码。我正在使用this solution.

感谢允许用户创建新帖子的代码!

结束

相关推荐

使用GET_USERS获取多个角色

我有一些这样的代码: $query_args = array(); $query_args[\'fields\'] = array( \'ID\', \'display_name\' ); $query_args[\'role\'] = \'subscriber\'; $users = get_users( $query_args ); foreach ($users as $user) $users_array[$user->ID] = $user->