Unverified Commit 80e91bd8 authored by kcristiano's avatar kcristiano Committed by GitHub

Merge pull request #137 from christianwach/codestyle

NFC: Give comments and docblocks some TLC
parents a3abbdc7 1c10119f
This diff is collapsed.
This diff is collapsed.
...@@ -33,53 +33,56 @@ ...@@ -33,53 +33,56 @@
*/ */
// this file must not accessed directly // This file must not accessed directly
if ( ! defined( 'ABSPATH' ) ) exit; if ( ! defined( 'ABSPATH' ) ) exit;
/** /**
* Define CiviCRM_For_WordPress_Shortcodes_Modal Class * Define CiviCRM_For_WordPress_Shortcodes_Modal Class.
*
* @since 4.6
*/ */
class CiviCRM_For_WordPress_Shortcodes_Modal { class CiviCRM_For_WordPress_Shortcodes_Modal {
/** /**
* Declare our properties * Plugin object reference.
*
* @since 4.6
* @access public
* @var object $civi The plugin object reference.
*/ */
// init property to store reference to Civi
public $civi; public $civi;
/** /**
* Instance constructor * Instance constructor.
* *
* @return object $this The object instance * @since 4.6
*/ */
function __construct() { function __construct() {
// store reference to Civi object // Store reference to CiviCRM plugin object
$this->civi = civi_wp(); $this->civi = civi_wp();
} }
/** /**
* Register hooks to handle the presence of shortcodes in content * Register hooks to handle the shortcode modal.
* *
* @return void * @since 4.6
*/ */
public function register_hooks() { public function register_hooks() {
// bail if Civi not installed yet // Bail if CiviCRM not installed yet
if ( ! CIVICRM_INSTALLED ) return; if ( ! CIVICRM_INSTALLED ) return;
// adds the CiviCRM button to post and page edit screens // Adds the CiviCRM button to post and page edit screens
// use priority 100 to position button to the farright // Use priority 100 to position button to the farright
add_action( 'media_buttons', array( $this, 'add_form_button' ), 100 ); add_action( 'media_buttons', array( $this, 'add_form_button' ), 100 );
// add the javascript and styles to make it all happen // Add the javascript and styles to make it all happen
add_action('load-post.php', array($this, 'add_core_resources')); add_action('load-post.php', array($this, 'add_core_resources'));
add_action('load-post-new.php', array($this, 'add_core_resources')); add_action('load-post-new.php', array($this, 'add_core_resources'));
add_action('load-page.php', array($this, 'add_core_resources')); add_action('load-page.php', array($this, 'add_core_resources'));
...@@ -89,14 +92,15 @@ class CiviCRM_For_WordPress_Shortcodes_Modal { ...@@ -89,14 +92,15 @@ class CiviCRM_For_WordPress_Shortcodes_Modal {
/** /**
* Callback method for 'media_buttons' hook as set in register_hooks() * Add button to editor for WP selected post types.
* *
* @param string $editor_id Unique editor identifier, e.g. 'content' * Callback method for 'media_buttons' hook as set in register_hooks().
* @return void *
* @since 4.7
*/ */
public function add_form_button() { public function add_form_button() {
// add button to WP selected post types, if allowed // Add button to WP selected post types, if allowed
if ( $this->post_type_has_button() ) { if ( $this->post_type_has_button() ) {
$civilogo = file_get_contents( plugin_dir_path( __FILE__ ) . '../assets/civilogo.svg.b64' ); $civilogo = file_get_contents( plugin_dir_path( __FILE__ ) . '../assets/civilogo.svg.b64' );
...@@ -110,9 +114,11 @@ class CiviCRM_For_WordPress_Shortcodes_Modal { ...@@ -110,9 +114,11 @@ class CiviCRM_For_WordPress_Shortcodes_Modal {
/** /**
* Callback method as set in register_hooks() * Add core resources.
*
* Callback method as set in register_hooks().
* *
* @return void * @since 4.7
*/ */
public function add_core_resources() { public function add_core_resources() {
if ($this->civi->initialize()) { if ($this->civi->initialize()) {
...@@ -124,23 +130,25 @@ class CiviCRM_For_WordPress_Shortcodes_Modal { ...@@ -124,23 +130,25 @@ class CiviCRM_For_WordPress_Shortcodes_Modal {
/** /**
* Does a WordPress post type have the CiviCRM button on it? * Does a WordPress post type have the CiviCRM button on it?
* *
* @return bool $has_button True if the post type has the button, false otherwise * @since 4.6
*
* @return bool $has_button True if the post type has the button, false otherwise.
*/ */
public function post_type_has_button() { public function post_type_has_button() {
// get screen object // Get screen object
$screen = get_current_screen(); $screen = get_current_screen();
// bail if no post type (e.g. Ninja Forms) // Bail if no post type (e.g. Ninja Forms)
if ( ! isset( $screen->post_type ) ) return; if ( ! isset( $screen->post_type ) ) return;
// get post types that support the editor // Get post types that support the editor
$capable_post_types = $this->get_post_types_with_editor(); $capable_post_types = $this->get_post_types_with_editor();
// default allowed to true on all capable post types // Default allowed to true on all capable post types
$allowed = ( in_array( $screen->post_type, $capable_post_types ) ) ? true : false; $allowed = ( in_array( $screen->post_type, $capable_post_types ) ) ? true : false;
// allow plugins to override // Allow plugins to override
$allowed = apply_filters( 'civicrm_restrict_button_appearance', $allowed, $screen ); $allowed = apply_filters( 'civicrm_restrict_button_appearance', $allowed, $screen );
return $allowed; return $allowed;
...@@ -149,9 +157,11 @@ class CiviCRM_For_WordPress_Shortcodes_Modal { ...@@ -149,9 +157,11 @@ class CiviCRM_For_WordPress_Shortcodes_Modal {
/** /**
* Get WordPress post types that support the editor * Get WordPress post types that support the editor.
*
* @since 4.6
* *
* @return array $supported_post_types Array of post types that have an editor * @return array $supported_post_types Array of post types that have an editor.
*/ */
public function get_post_types_with_editor() { public function get_post_types_with_editor() {
...@@ -160,17 +170,17 @@ class CiviCRM_For_WordPress_Shortcodes_Modal { ...@@ -160,17 +170,17 @@ class CiviCRM_For_WordPress_Shortcodes_Modal {
return $supported_post_types; return $supported_post_types;
} }
// get only post types with an admin UI // Get only post types with an admin UI
$args = array( $args = array(
'public' => true, 'public' => true,
'show_ui' => true, 'show_ui' => true,
); );
// get post types // Get post types
$post_types = get_post_types($args); $post_types = get_post_types($args);
foreach ($post_types AS $post_type) { foreach ($post_types AS $post_type) {
// filter only those which have an editor // Filter only those which have an editor
if (post_type_supports($post_type, 'editor')) { if (post_type_supports($post_type, 'editor')) {
$supported_post_types[] = $post_type; $supported_post_types[] = $post_type;
} }
...@@ -179,4 +189,4 @@ class CiviCRM_For_WordPress_Shortcodes_Modal { ...@@ -179,4 +189,4 @@ class CiviCRM_For_WordPress_Shortcodes_Modal {
return $supported_post_types; return $supported_post_types;
} }
} // class CiviCRM_For_WordPress_Shortcodes_Modal ends } // Class CiviCRM_For_WordPress_Shortcodes_Modal ends
This diff is collapsed.
...@@ -33,64 +33,72 @@ ...@@ -33,64 +33,72 @@
*/ */
// this file must not accessed directly // This file must not accessed directly
if ( ! defined( 'ABSPATH' ) ) exit; if ( ! defined( 'ABSPATH' ) ) exit;
/** /**
* Define CiviCRM_For_WordPress_Users Class * Define CiviCRM_For_WordPress_Users Class.
*
* @since 4.6
*/ */
class CiviCRM_For_WordPress_Users { class CiviCRM_For_WordPress_Users {
/** /**
* Declare our properties * Plugin object reference.
*
* @since 4.6
* @access public
* @var object $civi The plugin object reference.
*/ */
// init property to store reference to Civi
public $civi; public $civi;
/** /**
* Instance constructor * Instance constructor.
* *
* @return object $this The object instance * @since 4.6
*/ */
function __construct() { function __construct() {
// store reference to Civi object // Store reference to CiviCRM plugin object
$this->civi = civi_wp(); $this->civi = civi_wp();
} }
/** /**
* Register hooks to handle CiviCRM in a WordPress wpBasePage context * Register hooks.
* *
* @return void * @since 4.6
*/ */
public function register_hooks() { public function register_hooks() {
// add CiviCRM access capabilities to WordPress roles // Add CiviCRM access capabilities to WordPress roles
add_action( 'init', array( $this, 'set_access_capabilities' ) ); add_action( 'init', array( $this, 'set_access_capabilities' ) );
// do not hook into user updates if Civi not installed yet // Do not hook into user updates if CiviCRM not installed yet
if ( ! CIVICRM_INSTALLED ) return; if ( ! CIVICRM_INSTALLED ) return;
// synchronise users on insert and update // Synchronise users on insert and update
add_action( 'user_register', array( $this, 'update_user' ) ); add_action( 'user_register', array( $this, 'update_user' ) );
add_action( 'profile_update', array( $this, 'update_user' ) ); add_action( 'profile_update', array( $this, 'update_user' ) );
// delete ufMatch record when a WordPress user is deleted // Delete ufMatch record when a WordPress user is deleted
add_action( 'deleted_user', array( $this, 'delete_user_ufmatch' ), 10, 1 ); add_action( 'deleted_user', array( $this, 'delete_user_ufmatch' ), 10, 1 );
} }
/** /**
* Check permissions.
*
* Authentication function used by basepage_register_hooks() * Authentication function used by basepage_register_hooks()
* *
* @return bool True if authenticated, false otherwise * @since 4.6
*
* @param array $args The page arguments array.
* @return bool True if authenticated, false otherwise.
*/ */
public function check_permission( $args ) { public function check_permission( $args ) {
...@@ -100,12 +108,12 @@ class CiviCRM_For_WordPress_Users { ...@@ -100,12 +108,12 @@ class CiviCRM_For_WordPress_Users {
$config = CRM_Core_Config::singleton(); $config = CRM_Core_Config::singleton();
// set frontend true // Set frontend true
$config->userFrameworkFrontend = TRUE; $config->userFrameworkFrontend = TRUE;
require_once 'CRM/Utils/Array.php'; require_once 'CRM/Utils/Array.php';
// all profile and file urls, as well as user dashboard and tell-a-friend are valid // All profile and file urls, as well as user dashboard and tell-a-friend are valid
$arg1 = CRM_Utils_Array::value(1, $args); $arg1 = CRM_Utils_Array::value(1, $args);
$invalidPaths = array('admin'); $invalidPaths = array('admin');
if ( in_array( $arg1, $invalidPaths ) ) { if ( in_array( $arg1, $invalidPaths ) ) {
...@@ -118,9 +126,13 @@ class CiviCRM_For_WordPress_Users { ...@@ -118,9 +126,13 @@ class CiviCRM_For_WordPress_Users {
/** /**
* Get "permission denied" text.
*
* Called when authentication fails in basepage_register_hooks() * Called when authentication fails in basepage_register_hooks()
* *
* @return string Warning message * @since 4.6
*
* @return string Warning message.
*/ */
public function get_permission_denied() { public function get_permission_denied() {
return __( 'You do not have permission to access this content.', 'civicrm' ); return __( 'You do not have permission to access this content.', 'civicrm' );
...@@ -128,15 +140,17 @@ class CiviCRM_For_WordPress_Users { ...@@ -128,15 +140,17 @@ class CiviCRM_For_WordPress_Users {
/** /**
* Keep WordPress user synced with CiviCRM Contact * Handle WordPress user events.
*
* Callback function for 'user_register' hook * Callback function for 'user_register' hook
* Callback function for 'profile_update' hook * Callback function for 'profile_update' hook
* *
* CMW: seems to (wrongly) create new CiviCRM Contact every time a user changes their * CMW: seems to (wrongly) create new CiviCRM Contact every time a user changes their
* first_name or last_name attributes in WordPress. * first_name or last_name attributes in WordPress.
* *
* @since 4.6
*
* @param int $user_id The numeric ID of the WordPress user * @param int $user_id The numeric ID of the WordPress user
* @return void
*/ */
public function update_user( $user_id ) { public function update_user( $user_id ) {
...@@ -149,14 +163,15 @@ class CiviCRM_For_WordPress_Users { ...@@ -149,14 +163,15 @@ class CiviCRM_For_WordPress_Users {
/** /**
* Keep WordPress user synced with CiviCRM Contact * Keep WordPress user synced with CiviCRM Contact.
*
* @since 4.6
* *
* @param object $user The WordPress user object * @param object $user The WordPress user object.
* @return void
*/ */
public function sync_user( $user = FALSE ) { public function sync_user( $user = FALSE ) {
// sanity check // Sanity check
if ( $user === FALSE OR !is_a($user, 'WP_User') ) { if ( $user === FALSE OR !is_a($user, 'WP_User') ) {
return; return;
} }
...@@ -167,27 +182,29 @@ class CiviCRM_For_WordPress_Users { ...@@ -167,27 +182,29 @@ class CiviCRM_For_WordPress_Users {
require_once 'CRM/Core/BAO/UFMatch.php'; require_once 'CRM/Core/BAO/UFMatch.php';
// this does not return anything, so if we want to do anything further /*
// to the CiviCRM Contact, we have to search for it all over again... * This does not return anything, so if we want to do anything further
* to the CiviCRM Contact, we have to search for it all over again.
*/
CRM_Core_BAO_UFMatch::synchronize( CRM_Core_BAO_UFMatch::synchronize(
$user, // user object $user, // User object
TRUE, // update = true TRUE, // Update = true
'WordPress', // CMS 'WordPress', // CMS
'Individual' // contact type 'Individual' // contact type
); );
/* /*
// IN progress: synchronizeUFMatch does return the contact object, however // IN PROGRESS: synchronizeUFMatch does return the contact object, however
$civi_contact = CRM_Core_BAO_UFMatch::synchronizeUFMatch( $civi_contact = CRM_Core_BAO_UFMatch::synchronizeUFMatch(
$user, // user object $user, // User object
$user->ID, // ID $user->ID, // ID
$user->user_mail, // unique identifier $user->user_mail, // Unique identifier
null // unused null // Unused
'WordPress' // CMS 'WordPress' // CMS
'Individual' // contact type 'Individual' // contact type
); );
// now we can allow other plugins to do their thing // Now we can allow other plugins to do their thing
do_action( 'civicrm_contact_synced', $user, $civi_contact ); do_action( 'civicrm_contact_synced', $user, $civi_contact );
*/ */
...@@ -195,11 +212,13 @@ class CiviCRM_For_WordPress_Users { ...@@ -195,11 +212,13 @@ class CiviCRM_For_WordPress_Users {
/** /**
* When a WordPress user is deleted, delete the ufMatch record * When a WordPress user is deleted, delete the ufMatch record.
*
* Callback function for 'delete_user' hook * Callback function for 'delete_user' hook
* *
* @param $user_id The numerical ID of the WordPress user * @since 4.6
* @return void *
* @param $user_id The numerical ID of the WordPress user.
*/ */
public function delete_user_ufmatch( $user_id ) { public function delete_user_ufmatch( $user_id ) {
...@@ -207,7 +226,7 @@ class CiviCRM_For_WordPress_Users { ...@@ -207,7 +226,7 @@ class CiviCRM_For_WordPress_Users {
return; return;
} }
// delete the ufMatch record // Delete the ufMatch record
require_once 'CRM/Core/BAO/UFMatch.php'; require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::deleteUser($user_id); CRM_Core_BAO_UFMatch::deleteUser($user_id);
...@@ -215,13 +234,16 @@ class CiviCRM_For_WordPress_Users { ...@@ -215,13 +234,16 @@ class CiviCRM_For_WordPress_Users {
/** /**
* Function to create 'anonymous_user' role, if 'anonymous_user' role is not in * Create anonymous role and define capabilities.
* the WordPress installation and assign minimum capabilities for all WordPress roles *
* Function to create 'anonymous_user' role, if 'anonymous_user' role is not
* in the WordPress installation and assign minimum capabilities for all
* WordPress roles.
* *
* The legacy global scope function civicrm_wp_set_capabilities() is called from * The legacy global scope function civicrm_wp_set_capabilities() is called
* upgrade_4_3_alpha1() * from upgrade_4_3_alpha1()
* *
* @return void * @since 4.6
*/ */
public function set_wp_user_capabilities() { public function set_wp_user_capabilities() {
...@@ -245,7 +267,14 @@ class CiviCRM_For_WordPress_Users { ...@@ -245,7 +267,14 @@ class CiviCRM_For_WordPress_Users {
'view_public_civimail_content' => 1, 'view_public_civimail_content' => 1,
); );
// allow other plugins to filter /**
* Allow minimum capabilities to be filtered.
*
* @since 4.6
*
* @param array $default_min_capabilities The minimum capabilities.
* @return array $default_min_capabilities The modified capabilities.
*/
$min_capabilities = apply_filters( 'civicrm_min_capabilities', $default_min_capabilities ); $min_capabilities = apply_filters( 'civicrm_min_capabilities', $default_min_capabilities );
// Assign the Minimum capabilities (Civicrm permissions) to all WP roles // Assign the Minimum capabilities (Civicrm permissions) to all WP roles
...@@ -269,23 +298,24 @@ class CiviCRM_For_WordPress_Users { ...@@ -269,23 +298,24 @@ class CiviCRM_For_WordPress_Users {
/** /**
* Add CiviCRM access capabilities to WordPress roles * Add CiviCRM access capabilities to WordPress roles.
* this is a callback for the 'init' hook in register_hooks() *
* This is a callback for the 'init' hook in register_hooks().
* *
* The legacy global scope function wp_civicrm_capability() is called by * The legacy global scope function wp_civicrm_capability() is called by
* postProcess() in civicrm/CRM/ACL/Form/WordPress/Permissions.php * postProcess() in civicrm/CRM/ACL/Form/WordPress/Permissions.php
* *
* @return void * @since 4.6
*/ */
public function set_access_capabilities() { public function set_access_capabilities() {
// test for existing global // Test for existing global
global $wp_roles; global $wp_roles;
if ( ! isset( $wp_roles ) ) { if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles(); $wp_roles = new WP_Roles();
} }
// give access to civicrm page menu link to particular roles // Give access to civicrm page menu link to particular roles
$roles = apply_filters( 'civicrm_access_roles', array( 'super admin', 'administrator' ) ); $roles = apply_filters( 'civicrm_access_roles', array( 'super admin', 'administrator' ) );
foreach ( $roles as $role ) { foreach ( $roles as $role ) {
$roleObj = $wp_roles->get_role( $role ); $roleObj = $wp_roles->get_role( $role );
...@@ -302,15 +332,17 @@ class CiviCRM_For_WordPress_Users { ...@@ -302,15 +332,17 @@ class CiviCRM_For_WordPress_Users {
/** /**
* Get CiviCRM contact type * Get CiviCRM contact type.
*
* @since 4.6
* *
* @param string $default contact type * @param string $default The requested contact type.
* @return string $ctype contact type * @return string $ctype The computed contact type.
*/ */
public function get_civicrm_contact_type( $default = NULL ) { public function get_civicrm_contact_type( $default = NULL ) {
// here we are creating a new contact // Here we are creating a new contact
// get the contact type from the POST variables if any // Get the contact type from the POST variables if any
if ( isset( $_REQUEST['ctype'] ) ) { if ( isset( $_REQUEST['ctype'] ) ) {
$ctype = $_REQUEST['ctype']; $ctype = $_REQUEST['ctype'];
} elseif ( } elseif (
...@@ -335,6 +367,6 @@ class CiviCRM_For_WordPress_Users { ...@@ -335,6 +367,6 @@ class CiviCRM_For_WordPress_Users {
} }
} // class CiviCRM_For_WordPress_Users ends } // Class CiviCRM_For_WordPress_Users ends
...@@ -34,9 +34,9 @@ ...@@ -34,9 +34,9 @@
*/ */
// kick out if uninstall not called from WordPress // Kick out if uninstall not called from WordPress
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) { exit(); } if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) { exit(); }
// delete options that this plugin has set // Delete options that this plugin has set
delete_option( 'civicrm_activation_in_progress' ); delete_option( 'civicrm_activation_in_progress' );