Display only the posts authored by the current WP user on the ‘Posts’ page in the back-end

2 Jan

First, Wish you all a Happy New Year! :)
Now lets get down to the nerd stuff!
This is a very commonly faced problem by many WP devs. When logged in as a user with a role that is allowed to create / edit posts such as Author, Editor, Contributor or a custom role with the ‘edit_posts’ capability, the posts list on the ‘Posts’ page in the back-end shows all the published posts, even those by other users. The current user can see and edit his own posts, which is fine, but can see user’s posts which seems to be killing the sense of privacy in a multi-user system and is undesired by many developers. Doesn’t it look more secure and sophisticated when the posts list shows only the current users posts? In fact in a system where users are given accounts and privileges to create / edit posts, this fact is very important that they get to see only their work and not others. Also, it will reduce the posts list!

Unfortunately this is not possible with ‘edit_posts’ capability, as it displays all the published posts, and hence this hack can be used.

(more…)

Add items ANYWHERE to the WP 3.3 Admin Bar

30 Dec

The title is pretty loud and clear, we are going to see how to add new items or links to the Admin Bar. Now it does say WP 3.3, but according to the core file, this method should work well backwards up to WP 3.1.0. I believe as you reached here, you meet the following prerequisites:

  • WP Action Hooks: Just what, where and how about WP Action Hooks is enough

(Do I need to add ‘You should know WordPress and PHP’ as a prerequisite?)

Okay, time to add stuff to your WP Admin Bar. Like they say ‘An image speaks a thousand words’, I’ve put images which will help you better than my blabber! ;)
(more…)

Show or Hide a WP widget only on specific page/s without using a plugin

1 Sep

Widgets make a WP theme’s sidebar alive. Small but important pieces of info which shouldn’t be restricted to a single page, can be put into a widget and made available on all the pages through the sidebar. But sometimes you might want to show a widget only on specific pages or page. One would code multiple sidebars and call them according to the pages, by adding different widgets to them or simply use a plugin to do this. But you don’t need to code multiple sidebars, just follow this simple piece of code, and you’ll know how to show/hide widgets according to the pages without using a plugin.

Obviously, you should know the following before you read further:
1. WP – Yeah, of course ;) But more on the developer level.
2. WordPress Filters – What, Why, How, When?
3. Firebug powered FireFox – Stop developing websites if you don’t know what Firebug is :P !

You reached here? Kewl! Let’s get to work…

Consider the following use case – We don’t want to show the default ‘Archives’ widget on the home page of our site.
(more…)

Use jQuery to reorder your WP posts on the fly

13 Aug

If you use WP for a lot more than just publishing a blog and using the ready made themes and plugins, then I bet you know a whole lotta stuff can be done with the normal list of posts on your blog index. One such thing (and a highly desirable feature) is to be able to reorder your posts according to the various ordering options that are available with ‘query_posts‘ (or ‘WP_Query‘ for that matter). Usually, if you’re to modify the loop to display the posts ordered in a specific manner, you’d create a new ‘WP_Query’ object or pass the parameters to ‘query_posts’ and invoke it right before the loop starts. But using a simple technique that is already used by WP, we’ll learn how to reorder the posts list, by modifying ‘query_posts’ right from the frontend, using jQuery.

Checkout the demo: Demo
(more…)