Skip to content

Commit

Permalink
Merge pull request civicrm#12 from dlobo/CRM-12389
Browse files Browse the repository at this point in the history
CRM-12389
  • Loading branch information
colemanw committed Apr 20, 2013
2 parents 91dd2eb + 639c3ac commit 6142229
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions civicrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ function civicrm_run_installer() {
include ($installFile);
}

function civicrm_wp_set_title($title = '') {
global $civicrm_wp_title;
return empty($civicrm_wp_title) ? $title : $civicrm_wp_title;
}

function civicrm_setup_warning() {
$installLink = admin_url() . "options-general.php?page=civicrm-install";
echo '<div id="civicrm-warning" class="updated fade"><p><strong>' . t('CiviCRM is almost ready.') . '</strong> ' . t('You must <a href="!1">configure CiviCRM</a> for it to work.', array(
Expand All @@ -159,8 +154,19 @@ function civicrm_remove_wp_magic_quotes() {
$_REQUEST = stripslashes_deep($_REQUEST);
}

/**
* This was the original name of the initialization function and is
* retained for backward compatibility
*/
function civicrm_wp_initialize() {
return civicrm_initialize();
}

/**
* Initialize CiviCRM. Call this function from other modules too if
* they use the CiviCRM API.
*/
function civicrm_initialize() {
static $initialized = FALSE;
static $failure = FALSE;

Expand All @@ -169,11 +175,10 @@ function civicrm_wp_initialize() {
}

if (!$initialized) {

// Check for php version and ensure its greater than 5.
// do a fatal exit if
if ((int ) substr(PHP_VERSION, 0, 1) < 5) {
echo "CiviCRM requires PHP Version 5.2 or greater. You are running PHP Version " . PHP_VERSION . "<p>";
// Check for php version and ensure its greater than minPhpVersion
$minPhpVersion = '5.3.3';
if (version_compare(PHP_VERSION, $minPhpVersion) < 0) {
echo "CiviCRM requires PHP Version $minPhpVersion or greater. You are running PHP Version " . PHP_VERSION . "<p>";
exit();
}

Expand Down Expand Up @@ -291,7 +296,7 @@ function civicrm_wp_invoke() {
}

$alreadyInvoked = TRUE;
if (!civicrm_wp_initialize()) {
if (!civicrm_initialize()) {
return '';
}

Expand Down Expand Up @@ -342,7 +347,7 @@ function civicrm_wp_head() {
}

function civicrm_wp_frontend($shortcode = FALSE) {
if (!civicrm_wp_initialize()) {
if (!civicrm_initialize()) {
return;
}

Expand Down Expand Up @@ -484,14 +489,16 @@ function civicrm_check_permission($args) {

// an event registration page is valid
if (in_array('CiviEvent', $config->enableComponents)) {
if ($arg1 == 'event' &&
if (
$arg1 == 'event' &&
in_array($arg2, array('register', 'info', 'participant', 'ical', 'confirm'))
) {
return TRUE;
}

// also allow events to be mapped
if ($arg1 == 'contact' &&
if (
$arg1 == 'contact' &&
$arg2 == 'map' &&
$arg3 == 'event'
) {
Expand Down Expand Up @@ -551,11 +558,14 @@ function wp_civicrm_capability() {

function civicrm_wp_main() {
add_action('init', 'wp_civicrm_capability');
if (is_admin()) {

$isAdmin = is_admin();
if ($isAdmin) {
add_action('admin_menu', 'civicrm_wp_add_menu_items');

//Adding "embed form" button
if (in_array(basename($_SERVER['PHP_SELF']),
if (in_array(
basename($_SERVER['PHP_SELF']),
array('post.php', 'page.php', 'page-new.php', 'post-new.php')
)) {
add_action('media_buttons_context', 'civicrm_add_form_button');
Expand All @@ -571,40 +581,36 @@ function civicrm_wp_main() {
add_action('admin_notices', 'civicrm_setup_warning');
}
}

add_action('admin_head', 'civicrm_wp_head');
}

add_action('user_register', 'civicrm_user_register');
add_action('profile_update', 'civicrm_profile_update');

add_shortcode('civicrm', 'civicrm_shortcode_handler');

if (is_admin()) {
add_action('admin_head', 'civicrm_wp_head');
} else {
if (! $isAdmin) {
add_action('wp_head', 'civicrm_wp_head');
}

if (!is_admin()) {
add_filter('get_header', 'civicrm_wp_shortcode_includes');
}

if (!civicrm_wp_in_civicrm()) {
return;
}

if (!is_admin()) {
if (!$isAdmin) {
add_action('wp_footer', 'civicrm_buffer_end');

// we do this here rather than as an action, since we dont control
// the order
civicrm_buffer_start();

civicrm_wp_frontend();
}
}

function civicrm_add_form_button($context) {
if (!civicrm_wp_initialize()) {
if (!civicrm_initialize()) {
return '';
}

Expand Down Expand Up @@ -908,7 +914,10 @@ function civicrm_wp_in_civicrm() {
function civicrm_wp_shortcode_includes() {
global $post;
if (preg_match('/\[civicrm/', $post->post_content)) {
civicrm_wp_initialize();
if (!civicrm_initialize()) {
return;
}

CRM_Core_Resources::singleton()->addCoreResources();
}
}
Expand Down Expand Up @@ -942,10 +951,13 @@ function civicrm_profile_update($userID) {
function _civicrm_update_user($userID) {
$user = get_userdata($userID);
if ($user) {
civicrm_wp_initialize();
if (!civicrm_initialize()) {
return;
}

require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::synchronize($user,
CRM_Core_BAO_UFMatch::synchronize(
$user,
TRUE,
'WordPress',
'Individual'
Expand Down

0 comments on commit 6142229

Please sign in to comment.