Archive for Wordpress

bbPress login integration with php application

It is a frequest request, or probably a need, that when working on large custom applications that involve numerous frameworks (WordPress, bbPress, E-commerce platforms), to have the site as a whole work together in a logical fashion for the user experience.

If the entire site involves different application frameworks, this usually means that these applications have different code bases and different databases which warrants signing into each application..

If true, you will soon see the need to have a single sign-on capability for the entire site. Meaning simply, you sign on one time and don’t need to sign in again to access different parts of the site.

We are currently working on a PHP custom web development application for a client. Since this is a social networking application, the client requested a forum to be added and integrated seamlessly with the custom application.

We are a frequent user of WordPress and now that since a recent review of bbPress, are very confident that the basic forum functionality of bbPress will be a great fit for our clients needs.

Maybe someday we will have the time to wrap this functionality as a plugin, but for now, we kept our bbPress login integration as simple as possible by straight-up coding in the changes.  We assume you have already installed bbPress onto your site.

#1 Create bbPress user account with db Insert

What to do:  First thing to do is to create a bbPress user in the bbPress database. Unlike other application that need numerous inserts and settings making registering complex, with bbPress, we can take the short cut of creating a bbPress user by inserting a record into the bb_users table that bbPress creates upon install.  

You just need a screen name, email and a md5 password, usually from your registration form from the custom application.  

You need to take the password and change into a md5 string using md5 function like this:

$pwd = md5($_POST["password"]);

After the user submits the new registration in the custom application and your code creates a new user in your application, you then would take same info and insert into db like:

$sql = "INSERT INTO bb_users (                                          custom_account_id,                                        user_login,                                          user_pass,                                         user_nicename,                                         user_email,                                         user_url,                                         user_registered,                                         user_status,                                         display_name                                    )                                     VALUES (                                        '$account_id',                                        '$screen_name',                                        '$m5_password',                                        '$screen_name',                                        '$account_email',                                        '',                                        '$now',                                        '0',                                        '$screen_name'                                    )";

to tie the bb_users table to the custom account table we have for the custom application, we have added a new column to the bb_users table: 

custom_account_id  int  11

… this way we can perform updates on bb_users with our own account_id. 

 

#2 Create custom bbPress user login page

What to do:  There are different ways to accomplish this, but again we went for a simple way since bbPress is on the same server. We created a new file at the forum root and called it login.controller.php. We looked at the bb-login.php at same root to analyze what the code does and what includes and functions it uses to login a user. 

This file includes bb-load.php which is a base php file that sets up a lot of includes and global variables needed for the two bbPress function calls we need:

1) bb_login($user_login, $password, $remember_user) and …

2) bb_logout()

We create a header redirect with the user login (our screen name) and password and a mode for login or logout.  We send our variables via a GET call.  While my example does not encrypt any variables, you can add some extra security measures like encrypting/decrypting and checking referring url, etc.

Download sql and custom php login page:   bbpress-new-login.zip

Send comments if you have any questions and I will try to help!

 

Happy Coding!

 

 

How to display latest posts in wordpress page

Seems simple, and it is, but sometimes you just want a little control over displaying content and posts to your users instead of relying just on plugins and themes, etc. Well, how to display recent posts in WordPress, as a list, is a good way to start.

PHP

Since our goal for this how-to is to display latest posts as a list in php, I’ll assume you know how to add html where you need it:




<?php
$recent_posts = wp_get_recent_posts(10);

foreach($recent_posts as $post){
    if($post["post_status"] != “draft”) {
       echo “do your output here”;
    }
}
?>

This code will get the 10 latest posts (which is default) into your array for looping.

I also added a condition to make sure the post is not a draft, as I’m using this code as the posts loop on the home page of this blog.

That’s it for now … more to come later.

Happy coding!

 

How To embed Youtube video in WordPress

2 Simple Ways to Insert Youtube Video in your WordPress Blog

 

WordPress and Youtube are probably the most powerful web ‘tools’ you can leverage to expand your presence on the web. Bringing them together – putting Youtube videos in your WordPress blog – is easy in this How-To embed Youtube videos into your posts.

So easy there are two ways to do this even with limited web knowledge! Here they are:

 

#1 Embed Youtube HTML Code into your Post

Go to Youtube video page you want to embed and follow these easy instructions:

  1. Got to youtube video page you want to embed
  2. Click Share button just below video
  3. Click Embed button
  4. Copy this highlighted html code
  5. Go to wordpress post, set cursor where you want video placed in HTML Tab mode (on its own separate line)
  6. Now switch to HTML Tab mode, paste code
  7. Click update button to right (before doing anything else!)
 
 
#2 Embed Youtube Link into your Post – EASIER!

Go to Youtube video page you want to embed and follow these easy instructions:

  1. Got to youtube video page you want to embed
  2. You will see ‘Link to this video’, copy the highlighted link
  3. Go to wordpress post, set cursor where you want video placed in HTML Tab mode (on its own separate line) & paste code
  4. Click update button to right (before doing anything else!)

 

*** It’s important to click update right after paste. Web word editors are not like MS Word, they can act funny in formatting your text into the appropriate html code. In doing so, the editor can/will make mistakes you do not want. If you save immediately before switching to Visual tab, you lessen this issue.

 

Enjoy blogging!

 

How to hide a post or page

3 Ways to Hide a WordPress Post or Page

It’s not uncommon, for various reasons, to need to hide a post or page after you’ve already published it.

WordPress has at least 3 ways out of the box, via the admin section, to easily accomplish hiding a post and then, at a later time, publishing it so it’s visible to the public again.

It’s just a few clicks away …

 

#1 Change the visibility to Private

How To:  Go into Edit Post mode. On right hand side is the ‘Publish’ box/widget. Within this widget you will see ‘Visibility’. Click edit and select ‘Private’ radio button. Click OK and then click Publish.

What it does: As admin, you can still see the post but no one else will be able to access the page/post.

 

#2 Password protect the post or page

How To:  Go into Edit Post mode. On right hand side is the ‘Publish’ box/widget. Within this widget you will see ‘Visibility’. Click edit and select ‘Password Protect’ radio button. A password textbox will appear. Fill it in and Click OK and then click Publish and voilà!  You will receive a password box to enter your password upon entering post. 

What it does: Allows an option to make posts visibility to friends, associates, etc. but can access only by providing these users the password. Good to know option that can come in handy down the road.

 

#3 Change the status to Draft

How To:  Go into Edit Post mode. On right hand side is the ‘Publish’ box/widget. Within this widget you will see ‘Status’. Click edit and select ‘Draft’ from the dropdown. Click OK and then click Update.

What it does: Takes post back to Draft mode and removes from being seen from your blog.

WordPress Membership Plugin Review

Stars earned: 4 out of 10 |  Free version

Conclusion: A needed plugin held back by its implementation

 

Need for Membership Access to Content

We have a new client site that requires some content to be viewable to the public but most of the content is for logged in members only.

A Google search for “WordPress Membership content plugin” quickly finds you at the doorstep of the WordPress Membership plugin. The install is typically easy like most WordPress plugins. But that’s where the ease ends.

Default:  No Access to content!

Reading the install notes you’ll see that the default level of access once you enable the plugin is … no access!  This is problem number one as many in need of this plugin have a live active site and might not be super tech savvy, and providing a plugin with lock-down as default doesn’t make good sense. Clearly the default state should be no access restrictions and have the admin apply restrictions to posts, pages, categories, etc. as necessary.

Poor access management implementation

After inital setup the worst problem of using this plugin should be the easiest and simplest:  access level management.

The plugin provides a way to create and manage access levels. These access levels are then edited to allow or disallow access to posts, pages, categories. It seem impressive at first but soon becomes counter-intuitive.

The plugin only shows you the most recent 25 pages.  If you have more than that you are out of luck.  I explicitly denied access of the public to 3 pages but was still allowed access. What’s wrong? So this didn’t work or required some unknown way of getting the plugin to do what it is supposed to do.  The plugin did work when I applied the same settings to a category.

You can apply positive (allow access) or negative (do not allow access) rules to a content type (posts, pages, categories, etc.) But once you apply this type to a level as being in the negative or positive it cannot be used in the other. For example, I want to explicitly deny free access to page A and to explicitly allow access to page B. Well, you can’t. It’s one or the other because pages as a type go together. I think you can eventually achieve what you need, again, I think so, but it doesn’t make sense the way it works or to allow one explicit assignment for a content type but not the other.

 A better way and opposite approach

This plugin would be so effective by a simpler approach and one that would be the exact opposite of how it currently works. Instead of assigning content to the access levels, assign levels to the content.  These are not the same especially as to what it means for the user interface and how to manage your access.

First, access to everything should be open by default. Then simply select posts, pages or categories and then assign higher level access to the content. The plugin would then restrict access to that content by those levels.  That’s it!

All the confusing positive with negative options and inconsistent access will simply go away.

Conclusion

But the way to find out if it can work for you is to try it out … on a dev site first if possible.  Or look for the Member Access plugin which provides a simpler solution.  As for our client site, we’ll have to find another more intuitive solution.