?
Solved

Limit WP plugin to admin only

Posted on 2014-03-23
5
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

765 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