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) »
  • CiviCRM plugin clashing with my own WP Civi extension plugin
Pages: [1]

Author Topic: CiviCRM plugin clashing with my own WP Civi extension plugin  (Read 1064 times)

Erik Stainsby

  • I’m new here
  • *
  • Posts: 28
  • Karma: 1
  • Web+Db Programmer
  • CiviCRM version: 4.4.3 WP plugin
  • CMS version: WP 3.7.1
  • MySQL version: 5.5.34
  • PHP version: 5.3.10-1ubuntu3.8
CiviCRM plugin clashing with my own WP Civi extension plugin
February 07, 2013, 05:49:58 pm
... when a plugin I have written is activated.

Curiously, Civi reports in the error message that the current value of $civicrm_root: .:
The value set in civicrm.settings.php for $civicrm_root is: /home/domains/roaringsky.ca/public/wp-content/plugins/civicrm/
When I deactivate my plugin Civi behaves correctly again. My surmise is that my plugin is somehow loading prior to Civi's plugin and the read I perform does not export correctly for Civi to reuse. (?)

Because I assume my instance will be judged the culprit ( :P )  here is the use I make of Civi within my plugin ...

Code: [Select]
class RS_Conference_Plugin {

var $rs_version = '0.3.0';
var $crm_settings;
var $crm_config;
var $plugin_url;

public function __construct() {

include_once( ABSPATH.'wp-includes/pluggable.php');
include_once( ABSPATH.'wp-includes/shortcodes.php');


$this->crm_settings = plugin_dir_path(__FILE__).'../civicrm/civicrm.settings.php';
include_once($this->crm_settings);
$this->config = CRM_Core_Config::singleton();

[ .. snip .. ]
        }


        public function rs_conference_despool()
        {

[ .. snip .. ]

                // select all the CiviEvents that match up by date

$table_name = 'civicrm_event';

// compensate for the all-balls 00:00:00 timestamp
$real_end = new DateTime($conf->end_date);
$real_end->add(new DateInterval('PT23H59M'));

$sql = "SELECT id, title, summary, description, start_date, end_date FROM $table_name WHERE (start_date BETWEEN '".$conf->start_date."' AND '".date_format($real_end,'Y-m-d H:i:s')."' ) AND is_active = 1 AND is_template = 0 ORDER BY start_date ";
$dao = CRM_Core_DAO::executeQuery($sql);

// separate buffer
$list = array();
$list[] = '<div class="rs-event-list">';
while ($dao->fetch())
                {
                     // build out and buffer html markup
                [ .. snip .. ]
                }
        [ .. snip .. the rest of the despool function - no further Civi code .. ]
      }

}   /* end of class RS_Conference_Plugin   */

// standard WP class-instantiation technique ...
$civi_extn = new RS_Conference_Plugin();



Now within my plugin when both Civi and RS_Conference are activated, no problems. Reads and writes are fine to the db. (Writes are only to wp_rs_confernece_xxx  tables so far, but I intend to update Civi tables as well.)   The issue arises as I said when I return to the Civi environment.

Is there something I ought to be doing to discard/destroy my reference to the Config::singleton  ? Or the $dao object/db handle which could somehow be messing up the settings file's path variable ? Seems a stretch, but I am under pressure to get this working and willing to take any suggestions to help clear this up.

Thanks in advance.
Erik

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CiviCRM plugin clashing with my own WP Civi extension plugin
February 07, 2013, 07:28:49 pm

where is the error message thrown? i.e.what line?

also can u change the include_once($this->crm_settings) to

require_once $this->crm_settings;

and see what happens

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Erik Stainsby

  • I’m new here
  • *
  • Posts: 28
  • Karma: 1
  • Web+Db Programmer
  • CiviCRM version: 4.4.3 WP plugin
  • CMS version: WP 3.7.1
  • MySQL version: 5.5.34
  • PHP version: 5.3.10-1ubuntu3.8
Re: CiviCRM plugin clashing with my own WP Civi extension plugin
February 07, 2013, 08:32:11 pm
Thanks for the reply, Don.

The error was being raised when WP attempted to load the CiviCRM plugin admin page. I never did identify a specific line number. 
(Is there a debug.log which civi uses for such errors ?  I have the WP debug.log running but see no mention of Civi in that traffic.)

I have changed include_once to require_once as you suggested.  Interestingly it now loads some of the CiviCRM Home page and stalls with the animated spinner Loading ... below the Configure Your Dashboard button.  Also the black menu bar is unpopulated - no buttons at all. 

Hmmm ...



Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CiviCRM plugin clashing with my own WP Civi extension plugin
February 07, 2013, 08:45:35 pm

check the files here:

wp-content/plugins/files/civicrm/ConfigAndLog/

for the civicrm debug / error logs (on fatal errors)

ideally there should be a way for you to tell WP to load civicrm first before your plugin

you should also check civicrm_wp_initialize() in civicrm.php and potentially just call that to init civi in WP

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Erik Stainsby

  • I’m new here
  • *
  • Posts: 28
  • Karma: 1
  • Web+Db Programmer
  • CiviCRM version: 4.4.3 WP plugin
  • CMS version: WP 3.7.1
  • MySQL version: 5.5.34
  • PHP version: 5.3.10-1ubuntu3.8
Re: CiviCRM plugin clashing with my own WP Civi extension plugin
February 07, 2013, 08:57:03 pm
Knowing where the logs are is very useful, thanks.  It appears my Administrator user is not permitted to access this CiviCRM home page...

Code: [Select]
Feb 08 04:53:39  [info] $Fatal Error Details = Array
(
    [message] => You do not have permission to access this page
    [code] =>
)


Feb 08 04:53:39  [info] $backTrace = #0 /Users/erik/Sites/getcand.io/public/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(314): CRM_Core_Error::backtrace("backTrace", TRUE)
#1 /Users/erik/Sites/getcand.io/public/wp-content/plugins/civicrm/civicrm/CRM/Utils/System/WordPress.php(325): CRM_Core_Error::fatal("You do not have permission to access this page")
#2 /Users/erik/Sites/getcand.io/public/wp-content/plugins/civicrm/civicrm/CRM/Utils/System.php(212): CRM_Utils_System_WordPress->permissionDenied()
#3 /Users/erik/Sites/getcand.io/public/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(137): CRM_Utils_System::permissionDenied()
#4 /Users/erik/Sites/getcand.io/public/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(51): CRM_Core_Invoke::_invoke((Array:3))
#5 /Users/erik/Sites/getcand.io/public/wp-content/plugins/civicrm/civicrm.php(272): CRM_Core_Invoke::invoke((Array:3))
#6 [internal function](): civicrm_wp_invoke("")
#7 /Users/erik/Sites/getcand.io/public/wp-includes/plugin.php(405): call_user_func_array("civicrm_wp_invoke", (Array:1))
#8 /Users/erik/Sites/getcand.io/public/wp-admin/admin.php(151): do_action("toplevel_page_CiviCRM")
#9 {main}


I'll have a look at the civicrm_wp_initialize() call now.

Erik Stainsby

  • I’m new here
  • *
  • Posts: 28
  • Karma: 1
  • Web+Db Programmer
  • CiviCRM version: 4.4.3 WP plugin
  • CMS version: WP 3.7.1
  • MySQL version: 5.5.34
  • PHP version: 5.3.10-1ubuntu3.8
Re: CiviCRM plugin clashing with my own WP Civi extension plugin
February 07, 2013, 09:05:01 pm
[SOLVED]

Thanks Don. The stanza that works for me:

Code: [Select]
$this->crm = plugin_dir_path(__FILE__).'../civicrm/civicrm.php';
require_once($this->crm);
civicrm_wp_initialize();

The two plugins are now contentedly coexisting.

Much appreciate your help.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • WordPress Installations (Moderators: Kurund Jalmi, Coleman Watts) »
  • CiviCRM plugin clashing with my own WP Civi extension plugin

This forum was archived on 2017-11-26.