Skip to content
Snippets Groups Projects
civicrm.php 58 KiB
Newer Older
  • Learn to ignore specific revisions
  • Kevin Cristiano's avatar
    Kevin Cristiano committed
     * global scope function.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    register_activation_hook( CIVICRM_PLUGIN_FILE, array( civi_wp(), 'activate' ) );
    
    
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Tell WordPress to call plugin deactivation method - needed in order to reset
     * the option that is set on activation.
     */
    register_deactivation_hook( CIVICRM_PLUGIN_FILE, array( civi_wp(), 'deactivate' ) );
    
    
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
    // Uninstall uses the 'uninstall.php' method
    // See: http://codex.wordpress.org/Function_Reference/register_uninstall_hook
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
    
    
    
    /*
    --------------------------------------------------------------------------------
    The global scope functions below are to maintain backwards compatibility with
    previous versions of the CiviCRM WordPress plugin.
    --------------------------------------------------------------------------------
    */
    
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Add CiviCRM access capabilities to WordPress roles.
     *
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Called by postProcess() in civicrm/CRM/ACL/Form/WordPress/Permissions.php
     * Also a callback for the 'init' hook in civi_wp()->register_hooks()
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     *
     * @since 4.3
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function wp_civicrm_capability() {
      civi_wp()->users->set_access_capabilities();
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Test if CiviCRM is currently being displayed in WordPress.
     *
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Called by setTitle() in civicrm/CRM/Utils/System/WordPress.php
     * Also called at the top of this plugin file to determine AJAX status
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     *
     * @since 4.3
     *
     * @return bool True if CiviCRM is displayed in WordPress, false otherwise.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_wp_in_civicrm() {
      return civi_wp()->civicrm_in_wordpress();
    }
    
    /**
     * This was the original name of the initialization function and is
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * retained for backward compatibility.
     *
     * @since 4.3
     *
     * @return bool True if CiviCRM is initialized, false otherwise.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_wp_initialize() {
      return civi_wp()->initialize();
    }
    
    /**
     * Initialize CiviCRM. Call this function from other modules too if
     * they use the CiviCRM API.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     *
     * @since 4.3
     *
     * @return bool True if CiviCRM is initialized, false otherwise.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_initialize() {
      return civi_wp()->initialize();
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Callback from 'edit_post_link' hook to remove edit link in civicrm_set_post_blank().
     *
     * @since 4.3
     *
     * @return string Always empty.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_set_blank() {
      return civi_wp()->clear_edit_post_link();
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Authentication function used by civicrm_wp_frontend().
     *
     * @since 4.3
     *
     * @param array $args The page arguments array.
     * @return bool True if authenticated, false otherwise.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_check_permission( $args ) {
      return civi_wp()->users->check_permission( $args );
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Called when authentication fails in civicrm_wp_frontend().
     *
     * @since 4.3
     *
     * @return string Warning message.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_set_frontendmessage() {
      return civi_wp()->users->get_permission_denied();
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Invoke CiviCRM in a WordPress context.
     *
     * Callback function from add_menu_page().
     * Callback from WordPress 'init' and 'the_content' hooks.
     * Also used by civicrm_wp_shortcode_includes() and _civicrm_update_user().
     *
     * @since 4.3
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_wp_invoke() {
      civi_wp()->invoke();
    }
    
    /**
     * Method that runs only when civicrm plugin is activated.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     *
     * @since 4.3
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_activate() {
      civi_wp()->activate();
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Set WordPress user capabilities.
     *
     * Function to create anonymous_user' role, if 'anonymous_user' role is not in
     * the wordpress installation and assign minimum capabilities for all wordpress roles.
     * This function is called on plugin activation and also from upgrade_4_3_alpha1().
     *
     * @since 4.3
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_wp_set_capabilities() {
      civi_wp()->users->set_wp_user_capabilities();
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Callback function for add_options_page() that runs the CiviCRM installer.
     *
     * @since 4.3
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_run_installer() {
      civi_wp()->run_installer();
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Function to get the contact type.
     *
     * @since 4.3
     *
     * @param string $default The contact type.
     * @return string $ctype The contact type.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function civicrm_get_ctype( $default = NULL ) {
      return civi_wp()->users->get_civicrm_contact_type( $default );
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Getter function for global $wp_set_breadCrumb.
     *
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Called by appendBreadCrumb() in civicrm/CRM/Utils/System/WordPress.php
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     *
     * @since 4.3
     *
     * @return string $wp_set_breadCrumb The breadcrumb markup.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function wp_get_breadcrumb() {
      global $wp_set_breadCrumb;
      return $wp_set_breadCrumb;
    }
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Setter function for global $wp_set_breadCrumb.
     *
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Called by appendBreadCrumb() in civicrm/CRM/Utils/System/WordPress.php
     * Called by resetBreadCrumb() in civicrm/CRM/Utils/System/WordPress.php
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     *
     * @since 4.3
     *
     * @param string $breadCrumb The desired breadcrumb markup.
     * @return string $wp_set_breadCrumb The breadcrumb markup.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    function wp_set_breadcrumb( $breadCrumb ) {
      global $wp_set_breadCrumb;
      $wp_set_breadCrumb = $breadCrumb;
      return $wp_set_breadCrumb;
    }
    
    
    /**
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * Incorporate WP-CLI Integration.
     *
     * Based on drush civicrm functionality, work done by Andy Walker.
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     * https://github.com/andy-walker/wp-cli-civicrm
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     *
     * @since 4.5
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
     */
    if ( defined('WP_CLI') && WP_CLI ) {
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
      // Changed from __DIR__ because of possible symlink issues
    
    Kevin Cristiano's avatar
    Kevin Cristiano committed
      include_once CIVICRM_PLUGIN_DIR . 'wp-cli/civicrm.php';
    }