Solved

Limit WP plugin to admin only

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to count occurrences of each item in an array.

867 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

18 Experts available now in Live!

Get 1:1 Help Now