Solved

Limit WP plugin to admin only

Posted on 2014-03-23
5
287 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchiā€¦
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

738 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