Forums

[resolved] Workaround p2 theme to allow non-register users (everyone) to post (1 post)

  1. mobot123
    Member
    Posted 10 months ago #

    Some of the admin look for method to customize p2 theme, example like change text string on front-page post box, allow everyone to post without login. This is just to share some of the workaround to enable the possibility of doing that... At the same time, to document what I found, so, in future I might need it for myself. :)

    1. First of all, I assume p2 theme installed and apply. Make sure "Theme Options" -> "Allow any registered member to post" checked.

    2. You are on your admin account, go to users to see all the users available. Create a dummy/anonymous user (you need this account, as the workaround/hack will make all users auto-login with this user account, or by default if you not sign-in, you are on this account. You need this as wordpress gonna know who post it, eventually)

    3. Find out user ID for dummy/anonymous account. After you created anonymous/dummy account, refresh users page, it will appear, just put your mouse stop at the anonymous/dummy username, it will appear the URL something like this: "wp-admin/user-edit.php?user_id=2&wp_http_referer=%"
    the user_id=2 where the 2 is the user ID and you gonna need this!

    4. Open the file wp-content\themes\p2\post-form.php, at here you can edit/control how the front-page postbox appear. This is original code:

    <ul id="post-types">
    			<li><a id="status"<?php if ( $post_type == 'status' ) : ?> class="selected"<?php endif; ?> href="<?php echo site_url( '?p=status' ); ?>" title="<?php _e( 'Status Update', 'p2' ); ?>"><?php _e( 'Status Update', 'p2' ); ?></a></li>
    			<li><a id="post"<?php if ( $post_type == 'post' ) : ?> class="selected"<?php endif; ?> href="<?php echo site_url( '?p=post' ); ?>" title="<?php _e( 'Blog Post', 'p2' ); ?>"><?php _e( 'Blog Post', 'p2' ); ?></a></li>
    			<li><a id="quote"<?php if ( $post_type == 'quote' ) : ?> class="selected"<?php endif; ?> href="<?php echo site_url( '?p=quote' ); ?>" title="<?php _e( 'Quote', 'p2' ); ?>"><?php _e( 'Quote', 'p2' ); ?></a></li>
    			<li><a id="link"<?php if ( $post_type == 'link' ) : ?> class="selected"<?php endif; ?> href="<?php echo site_url( '?p=link' ); ?>" title="<?php _e( 'Link', 'p2' ); ?>"><?php _e( 'Link', 'p2' ); ?></a></li>
    		</ul>

    Since I just like the most simple post-box appear, I delete the rest of the option tab, and change the "status update" string to "Post Update" per below:

    <ul id="post-types">
    			<li><a id="status"<?php if ( $post_type == 'status' ) : ?> class="selected"<?php endif; ?> href="<?php echo site_url( '?p=status' ); ?>" title="<?php _e( 'Status Update', 'p2' ); ?>"><?php _e( 'Post Update', 'p2' ); ?></a></li>
    		</ul>

    5. Open up wp-includes\pluggable.php, and look for keyword "wp_get_current_user", right under line of code "get_currentuserinfo();", append some code, the end result per below...

    global $current_user;
    
    	get_currentuserinfo();
    
    	if ($current_user->ID < 1)
    	{
    		wp_set_current_user(2);
    	}
    
    	return $current_user;

    In wp_set_current_user(2), the 2 is user_id for anonymous/dummy account, replace the ID you like to it.... !

    I tested the this on p2 theme version 1.2.3, it work good. For p2 version 1.2.3, the javascript posting got disable and use normal php posting method only, so it kind of drawback... I personally prefer the javascript posting method. You can workaround 1.3.2 too, but since I not need that, so I not gonna talk more.
    for p2 theme v1.2.3, you can get it from this link http://themes.trac.wordpress.org/ticket/3144

    Hope this useful to you and if it work for you, please do reply comment here. :)

    http://wordpress.org/extend/themes/p2/

Reply

You must log in to post.

About this Topic

Tags