New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autologin code #4

Merged
merged 2 commits into from Oct 9, 2018
Jump to file or symbol
Failed to load files and symbols.
+53 −55
Diff settings

Always

Just for now

View
@@ -133,27 +133,17 @@ Enabling the **Cut and Paste Attribution** adds to the display a field with an a
## Author Account Setup
![](images/author-account-none.jpg)
To provide access to the media uploader, this site uses a Wordpress Authoring Role account that is logged into invisibly to your site. So your site needs a user account with a name of **sharer** and a role of **Author**. If this site is on a mulitsite Wordpress install, and the SPLOTBox has been used on another site, the `sharer` account already exists, so you need to add it to the site via the Author tools.
To provide access to the media uploader this site uses a Wordpress Authoring account that is logged into invisibly to your site visitors (for anyone logged in with an Editor or Administrator account, like you, this account is not used). So your site needs an active user with a name of **sharer** and a role of **Author**.
If this account does not exist, create it now. If it does, use the instructions below to generate a new password and then add it to the SPLOTbox Options.
If this account does not exist, create it now.
![](images/add-author.jpg)
You can follow the link to create an account; for an email you can use a fictitious one on your domain. We suggest using the strong password that Wordpress suggests. Copy that password, and perhaps save it in a safe place. Uncheck the box about sending the new user an email. This user never reads email.
On a stand-alone Wordpress install of the SPLOTbox, you can just paste it into the option for the password field for the Splotbox options (click the **Show** button to reveal the editing field).
![](images/author-add-multisite.jpg)
If this site is on a mulitsite Wordpress install and the SPLOTbox has been used on another internal site, the `sharer` account already exists. So you need to add it to the site via the Authoring tools. However, you still have to enter the password, so make sure you know the passord that was used on another site. If you do not have access to it, you will have to reset the password at the Network Admin level, and then update the password on the options of all sites using the SPLOTbox.
You can follow the link to create an account; for an email you can use a fictitious one on your domain. We suggest using the strong password that Wordpress suggests.
![](images/authoring-account.jpg)
When everything is set up correctly, the options will indicate that you have been a good options configurator!
If the account is incorrectly set up, when trying the SPLOTbox on a site where you are *not* logged in as an Administrator or Editor, when you try to access the collect form, you will see a Wordpress login. This nearly always means the password for the `sharer` user does not match the settings in the options.
** Note: As of version 0.9 of SPLOTBox you no longer need to copy the password into the options page. ** If you are using a version of the theme that has a password field in the options, maybe it's a good time to update?
## Customize the Share form
You can now customize the field labels and the descriptions of the form where people submit new items to a SPLOTbox site. On your site navigate to the share form, and activate the Wordpress Customizer from the admin bar.
@@ -342,14 +342,6 @@ public function get_settings() {
'std' => splotbox_author_user_check( 'sharer' ),
'type' => 'heading'
);
$this->settings['pkey'] = array(
'title' => __( 'Author Account Password' ),
'desc' => __( 'When you create the account, we suggest using the generated strong password, make sure you save it so you can add it here.' ),
'std' => '',
'type' => 'password',
'section' => 'general'
);
/* Reset
===========================================*/
View
@@ -286,30 +286,38 @@ function login_link( $url ) {
// Auto Login
// create a link that can automatically log in as a specific user, bypass login screen
// -- h/t http://www.wpexplorer.com/automatic-wordpress-login-php/
add_action( 'after_setup_theme', 'splotbox_autologin');
function splot_redirect_url() {
// where to send them after login ok
return ( site_url('/') . 'share' );
}
function splotbox_autologin() {
function splot_user_login( $user_login = 'sharer' ) {
// login the special user account to allow authoring
// check for the correct user
$autologin_user = get_user_by( 'login', $user_login );
// URL Paramter to check for to trigger login
if ( isset($_GET['autologin'] ) AND $_GET['autologin'] == 'sharer') {
if ( $autologin_user ) {
// ACCOUNT USERNAME TO LOGIN TO
$creds['user_login'] = 'sharer';
// just in case we have old cookies
wp_clear_auth_cookie();
// ACCOUNT PASSWORD TO USE- stored as option
$creds['user_password'] = splotbox_option('pkey');
$creds['remember'] = true;
$autologin_user = wp_signon( $creds, is_ssl() );
// set the user directly
wp_set_current_user( $autologin_user->id, $autologin_user->user_login );
if ( !is_wp_error($autologin_user) ) {
wp_redirect ( site_url() . '/share' );
} else {
die ('Bad news! login error: ' . $autologin_user->get_error_message() );
}
// new cookie
wp_set_auth_cookie( $autologin_user->id);
// do the login
do_action( 'wp_login', $autologin_user->user_login );
// send 'em on their way
wp_redirect( splot_redirect_url() );
} else {
// uh on, problem
die ('Bad news. Looks like there is a missing account for "' . $user_login . '".');
}
}
@@ -1096,7 +1104,7 @@ function splot_is_menu_location_used( $location = 'primary' ) {
function splot_default_menu() {
// site home with trailing slash
$splot_home = home_url('/');
$splot_home = site_url('/');
return ( '<li><a href="' . $splot_home . '">Home</a></li><li><a href="' . $splot_home . 'share' . '">Share</a></li><li><a href="' . $splot_home . 'random' . '">Random</a></li>' );
View
@@ -116,7 +116,7 @@
<div class="blog-logo">
<a class="logo" href='<?php echo esc_url( home_url( '/' ) ); ?>' title='<?php echo esc_attr( get_bloginfo( 'title' ) ); ?> &mdash; <?php echo esc_attr( get_bloginfo( 'description' ) ); ?>' rel='home'>
<a class="logo" href='<?php echo esc_url( site_url( '/' ) ); ?>' title='<?php echo esc_attr( get_bloginfo( 'title' ) ); ?> &mdash; <?php echo esc_attr( get_bloginfo( 'description' ) ); ?>' rel='home'>
<img src='<?php echo esc_url( get_theme_mod( 'garfunkel_logo' ) ); ?>' alt='<?php echo esc_attr( get_bloginfo( 'title' ) ); ?>'>
</a>
@@ -125,7 +125,7 @@
<?php elseif ( get_bloginfo( 'description' ) || get_bloginfo( 'title' ) ) : ?>
<h1 class="blog-title">
<a href="<?php echo esc_url( home_url() ); ?>" title="<?php echo esc_attr( get_bloginfo( 'title' ) ); ?> &mdash; <?php echo esc_attr( get_bloginfo( 'description' ) ); ?>" rel="home"><?php echo esc_attr( get_bloginfo( 'title' ) ); ?></a>
<a href="<?php echo esc_url( site_url() ); ?>" title="<?php echo esc_attr( get_bloginfo( 'title' ) ); ?> &mdash; <?php echo esc_attr( get_bloginfo( 'description' ) ); ?>" rel="home"><?php echo esc_attr( get_bloginfo( 'title' ) ); ?></a>
</h1>
<?php if ( get_bloginfo( 'description' ) ) : ?>
View
@@ -2,8 +2,10 @@
// ------------------------ defaults ------------------------
// default welcome message
$feedback_msg = '';
// defaultz
$feedback_msg = $log_out_warning = $wAccess = '';
$errors = array();
// the passcode to enter
$wAccessCode = splotbox_option('accesscode');
@@ -18,27 +20,27 @@
if ( current_user_can( 'edit_others_posts' ) ) {
// If user has edit/admin role, send them to the tool
wp_redirect ( home_url('/') . 'share' );
wp_redirect( splot_redirect_url() );
exit;
} else {
// if the correct user found, go directly to the tool
if ( splotbox_check_user() ) {
wp_redirect ( home_url('/') . 'share');
wp_redirect( splot_redirect_url() );
exit;
} else {
// we need to force a click through a logout
$log_out_warning = true;
$feedback_msg = 'First, please <a href="' . wp_logout_url( home_url('/') . 'share' ) . '">activate lasers</a>';
$feedback_msg = 'First, please <a href="' . wp_logout_url( site_url('/') . 'share' ) . '">activate lasers</a>';
}
}
} elseif ( $wAccessCode == '') {
// no code required, log 'em in
wp_redirect ( home_url() . '/wp-login.php?autologin=sharer' );
splot_user_login();
exit;
}
@@ -72,7 +74,7 @@
} else {
wp_redirect ( site_url() . '/wp-login.php?autologin=sharer' );
splot_user_login();
exit;
}
View
@@ -51,6 +51,7 @@
$wMediaType = url_is_media_type($wMediaURL);
$wCats = ( isset ($_POST['wCats'] ) ) ? $_POST['wCats'] : array();
$wLicense = $_POST['wLicense'];
if ( isset ($_POST['wAuthor'] ) ) $post_id = $_POST['post_id'];
// let's do some validation, store an error message for each problem found
$errors = array();
@@ -129,15 +130,20 @@
if ( splotbox_option('new_item_status') == 'publish' ) {
// feed back for published item
$feedback_msg = 'Your shared media item <strong>' . $wTitle . '</strong> has been published! You can <a href="'. site_url() . '/?p=' . $post_id . '">view it now</a>. Or you can <a href="' . site_url() . '/share">share another</a>.';
$feedback_msg = 'Your shared media item <strong>' . $wTitle . '</strong> has been published! You can <a href="'. get_permalink( $post_id ) . '">view it now</a>. Or you can <a href="' . site_url() . '">return to ' . get_bloginfo() . '</a>.';
// $feedback_msg = 'Your shared media item <strong>' . $wTitle . '</strong> has been published! You can <a href="'. site_url() . '/?p=' . $post_id . '">view it now</a>. Or you can <a href="' . site_url() . '/share">share another</a>.';
} else {
// feed back for item left in draft
$feedback_msg = 'Your shared media item <strong>' . $wTitle . '</strong> has been submitted as a draft. You can <a href="'. site_url() . '/?p=' . $post_id . '">preview it now</a>. Once it has been approved by a moderator, everyone else can see it.';
$feedback_msg = 'Your entry for <strong>' . $wTitle . '</strong> has been submitted as a draft. Once it has been approved by a moderator, everyone can see it at <a href="' . site_url() . '">return to ' . get_bloginfo() . '</a>.';
// $feedback_msg = 'Your shared media item <strong>' . $wTitle . '</strong> has been submitted as a draft. You can <a href="'. site_url() . '/?p=' . $post_id . '">preview it now</a>. Once it has been approved by a moderator, everyone else can see it.';
}
// logout the special user
if ( splotbox_check_user()=== true ) wp_logout();
if ( splotbox_option( 'notify' ) != '') {
// Let's do some EMAIL!
View
@@ -2,7 +2,7 @@
Theme Name: Splotbox
Theme URI: http://github.com/cogdog/splotbox
Description: SPLOT Media Collector (Child of Garfunkel)
Version: 0.8
Version: 0.9
Template: garfunkel
Author: CogDog
Author URI: http://cog.dog/
ProTip! Use n and p to navigate between commits in a pull request.