Eric Mann
Forum Replies Created
-
Forum: Everything else WordPress
In reply to: Different User Levels on RegistrationIt seems lately that I’m the only one ever to solve my problems … but if you find any of this useful, please let me know!
I was able to set up Premium registration by modifying the wp-login.php and registration.php files slightly.
In wp-login.php I had to copy the function “register_new_user” to define the function “register_premium_user.” From there, I changed:
$user_id = wp_create_user( $user_login, $user_pass, $user_email );To
$capa='contributor'; $user_id = wp_create_user( $user_login, $user_pass, $user_email, $capa );This sent the appropriate user level to the registration scripts. In order to call this function, though, I also had to copy the case “register” and create a new case “premregister.” Premium users can register by pointing to ‘wp-login.php?action=premregister’.
Next I had to change the line:
$errors = register_new_user($user_login, $user_email);To
$errors = register_premium_user($user_login, $user_email);And a little further down, I had to change:
<form name="registerform" id="registerform" action="wp-login.php?action=register" method="post">To
<form name="registerform" id="registerform" action="wp-login.php?action=premregister" method="post">Now we have premium users being directed to the correct registration page and being recognized as premium users. The final changes are in the registration.php file.
At the very bottom is the function “wp_create_user.” I had to change it a little bit to recognize my new value and send it on to the function “wp_insert_user” by changing this:
function wp_create_user($username, $password, $email = '') { global $wpdb; $user_login = $wpdb->escape($username); $user_email = $wpdb->escape($email); $user_pass = $password; $userdata = compact('user_login', 'user_email', 'user_pass'); return wp_insert_user($userdata); }To this:
function wp_create_user($username, $password, $email = '', $capable = '') { global $wpdb; $user_login = $wpdb->escape($username); $user_email = $wpdb->escape($email); $user_pass = $password; $role = $wpdb->escape($capable); $userdata = compact('user_login', 'user_email', 'user_pass', 'role'); return wp_insert_user($userdata); }The empty ” after my $capable variable make it optional, so this addition won’t affect any other part of WP’s operation.
Unfortunately, WP only writes user roles on updates, not creation, so it takes one last bit of modification to make this all work. Scroll back up to the “wp_insert_user” function and change this:
if ( $update && isset($role) ) { $user = new WP_User($user_id); $user->set_role($role); } if ( !$update ) ) { $user = new WP_User($user_id); $user->set_role(get_option('default_role')); }To this:
if ( $update && isset($role) ) { $user = new WP_User($user_id); $user->set_role($role); } if ( !$update && isset($role) ) { $user = new WP_User($user_id); $user->set_role($role); } else { $user = new WP_User($user_id); $user->set_role(get_option('default_role')); }Now, anyone who registers through wp-login.php?action=register will appear as a regular subscriber. Anyone who instead uses wp-login?action=premregister will appear as a contributor (merely for user level 1, it doesn’t matter what you call them so long as you stay consistent).
It took me 2 days to figure this out, let me know if it saves you some headache!
Forum: Plugins
In reply to: Premium ContentI ended up having to write my own script, actually. On the main site page (index.php) I just swapped out the part of the loop referring to “the_content” with “the_excerpt”:
<div class="post-content"> <?php the_content(); ?> </div>Becomes
<div class="post-content"> <?php the_excerpt(); ?> </div>Then I changed the post page (single.php) so that, for the first 30 days a post is up, everyone can see it. After 30 days, you need to be registered and logged in (authenticated) to see anything but the excerpt:
<div class="post-content"> <?php the_content(); ?> </div>Becomes:
<div class="post-content"> <?php global $user_ID; get_currentuserinfo(); ?> <?php $today=date(z); ?> <?php $postday=the_date('z', '', '', FALSE); ?> <?php if($today - 30 > $postday && $user_ID == '') { echo '<p style="font-size: 36px;"><center><a href="<?php bloginfo('url'); ?>/wp-login.php?action=register">Please Register!</a></center></p>'; echo '<p style="font-size: 11px; font-family: Arial, Helvetica, sans-serif;">You must be a registered user to view this post. Until you complete your registration, you will only be able to view an excerpt:</p>'; the_excerpt(); } else { the_content(); } ?> <!--<?php the_content(); ?>--> </div>I hope that helps!
Forum: Fixing WordPress
In reply to: Post PreviewProblem solved!
My site is linked to a subdomain, but hosted in a specific folder. When I upgraded to WP 2.1, I had problems with this setup – namely telling WP where my files were located. It crashed unless I told it both the folder (http://randomstring.host.net/blog) and where people accessed my site (http://mysite.mydomain.com).
When I upgraded to WP 2.3 (and later to 2.5), this caused problems. The “Preview” link took me to a site like http://mysite.mydomain.com/?…preview=true. Since WP thought my blog was at a different address, though, I could never see my posts.
Changing everything to JUST reference http://mysite.mydomain.com fixed the problem. Now, I can preview posts. I can also view my page when I’m logged in and it’s under Maintenance Mode.
Forum: Fixing WordPress
In reply to: Upgrade Caused Problems!I had to change the Blog URL to mindshare.eamann.com, but leave the WordPress URL as a link to the actual directory. Now everything works perfectly!
Forum: Installing WordPress
In reply to: Upgrade FailureI had to change the Blog URL to mindshare.eamann.com, but leave the WordPress URL as a link to the actual directory. Now everything works perfectly!
Forum: Fixing WordPress
In reply to: Visual – Code Tabs Missing!I figured it out! On the user profile page there is a radio button activating a “visual editing mode.” I must have accidentally deactivated it!