Solved

Limit WP plugin to admin only

Posted on 2014-03-23
5
286 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
ID: 39948616
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
ID: 39948640
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
ID: 39948642
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
ID: 39950148
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
ID: 40009073
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What's wrong with this PDO query? 5 27
what do I need to host my own web sites? 13 51
Need to remove %20 from url in get 17 36
jQuery Toggle & Anchor Links 5 43
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 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