Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to limit access to a page using wordpress user roles that isn't included in the wordpress install.

For example I have a CS Cart install with only a couple of products but I need to limit access to these pages to certain users.

Can I add something in to my CS Cart install to call on Wordpress to be able to limit access if the user is just a subscriber?

share|improve this question
    
Is the CS Cart install in the WordPress directory or outside? –  AlxVallejo Mar 13 '12 at 16:03
    
It is in it's own folder but in the root of the WP install –  Vince Pettit Mar 13 '12 at 16:08
add comment

4 Answers

up vote 0 down vote accepted
+50

if you can include the wp-load.php from WP install; after this you can use all WP Core functions and can also check the user and his rights with core function - current_user_can().

But maybe it's easier to create an bridge from CS Cart to WP, if CS Cart has an own user table; i dont know.

share|improve this answer
    
It has it's own user tables but at the moment I'm not worried about the user having another login, I need the functionality of being able to block access to certain users depending on their WP login, so being able to include the wp-load.php function sounds ideal. Is that literally a case of including it by referencing it in my WP install? –  Vince Pettit Mar 23 '12 at 11:49
    
yes, if you include the wp-load.php, then can you do, want you want and know from wp, same functions, class etc. all, what WP has. If i will data from WP in other systems, i do it this much often, also i buidl bridges to other systems, like Magento or forum-apps. –  bueltge Mar 23 '12 at 21:24
add comment

This is certainly possible but will require you to alter CS Cart a titbit. I'm not too familiar with CS Cart's inner workings, from the little that I've explored the source code (they actually make you fill in a form to download a community edition, bleh) you would want to do something of this kind:

$current_working_directory = getcwd();
chdir( 'WORDPRESS_ROOT' ); // load up 
require_once 'wp-load.php'; // possibly with SHORTINIT to reduce load
// include wp-includes/capabilities.php if SHORTINIT
// include wp-includes/user.php and other dependencies
$permission = current_user_can( 'browse_cs_cart_page' );
chdir( $current_working_directory );

if ( !$permission ) {
    die( 'You do not have permission to access this page. Please login in my WordPress site before you can proceed to here' );
} else {
    // show page
}

This would probably be part of a plugin.

Now, current_user_can will use the cookies that WordPress reads and compares to issued cookies to users. Without a plugin like Root Cookie WordPress will not be able to read it (although, if you're saying that it's in the same root directory and the domain is the same you should be able to pull it off without fiddling with cookies, the browser should send them to both WordPress and CS Cart, check with your debug tool of choice).

SHORTINIT is not mandatory but should improve the speed and memory consumption a bit if you're worried about performance.

This all is fairly easy and should require no more than a couple of hours of fiddling on the CS Cart side (writing a plugin i.e.). WordPress takes care of the rest. Good luck and let us know how it goes.

Further reading:

  1. http://wordpress.org/support/topic/load-wp-core-in-another-framework-shortinit-wp_query
  2. http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/capabilities.php#L839
  3. http://docs.cs-cart.com/common.php?dispatch=docs/view&node_name=addons
  4. http://open-source-experiments.blogspot.com/2009/02/setting-up-common-login-across-multiple.html
share|improve this answer
add comment

No, it is not possible, not cleanly anyway

There are kludges that will get you half there but they are ugly, and trivial to bypass, making it a waste of time, and time is money. It would thus be insecure, costly to build, and costly to maintain, without actually delivering the goal.

You would be far better off going with a piece of software that integrates directly into WordPress, such as an eCommerce plugin, most of which are free and have a lot of features, e.g.:

  • Jigoshop
  • WooCommerce
  • WP-Ecommerce
share|improve this answer
    
None of those have the required features that CS Cart offers, we needed the flexibility of configurable products with multiple rules. –  Vince Pettit Mar 21 '12 at 12:01
    
CS Cart doesn't offer that either, else you wouldn't need to ask this question. But you CAN add it to jigoshop or woocommerce using the WordPress APIs. They're not closed silos of code that cannot be touched. Every product in those is a post type, so you can use filters to filter out products in listings via role –  Tom J Nowell Mar 21 '12 at 12:04
    
Whereas you can't do a query filter and remove products in product category X Y and Z for admins or subscribers in CS Cart. You'd need to modify CS Cart to include the wordpress headers etc which would slow things down, then you'd need to faff around with the cookies to keep everything on the same login, and then you'd need to check, so you would be making a heck of a lot of modifications –  Tom J Nowell Mar 21 '12 at 12:06
    
Eitherway to accomplish anything like this, you will be writing php, what you're asking is the 'hard way', it isn't the smartest way. –  Tom J Nowell Mar 21 '12 at 12:07
add comment

If you just need to restrict to a specific WP page (that the CS cart is embedded within it with a [shortcode] or something, I presume - I don't know CS cart), the best way of doing this is by using one of the role managers plugin.

This one - User Access Manager - is a bit out of date, but it handles specific page restrictions out of the box. check it out & see if it fits.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.