One of the issues we need or at least should tackle before resubmitting CiviCRM 4.7.x to the WP plugin repo is address the issue of WordPress in it's own directory. While this is not the standard or common way of installing, it is used. It is more common for Agency installed or Enterprise sites than stand alone smaller organizations.
Currently CiviCRM does not handle this well. WordPress ends up with two urls - one for the home page and one fro the admin. So http://example.com is the public facing web site, and http://example.com/wp is the path to wp-admin, the content directory and CiviCRM.
The settings appear in the admin as follows:
Then when we install CiviCRM we get the Green Light:
And the directories are set as follows:
In civicrm.settings.php we get the following:
The CMS settings are now set to have the basepage set to: https://example.com/wp/civicrm
First issue is when we try and add a CiviCRM component via the shortcode button.
If we try and use a CiviCRM link such as https://example.com/wp/civicrm/?q=civicrm%2Fcontribute%2Ftransact&reset=1&id=1 WP sends us to https://example.com/civicrm/?q=civicrm%2Fcontribute%2Ftransact&reset=1&id=1 This results in a 404 error.
If we go and make the base page 'civicrm' a child page (using a parent named 'wp') then this link https://example.com/wp/civicrm/?q=civicrm%2Fcontribute%2Ftransact&reset=1&id=1 becomes valid and works.
However, the shortcode button is still broken.
Testing and Planed fixes:
In the file: civicrm/CRM/Utils/System/WordPress.php replace the function private function getBaseUrl($absolute, $frontend, $forceBackend) with the following:
With this change, the backend and full CiviCRM links on the front end work fine. Needs more testing on standard installs and subdirectory installs.
Corresponing updates to civicrm.settings.php can be made to set the above constants:
The shortcode button is still an issue.
2. In the file civicrm\includes\civicrm.shortcodes.modal.php replace existing function add_form_button() with the following:
Modal had been called with a hardcoded link to wp-admin, so the modal could not display,
Update June 8 2016:
Created the following PRs:
These PRs are the foundation to support WP In it's own Directory.
Update Installer with settings to support
If wp-config.php has defined an alternate WP Content directory :
Test to see if the option 'home' matches the option 'siteurl'
If WP is in it's own directory these will not match
If either condition exists, then enable the below override
Jefferson Sprint Sept 27 2016
Tested 4.7.12-rc against following WP alternate configurations:
A) WordPress wp-content directory moved
Result – Success
B) WP plugins folder moved
Result - Success
C) WordPress wp-content and uploads directories moved:
Result - Success
D) WordPress in it's own directory and moving wp-content, plugins and uploads directories
Result - Failure on install - Uploads directory cannot be moved along with WP in it's own directory. Or at least I have failed at this test.
E) WordPress in it's own directory and moving wp-content, plugins directories
Update civicrm.settings.php with the following code block, replacing installer's CIVICRM_UF_BASEURL section
Then add the following:
This is because the [civicrm.root] variable returns - http://wpcrazy.dev/wp/srv/www/wpcrazy/alt-plugins/civicrm/civicrm/ instead of http://wpcrazy.dev/alt-plugins/civicrm/civicrm/
After above changes: Result - Success
Update installer - test for site_url() home_url() and admin_url() and set as below - look at getCiviSourceStorage in \Civi\Core\Paths – determine if this can be corrected for alternate wp-content plus WP in subdirectory. If not set at install:
Update from Edale Sprint 2016:
23 April 2017:
PR: https://github.com/civicrm/civicrm-core/pull/10214 and PR: https://github.com/civicrm/civicrm-wordpress/pull/105 implements the above. Currently adds the civicrm.settings.extra.php file for WP only and adds the minimum number of defines to get all common install scenarios automated.
17 October 2017
Changes Merged Release scheduled 4.7.27
19 October 2017
Further testing due to CRM-21297 has uncovered that if wp is in its own directory AND the content directory has been moved there is an issue with ckeditor. https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Resources.php#L737 uses "[civicrm.root]" and does not find the new settings via civicrm.settings.php. https://github.com/civicrm/civicrm-core/blob/master/CRM/Admin/Page/CKEditorConfig.php#L273 uses "[civicrm.files]" and this also does not find the overridden settings.