Tips & Tutorials

You do not have sufficient privileges to access this page ?

Thursday, June 24th, 2010

Have you ever changed something in your WordPress admin and received an error that leaves you scratching your head for 2 days and not knowing what the heck went wrong? I just experienced that while working on one of the WordPress themes.

By default, everything worked just fine. By default meaning if you set all default values (database, tables and what not during installation), there was no error of any sort. I never actually changed anything in installations and trusting WordPress security for fixing any bugs or errors it might get. So, I never got the error. But then as security loopholes and vulnerability for hacks exist in any system, people tend to make is more secure and hard to hack by changing setttings on their own. One them being the table prefixes (wp_) for WordPress.

So, during installation, there was an instance when the default wp_ table prefix was changed to gpp_. Now, this theme had theme options and its short name also used gpp_ so it saved all the theme option values within gpp_*. The table prefix gpp_ also saves one of its very important field – gpp_user_roles, gpp_ coming from the prefix which otherwise would have been wp_user_roles. This field saves who can access the admin panel.

Now, the problem was whenever I reset the Theme Options, I used to get the “You do not have sufficient privileges to access this page.” error.

I looked all over the place, googled quite a number of times and found out that there was a field called wp_user_roles and wp_ was replaced with whatever table prefix you set. I then analyzed like 5-6 times trying to create a new install of WordPress, activating the theme, saving the theme options and resetting the theme options. At last I found out that everytime I reset the theme options, all instance of gpp_option_names were getting deleted including gpp_user_roles. So, that explained why I was getting insufficient privileges error.

Then, I looked at the reset code.

$query = "DELETE FROM $wpdb->options WHERE option_name LIKE 'gpp_%'";

It looked okay. gpp_ wasn’t hardcoded anywhere and the statement just looked okay. It deleted all instance starting with gpp_.

Then I tested another table prefix gpps_.

Oops! It deleted that too.

I tried another prefix : gppssssssss_.

My goodness! It deleted that too. Still getting the same error. The statement says specifically to just remove the ones matching gpp_ not gpps_ or gppssssssss_.

This left me thinking quite a lot and searching a lot. At one point I even thought LIKE and DELETE don’t go well together or if its deleting everything that started with g. But this wasn’t the case.

Then, one of my friends suggested if _% is some syntax in MySQL. It wasn’t. But I did find out that _ and % characters didn’t always play well with querying. In fact they were both used as wildcards. This was a bug with MySQL and perhaps it still is. So, the query was only understanding to delete all instances that started with gpp, not gpp_.

Solution

Finally, I found that in order to search for gpp_ in queries, you need to add a backslash otherwise it will just assume it as an escape character. So it needed to be gpp\_. Hence the query:

$query = "DELETE FROM $wpdb->options WHERE option_name LIKE 'gpp\_%'";

That solved the issue of just deleting all the instance that started with gpp_. But then, if someone somehow had a table prefix with gpp_, he is still going to be in trouble. So, I had to change the query to

$query = “DELETE FROM $wpdb->options WHERE option_name LIKE ‘gpp\_%’ AND option_name != ‘gpp_user_roles’”;

This saved the table data gpp_user_roles. So, no more  You do not have sufficient privileges to access this page error.

I hope my 2 days of brain jam and timeless research helped you if you are having the same problem. I am happy to have learnt one new thing although it would have been easier and quicker if I was a hardcore programmer.

Cheers!

Working together with MooTools & jQuery: Revisited

Friday, November 27th, 2009

Approximately a year ago, while I was starting to work with WordPress and trying out different plugins, I had encountered problems trying to integrate plugins that used MooTools and plugins that use jQuery. I had posted a possible solution in there as well. Here are solutions from jQuery site, if you want to know more.

So, after a year with playing around a lot of plugins that uses mootools / scriptaculous and other plugins that uses jQuery (which I prefer), I want to share one easy solution that I have found. I haven’t had any problems till now with this solution and I have been using and recommending to to all my themes.

You do not have to define and noConflict function as recommended by jQuery site. Simply, refrain from using $ as a shortcut to jQuery which means that you have to use jQuery in place of all $ used by your jQuery code. So, your code will look something like this:

jQuery(document).ready(function(){
   jQuery("div").hide();
});

I know its a bit tedious but it works well without having to take all the headaches of what is happening. So, while your jQuery plugin work perfectly, you can enjoy the features from other plugins using MooTools or other libraries.

Happy Thanksgiving to all. Once again, I would like to personally thank everyone for being a part of WPshoppe.

:o

Enabling Comments in Pages in WordPress

Thursday, November 19th, 2009

I have been working with WordPress themes for more than a year now and while most of the time, I am only using the default theme and changing the codes and styles as I want, one question has been circling my mind all this time. How do I enable comments in pages and not just posts?

First, I thought it was not possible. I have been getting quite many pingbacks and trackbacks on pages too but even though I approve them from my admin area, I don’t see anything on the page when I visit it. I never thought twice of what might be the cause. I always thought, well its not possible in pages.

Anyway, I just got a question from Kurt about this and a few times earlier. I never looked at the possibility but had this in mind, maybe the page doesn’t have comment template function call. I didn’t look at the code fully. Page.php was always what it was.

So, I just had some time and looked at page.php. Indeed, this was pretty simple. I compared with single.php and I didn’t see comment template call on page.php. I did a quick testing by putting this code:

<?php comments_template(); ?>

and saw the the page. Voila, there it was!

So, if anyone else is having this very problem of “how to enable comments on pages”, here is what you have to do. Put this code

<?php comments_template(); ?>

right before your closing content div. So, the code might look something like this:

<?php get_header(); ?>

<div id="content">
<?php // all page content goes here ?>
<?php comments_template(); ?>
</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

I would love to know if you have any other ideas about how to enable comments on pages. This might not be so important since Pages aren’t there for commenting in the first place. I guess thats why the default themes (or most) doesn’t have this enabled.

Learning jQuery

Wednesday, April 29th, 2009

Oh.. Its been a long time since I posted. Nothing much going on. Been busy most of the time. I have been trying to come up with a new photography theme for Graph Paper Press. Apart from that I am doing a little jQuery. It had been a long time I looked at tutorials and today I just found the jQuery for Designers site totally revamped. I used to surf the site before but it had an old look. I was kind of excited and surprised at how stunning the new design is. Now that makes me do some more jQuery. :)

Check that site out if you are also learning jQuery!

WordPress Care #1

Tuesday, December 30th, 2008

careFirst thing that I came to know of while working with WordPress. I will probably encounter a few more later as I continue working on it. You can share yours! :)

(more…)

Working together with jQuery and MooTools

Wednesday, December 24th, 2008

jQuery and mootoolsIf you are also stuck with JavaScript framework wars and are in trouble trying to make it work together, here is a good tip. I recently was working with a WordPress Theme for a client and had to build a plugin. I have been a fan of jQuery and immediately started using it to create the small plugin for the site. It worked great!

(more…)

Child Themes for WordPress

Thursday, December 18th, 2008

Every heard of Child Themes? This is a very less discussed term in the WordPress Theme Development world. But this is nothing too complex. It is very similar to how to develop normal WordPress themes. So, you just have to create a folder name (such as simpleX Child) inside the themes folder and add a style.css in it. The style.css should include the following (at the least):

(more…)

Removing the Fugly Search Bar on YouTube embeds

Tuesday, December 9th, 2008

All of a sudden you see the fugly search bar on every YouTube video embeds. Though it is now made optional due a lot of negative responses over the web about the newly added feature. There is an explanation to why it added the search bar here. But who and why on earth was it approved? Every one was wondering if it was due to a virus.

(more…)

Adding rel=”nofollow” to WP functions

Friday, December 5th, 2008

Recently, one of my clients requested me add a rel=”nofollow” argument in the about page of his site. WordPress by default only adds that to its comments section to prevent spam marketing. There might be various ways doing so but I found it pretty difficult to find a good solution in this case. Why? Because the page list wasn’t being called directly using wp_list_pages(). It used a custom function. Not only that, due to some customization to the function, it also used a php variable in the parameter.

(more…)

Ever landed on a 404 Error Page after upgrading?

Thursday, December 4th, 2008

I recently upgraded wpshoppe.com from 2.6.3 to 2.6.5. At first, it was working fine and I did make 2 posts after the upgrade. I thought it was successfully upgraded but 2 days after that when I tried to login to wp-admin it was redirecting to 404 Error Page. I am not sure how that actually happened but I searched over the net and found few answers.

(more…)