Solved

Limit WP plugin to admin only

Posted on 2014-03-23
5
281 Views
Last Modified: 2014-04-18
I want to try a plugin called Wordpress Front End Editor: http://wordpress.org/plugins/wp-front-end-editor/

However, I want to limit the plugin so it only works for the admin user, so I can test it out and use it for a while before I let my contributors use it.

The plugin loads with this:


if ( ! class_exists( 'WP_Front_End_Editor' ) ) {
      require_once( 'class-wp-front-end-editor.php' );
WP_Front_End_Editor::instance();
}

in a file called: wp-front-end-editor.php

Now, in testing this, I find I can comment out the:

WP_Front_End_Editor::instance();

line and the plugin doesn't load.

Cool, I think, all I have to do is add an 'if user is admin' and it will load for me and not anyone else.

So I do this:

if ( ! class_exists( 'WP_Front_End_Editor' ) ) {
      require_once( 'class-wp-front-end-editor.php' );
if (current_user_can( 'manage_options' )) {   //if admin
WP_Front_End_Editor::instance();
} //close if admin
}


But when I do that, the whole site crashes and won't load. If I take the if statement out, all is well again.

What's causing that to happen and how do I solve this?

Thanks for any help/ideas,

Chris
0
Comment
Question by:St_Aug_Beach_Bum
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:mankowitz
Comment Utility
What error are you getting? Print out everything you get.

Also, are you sure that the current info is loaded? Try adding this:

if ( ! class_exists( 'WP_Front_End_Editor' ) ) {
      require_once( 'class-wp-front-end-editor.php' );
get_currentuserinfo(); //   <--- make sure current info is loaded
if (current_user_can( 'manage_options' )) {   //if admin
WP_Front_End_Editor::instance();
} //close if admin
}
0
 

Author Comment

by:St_Aug_Beach_Bum
Comment Utility
Hi Mankowitz,

Tried the code above and got the same results - no errors on page (I have php config set to show errors). Just a blank page (blank source too).

I commented out the if statement and just left the:

get_currentuserinfo(); //   <--- make sure current info is loaded

in there, and that caused the white page as well... indicate anything?

Chris
0
 

Author Comment

by:St_Aug_Beach_Bum
Comment Utility
Though I can do something like this:

if ( ! class_exists( 'WP_Front_End_Editor' ) ) {
      require_once( 'class-wp-front-end-editor.php' );
if ('4' == '4') {   //if test
WP_Front_End_Editor::instance();
} //close if test
}

It works - (and if the numbers don't match, it doesn't load) - so I know an if statement can be there and the if statement will work. Just seems trying to load user info in there doesn't.

Tried the if on the outside of the rest of the code too and that caused the error too.
0
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
Comment Utility
Unfortunately at this point, probably need a debugger. I'm not sure what's failing, and you'd probably have to look through the error log in order to find out. Do you have access to the httpd error log?

One last hail mary attempt, though. Try this:

($user->has_cap('manage_options'))

instead of

(current_user_can( 'manage_options' ))
0
 

Author Comment

by:St_Aug_Beach_Bum
Comment Utility
Never did get this figured out but tackled it from another angle and limited it to my ip address :)

Thanks very much for your help though!

Chris
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now