CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • WordPress Installations (Moderators: Kurund Jalmi, Coleman Watts) »
  • Problems with separate wp-content folder
Pages: [1]

Author Topic: Problems with separate wp-content folder  (Read 1182 times)

wingfingerbill

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 4.4.14
  • CMS version: WordPress 4.1.1
  • MySQL version: 5.6.23
  • PHP version: 5.5.23
Problems with separate wp-content folder
April 05, 2015, 09:09:45 am
Hi

I'm trying to get to the bottom of how to run CiviCRM on a WordPress site where the wp-content folder is outside the wordpress (aka cms) folder.

I've set up a nice, tidy test site. Here's the structure:

Code: [Select]
public_html
   cms    (ie: all the wordpress core files)
   wp-content
      plugins
         civicrm
         files
         etc...
      themes
      uploads
      etc...
   cgi-bin
   etc...

I've been using this arrangement for many years on a client's website, despite repeated mutterings from our long-suffering Civi-guru, Upperholme, who's job would be so much simpler if we only stuck to the conventional, plain vanilla structure that WordPress ships with (ie: wp-content as a sub-folder of cms).

Unfortunately, there's a whole load of other stuff going on on the site - including Google maps accessed from embedded widgets on external sites, cost-calculator widgets, and newsletters compiled from WordPress posts (and now sent out via Civi). These had already been coded and running long before CiviCRM was made available to WordPress, so I'm reluctant to embark on rejigging all that legacy code, when Civi really ought to be able to cope. And it has done - more-or-less - for several years.

But upgrades are a nightmare - and we now really need to move on from Civi 4.4.4 and WP 3.8.5.

In theory, Civi should cope fine with this structure (which has a few other advantages for us which I won't go into here). There's even documentation on how to do it: http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=124813718  But I've never been able to get it working without at least one hack to the Civi codebase.


The test set-up

On my test site, I've done a clean install of WordPress 4.1.1 running the Twenty Fourteen theme. I've changed the structure as above, using the standard technique referenced by Lobo in the documentation: http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content   All works fine, of course - every single one of our sites uses this layout.

I did a clean install of CiviCRM 4.4.14 and added the settings_location.php file, checked and adjusted the various paths and urls, and did a bit of cache clearing etc. (CiviCRM 4.4.14 because when I get this working, I'll need to import the data from another site - which is running 4.4.14.)

The root-level index.php loads WordPress from the /cms/ folder so that we don't have to see /cms/ in any frontend urls. Pretty standard stuff:

Code: [Select]
require( dirname( __FILE__ ) . '/cms/wp-blog-header.php' );
So, in civicrm.settings.php I have:

Code: [Select]
define( 'CIVICRM_UF_BASEURL', 'http://www.domain_name.co.uk/' );
And because the backend can only be accessed via the /cms/ folder, I've also added a rewrite rule in the root level .htaccess file that sticks cms/ in front of any request that starts with wp-admin/ :

Code: [Select]
RewriteRule ^wp-admin/(.*)$ http://www.domain_name.co.uk/cms/wp-admin/$1 [R=302,L]

The problem

 All this appears to be working quite happily - until I try to submit any of the forms from CiviCRM. I can't even enter my organization name, let alone change any System Settings or search for contacts (not that there are any!). Whenever I hit a button, the form either resets itself (losing any data I've entered) or - when I try to edit  Organization Address and Contact Info - hides ('freezes'?) all the form elements (again losing my data).

So presumably it's something to do with QuickForm - which has so many levels of abstraction that I just can't get my head round it. But I'm guessing a simple tweak somewhere will get it all working. It feels tantalisingly close!

Thanks for reading all this - if you have.  Any advice? All suggestions welcome.

Thanks

Bill


« Last Edit: April 05, 2015, 09:51:05 am by wingfingerbill »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Problems with separate wp-content folder
April 05, 2015, 10:55:58 am
Maybe look at this function:
https://github.com/civicrm/civicrm-core/blob/4.5/CRM/Utils/System/WordPress.php#L242
Try asking your question on the new CiviCRM help site.

wingfingerbill

  • I’m new here
  • *
  • Posts: 18
  • Karma: 1
  • CiviCRM version: 4.4.14
  • CMS version: WordPress 4.1.1
  • MySQL version: 5.6.23
  • PHP version: 5.5.23
Re: Problems with separate wp-content folder
April 05, 2015, 04:11:13 pm
Thanks Coleman  :)

That pointed me in the right direction and I'm definitely making progress now.

I've now hacked WordPress.php in order to add some WordPress-style hooks to functions postURL() and url(). These allow the urls to be filtered before returning. (A Civi-style hook might be more appropriate, but I don't know how to create a new one.)

Code: [Select]
$filtered_url = apply_filters( 'wf_civi_url', $raw_url);
return $filtered_url;

I'm then filtering the raw urls in plugins/files/civicrm/php/civicrmHooks.php:

Code: [Select]
function wf_civi_url_filter($url) {
if(substr($url,0,10) == '/wp-admin/') {
$url = '/cms'.$url;
} else {
$url = str_replace('.uk/wp-admin','.uk/cms/wp-admin',$url);
}
return  $url;
}
add_filter('wf_civi_url','wf_civi_url_filter');

This has fixed the form processing problem, and has also allowed me to remove the RewriteRule in .htaccess. There may still be other issues, of course, but they haven't surfaced yet.

I still get the feeling that I must be 'doing it wrong' - because there's no mention of all this in the documentation. But maybe it's the combination of moving wp-content and also giving WordPress its own cms folder (which keeps everything nice and tidy when there are lots of other items at root level) that's causing the problems. And I suspect that using 'pretty permalinks' may also be making it harder for Civi to cope.

I hope this helps others. It would be great if a future release of CiviCRM could build in some hooks to allow this filtering without any hacks.

If I make any further discoveries as I attempt to upgrade this client's site to the latest WP and Civi versions, I'll post them here.

Bill

haystack

  • I post occasionally
  • **
  • Posts: 61
  • Karma: 2
  • CiviCRM version: 4.n
  • CMS version: WordPress 4.n
  • MySQL version: 5.n
  • PHP version: 5.n
Re: Problems with separate wp-content folder
April 13, 2015, 03:48:49 am
@wingfingerbill You might also like to look at the list of assumptions that CiviCRM makes regarding WordPress that I compiled here:

https://github.com/civicrm/civicrm-wordpress/pull/63#issuecomment-61738465

They may not be current still, but hope they help.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • WordPress Installations (Moderators: Kurund Jalmi, Coleman Watts) »
  • Problems with separate wp-content folder

This forum was archived on 2017-11-26.