├── assets ├── css │ └── acf │ │ ├── acfe │ │ └── pages │ │ │ └── page-settings-acfe.css │ │ └── pages │ │ └── page-admin-acf-migrate.css ├── images │ └── acf │ │ └── manual-sync │ │ ├── ui-icons_222222_256x240.png │ │ ├── ui-icons_2e83ff_256x240.png │ │ ├── ui-icons_454545_256x240.png │ │ ├── ui-icons_888888_256x240.png │ │ ├── ui-icons_cd0a0a_256x240.png │ │ ├── ui-bg_glass_55_fbf9ee_1x400.png │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ ├── ui-bg_glass_75_dadada_1x400.png │ │ ├── ui-bg_glass_75_e6e6e6_1x400.png │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ └── ui-bg_highlight-soft_75_cccccc_1x100.png ├── civicrm │ ├── custom_php │ │ └── .editorconfig │ └── custom_templates │ │ ├── .editorconfig │ │ └── CRM │ │ └── Contact │ │ └── Form │ │ └── Task │ │ └── CreateWordPressUsers.tpl ├── templates │ ├── help │ │ └── settings-help.php │ ├── civicrm │ │ ├── cwps-acf-activity-type-cpt.tpl │ │ ├── cwps-acf-contact-type-cpt.tpl │ │ ├── cwps-acf-participant-role-cpt.tpl │ │ ├── cwps-acf-participant-cpt.tpl │ │ └── cwps-acf-geo-mashup-compat.tpl │ ├── wordpress │ │ ├── taxonomies │ │ │ ├── term-participant-role-add.php │ │ │ ├── term-participant-role-edit.php │ │ │ ├── term-add.php │ │ │ └── term-edit.php │ │ ├── metaboxes │ │ │ ├── metabox-admin-settings-submit.php │ │ │ ├── metabox-acf-migrate-submit.php │ │ │ ├── metabox-admin-settings-acf.php │ │ │ ├── metabox-admin-settings-acfe.php │ │ │ ├── metabox-acf-groups-terms.php │ │ │ ├── metabox-acf-contacts-posts.php │ │ │ ├── metabox-acf-posts-contacts.php │ │ │ ├── metabox-acf-activities-posts.php │ │ │ ├── metabox-acf-posts-activities.php │ │ │ ├── metabox-acf-participants-posts.php │ │ │ ├── metabox-acf-posts-participants.php │ │ │ ├── metabox-acf-migrate-info.php │ │ │ └── metabox-admin-settings-profile.php │ │ ├── shortcodes │ │ │ └── shortcode-address.php │ │ └── pages │ │ │ ├── page-admin-acf-migrate.php │ │ │ ├── page-admin-settings.php │ │ │ └── page-admin-acf-sync.php │ └── buddypress │ │ └── metaboxes │ │ └── metabox-bp-field-content.php └── js │ └── acf │ ├── fields │ ├── civicrm-attachment-field.js │ ├── civicrm-activity-target-field.js │ ├── civicrm-activity-creator-field.js │ ├── civicrm-activity-assignee-field.js │ ├── civicrm-event-field.js │ ├── civicrm-contact-field.js │ ├── civicrm-relationship-field.js │ ├── civicrm-contact-ref-field.js │ ├── civicrm-multiset-field.js │ ├── civicrm-yes-no-field.js │ ├── civicrm-phone-field.js │ ├── civicrm-im-field.js │ ├── civicrm-address-field.js │ └── civicrm-event-group-field.js │ └── acfe │ ├── fields │ ├── civicrm-address-country-field.js │ ├── cwps-field-action-reference-case.js │ ├── cwps-field-action-reference-participant.js │ ├── cwps-field-action-reference-contact.js │ ├── civicrm-address-state-field.js │ └── civicrm-address-county-field.js │ └── pages │ └── page-settings-acfe.js ├── .editorconfig ├── phpcs.xml ├── includes ├── acf │ ├── acfe │ │ ├── locations │ │ │ └── cwps-acf-acfe-location-bypass.php │ │ ├── classes │ │ │ └── cwps-acf-acfe.php │ │ └── fields │ │ │ ├── cwps-acf-acfe-field-action-reference-case.php │ │ │ ├── cwps-acf-acfe-field-action-reference-contact.php │ │ │ ├── cwps-acf-acfe-field-action-reference-participant.php │ │ │ └── cwps-acf-acfe-field-address-country.php │ ├── classes │ │ ├── cwps-acf-civicrm-base.php │ │ ├── cwps-acf-acf.php │ │ ├── cwps-acf-acf-blocks.php │ │ ├── cwps-acf-participant-cpt-term-html.php │ │ └── cwps-acf-civicrm-campaign.php │ └── fields │ │ └── cwps-acf-field-civicrm-contact-id.php ├── buddypress │ └── cwps-bp-buddyboss.php ├── mapper │ ├── cwps-mapper.php │ ├── cwps-mapper-hooks.php │ └── cwps-mapper-hooks-acf.php └── civicrm │ ├── cwps-civicrm-contact-field.php │ └── cwps-civicrm-bulk.php ├── deploy.sh └── README.md /assets/css/acf/acfe/pages/page-settings-acfe.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Styles for the ACFE meta box on the Settings Page. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-icons_454545_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-icons_454545_256x240.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-icons_888888_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-icons_888888_256x240.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-bg_glass_55_fbf9ee_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-bg_glass_55_fbf9ee_1x400.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-bg_glass_75_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-bg_glass_75_dadada_1x400.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-bg_glass_75_e6e6e6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-bg_glass_75_e6e6e6_1x400.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-bg_glass_95_fef1ec_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-bg_glass_95_fef1ec_1x400.png -------------------------------------------------------------------------------- /assets/images/acf/manual-sync/ui-bg_highlight-soft_75_cccccc_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/christianwach/civicrm-wp-profile-sync/HEAD/assets/images/acf/manual-sync/ui-bg_highlight-soft_75_cccccc_1x100.png -------------------------------------------------------------------------------- /assets/civicrm/custom_php/.editorconfig: -------------------------------------------------------------------------------- 1 | # CiviCRM-style editor configuration normalization. 2 | # @see https://editorconfig.org/ 3 | 4 | # This is the not top-most .editorconfig file; search in parent directories. 5 | root = false 6 | 7 | # Indentation. 8 | [*.{php,tpl}] 9 | indent_style = space 10 | indent_size = 2 11 | -------------------------------------------------------------------------------- /assets/civicrm/custom_templates/.editorconfig: -------------------------------------------------------------------------------- 1 | # CiviCRM-style editor configuration normalization. 2 | # @see https://editorconfig.org/ 3 | 4 | # This is the not top-most .editorconfig file; search in parent directories. 5 | root = false 6 | 7 | # Indentation. 8 | [*.{php,tpl}] 9 | indent_style = space 10 | indent_size = 2 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://editorconfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | # Tab indentation 13 | [*.php] 14 | indent_style = tab 15 | -------------------------------------------------------------------------------- /assets/templates/help/settings-help.php: -------------------------------------------------------------------------------- 1 | 12 |

13 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-attachment-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Attachment Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | /** 8 | * Register ACF Field Type. 9 | * 10 | * @since 0.5.4 11 | */ 12 | (function($, undefined){ 13 | 14 | // Extend the Repeater Field model. 15 | var Field = acf.models.RepeaterField.extend({ 16 | type: 'civicrm_attachment', 17 | }); 18 | 19 | // Register it. 20 | acf.registerFieldType( Field ); 21 | 22 | })(jQuery); 23 | -------------------------------------------------------------------------------- /assets/css/acf/pages/page-admin-acf-migrate.css: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync "ACF Migrate" Styles 3 | * 4 | * Implements styling for CiviCRM Profile Sync "ACF Migrate" page. 5 | * 6 | * @package WordPress 7 | * @subpackage CiviCRM_Profile_Sync 8 | */ 9 | 10 | 11 | /* Admin Screen setup 12 | ----------------------------------*/ 13 | #cwps_info h4 { 14 | font-size: 1.1em; 15 | } 16 | 17 | #cwps_info p, #cwps_info ul li { 18 | font-size: 14px; 19 | } 20 | 21 | #cwps_info code { 22 | font-size: 13px; 23 | } 24 | 25 | #cwps_info ul { 26 | list-style: disc; 27 | padding-left: 20px; 28 | } 29 | -------------------------------------------------------------------------------- /assets/templates/civicrm/cwps-acf-activity-type-cpt.tpl: -------------------------------------------------------------------------------- 1 | {* template block that contains the new fields *} 2 | 3 | 4 | 5 | 6 | 7 |
{$form.cwps_acf_cpt.html}
8 | 9 | {* reposition the above blocks after #someOtherBlock *} 10 | 18 | -------------------------------------------------------------------------------- /assets/templates/civicrm/cwps-acf-contact-type-cpt.tpl: -------------------------------------------------------------------------------- 1 | {* template block that contains the new fields *} 2 | 3 | 4 | 5 | 6 | 7 |
{$form.cwps_acf_cpt.html}
8 | 9 | {* reposition the above blocks after #someOtherBlock *} 10 | 18 | -------------------------------------------------------------------------------- /assets/templates/civicrm/cwps-acf-participant-role-cpt.tpl: -------------------------------------------------------------------------------- 1 | {* template block that contains the new fields *} 2 | 3 | 4 | 5 | 6 | 7 |
{$form.cwps_acf_cpt.html}
8 | 9 | {* reposition the above blocks after #someOtherBlock *} 10 | 18 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-activity-target-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Activity Target Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'civicrm_activity_target', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'civicrm_activity_target' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'civicrm_activity_target' ); 20 | 21 | })(jQuery); 22 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-activity-creator-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Activity Creator Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'civicrm_activity_creator', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'civicrm_activity_creator' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'civicrm_activity_creator' ); 20 | 21 | })(jQuery); 22 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-activity-assignee-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Activity Assignee Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'civicrm_activity_assignee', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'civicrm_activity_assignee' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'civicrm_activity_assignee' ); 20 | 21 | })(jQuery); 22 | -------------------------------------------------------------------------------- /assets/templates/civicrm/cwps-acf-participant-cpt.tpl: -------------------------------------------------------------------------------- 1 | {* template block that contains the new fields *} 2 | 3 | 4 | 5 | 10 | 11 |
6 | {$form.cwps_acf_enable_cpt.html} 7 |
8 | {$cwps_acf_enable_cpt_help} 9 |
12 | 13 | {* reposition the above block after #someOtherBlock *} 14 | 22 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-event-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Participant Event Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'civicrm_event', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'civicrm_event' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'civicrm_event' ); 20 | acf.registerConditionForFieldType( 'SelectEqualTo', 'civicrm_event' ); 21 | acf.registerConditionForFieldType( 'SelectNotEqualTo', 'civicrm_event' ); 22 | 23 | })(jQuery); 24 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-contact-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Contact Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'civicrm_contact', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add some basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'civicrm_contact' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'civicrm_contact' ); 20 | acf.registerConditionForFieldType( 'SelectEqualTo', 'civicrm_contact' ); 21 | acf.registerConditionForFieldType( 'SelectNotEqualTo', 'civicrm_contact' ); 22 | 23 | })(jQuery); 24 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-relationship-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Relationship. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'civicrm_relationship', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'civicrm_relationship' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'civicrm_relationship' ); 20 | acf.registerConditionForFieldType( 'SelectEqualTo', 'civicrm_relationship' ); 21 | acf.registerConditionForFieldType( 'SelectNotEqualTo', 'civicrm_relationship' ); 22 | 23 | })(jQuery); 24 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-contact-ref-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Contact Reference Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'civicrm_contact_ref', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'civicrm_contact_ref' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'civicrm_contact_ref' ); 20 | //acf.registerConditionForFieldType( 'SelectEqualTo', 'civicrm_contact_ref' ); 21 | //acf.registerConditionForFieldType( 'SelectNotEqualTo', 'civicrm_contact_ref' ); 22 | 23 | })(jQuery); 24 | -------------------------------------------------------------------------------- /assets/js/acf/acfe/fields/civicrm-address-country-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM ACFE Country Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'cwps_acfe_address_country', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'cwps_acfe_address_country' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'cwps_acfe_address_country' ); 20 | acf.registerConditionForFieldType( 'SelectEqualTo', 'cwps_acfe_address_country' ); 21 | acf.registerConditionForFieldType( 'SelectNotEqualTo', 'cwps_acfe_address_country' ); 22 | 23 | })(jQuery); 24 | -------------------------------------------------------------------------------- /assets/js/acf/acfe/fields/cwps-field-action-reference-case.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Case Reference Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'cwps_acfe_case_action_ref', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'cwps_acfe_case_action_ref' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'cwps_acfe_case_action_ref' ); 20 | acf.registerConditionForFieldType( 'SelectEqualTo', 'cwps_acfe_case_action_ref' ); 21 | acf.registerConditionForFieldType( 'SelectNotEqualTo', 'cwps_acfe_case_action_ref' ); 22 | 23 | })(jQuery); 24 | -------------------------------------------------------------------------------- /assets/js/acf/acfe/fields/cwps-field-action-reference-participant.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Participant Reference Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | type: 'cwps_acfe_participant_action_ref', 12 | }); 13 | 14 | // Register it. 15 | acf.registerFieldType( Field ); 16 | 17 | // Add basic condition types. 18 | acf.registerConditionForFieldType( 'hasValue', 'cwps_acfe_participant_action_ref' ); 19 | acf.registerConditionForFieldType( 'hasNoValue', 'cwps_acfe_participant_action_ref' ); 20 | acf.registerConditionForFieldType( 'SelectEqualTo', 'cwps_acfe_participant_action_ref' ); 21 | acf.registerConditionForFieldType( 'SelectNotEqualTo', 'cwps_acfe_participant_action_ref' ); 22 | 23 | })(jQuery); 24 | -------------------------------------------------------------------------------- /assets/templates/wordpress/taxonomies/term-participant-role-add.php: -------------------------------------------------------------------------------- 1 | 12 |
13 | 14 | 15 |
16 |
17 | 18 | 19 |
20 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-admin-settings-submit.php: -------------------------------------------------------------------------------- 1 | 12 |
13 |
14 |
15 |
16 | 17 |
18 |
19 |
20 |
21 | 22 |
23 |
24 | 25 | 26 |
27 |
28 |
29 |
30 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-multiset-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Multiple Record Set Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | /** 8 | * Register ACF Field Type. 9 | * 10 | * @since 0.8 11 | */ 12 | (function($, undefined){ 13 | 14 | // Extend the Repeater Field model. 15 | var Field = acf.models.RepeaterField.extend({ 16 | type: 'civicrm_multiset', 17 | }); 18 | 19 | // Register it. 20 | acf.registerFieldType( Field ); 21 | 22 | })(jQuery); 23 | 24 | /** 25 | * Perform actions when dom_ready fires. 26 | * 27 | * @since 0.8 28 | */ 29 | jQuery(document).ready(function($) { 30 | 31 | /** 32 | * Callback for clicks on the "Add Record Set" button. 33 | * 34 | * @since 0.8 35 | * 36 | * @param {Object} event The click event object. 37 | */ 38 | $('.acf-field.civicrm_multiset .acf-actions .acf-button.button-primary').click( function( event ) { 39 | 40 | console.log( 'Add Record Set clicked' ); 41 | 42 | }); 43 | 44 | }); // End document.ready() 45 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-migrate-submit.php: -------------------------------------------------------------------------------- 1 | 12 |
13 |
14 |
15 |
16 | 17 |
18 |
19 |
20 |
21 | 22 |
23 |
24 | 25 | 26 |
27 |
28 |
29 |
30 | -------------------------------------------------------------------------------- /assets/templates/wordpress/taxonomies/term-participant-role-edit.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | /> 16 | 17 | 18 | 19 | 20 | 21 | /> 22 | 23 | 24 | -------------------------------------------------------------------------------- /assets/js/acf/acfe/fields/cwps-field-action-reference-contact.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Contact Reference Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Extend the Select Field model. 10 | var Field = acf.models.SelectField.extend({ 11 | 12 | type: 'cwps_acfe_contact_action_ref', 13 | 14 | /* 15 | render: function() { 16 | console.log( 'here', here ); 17 | acf.models.SelectField.render(); 18 | } 19 | 20 | wait: 'load', 21 | 22 | actions: { 23 | 'new_field': 'newField' 24 | }, 25 | 26 | newField: function(field) { 27 | 28 | } 29 | */ 30 | 31 | }); 32 | 33 | // Register it. 34 | acf.registerFieldType( Field ); 35 | 36 | // Add basic condition types. 37 | acf.registerConditionForFieldType( 'hasValue', 'cwps_acfe_contact_action_ref' ); 38 | acf.registerConditionForFieldType( 'hasNoValue', 'cwps_acfe_contact_action_ref' ); 39 | acf.registerConditionForFieldType( 'SelectEqualTo', 'cwps_acfe_contact_action_ref' ); 40 | acf.registerConditionForFieldType( 'SelectNotEqualTo', 'cwps_acfe_contact_action_ref' ); 41 | 42 | })(jQuery); 43 | -------------------------------------------------------------------------------- /assets/civicrm/custom_templates/CRM/Contact/Form/Task/CreateWordPressUsers.tpl: -------------------------------------------------------------------------------- 1 | {if $rows} 2 |
3 | {include file="CRM/common/formButtons.tpl" location="top"} 4 |
5 | 6 |
7 | 8 |
9 |
10 | 11 | 12 | 13 | 14 | 15 | 18 | {foreach from=$rows item=row} 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | {/foreach} 27 |
{$tableID}{$tableType}{$tableDisplayName}{$tableEmail} 16 | {$tableUser} 17 |
{$row.id}{$row.contact_type}{$row.display_name}{$row.email}{$row.has_user}
28 |
29 | 30 |
31 | {include file="CRM/common/formButtons.tpl" location="bottom"} 32 |
33 | 34 | {else} 35 | 36 |
37 |
38 | {$notFound} 39 |
40 | 41 | {/if} 42 | -------------------------------------------------------------------------------- /assets/templates/wordpress/taxonomies/term-add.php: -------------------------------------------------------------------------------- 1 | 12 |
13 | 14 | 22 |

23 |
24 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-admin-settings-acf.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 17 | 27 | 28 |
15 | 16 | 18 |

19 | > 20 |

21 | 22 |

23 | 24 |

25 | 26 |
29 | -------------------------------------------------------------------------------- /assets/templates/wordpress/shortcodes/shortcode-address.php: -------------------------------------------------------------------------------- 1 | 15 | 16 |
17 | 18 | 19 |
20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
45 | 46 | 47 | 48 |
49 | 50 | 51 |
52 | -------------------------------------------------------------------------------- /assets/templates/wordpress/taxonomies/term-edit.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 31 |

32 | 33 | 34 | -------------------------------------------------------------------------------- /assets/js/acf/acfe/pages/page-settings-acfe.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Javascript for the Settings Page. 3 | * 4 | * Implements visibility toggles on the plugin's Settings Page. 5 | * 6 | * @package CiviCRM_WP_Profile_Sync 7 | */ 8 | 9 | /** 10 | * Pass the jQuery shortcut in. 11 | * 12 | * @since 0.6.6 13 | * 14 | * @param {Object} $ The jQuery object. 15 | */ 16 | ( function( $ ) { 17 | 18 | /** 19 | * Act on document ready. 20 | * 21 | * @since 0.6.6 22 | */ 23 | $(document).ready( function() { 24 | 25 | // Define vars. 26 | var acf_enabled = $('#cwps_acf_integration_checkbox'), 27 | acfe_enabled = $('#cwps_acfe_integration_enabled'), 28 | metabox = $('#cwps_acfe_integration'); 29 | transients = $('table.cwps_acfe_transients'); 30 | 31 | // Initial visibility toggles. 32 | if ( acf_enabled.prop( 'checked' ) ) { 33 | metabox.show(); 34 | } else { 35 | metabox.hide(); 36 | } 37 | if ( acfe_enabled.prop( 'checked' ) ) { 38 | transients.show(); 39 | } else { 40 | transients.hide(); 41 | } 42 | 43 | /** 44 | * Add a click event listener to the "ACF Integration Enabled" checkbox. 45 | * 46 | * @since 0.6.6 47 | * 48 | * @param {Object} event The event object. 49 | */ 50 | acf_enabled.on( 'click', function( event ) { 51 | if ( acf_enabled.prop( 'checked' ) ) { 52 | metabox.show(); 53 | } else { 54 | metabox.hide(); 55 | } 56 | } ); 57 | 58 | /** 59 | * Add a click event listener to the "ACF Extended Forms Integration Enabled" checkbox. 60 | * 61 | * @since 0.6.6 62 | * 63 | * @param {Object} event The event object. 64 | */ 65 | acfe_enabled.on( 'click', function( event ) { 66 | if ( acfe_enabled.prop( 'checked' ) ) { 67 | transients.show(); 68 | } else { 69 | transients.hide(); 70 | } 71 | } ); 72 | 73 | }); 74 | 75 | } )( jQuery ); 76 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-yes-no-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Yes/No. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Declare the Field type. 10 | var Radio = acf.getFieldType( 'radio' ); 11 | var Field = Radio.extend({ 12 | type: 'civicrm_yes_no', 13 | }); 14 | 15 | // Register it. 16 | acf.registerFieldType( Field ); 17 | 18 | // Get condition types. 19 | var EqualTo = acf.getConditionType( 'EqualTo' ); 20 | var NotEqualTo = acf.getConditionType( 'NotEqualTo' ); 21 | 22 | /** 23 | * CiviCRM Yes/No "EqualTo" condition. 24 | * 25 | * @since 0.6.6 26 | */ 27 | var CiviCRMYesNoEqualTo = EqualTo.extend({ 28 | type: 'CiviCRMYesNoEqualTo', 29 | choiceType: 'select', 30 | fieldTypes: [ 'civicrm_yes_no' ], 31 | choices: function( field ) { 32 | return [ 33 | { 34 | id: 1, 35 | text: acf.__( 'Yes' ) 36 | }, 37 | { 38 | id: 0, 39 | text: acf.__( 'No' ) 40 | }, 41 | { 42 | id: 2, 43 | text: acf.__( 'Unknown' ) 44 | } 45 | ]; 46 | } 47 | }); 48 | 49 | /** 50 | * CiviCRM Yes/No "NotEqualTo" condition. 51 | * 52 | * @since 0.6.6 53 | */ 54 | var CiviCRMYesNoNotEqualTo = NotEqualTo.extend({ 55 | type: 'CiviCRMYesNoNotEqualTo', 56 | choiceType: 'select', 57 | fieldTypes: [ 'civicrm_yes_no' ], 58 | choices: function( field ) { 59 | return [ 60 | { 61 | id: 1, 62 | text: acf.__( 'Yes' ) 63 | }, 64 | { 65 | id: 0, 66 | text: acf.__( 'No' ) 67 | }, 68 | { 69 | id: 2, 70 | text: acf.__( 'Unknown' ) 71 | } 72 | ]; 73 | } 74 | }); 75 | 76 | // Register condition types. 77 | acf.registerConditionType( CiviCRMYesNoEqualTo ); 78 | acf.registerConditionType( CiviCRMYesNoNotEqualTo ); 79 | 80 | // Add condition types. 81 | acf.registerConditionForFieldType( 'CiviCRMYesNoEqualTo', 'civicrm_yes_no' ); 82 | acf.registerConditionForFieldType( 'CiviCRMYesNoNotEqualTo', 'civicrm_yes_no' ); 83 | 84 | })(jQuery); 85 | -------------------------------------------------------------------------------- /assets/templates/wordpress/pages/page-admin-acf-migrate.php: -------------------------------------------------------------------------------- 1 | 12 |
13 | 14 |

15 | 16 | 33 | 34 | 35 |
36 | 37 | 38 | 39 | 40 | 41 |
42 | 43 |
44 | 45 | 47 | 48 |
49 | id, 'side', null ); ?> 50 |
51 | 52 |
53 | id, 'normal', null ); ?> 54 | id, 'advanced', null ); ?> 55 |
56 | 57 |
58 |
59 | 60 |
61 | 62 |
63 | 64 |
65 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-admin-settings-acfe.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 17 | 27 | 28 |
15 | 16 | 18 |

19 | > 20 |

21 | 22 |

23 | 24 |

25 | 26 |
29 | 30 | 31 | 32 | 35 | 41 | 42 |
33 | 34 | 36 |

37 | > 38 |

39 |

40 |
43 | -------------------------------------------------------------------------------- /assets/templates/wordpress/pages/page-admin-settings.php: -------------------------------------------------------------------------------- 1 | 12 |
13 | 14 |

15 | 16 | 17 | 34 | 35 |
36 | 37 | 38 | 39 |
40 | 41 | 42 | 43 | 44 | 45 |
46 | 47 |
48 | 49 | 51 | 52 |
53 | id, 'side', null ); ?> 54 |
55 | 56 |
57 | id, 'normal', null ); ?> 58 | id, 'advanced', null ); ?> 59 |
60 | 61 |
62 |
63 | 64 |
65 | 66 |
67 | 68 |
69 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | . 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 0 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | assets/civicrm/* 68 | 69 | 70 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-phone-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Phone Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | /** 8 | * Register ACF Field Type. 9 | * 10 | * @since 0.4 11 | */ 12 | (function($, undefined){ 13 | 14 | // Extend the Repeater Field model. 15 | var Field = acf.models.RepeaterField.extend({ 16 | type: 'civicrm_phone', 17 | }); 18 | 19 | // Register it. 20 | acf.registerFieldType( Field ); 21 | 22 | })(jQuery); 23 | 24 | /** 25 | * Perform actions when dom_ready fires. 26 | * 27 | * @since 0.4 28 | */ 29 | jQuery(document).ready(function($) { 30 | 31 | /** 32 | * Set up click handler for the "Primary Phone Record" radio buttons. 33 | * 34 | * @since 0.4 35 | * 36 | * @param {Object} event The click event object. 37 | */ 38 | function cwps_acf_primary_phone_selector() { 39 | 40 | // Declare vars. 41 | var scope = $('.acf-field.civicrm_phone'), 42 | radios = '.acf-input ul.acf-radio-list li label input'; 43 | 44 | // Unbind first to allow repeated calls to this function. 45 | scope.off( 'click', radios ); 46 | 47 | /** 48 | * Callback for clicks on the "Primary Phone Record" radio buttons. 49 | * 50 | * @since 0.4 51 | */ 52 | scope.on( 'click', radios, function( event ) { 53 | 54 | // Prevent bubbling. 55 | event.stopPropagation(); 56 | 57 | // Declare vars. 58 | var container, buttons; 59 | 60 | // Get container element. 61 | container = $(this).parents( 'table.acf-table tbody' ); 62 | 63 | // Get radio button elements. 64 | buttons = $( 'ul.acf-radio-list li label input', container ); 65 | 66 | // Set all radio buttons to unchecked. 67 | buttons.prop( 'checked', false ); 68 | buttons.parent().removeClass( 'selected' ); 69 | 70 | // Keep this radio button checked. 71 | $(this).prop( 'checked', true ); 72 | $(this).parent().addClass( 'selected' ); 73 | 74 | }); 75 | 76 | } 77 | 78 | // Set up click handler immediately. 79 | cwps_acf_primary_phone_selector(); 80 | 81 | /** 82 | * Callback for clicks on the "Add Phone Number" button. 83 | * 84 | * @since 0.4 85 | * 86 | * @param {Object} event The click event object. 87 | */ 88 | $('.acf-field.civicrm_phone .acf-actions .acf-button.button-primary').click( function( event ) { 89 | 90 | // Reset click handler because the DOM has been added to. 91 | cwps_acf_primary_phone_selector(); 92 | 93 | }); 94 | 95 | }); // End document.ready() 96 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-im-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Instant Messenger Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | /** 8 | * Register ACF Field Type. 9 | * 10 | * @since 0.4 11 | */ 12 | (function($, undefined){ 13 | 14 | // Extend the Repeater Field model. 15 | var Field = acf.models.RepeaterField.extend({ 16 | type: 'civicrm_im', 17 | }); 18 | 19 | // Register it. 20 | acf.registerFieldType( Field ); 21 | 22 | })(jQuery); 23 | 24 | /** 25 | * Perform actions when dom_ready fires. 26 | * 27 | * @since 0.4 28 | */ 29 | jQuery(document).ready(function($) { 30 | 31 | /** 32 | * Set up click handler for the "Primary Instant Messenger" radio buttons. 33 | * 34 | * @since 0.4 35 | * 36 | * @param {Object} event The click event object. 37 | */ 38 | function cwps_acf_primary_im_selector() { 39 | 40 | // Declare vars. 41 | var scope = $('.acf-field.civicrm_im'), 42 | radios = '.acf-input ul.acf-radio-list li label input'; 43 | 44 | // Unbind first to allow repeated calls to this function. 45 | scope.off( 'click', radios ); 46 | 47 | /** 48 | * Callback for clicks on the "Primary Instant Messenger" radio buttons. 49 | * 50 | * @since 0.4 51 | */ 52 | scope.on( 'click', radios, function( event ) { 53 | 54 | // Prevent bubbling. 55 | event.stopPropagation(); 56 | 57 | // Declare vars. 58 | var container, buttons; 59 | 60 | // Get container element. 61 | container = $(this).parents( 'table.acf-table tbody' ); 62 | 63 | // Get radio button elements. 64 | buttons = $( 'ul.acf-radio-list li label input', container ); 65 | 66 | // Set all radio buttons to unchecked. 67 | buttons.prop( 'checked', false ); 68 | buttons.parent().removeClass( 'selected' ); 69 | 70 | // Keep this radio button checked. 71 | $(this).prop( 'checked', true ); 72 | $(this).parent().addClass( 'selected' ); 73 | 74 | }); 75 | 76 | } 77 | 78 | // Set up click handler immediately. 79 | cwps_acf_primary_im_selector(); 80 | 81 | /** 82 | * Callback for clicks on the "Add Instant Messenger" button. 83 | * 84 | * @since 0.4 85 | * 86 | * @param {Object} event The click event object. 87 | */ 88 | $('.acf-field.civicrm_im .acf-actions .acf-button.button-primary').click( function( event ) { 89 | 90 | // Reset click handler because the DOM has been added to. 91 | cwps_acf_primary_im_selector(); 92 | 93 | }); 94 | 95 | }); // End document.ready() 96 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-groups-terms.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 | 16 |

17 | 18 | 19 | 20 | 21 | $label ) : ?> 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
36 | 37 | 38 | 39 |
49 | 50 | 51 |
52 |

53 |
54 | 55 | 56 | 57 |
58 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-address-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Address Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | /** 8 | * Register ACF Field Type. 9 | * 10 | * @since 0.8.2 11 | */ 12 | (function($, undefined){ 13 | 14 | // Extend the Repeater Field model. 15 | var Field = acf.models.RepeaterField.extend({ 16 | type: 'civicrm_address', 17 | }); 18 | 19 | // Register it. 20 | acf.registerFieldType( Field ); 21 | 22 | })(jQuery); 23 | 24 | /** 25 | * Perform actions when dom_ready fires. 26 | * 27 | * @since 0.8.2 28 | */ 29 | jQuery(document).ready(function($) { 30 | 31 | /** 32 | * Set up click handler for the "Primary Address" radio buttons. 33 | * 34 | * @since 0.8.2 35 | * 36 | * @param {Object} event The click event object. 37 | */ 38 | function cwps_acf_primary_address_selector() { 39 | 40 | // Declare vars. 41 | var scope = $('.acf-field.civicrm_address'), 42 | radios = '.acf-input ul.acf-radio-list li label input'; 43 | 44 | // Unbind first to allow repeated calls to this function. 45 | scope.off( 'click', radios ); 46 | 47 | /** 48 | * Callback for clicks on the "Primary Address Record" radio buttons. 49 | * 50 | * @since 0.8.2 51 | */ 52 | scope.on( 'click', radios, function( event ) { 53 | 54 | // Prevent bubbling. 55 | event.stopPropagation(); 56 | 57 | // Declare vars. 58 | var container, buttons; 59 | 60 | // Get container element. 61 | container = $(this).parents( 'table.acf-table tbody' ); 62 | 63 | // Get radio button elements. 64 | buttons = $( 'ul.acf-radio-list li label input', container ); 65 | 66 | // Set all radio buttons to unchecked. 67 | buttons.prop( 'checked', false ); 68 | buttons.parent().removeClass( 'selected' ); 69 | 70 | // Keep this radio button checked. 71 | $(this).prop( 'checked', true ); 72 | $(this).parent().addClass( 'selected' ); 73 | 74 | }); 75 | 76 | } 77 | 78 | // Set up click handler immediately. 79 | cwps_acf_primary_address_selector(); 80 | 81 | /** 82 | * Callback for clicks on the "Add Address" button. 83 | * 84 | * @since 0.8.2 85 | * 86 | * @param {Object} event The click event object. 87 | */ 88 | $('.acf-field.civicrm_address .acf-actions .acf-button.button-primary').click( function( event ) { 89 | 90 | // Reset click handler because the DOM has been added to. 91 | cwps_acf_primary_address_selector(); 92 | 93 | }); 94 | 95 | }); // End document.ready() 96 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-contacts-posts.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 | 16 |

17 | 18 | 19 | 20 | 21 | $label ) : ?> 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
36 | 37 | 38 | 39 |
49 | 50 | 51 |
52 |

53 |
54 | 55 | 56 | 57 |
58 | -------------------------------------------------------------------------------- /assets/templates/wordpress/pages/page-admin-acf-sync.php: -------------------------------------------------------------------------------- 1 | 12 |
13 | 14 |

15 | 16 | 33 | 34 |

35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 |
52 | 53 |
54 | 55 |
56 | id, 'normal', '' ); ?> 57 |
58 | 59 |
60 | id, 'side', '' ); ?> 61 |
62 | 63 |
64 |
65 | 66 |
67 | 68 |
69 | 70 |
71 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-posts-contacts.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 | 16 |

17 | 18 | 19 | 20 | 21 | $label ) : ?> 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
36 | 37 | 38 | 39 |
49 | 50 | 51 |
52 |

53 |
54 | 55 | 56 | 57 |
58 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-activities-posts.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 | 16 |

17 | 18 | 19 | 20 | 21 | $label ) : ?> 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
36 | 37 | 38 | 39 |
49 | 50 | 51 |
52 |

53 |
54 | 55 | 56 | 57 |
58 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-posts-activities.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 | 16 |

17 | 18 | 19 | 20 | 21 | $label ) : ?> 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
36 | 37 | 38 | 39 |
49 | 50 | 51 |
52 |

53 |
54 | 55 | 56 | 57 |
58 | 59 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-participants-posts.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 | 16 |

17 | 18 | 19 | 20 | 21 | $label ) : ?> 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
36 | 37 | 38 | 39 |
49 | 50 | 51 |
52 |

53 |
54 | 55 | 56 | 57 |
58 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-posts-participants.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |
15 | 16 |

17 | 18 | 19 | 20 | 21 | $label ) : ?> 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
36 | 37 | 38 | 39 |
49 | 50 | 51 |
52 |

53 |
54 | 55 | 56 | 57 |
58 | 59 | -------------------------------------------------------------------------------- /includes/acf/acfe/locations/cwps-acf-acfe-location-bypass.php: -------------------------------------------------------------------------------- 1 | name = 'form_civicrm'; 32 | $this->label = __( 'CiviCRM Entity for ACFE', 'civicrm-wp-profile-sync' ); 33 | $this->category = 'forms'; 34 | $this->object_type = 'civicrm'; 35 | 36 | } 37 | 38 | // ----------------------------------------------------------------------------------- 39 | 40 | /** 41 | * Matches the provided rule against the screen args. 42 | * 43 | * Since this is not a true "location" but rather a way of linking a Field 44 | * Group to a CiviCRM Entity, all that's needed is to test for the presence 45 | * of the key in the "screen". 46 | * 47 | * @since 0.5 48 | * 49 | * @param array $rule The Location Rule. 50 | * @param array $screen The screen args. 51 | * @param array $field_group The Field Group settings. 52 | * @return bool True if the rule applies, false otherwise. 53 | */ 54 | public function match( $rule, $screen, $field_group ) { 55 | 56 | // Bail if not the screen we're after. 57 | if ( ! array_key_exists( $this->name, $screen ) ) { 58 | return false; 59 | } 60 | 61 | // --< 62 | return true; 63 | 64 | } 65 | 66 | /** 67 | * Returns an array of operators for this Location Type. 68 | * 69 | * Linking a Field Group to a CiviCRM Entity only require the equality operator. 70 | * 71 | * @since 0.5 72 | * 73 | * @param array $rule THe Location Rule. 74 | * @return array The array of labelled operators. 75 | */ 76 | public static function get_operators( $rule ) { 77 | 78 | return [ 79 | '==' => __( 'is', 'civicrm-wp-profile-sync' ), 80 | ]; 81 | 82 | } 83 | 84 | /** 85 | * Returns an array of possible values for this location. 86 | * 87 | * @since 0.5 88 | * 89 | * @param array $rule The Location Rule. 90 | * @return array 91 | */ 92 | public function get_values( $rule ) { 93 | 94 | /** 95 | * Requests a nested array of possible values from Entity classes. 96 | * 97 | * @since 0.5 98 | * 99 | * @param array The empty default Entity values array. 100 | * @param array $rule The current Location Rule. 101 | */ 102 | $entities = apply_filters( 'cwps/acf/bypass/location/query_entities', [], $rule ); 103 | 104 | // --< 105 | return $entities; 106 | 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /assets/templates/civicrm/cwps-acf-geo-mashup-compat.tpl: -------------------------------------------------------------------------------- 1 | {* template block that contains the new fields *} 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
{$form.geo_mashup.html} {$geo_mashup_help}
{$form.geo_mashup_metabox.html} {$geo_mashup_metabox_help}
12 | 13 | {* reposition the above block after #someOtherBlock *} 14 | 99 | -------------------------------------------------------------------------------- /includes/buddypress/cwps-bp-buddyboss.php: -------------------------------------------------------------------------------- 1 | plugin = $bp_loader->plugin; 52 | $this->bp_loader = $bp_loader; 53 | 54 | // Init when the CiviCRM object is loaded. 55 | add_action( 'cwps/buddypress/loaded', [ $this, 'initialise' ] ); 56 | 57 | } 58 | 59 | /** 60 | * Do stuff on plugin init. 61 | * 62 | * @since 0.5 63 | */ 64 | public function initialise() { 65 | 66 | // Register hooks. 67 | $this->register_hooks(); 68 | 69 | /** 70 | * Broadcast that this class is now loaded. 71 | * 72 | * @since 0.5 73 | */ 74 | do_action( 'cwps/buddypress/buddyboss/loaded' ); 75 | 76 | } 77 | 78 | /** 79 | * Register hooks. 80 | * 81 | * @since 0.5 82 | */ 83 | public function register_hooks() { 84 | 85 | // Hook into CiviCRM-to-WordPress Contact sync process. 86 | add_action( 'cwps/civicrm/contact/contact_sync/post', [ $this, 'contact_synced' ], 20 ); 87 | 88 | } 89 | 90 | // ----------------------------------------------------------------------------------- 91 | 92 | /** 93 | * Trigger the sync process to populate the core BuddyBoss xProfile Fields. 94 | * 95 | * @since 0.5 96 | * 97 | * @param array $args The array of CiviCRM params. 98 | */ 99 | public function contact_synced( $args ) { 100 | 101 | // Check if our setting allows Nickname sync. 102 | $nickname_sync = $this->plugin->admin->setting_get( 'user_profile_nickname_sync', 1 ); 103 | 104 | // Prevent sync if not. 105 | if ( 1 !== (int) $nickname_sync ) { 106 | add_filter( 'bp_xprofile_nickname_field_id', [ $this, 'nickname_sync_prevent' ] ); 107 | } 108 | 109 | // Trigger the sync process. 110 | bp_xprofile_sync_bp_profile( $args['user_id'] ); 111 | 112 | // Reinstate normal operation. 113 | if ( 1 !== (int) $nickname_sync ) { 114 | remove_filter( 'bp_xprofile_nickname_field_id', [ $this, 'nickname_sync_prevent' ] ); 115 | } 116 | 117 | } 118 | 119 | /** 120 | * Prevents Nickname sync to BuddyBoss. 121 | * 122 | * @since 0.5 123 | * 124 | * @param integer $field_id The numeric ID of the BuddyBoss Nickname Field. 125 | * @return integer Set to "0" to prevent Nickname sync. 126 | */ 127 | public function nickname_sync_prevent( $field_id ) { 128 | return 0; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /includes/acf/classes/cwps-acf-civicrm-base.php: -------------------------------------------------------------------------------- 1 | fields_handled_hooks_add(); 54 | 55 | } 56 | 57 | /** 58 | * Register the "Handled Fields" callbacks. 59 | * 60 | * @since 0.4 61 | */ 62 | public function fields_handled_hooks_add() { 63 | 64 | // Add our handled Fields. 65 | add_filter( 'cwps/acf/civicrm/fields_handled', [ $this, 'fields_handled_add' ] ); 66 | 67 | // Process our handled Fields. 68 | add_action( 'cwps/acf/contact/acf_fields_saved', [ $this, 'fields_handled_update' ], 10 ); 69 | 70 | } 71 | 72 | /** 73 | * Unregister the "Handled Fields" callbacks. 74 | * 75 | * @since 0.4 76 | */ 77 | public function fields_handled_hooks_remove() { 78 | 79 | // Remove our handled Fields. 80 | remove_filter( 'cwps/acf/civicrm/fields_handled', [ $this, 'fields_handled_add' ] ); 81 | 82 | // Suspend processing our handled Fields. 83 | remove_action( 'cwps/acf/contact/acf_fields_saved', [ $this, 'fields_handled_update' ], 10 ); 84 | 85 | } 86 | 87 | /** 88 | * Getter method for the "Handled Fields" array. 89 | * 90 | * @since 0.4 91 | * 92 | * @return array $fields_handled The array of Contact Fields which must be handled separately. 93 | */ 94 | public function fields_handled_get() { 95 | 96 | // --< 97 | return $this->fields_handled; 98 | 99 | } 100 | 101 | /** 102 | * Filter the "Handled Fields" array. 103 | * 104 | * @since 0.4 105 | * 106 | * @param array $fields_handled The existing array of Fields which must be handled separately. 107 | * @return array $fields_handled The modified array of Fields which must be handled separately. 108 | */ 109 | public function fields_handled_add( $fields_handled = [] ) { 110 | 111 | // Add ours. 112 | $fields_handled = array_merge( $fields_handled, $this->fields_handled ); 113 | 114 | // --< 115 | return $fields_handled; 116 | 117 | } 118 | 119 | /** 120 | * Update a CiviCRM Contact's Fields with data from ACF Fields. 121 | * 122 | * @since 0.4 123 | * 124 | * @param array $args The array of WordPress params. 125 | * @return bool True if updates were successful, or false on failure. 126 | */ 127 | public function fields_handled_update( $args ) { 128 | 129 | // --< 130 | return true; 131 | 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /includes/mapper/cwps-mapper.php: -------------------------------------------------------------------------------- 1 | 'm/d/Y', 59 | 'dd/mm/yy' => 'd/m/Y', 60 | 'yy-mm-dd' => 'Y-m-d', 61 | 'dd-mm-yy' => 'd-m-Y', 62 | 'dd.mm.yy' => 'd.m.Y', 63 | 'M d, yy' => 'M d, Y', 64 | 'd M yy' => 'j M Y', 65 | 'MM d, yy' => 'F j, Y', 66 | 'd MM yy' => 'd F Y', 67 | 'DD, d MM yy' => 'l, d F Y', 68 | 'mm/dd' => 'm/d', 69 | 'dd-mm' => 'd-m', 70 | 'M yy' => 'm Y', 71 | 'M Y' => 'm Y', 72 | 'yy' => 'Y', 73 | ]; 74 | 75 | /** 76 | * Initialises this object. 77 | * 78 | * @since 0.4 79 | * 80 | * @param object $parent The parent object. 81 | */ 82 | public function __construct( $parent ) { 83 | 84 | // Store reference. 85 | $this->plugin = $parent; 86 | 87 | // Boot when plugin is loaded. 88 | add_action( 'civicrm_wp_profile_sync_init', [ $this, 'initialise' ] ); 89 | 90 | } 91 | 92 | /** 93 | * Do stuff on plugin init. 94 | * 95 | * @since 0.4 96 | */ 97 | public function initialise() { 98 | 99 | // Include files. 100 | $this->include_files(); 101 | 102 | // Set up objects and references. 103 | $this->setup_objects(); 104 | 105 | /** 106 | * Broadcast that this class is now loaded. 107 | * 108 | * @since 0.4 109 | */ 110 | do_action( 'cwps/mapper/loaded' ); 111 | 112 | } 113 | 114 | /** 115 | * Include files. 116 | * 117 | * @since 0.4 118 | */ 119 | public function include_files() { 120 | 121 | // Include class files. 122 | require CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/mapper/cwps-mapper-hooks.php'; 123 | require CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/mapper/cwps-mapper-ufmatch.php'; 124 | 125 | } 126 | 127 | /** 128 | * Set up this plugin's objects. 129 | * 130 | * @since 0.4 131 | */ 132 | public function setup_objects() { 133 | 134 | // Initialise objects. 135 | $this->hooks = new CiviCRM_WP_Profile_Sync_Mapper_Hooks( $this ); 136 | $this->ufmatch = new CiviCRM_WP_Profile_Sync_Mapper_UFMatch( $this ); 137 | 138 | } 139 | 140 | /** 141 | * Register hooks. 142 | * 143 | * @since 0.4 144 | */ 145 | public function register_hooks() { 146 | 147 | // Add callbacks. 148 | $this->hooks->register_hooks(); 149 | $this->ufmatch->register_hooks(); 150 | 151 | } 152 | 153 | /** 154 | * Unregister hooks. 155 | * 156 | * @since 0.4 157 | */ 158 | public function unregister_hooks() { 159 | 160 | // Remove all callbacks. 161 | $this->hooks->unregister_hooks(); 162 | $this->ufmatch->unregister_hooks(); 163 | 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /includes/mapper/cwps-mapper-hooks.php: -------------------------------------------------------------------------------- 1 | plugin = $parent->plugin; 81 | $this->mapper = $parent; 82 | 83 | // Boot when Mapper is loaded. 84 | add_action( 'cwps/mapper/loaded', [ $this, 'initialise' ] ); 85 | 86 | } 87 | 88 | /** 89 | * Do stuff on plugin init. 90 | * 91 | * @since 0.4 92 | */ 93 | public function initialise() { 94 | 95 | // Include files. 96 | $this->include_files(); 97 | 98 | // Set up objects and references. 99 | $this->setup_objects(); 100 | 101 | /** 102 | * Broadcast that this class is now loaded. 103 | * 104 | * @since 0.4 105 | */ 106 | do_action( 'cwps/mapper/hooks/loaded' ); 107 | 108 | } 109 | 110 | /** 111 | * Include files. 112 | * 113 | * @since 0.4 114 | */ 115 | public function include_files() { 116 | 117 | // Include class files. 118 | require CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/mapper/cwps-mapper-hooks-core.php'; 119 | 120 | // Maybe load legacy CAI file. 121 | if ( $this->plugin->cai->is_loaded() ) { 122 | require CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/mapper/cwps-mapper-hooks-acf.php'; 123 | } 124 | 125 | } 126 | 127 | /** 128 | * Set up this plugin's objects. 129 | * 130 | * @since 0.4 131 | */ 132 | public function setup_objects() { 133 | 134 | // Initialise objects. 135 | $this->core = new CiviCRM_WP_Profile_Sync_Mapper_Hooks_Core( $this ); 136 | 137 | // Maybe initialise legacy CAI object. 138 | if ( $this->plugin->cai->is_loaded() ) { 139 | $this->acf = new CiviCRM_WP_Profile_Sync_Mapper_Hooks_ACF( $this ); 140 | $this->acf_loaded = true; 141 | } 142 | 143 | } 144 | 145 | /** 146 | * Register hooks. 147 | * 148 | * @since 0.4 149 | */ 150 | public function register_hooks() { 151 | 152 | // Add core callbacks. 153 | $this->core->register_hooks(); 154 | 155 | // Maybe add ACF callbacks. 156 | if ( true === $this->acf_loaded ) { 157 | $this->acf->register_hooks(); 158 | } 159 | 160 | } 161 | 162 | /** 163 | * Unregister hooks. 164 | * 165 | * @since 0.4 166 | */ 167 | public function unregister_hooks() { 168 | 169 | // Remove core callbacks. 170 | $this->core->unregister_hooks(); 171 | 172 | // Maybe add ACF callbacks. 173 | if ( true === $this->acf_loaded ) { 174 | $this->acf->unregister_hooks(); 175 | } 176 | 177 | } 178 | 179 | } 180 | -------------------------------------------------------------------------------- /assets/templates/wordpress/metaboxes/metabox-acf-migrate-info.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 |

15 | 16 |

17 | 18 |

19 | 20 |

21 | 22 |

23 | 24 |

25 | 26 |

27 | 28 |

29 | 30 |

31 | 32 |

33 | 34 | 35 | 36 |

37 | 38 | 39 | 40 |

41 | 42 | 43 | 44 | 45 | 46 |

47 | 48 |

49 | 50 |

51 | ', 57 | '' 58 | ); 59 | 60 | ?> 61 |

62 | 63 |

64 | 65 | 66 | -------------------------------------------------------------------------------- /includes/acf/classes/cwps-acf-acf.php: -------------------------------------------------------------------------------- 1 | plugin = $acf_loader->plugin; 94 | $this->acf_loader = $acf_loader; 95 | 96 | // Init when this plugin is loaded. 97 | add_action( 'cwps/acf/loaded', [ $this, 'initialise' ] ); 98 | 99 | } 100 | 101 | /** 102 | * Initialise this object. 103 | * 104 | * @since 0.4 105 | */ 106 | public function initialise() { 107 | 108 | // Include files. 109 | $this->include_files(); 110 | 111 | // Set up objects and references. 112 | $this->setup_objects(); 113 | 114 | // Register hooks. 115 | $this->register_hooks(); 116 | 117 | /** 118 | * Broadcast that this class is now loaded. 119 | * 120 | * @since 0.4 121 | */ 122 | do_action( 'cwps/acf/acf/loaded' ); 123 | 124 | } 125 | 126 | /** 127 | * Include files. 128 | * 129 | * @since 0.4 130 | */ 131 | public function include_files() { 132 | 133 | // Include class files. 134 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/classes/cwps-acf-acf-field-type.php'; 135 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/classes/cwps-acf-acf-field-group.php'; 136 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/classes/cwps-acf-acf-field.php'; 137 | // phpcs:ignore Squiz.Commenting.InlineComment.InvalidEndChar 138 | // include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/classes/cwps-acf-acf-blocks.php'; 139 | 140 | } 141 | 142 | /** 143 | * Set up this plugin's objects. 144 | * 145 | * @since 0.4 146 | */ 147 | public function setup_objects() { 148 | 149 | // Init Field Type object. 150 | $this->field_type = new CiviCRM_Profile_Sync_ACF_Field_Type( $this ); 151 | 152 | // Init Field Group object. 153 | $this->field_group = new CiviCRM_Profile_Sync_ACF_Field_Group( $this ); 154 | 155 | // Init Field object. 156 | $this->field = new CiviCRM_Profile_Sync_ACF_Field( $this ); 157 | 158 | /* 159 | // Init Blocks object. 160 | $this->blocks = new CiviCRM_Profile_Sync_ACF_Blocks( $this ); 161 | */ 162 | 163 | } 164 | 165 | /** 166 | * Register hooks. 167 | * 168 | * @since 0.4 169 | */ 170 | public function register_hooks() { 171 | 172 | } 173 | 174 | /** 175 | * Checks if ACF Pro is installed. 176 | * 177 | * @since 0.5 178 | * 179 | * @return bool $is_pro True if ACF Pro is installed, false otherwise. 180 | */ 181 | public function is_pro() { 182 | 183 | // Return the property from the Loader object. 184 | return $this->acf_loader->acf_pro; 185 | 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /includes/civicrm/cwps-civicrm-contact-field.php: -------------------------------------------------------------------------------- 1 | plugin = $parent->plugin; 52 | $this->civicrm = $parent; 53 | 54 | // Init when the CiviCRM object is loaded. 55 | add_action( 'cwps/civicrm/loaded', [ $this, 'initialise' ] ); 56 | 57 | } 58 | 59 | /** 60 | * Do stuff on plugin init. 61 | * 62 | * @since 0.5 63 | */ 64 | public function initialise() { 65 | 66 | } 67 | 68 | /** 69 | * Register hooks. 70 | * 71 | * @since 0.5.2 72 | */ 73 | public function register_hooks() { 74 | 75 | } 76 | 77 | /** 78 | * Unregister hooks. 79 | * 80 | * @since 0.5.2 81 | */ 82 | public function unregister_hooks() { 83 | 84 | } 85 | 86 | // ----------------------------------------------------------------------------------- 87 | 88 | /** 89 | * Get the Contact Field options for a given Field Name. 90 | * 91 | * @since 0.5 92 | * 93 | * @param string $name The name of the Contact Field. 94 | * @return array $field The array of Contact Field data. 95 | */ 96 | public function get_by_name( $name ) { 97 | 98 | // Init return. 99 | $field = []; 100 | 101 | // Try and init CiviCRM. 102 | if ( ! $this->civicrm->is_initialised() ) { 103 | return $field; 104 | } 105 | 106 | // Construct params. 107 | $params = [ 108 | 'version' => 3, 109 | 'name' => $name, 110 | 'action' => 'get', 111 | ]; 112 | 113 | // Call the API. 114 | $result = civicrm_api( 'Contact', 'getfield', $params ); 115 | 116 | // Bail if there's an error. 117 | if ( ! empty( $result['is_error'] ) && 1 === (int) $result['is_error'] ) { 118 | return $field; 119 | } 120 | 121 | // Bail if there are no results. 122 | if ( empty( $result['values'] ) ) { 123 | return $field; 124 | } 125 | 126 | // The result set is the item. 127 | $field = $result['values']; 128 | 129 | // --< 130 | return $field; 131 | 132 | } 133 | 134 | /** 135 | * Get "age" as a string for a given date. 136 | * 137 | * @since 0.5 138 | * 139 | * @param string $date The date in CiviCRM-style "Ymdhis" format. 140 | * @return string $age_string The age expressed as a string. 141 | */ 142 | public function date_age_get( $date ) { 143 | 144 | // TODO: Duplicated in ACF. 145 | 146 | // Init return. 147 | $age_string = ''; 148 | 149 | // CiviCRM has handy methods for this. 150 | $age_date = CRM_Utils_Date::customFormat( $date, '%Y%m%d' ); 151 | $age = CRM_Utils_Date::calculateAge( $age_date ); 152 | $years = $age['years'] ?? null; 153 | $months = $age['months'] ?? null; 154 | 155 | // Maybe construct string from years. 156 | if ( $years ) { 157 | $age_string = sprintf( 158 | /* translators: %d: The number of years */ 159 | _n( '%d year', '%d years', $years, 'civicrm-wp-profile-sync' ), 160 | (int) $years 161 | ); 162 | } 163 | 164 | // Maybe construct string from months. 165 | if ( $months ) { 166 | $age_string = sprintf( 167 | /* translators: %d: The number of months */ 168 | _n( '%d month', '%d months', $months, 'civicrm-wp-profile-sync' ), 169 | (int) $months 170 | ); 171 | } 172 | 173 | // Maybe construct string for less than a month. 174 | if ( empty( $years ) && 0 === $months ) { 175 | $age_string = __( 'Under a month', 'civicrm-wp-profile-sync' ); 176 | } 177 | 178 | // --< 179 | return $age_string; 180 | 181 | } 182 | 183 | } 184 | -------------------------------------------------------------------------------- /includes/acf/classes/cwps-acf-acf-blocks.php: -------------------------------------------------------------------------------- 1 | plugin = $parent->acf_loader->plugin; 61 | $this->acf_loader = $parent->acf_loader; 62 | $this->acf = $parent; 63 | 64 | // Init when the parent class is loaded. 65 | add_action( 'cwps/acf/acf/loaded', [ $this, 'register_hooks' ] ); 66 | 67 | } 68 | 69 | /** 70 | * Register WordPress hooks. 71 | * 72 | * @since 0.4 73 | */ 74 | public function register_hooks() { 75 | 76 | // Can we add Blocks? 77 | if ( ! function_exists( 'acf_register_block_type' ) ) { 78 | return; 79 | } 80 | 81 | // Add some Blocks. 82 | add_action( 'acf/init', [ $this, 'register_blocks' ] ); 83 | 84 | } 85 | 86 | // ----------------------------------------------------------------------------------- 87 | 88 | /** 89 | * Register some Blocks. 90 | * 91 | * @since 0.4 92 | */ 93 | public function register_blocks() { 94 | 95 | // Add some Blocks. 96 | 97 | // Define Block. 98 | $block = [ 99 | 'name' => 'cwps-phone', 100 | 'title' => __( 'CiviCRM Phone', 'civicrm-wp-profile-sync' ), 101 | 'description' => __( 'A custom phone block.', 'civicrm-wp-profile-sync' ), 102 | 'render_callback' => [ 'CiviCRM_Profile_Sync_ACF_Blocks', 'block_test_render' ], 103 | 'category' => 'common', 104 | 'keywords' => [ 'civicrm' ], 105 | 'post_types' => [ 'page' ], 106 | ]; 107 | 108 | /* 109 | $e = new \Exception(); 110 | $trace = $e->getTraceAsString(); 111 | $log = [ 112 | 'method' => __METHOD__, 113 | 'block' => $block, 114 | 'callable' => is_callable( $block['render_callback'] ), 115 | //'backtrace' => $trace, 116 | ]; 117 | $this->plugin->log_error( $log ); 118 | */ 119 | 120 | // Register it. 121 | $result = acf_register_block_type( $block ); 122 | 123 | /* 124 | $e = new \Exception(); 125 | $trace = $e->getTraceAsString(); 126 | $log = [ 127 | 'method' => __METHOD__, 128 | 'result' => $result, 129 | //'backtrace' => $trace, 130 | ]; 131 | $this->plugin->log_error( $log ); 132 | */ 133 | 134 | } 135 | 136 | /** 137 | * Render a Test Block. 138 | * 139 | * @since 0.4 140 | * 141 | * @param array $block The Block settings and attributes. 142 | * @param string $content The Block inner HTML (empty). 143 | * @param bool $is_preview True during AJAX preview. 144 | * @param integer|string $post_id The Post ID this Block is saved to. 145 | */ 146 | public function block_test_render( $block, $content = '', $is_preview = false, $post_id = 0 ) { 147 | 148 | // Create ID attribute allowing for custom "anchor" value. 149 | $id = 'cwps-test-' . $block['id']; 150 | if ( ! empty( $block['anchor'] ) ) { 151 | $id = $block['anchor']; 152 | } 153 | 154 | // Create class attribute allowing for custom "className" and "align" values. 155 | $class_name = 'cwps-test-class'; 156 | if ( ! empty( $block['className'] ) ) { 157 | $class_name .= ' ' . $block['className']; 158 | } 159 | if ( ! empty( $block['align'] ) ) { 160 | $class_name .= ' align' . $block['align']; 161 | } 162 | 163 | // Load values and assign defaults. 164 | // phpcs:ignore Squiz.Commenting.InlineComment.InvalidEndChar 165 | // $data = get_field( 'selector' ); 166 | 167 | ?> 168 |
169 | Markup via complex class method 170 |
171 | 12 | 13 | 14 | 17 | 29 | 30 | 34 | 35 | 38 | 54 | 55 | 59 | 60 | 63 | 90 | 91 | 92 | 95 | 101 | 102 |
15 | 16 | 18 |

19 | 26 |

27 |

28 |
36 | 37 | 39 | 40 |

41 | 50 |

51 |

52 | 53 |
61 | 62 | 64 | 65 |

66 | 75 |

76 |

77 | ', 83 | '' 84 | ); 85 | 86 | ?> 87 |

88 | 89 |
93 | 94 | 96 |

97 | > 98 |

99 |

100 |
103 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # ---------------------------------------------------------------------------------------- 4 | # Title: Deploy to WordPress Plugin Directory. 5 | # Description: Deploys the latest version of this plugin to the WordPress Plugin Directory. 6 | # Version: 1.0.0 7 | # ---------------------------------------------------------------------------------------- 8 | # A modification of Dean Clatworthy's deploy script as found here: 9 | # @see https://github.com/deanc/wordpress-plugin-git-svn 10 | # This script lives in the plugin's git repo & doesn't require an existing SVN repo. 11 | # ---------------------------------------------------------------------------------------- 12 | 13 | # Main config. 14 | # This should be the slug of your plugin. 15 | PLUGINSLUG="civicrm-wp-profile-sync" 16 | # This should be the name of your main PHP file in the WordPress plugin. 17 | MAINFILE="civicrm-wp-profile-sync.php" 18 | 19 | # git config 20 | CURRENTDIR=`pwd` 21 | # This file should be in the base of your git repository. 22 | GITPATH="${CURRENTDIR}/" 23 | 24 | # svn config 25 | # Path to a temp SVN repo. No trailing slash required and don't add trunk. 26 | SVNPATH="/tmp/${PLUGINSLUG}" 27 | # Remote SVN repo on wordpress.org, with no trailing slash. 28 | SVNURL="https://plugins.svn.wordpress.org/${PLUGINSLUG}/" 29 | # Your svn username. 30 | SVNUSER="needle" 31 | 32 | # ---------------------------------------------------------------------------------------- 33 | 34 | # Let's begin. 35 | echo ".........................................." 36 | echo "Preparing to deploy WordPress plugin" 37 | echo ".........................................." 38 | echo 39 | 40 | # Check version in readme.txt is the same as plugin file after translating both to 41 | # Unix line breaks to work around grep's failure to identify Mac line breaks. 42 | NEWVERSION1=`grep "^Stable tag:" ${GITPATH}/readme.txt | awk -F' ' '{print $NF}'` 43 | echo "readme.txt version: ${NEWVERSION1}" 44 | NEWVERSION2=`grep "^ \* Version:" ${GITPATH}/${MAINFILE} | awk -F' ' '{print $NF}'` 45 | echo "${MAINFILE} version: ${NEWVERSION2}" 46 | if [ "${NEWVERSION1}" != "${NEWVERSION2}" ]; then 47 | echo "Version in readme.txt & ${MAINFILE} don't match. Exiting."; 48 | exit 1; 49 | fi 50 | 51 | echo "Versions match in readme.txt and ${MAINFILE}. Let's proceed..." 52 | 53 | if git show-ref --tags --quiet --verify -- "refs/tags/${NEWVERSION1}" 54 | then 55 | echo "Version ${NEWVERSION1} already exists as git tag. Exiting."; 56 | exit 1; 57 | else 58 | echo "git version does not exist. Let's proceed..." 59 | fi 60 | 61 | # ---------------------------------------------------------------------------------------- 62 | # Okay, let's do git housekeeping. 63 | # ---------------------------------------------------------------------------------------- 64 | 65 | cd $GITPATH 66 | echo -e "Enter a commit message for this new version: \c" 67 | read COMMITMSG 68 | git commit -am "${COMMITMSG}" 69 | 70 | echo "Tagging new version in git" 71 | git tag -a "${NEWVERSION1}" -m "Tagging version ${NEWVERSION1}" 72 | 73 | echo "Pushing latest commit to origin, with tags" 74 | git push origin master 75 | git push origin master --tags 76 | 77 | # ---------------------------------------------------------------------------------------- 78 | # Now do git-to-svn procedure. 79 | # ---------------------------------------------------------------------------------------- 80 | 81 | echo 82 | echo "Creating local copy of SVN repo..." 83 | svn co $SVNURL $SVNPATH 84 | 85 | echo "Exporting the HEAD of master from git to the trunk of SVN" 86 | git checkout-index -a -f --prefix=$SVNPATH/trunk/ 87 | 88 | echo "Ignoring GitHub specific files and deployment script" 89 | svn propset svn:ignore "deploy.sh 90 | README.md 91 | phpcs.xml 92 | docs 93 | screenshots 94 | .editorconfig 95 | .git 96 | .gitignore 97 | .phpcs 98 | .DS_Store" "${SVNPATH}/trunk/" 99 | 100 | echo "Changing directory to SVN and committing to trunk" 101 | cd $SVNPATH/trunk/ 102 | 103 | # Remove "GitHub Plugin URI" line. 104 | # mv "${MAINFILE}" tmp.php 105 | # sed '/GitHub Plugin URI:/d' tmp.php > "${MAINFILE}" 106 | # rm tmp.php 107 | 108 | # Add all new files that are not set to be ignored. 109 | svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add 110 | 111 | # TODO - remove files that were deleted from Git repo. 112 | 113 | svn commit --username=$SVNUSER -m "${COMMITMSG}" 114 | 115 | echo "Creating new SVN tag & committing it" 116 | cd $SVNPATH 117 | svn copy trunk/ tags/$NEWVERSION1/ 118 | cd $SVNPATH/tags/$NEWVERSION1 119 | svn commit --username=$SVNUSER -m "Tagging version ${NEWVERSION1}" 120 | 121 | # Clean up. 122 | echo "Removing temporary directory ${SVNPATH}" 123 | rm -fr $SVNPATH/ 124 | echo "*** All done! ***" 125 | -------------------------------------------------------------------------------- /includes/mapper/cwps-mapper-hooks-acf.php: -------------------------------------------------------------------------------- 1 | 'm/d/Y', 62 | 'dd/mm/yy' => 'd/m/Y', 63 | 'yy-mm-dd' => 'Y-m-d', 64 | 'dd-mm-yy' => 'd-m-Y', 65 | 'dd.mm.yy' => 'd.m.Y', 66 | 'M d, yy' => 'M d, Y', 67 | 'd M yy' => 'j M Y', 68 | 'MM d, yy' => 'F j, Y', 69 | 'd MM yy' => 'd F Y', 70 | 'DD, d MM yy' => 'l, d F Y', 71 | 'mm/dd' => 'm/d', 72 | 'dd-mm' => 'd-m', 73 | 'M yy' => 'm Y', 74 | 'M Y' => 'm Y', 75 | 'yy' => 'Y', 76 | ]; 77 | 78 | /** 79 | * Define time format mappings (CiviCRM to ACF). 80 | * 81 | * @since 0.4 82 | * @access public 83 | * @var array 84 | */ 85 | public $time_mappings = [ 86 | '1' => 'g:i a', 87 | '2' => 'H:i', 88 | ]; 89 | 90 | /** 91 | * Constructor. 92 | * 93 | * @since 0.4 94 | * 95 | * @param object $parent The parent object. 96 | */ 97 | public function __construct( $parent ) { 98 | 99 | // Store references. 100 | $this->plugin = $parent->mapper->plugin; 101 | $this->mapper = $parent->mapper; 102 | $this->hooks = $parent; 103 | 104 | // Init when this plugin is loaded. 105 | add_action( 'cwps/mapper/hooks/loaded', [ $this, 'initialise' ] ); 106 | 107 | } 108 | 109 | /** 110 | * Initialise this object. 111 | * 112 | * @since 0.4 113 | */ 114 | public function initialise() { 115 | 116 | // Register hooks. 117 | $this->register_hooks(); 118 | 119 | } 120 | 121 | /** 122 | * Register hooks. 123 | * 124 | * @since 0.4 125 | */ 126 | public function register_hooks() { 127 | 128 | // Register ACF hooks. 129 | $this->hooks_acf_add(); 130 | 131 | } 132 | 133 | /** 134 | * Unregister hooks. 135 | * 136 | * @since 0.4 137 | */ 138 | public function unregister_hooks() { 139 | 140 | // Unregister ACF hooks. 141 | $this->hooks_acf_remove(); 142 | 143 | } 144 | 145 | // ----------------------------------------------------------------------------------- 146 | 147 | /** 148 | * Register WordPress hooks. 149 | * 150 | * @since 0.4 151 | */ 152 | public function hooks_acf_add() { 153 | 154 | // Callbacks for ACF Fields pre- and post-edited actions. 155 | // phpcs:ignore Squiz.Commenting.InlineComment.InvalidEndChar 156 | // add_action( 'acf/save_post', [ $this, 'acf_fields_saved' ], 5, 1 ); 157 | add_action( 'acf/save_post', [ $this, 'acf_fields_saved' ], 20, 1 ); 158 | 159 | } 160 | 161 | /** 162 | * Remove WordPress hooks. 163 | * 164 | * @since 0.4 165 | */ 166 | public function hooks_acf_remove() { 167 | 168 | // Remove callbacks for ACF Fields pre- and post-edited actions. 169 | // phpcs:ignore Squiz.Commenting.InlineComment.InvalidEndChar 170 | // remove_action( 'acf/save_post', [ $this, 'acf_fields_saved' ], 5 ); 171 | remove_action( 'acf/save_post', [ $this, 'acf_fields_saved' ], 20 ); 172 | 173 | } 174 | 175 | // ----------------------------------------------------------------------------------- 176 | 177 | /** 178 | * Fires when ACF Fields have been saved. 179 | * 180 | * @since 0.4 181 | * 182 | * @param integer $post_id The ACF "Post ID". 183 | */ 184 | public function acf_fields_saved( $post_id ) { 185 | 186 | // Bail if there was a Multisite switch. 187 | if ( is_multisite() && ms_is_switched() ) { 188 | return; 189 | } 190 | 191 | // Remove CiviCRM callbacks to prevent recursion. 192 | $this->hooks->core->hooks_civicrm_remove(); 193 | 194 | // Let's make an array of the params. 195 | $args = [ 196 | 'post_id' => $post_id, 197 | ]; 198 | 199 | /** 200 | * Broadcast that ACF Fields have been saved. 201 | * 202 | * @since 0.4 203 | * 204 | * @param array $args The array of WordPress params. 205 | */ 206 | do_action( 'cwps/mapper/acf_fields_saved', $args ); 207 | 208 | // Reinstate CiviCRM callbacks. 209 | $this->hooks->core->hooks_civicrm_add(); 210 | 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /includes/civicrm/cwps-civicrm-bulk.php: -------------------------------------------------------------------------------- 1 | plugin = $parent->plugin; 52 | 53 | // Store CiviCRM object reference. 54 | $this->civicrm = $parent; 55 | 56 | // Init when the CiviCRM object is loaded. 57 | add_action( 'cwps/civicrm/loaded', [ $this, 'initialise' ] ); 58 | 59 | } 60 | 61 | /** 62 | * Do stuff on plugin init. 63 | * 64 | * @since 0.4 65 | */ 66 | public function initialise() { 67 | 68 | // Register hooks. 69 | $this->register_hooks(); 70 | 71 | } 72 | 73 | /** 74 | * Register CiviCRM hooks. 75 | * 76 | * @since 0.4 77 | */ 78 | public function register_hooks() { 79 | 80 | // Are we allowing bulk operations? 81 | if ( CIVICRM_WP_PROFILE_SYNC_BULK !== true ) { 82 | return; 83 | } 84 | 85 | // Add an item to the Actions dropdown. 86 | add_action( 'civicrm_searchTasks', [ $this, 'bulk_operations' ], 10, 2 ); 87 | 88 | // Register PHP and template directories. 89 | add_action( 'civicrm_config', [ $this, 'register_php_directory' ], 10 ); 90 | add_action( 'civicrm_config', [ $this, 'register_template_directory' ], 10 ); 91 | 92 | // Prevent recursion when bulk adding WordPress Users via CiviCRM. 93 | add_action( 'civicrm_wp_profile_sync_user_add_pre', [ $this, 'contact_bulk_added_pre' ], 10 ); 94 | add_action( 'civicrm_wp_profile_sync_user_add_post', [ $this, 'contact_bulk_added_post' ], 10 ); 95 | 96 | } 97 | 98 | // ----------------------------------------------------------------------------------- 99 | 100 | /** 101 | * Register directory that CiviCRM searches in for new PHP files. 102 | * 103 | * This only works with *new* PHP files. One cannot override existing PHP 104 | * with this technique - instead, the file must be placed in the path: 105 | * defined in $config->customPHPPathDir 106 | * 107 | * @since 0.1 108 | * 109 | * @param object $config The CiviCRM config object. 110 | */ 111 | public function register_php_directory( &$config ) { 112 | 113 | // Define our custom path. 114 | $custom_path = CIVICRM_WP_PROFILE_SYNC_PATH . 'assets/civicrm/custom_php'; 115 | 116 | // Add to include path. 117 | $include_path = $custom_path . PATH_SEPARATOR . get_include_path(); 118 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_set_include_path 119 | set_include_path( $include_path ); 120 | 121 | } 122 | 123 | /** 124 | * Register directories that CiviCRM searches for php and template files. 125 | * 126 | * @since 0.1 127 | * 128 | * @param object $config The CiviCRM config object. 129 | */ 130 | public function register_template_directory( &$config ) { 131 | 132 | // Define our custom path. 133 | $custom_path = CIVICRM_WP_PROFILE_SYNC_PATH . 'assets/civicrm/custom_templates'; 134 | 135 | // Get template instance. 136 | $template = CRM_Core_Smarty::singleton(); 137 | 138 | // Add our custom template directory. 139 | $template->addTemplateDir( $custom_path ); 140 | 141 | // Register template directories. 142 | $template_include_path = $custom_path . PATH_SEPARATOR . get_include_path(); 143 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_set_include_path 144 | set_include_path( $template_include_path ); 145 | 146 | } 147 | 148 | /** 149 | * Add an option to the Actions dropdown. 150 | * 151 | * @since 0.1 152 | * 153 | * @param string $object_name The CiviCRM object type. 154 | * @param array $tasks The CiviCRM tasks array to add our option to. 155 | */ 156 | public function bulk_operations( $object_name, &$tasks ) { 157 | 158 | // Only handle Contacts. 159 | if ( 'contact' !== $object_name ) { 160 | return; 161 | } 162 | 163 | // Add our item to the tasks array. 164 | $tasks[] = [ 165 | 'title' => __( 'Create WordPress Users from Contacts', 'civicrm-wp-profile-sync' ), 166 | 'class' => 'CRM_Contact_Form_Task_CreateWordPressUsers', 167 | ]; 168 | 169 | } 170 | 171 | // ----------------------------------------------------------------------------------- 172 | 173 | /** 174 | * Prevent recursion when a WordPress User is about to be bulk added. 175 | * 176 | * @since 0.1 177 | */ 178 | public function contact_bulk_added_pre() { 179 | 180 | // Remove WordPress and BuddyPress callbacks to prevent recursion. 181 | $this->plugin->hooks_wp_remove(); 182 | $this->plugin->hooks_bp_remove(); 183 | 184 | } 185 | 186 | /** 187 | * Re-hook when a WordPress User has been bulk added. 188 | * 189 | * @since 0.1 190 | */ 191 | public function contact_bulk_added_post() { 192 | 193 | // Re-add WordPress and BuddyPress callbacks. 194 | $this->plugin->hooks_wp_add(); 195 | $this->plugin->hooks_bp_add(); 196 | 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /assets/js/acf/fields/civicrm-event-group-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM Participant Event Type Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | /** 8 | * Pass the jQuery shortcut in. 9 | * 10 | * @since 0.5 11 | * 12 | * @param {Object} $ The jQuery object. 13 | */ 14 | (function($) { 15 | 16 | /** 17 | * Create Settings class. 18 | * 19 | * @since 0.5 20 | */ 21 | function CWPS_Event_Group_Settings() { 22 | 23 | // Prevent reference collisions. 24 | var me = this; 25 | 26 | /** 27 | * Initialise Settings. 28 | * 29 | * @since 0.5 30 | */ 31 | this.init = function() { 32 | me.init_localisation(); 33 | me.init_settings(); 34 | }; 35 | 36 | /** 37 | * Do setup when jQuery reports that the DOM is ready. 38 | * 39 | * @since 0.5 40 | */ 41 | this.dom_ready = function() {}; 42 | 43 | // Init localisation array. 44 | me.localisation = []; 45 | 46 | /** 47 | * Init localisation from settings object. 48 | * 49 | * @since 0.5 50 | */ 51 | this.init_localisation = function() { 52 | if ( 'undefined' !== typeof CWPS_Event_Group_Vars ) { 53 | me.localisation = CWPS_Event_Group_Vars.localisation; 54 | } 55 | }; 56 | 57 | /** 58 | * Getter for localisation. 59 | * 60 | * @since 0.5 61 | * 62 | * @param {String} identifier The identifier for the desired localisation string. 63 | * @return {String} The localised string. 64 | */ 65 | this.get_localisation = function( identifier ) { 66 | return me.localisation[identifier]; 67 | }; 68 | 69 | // Init settings array. 70 | me.settings = []; 71 | 72 | /** 73 | * Init settings from settings object. 74 | * 75 | * @since 0.5 76 | */ 77 | this.init_settings = function() { 78 | if ( 'undefined' !== typeof CWPS_Event_Group_Vars ) { 79 | me.settings = CWPS_Event_Group_Vars.settings; 80 | } 81 | }; 82 | 83 | /** 84 | * Getter for retrieving a setting. 85 | * 86 | * @since 0.5 87 | * 88 | * @param {String} The identifier for the desired setting. 89 | * @return The value of the setting. 90 | */ 91 | this.get_setting = function( identifier ) { 92 | return me.settings[identifier]; 93 | }; 94 | 95 | } 96 | 97 | /** 98 | * Create Select class. 99 | * 100 | * @since 0.5 101 | */ 102 | function CWPS_Event_Group_Select() { 103 | 104 | // Prevent reference collisions. 105 | var me = this; 106 | 107 | /** 108 | * Initialise Select. 109 | * 110 | * @since 0.5 111 | */ 112 | this.init = function() {}; 113 | 114 | /** 115 | * Do setup when jQuery reports that the DOM is ready. 116 | * 117 | * @since 0.5 118 | */ 119 | this.dom_ready = function() { 120 | me.setup(); 121 | me.listeners(); 122 | }; 123 | 124 | /** 125 | * Do initial setup. 126 | * 127 | * @since 0.5 128 | */ 129 | this.setup = function() { 130 | 131 | // Assign properties. 132 | me.event_id = $('select[name*="field_cwps_participant_event_id"]'); 133 | me.event_type = $('select[name*="field_cwps_participant_event_type"]'); 134 | 135 | }; 136 | 137 | /** 138 | * Initialise listeners. 139 | * 140 | * @since 0.5 141 | */ 142 | this.listeners = function() { 143 | 144 | /** 145 | * Add an onchange event listener to the "Event ID" select. 146 | * 147 | * @param {Object} event The event object. 148 | */ 149 | me.event_id.on( 'change', function( event ) { 150 | 151 | // Bail if nothing selected. 152 | if ( ! me.event_id.val() ) { 153 | me.event_type.val( '' ); 154 | me.event_type.trigger( 'change' ); 155 | return; 156 | } 157 | 158 | // Submit value to server. 159 | me.send( me.event_id.val() ); 160 | 161 | }); 162 | 163 | 164 | }; 165 | 166 | /** 167 | * Send AJAX request. 168 | * 169 | * @since 0.5 170 | * 171 | * @param {Mixed} value The value to send. 172 | */ 173 | this.send = function( value ) { 174 | 175 | // Define vars. 176 | var url, ajax_nonce, data; 177 | 178 | // URL to post to. 179 | url = CWPS_Event_Group_Settings.get_setting( 'ajax_url' ); 180 | ajax_nonce = CWPS_Event_Group_Settings.get_setting( 'ajax_nonce' ); 181 | 182 | // Data received by WordPress. 183 | data = { 184 | action: 'event_type_get_value', 185 | _ajax_nonce: ajax_nonce, 186 | value: value 187 | }; 188 | 189 | // Use jQuery post method. 190 | $.post( url, data, 191 | 192 | /** 193 | * AJAX callback which receives response from the server. 194 | * 195 | * @since 0.5 196 | * 197 | * @param {Array} data The value to send. 198 | * @param {String} textStatus The status of the response. 199 | */ 200 | function( data, textStatus ) { 201 | if ( textStatus == 'success' ) { 202 | me.feedback( data ); 203 | } else { 204 | if ( console.log ) { 205 | console.log( textStatus ); 206 | } 207 | } 208 | }, 209 | 210 | // Expected format. 211 | 'json' 212 | 213 | ); 214 | 215 | }; 216 | 217 | /** 218 | * Provide feedback given a set of data from the server. 219 | * 220 | * @since 0.5 221 | * 222 | * @param {Array} data The data received from the server. 223 | */ 224 | this.feedback = function(data) { 225 | 226 | // Set the value of the select. 227 | if ( data.success ) { 228 | me.event_type.val( data.result ); 229 | me.event_type.trigger( 'change' ); 230 | } 231 | 232 | }; 233 | 234 | } 235 | 236 | // Init Settings and Select classes. 237 | var CWPS_Event_Group_Settings = new CWPS_Event_Group_Settings(); 238 | var CWPS_Event_Group_Select = new CWPS_Event_Group_Select(); 239 | CWPS_Event_Group_Settings.init(); 240 | CWPS_Event_Group_Select.init(); 241 | 242 | /** 243 | * Trigger dom_ready methods where necessary. 244 | * 245 | * @since 0.5 246 | * 247 | * @param {Object} $ The jQuery object. 248 | */ 249 | $(document).ready(function($) { 250 | CWPS_Event_Group_Settings.dom_ready(); 251 | CWPS_Event_Group_Select.dom_ready(); 252 | }); // End document.ready() 253 | 254 | })(jQuery); 255 | -------------------------------------------------------------------------------- /assets/js/acf/acfe/fields/civicrm-address-state-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * CiviCRM Profile Sync Custom ACF Field Type - CiviCRM ACFE State Field. 3 | * 4 | * @package CiviCRM_WP_Profile_Sync 5 | */ 6 | 7 | (function($, undefined){ 8 | 9 | // Bail if ACF isn't defined for some reason. 10 | if ( typeof acf === 'undefined' ) { 11 | return; 12 | } 13 | 14 | /** 15 | * Create Settings class. 16 | * 17 | * @since 0.5 18 | */ 19 | function CWPS_ACFE_State_Settings() { 20 | 21 | // Prevent reference collisions. 22 | var me = this; 23 | 24 | /** 25 | * Initialise Settings. 26 | * 27 | * This method should only be called once. 28 | * 29 | * @since 0.5 30 | */ 31 | this.init = function() { 32 | me.init_settings(); 33 | }; 34 | 35 | // Init settings array. 36 | me.settings = []; 37 | 38 | /** 39 | * Init settings from settings object. 40 | * 41 | * @since 0.5 42 | */ 43 | this.init_settings = function() { 44 | if ( 'undefined' !== typeof CWPS_ACFE_State_Vars ) { 45 | me.settings = CWPS_ACFE_State_Vars.settings; 46 | } 47 | }; 48 | 49 | /** 50 | * Getter for retrieving a setting. 51 | * 52 | * @since 0.5 53 | * 54 | * @param {String} The identifier for the desired setting. 55 | * @return The value of the setting. 56 | */ 57 | this.get_setting = function( identifier ) { 58 | return me.settings[identifier]; 59 | }; 60 | 61 | /** 62 | * Getter for retrieving the array of States for a given Country ID. 63 | * 64 | * @since 0.5 65 | * 66 | * @param {Integer} The numeric ID of the Country. 67 | * @return {Array} The array of data for the States. 68 | */ 69 | this.get_states_for_country = function( country_id ) { 70 | var states = me.get_setting('states'); 71 | if ( states[country_id] ) { 72 | return states[country_id]; 73 | } 74 | return []; 75 | }; 76 | 77 | // Init pseudocache. 78 | me.states_pseudocache = []; 79 | 80 | /** 81 | * Getter for retrieving the array of States for a given Country ID. 82 | * 83 | * @since 0.5 84 | * 85 | * @param {Integer} country_id The numeric ID of the Country. 86 | * @return {Array} The rendered markup for the States. 87 | */ 88 | this.get_states_markup = function( country_id ) { 89 | if ( me.states_pseudocache[country_id] ) { 90 | return me.states_pseudocache[country_id]; 91 | } 92 | return []; 93 | }; 94 | 95 | /** 96 | * Setter for storing the markup of States for a given Country ID. 97 | * 98 | * @since 0.5 99 | * 100 | * @param {Integer} country_id The numeric ID of the Country. 101 | * @param {Array} markup The rendered markup for the States. 102 | */ 103 | this.set_states_markup = function( country_id, markup ) { 104 | if ( ! me.states_pseudocache[country_id] ) { 105 | me.states_pseudocache[country_id] = markup; 106 | } 107 | }; 108 | 109 | } 110 | 111 | // Init Settings class. 112 | var cwps_acfe_state_settings = new CWPS_ACFE_State_Settings(); 113 | cwps_acfe_state_settings.init(); 114 | 115 | // Extend the Select Field model. 116 | var Field = acf.models.SelectField.extend({ 117 | type: 'cwps_acfe_address_state', 118 | }); 119 | 120 | // Register it. 121 | acf.registerFieldType( Field ); 122 | 123 | // Add condition types. 124 | acf.registerConditionForFieldType( 'hasValue', 'cwps_acfe_address_state' ); 125 | acf.registerConditionForFieldType( 'hasNoValue', 'cwps_acfe_address_state' ); 126 | acf.registerConditionForFieldType( 'SelectEqualTo', 'cwps_acfe_address_state' ); 127 | acf.registerConditionForFieldType( 'SelectNotEqualTo', 'cwps_acfe_address_state' ); 128 | 129 | /** 130 | * Acts when CiviCRM ACFE State Fields are ready. 131 | * 132 | * @since 0.5 133 | * 134 | * @param {Object} field The ACF Field object. 135 | */ 136 | acf.addAction( 'ready_field/type=cwps_acfe_address_state', function( field ) { 137 | 138 | var classes, classes_array, country_field_key = '', $country_field; 139 | 140 | // Get the declared classes. 141 | classes = field.$el.prop('class'); 142 | if ( ! classes ) { 143 | return; 144 | } 145 | 146 | // Convert to array. 147 | classes_array = classes.split(' '); 148 | 149 | // Loop to find the one we want. 150 | for (var i = 0, item; item = classes_array[i++];) { 151 | if ( item.match( 'cwps-country-' ) ) { 152 | country_field_key = item.split( '-' )[2]; 153 | break; 154 | } 155 | } 156 | 157 | // Bail if not found or "none". 158 | if ( country_field_key === '' || country_field_key === 'none' ) { 159 | return; 160 | } 161 | 162 | // Get the CiviCRM ACFE State Field. 163 | $country_field = acf.findField( country_field_key ); 164 | 165 | /** 166 | * Acts when the CiviCRM ACFE Country Field is changed. 167 | * 168 | * @since 0.5 169 | * 170 | * @param {Object} e The jQuery Event. 171 | */ 172 | $country_field.on( 'change', 'select', function( e ) { 173 | 174 | var country_id = $(this).val(), states, new_options = []; 175 | 176 | // Clear it. 177 | field.$el.val( null ).trigger( 'change' ); 178 | field.select2.$el.val( null ).trigger( 'change' ); 179 | field.select2.$el.children( 'option' ).remove(); 180 | 181 | // Do we have existing markup? 182 | existing = cwps_acfe_state_settings.get_states_markup( country_id ); 183 | if ( existing.length ) { 184 | field.select2.$el.append( existing ).trigger( 'change' ); 185 | field.$el.val( null ).trigger( 'change' ); 186 | field.select2.$el.val( null ).trigger( 'change' ); 187 | return; 188 | } 189 | 190 | // Get States for this Country ID. 191 | states = cwps_acfe_state_settings.get_states_for_country( country_id ); 192 | if ( ! states.length ) { 193 | return; 194 | } 195 | 196 | // Repopulate the options. 197 | new_options.push( new Option( '- ' + field.get( 'placeholder' ) + ' -', '', false, false ) ); 198 | for ( data of states ) { 199 | new_options.push( new Option( data.text, data.id, false, false ) ); 200 | } 201 | field.select2.$el.append( new_options ).trigger( 'change' ); 202 | 203 | // Cache these. 204 | cwps_acfe_state_settings.set_states_markup( country_id, new_options ); 205 | 206 | } ); 207 | 208 | } ); 209 | 210 | })(jQuery); 211 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CiviCRM Profile Sync 2 | ==================== 3 | 4 | **Contributors:** [needle](https://profiles.wordpress.org/needle/), [cuny-academic-commons](https://profiles.wordpress.org/cuny-academic-commons/), [kcristiano](https://profiles.wordpress.org/kcristiano/), [tadpolecc](https://profiles.wordpress.org/tadpolecc/)
5 | **Donate link:** https://www.paypal.me/interactivist
6 | **Tags:** civicrm, buddypress, acf, profile, sync
7 | **Requires PHP:** 7.4
8 | **Requires at least:** 4.9
9 | **Tested up to:** 6.8
10 | **Stable tag:** 0.7.4a
11 | **License:** GPLv2 or later
12 | **License URI:** https://www.gnu.org/licenses/gpl-2.0.html 13 | 14 | Keeps a WordPress User profile in sync with a CiviCRM Contact and integrates WordPress and CiviCRM Entities with data synced via Advanced Custom Fields. 15 | 16 | 17 | 18 | ## Description 19 | 20 | Please note: this is the development repository for CiviCRM Profile Sync. The plugin can be found in the [WordPress Plugin Directory](https://wordpress.org/plugins/civicrm-wp-profile-sync/), which is the best place to get it from if you're not a developer. 21 | 22 | ### WordPress Integration 23 | 24 | At its simplest, the CiviCRM Profile Sync plugin keeps the "First Name", "Last Name", "Nickname", "Email Address" and "Website" fields of a WordPress User Profile in sync with their corresponding fields in a CiviCRM Contact. The synchronisation takes place regardless of whether the changes are made in WordPress or CiviCRM. 25 | 26 | ### BuddyPress Integration 27 | 28 | The plugin also supports syncing the "First Name" and "Last Name" fields of the WordPress User and CiviCRM Contact with BuddyPress when using the BP xProfile WordPress User Sync plugin. Further integration with BuddyPress is in the pipeline. 29 | 30 | ### ACF Integration 31 | 32 | CiviCRM Profile Sync enables integration between CiviCRM Entities and WordPress Entities with data synced via Advanced Custom Fields. 33 | 34 | Whilst ACF integration is not complete in its coverage of the CiviCRM Entities that can be linked, it is fairly comprehensive in its mapping of the built-in CiviCRM Custom Field Types with their corresponding ACF Field Types. 35 | 36 | So if, for example, you want to display (or create) a Contact Type on your WordPress site with ACF Fields that contain synced CiviCRM data, this feature could work for you. 37 | 38 | Please refer to the [ACF Integration Documentation](/docs/ACF.md) for details. 39 | 40 | ### Form-building with ACF Extended 41 | 42 | CiviCRM Profile Sync enables Forms to be built for the front-end of your website with the UI provided by the ACF Extended plugin. These Forms can send their data directly to CiviCRM in a similar (though more limited) way to Caldera Forms CiviCRM. 43 | 44 | Form building with ACF Extended is currently limited to submitting data for Contacts, Participants, Activities and Cases. This does, however, provide enough functionality to build some fairly powerful and useful Forms. 45 | 46 | Please refer to the [ACFE Form-building Documentation](/docs/ACFE.md) for details. 47 | 48 | ### Requirements 49 | 50 | This plugin recommends a minimum of WordPress 4.9 and CiviCRM 5.23. 51 | 52 | If you want to maintain sync with BuddyPress user profiles, then it also requires BuddyPress 3.0 and the [BP xProfile WordPress User Sync](https://wordpress.org/plugins/bp-xprofile-wp-user-sync/) plugin to do so. 53 | 54 | For integration with Advanced Custom Fields, this plugin recommends a minimum of ACF 5.8 or ACF Pro 5.8. 55 | 56 | 57 | 58 | ## Installation 59 | 60 | There are two ways to install from GitHub: 61 | 62 | ### ZIP Download 63 | 64 | If you have downloaded CiviCRM Profile Sync as a ZIP file from the GitHub repository, do the following to install the plugin: 65 | 66 | 1. Unzip the .zip file and, if needed, rename the enclosing folder so that the plugin's files are located directly inside `/wp-content/plugins/civicrm-wp-profile-sync` 67 | 2. CiviCRM Profile Sync is installed. Read on for activation 68 | 69 | ### git clone 70 | 71 | If you have cloned the code from GitHub, it is assumed that you know what you're doing. 72 | 73 | 74 | 75 | ## Activation 76 | 77 | CiviCRM Profile Sync has some particular requirements when it comes to how it is activated. These correspond to the different types of WordPress install: 78 | 79 | ### Single Site 80 | 81 | Easy - just activate the plugin and you are done! 82 | 83 | ### Multisite 84 | 85 | Since Users and User metadata are stored in a single place for all sites, CiviCRM Profile Sync's User Profile settings cannot be configured on a per-site basis. This means that (whether CiviCRM Profile Sync is network-activated or not) whichever settings page you go to, you will see CiviCRM Profile Sync settings that are held in common for all sites. 86 | 87 | It is, of course, possible to activate CiviCRM in many different ways in Multisite - it could be network-activated, activated on the main site, and/or activated on one or more sub-sites. CiviCRM could also be in Multi-Domain mode or each instance could have its own database. It is recommended that you activate CiviCRM Profile Sync in the same way that CiviCRM is activated. 88 | 89 | If CiviCRM is not in Multi-Domain mode, you may have to write some custom code to propagate changed User details to other CiviCRM instances because (depending on the site on which a particular User's details are changed) only the Contact on the CiviCRM instance linked to that site will be updated. 90 | 91 | Test early, test often and - above all - test on a development site first. 92 | 93 | ### Multi-Network 94 | 95 | In Multi-Network, Users and User metadata are stored in one place for all Networks but `site_options` are stored on a per-Network basis. As a result, it is not simple for CiviCRM Profile Sync to store a single collection of User Profile settings for all Networks. You will have to make sure that they are the same across all the Networks where both CiviCRM and this plugin are activated. 96 | 97 | A consequence of this architecture is that (depending on how you have set up CiviCRM across the Networks) there may be mismatches between the User data in WordPress and the Contact data in your CiviCRM instances. If CiviCRM is not in Multi-Domain mode, you will have to write some custom code to keep the data synced between WordPress and your CiviCRM instances. 98 | 99 | I'll say it again: test early, test often and - above all - test on a development site first. 100 | -------------------------------------------------------------------------------- /includes/acf/acfe/classes/cwps-acf-acfe.php: -------------------------------------------------------------------------------- 1 | plugin = $acf_loader->plugin; 79 | $this->acf_loader = $acf_loader; 80 | 81 | // Init when this plugin is loaded. 82 | add_action( 'cwps/acf/loaded', [ $this, 'initialise' ] ); 83 | 84 | } 85 | 86 | /** 87 | * Initialise this object. 88 | * 89 | * @since 0.5 90 | */ 91 | public function initialise() { 92 | 93 | // Only do this once. 94 | static $done; 95 | if ( isset( $done ) && true === $done ) { 96 | return; 97 | } 98 | 99 | // Bail if the "ACF Extended" plugin isn't found. 100 | if ( ! defined( 'ACFE_VERSION' ) ) { 101 | $done = true; 102 | return; 103 | } 104 | 105 | // Store ACF Extended version. 106 | $this->acfe_version = ACFE_VERSION; 107 | 108 | // Return early if ACF Extended Integration has been disabled. 109 | $acf_enabled = (int) $this->plugin->admin->setting_get( 'acfe_integration_enabled', 1 ); 110 | if ( 1 !== $acf_enabled ) { 111 | 112 | // Include Admin class and init. 113 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/classes/cwps-acf-acfe-admin.php'; 114 | $this->admin = new CiviCRM_Profile_Sync_ACF_ACFE_Admin( $this ); 115 | $this->admin->initialise(); 116 | 117 | $done = true; 118 | return; 119 | 120 | } 121 | 122 | // Include files. 123 | $this->include_files(); 124 | 125 | // Set up objects and references. 126 | $this->setup_objects(); 127 | 128 | // Register hooks. 129 | $this->register_hooks(); 130 | 131 | /** 132 | * Broadcast that this class is now loaded. 133 | * 134 | * @since 0.5 135 | */ 136 | do_action( 'cwps/acf/acfe/loaded' ); 137 | 138 | // Okay, we're done. 139 | $done = true; 140 | 141 | } 142 | 143 | /** 144 | * Include files. 145 | * 146 | * @since 0.5 147 | */ 148 | public function include_files() { 149 | 150 | // Include class files. 151 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/classes/cwps-acf-acfe-admin.php'; 152 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/classes/cwps-acf-acfe-form.php'; 153 | 154 | } 155 | 156 | /** 157 | * Set up this plugin's objects. 158 | * 159 | * @since 0.5 160 | */ 161 | public function setup_objects() { 162 | 163 | // Init objects. 164 | $this->admin = new CiviCRM_Profile_Sync_ACF_ACFE_Admin( $this ); 165 | $this->form = new CiviCRM_Profile_Sync_ACF_ACFE_Form( $this ); 166 | 167 | } 168 | 169 | /** 170 | * Register hooks. 171 | * 172 | * @since 0.5 173 | */ 174 | public function register_hooks() { 175 | 176 | // Include any Field Types that we have defined after ACFE does. 177 | add_action( 'acf/include_field_types', [ $this, 'register_field_types' ], 100 ); 178 | 179 | } 180 | 181 | /** 182 | * Registers the Field Types for ACF5+. 183 | * 184 | * @since 0.5 185 | * 186 | * @param integer $api_version The ACF Field API version. 187 | */ 188 | public function register_field_types( $api_version ) { 189 | 190 | // Include Reference Field Types. 191 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/fields/cwps-acf-acfe-field-action-reference-contact.php'; 192 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/fields/cwps-acf-acfe-field-action-reference-case.php'; 193 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/fields/cwps-acf-acfe-field-action-reference-participant.php'; 194 | 195 | // Init Reference Field Types. 196 | new CiviCRM_Profile_Sync_ACF_ACFE_Form_Contact_Action_Ref( $this ); 197 | new CiviCRM_Profile_Sync_ACF_ACFE_Form_Case_Action_Ref( $this ); 198 | new CiviCRM_Profile_Sync_ACF_ACFE_Form_Participant_Action_Ref( $this ); 199 | 200 | // Include Field Types. 201 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/fields/cwps-acf-acfe-field-address-county.php'; 202 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/fields/cwps-acf-acfe-field-address-state.php'; 203 | include CIVICRM_WP_PROFILE_SYNC_PATH . 'includes/acf/acfe/fields/cwps-acf-acfe-field-address-country.php'; 204 | 205 | // Init Field Types. 206 | new CiviCRM_Profile_Sync_ACF_ACFE_Form_Address_County( $this ); 207 | new CiviCRM_Profile_Sync_ACF_ACFE_Form_Address_State( $this ); 208 | new CiviCRM_Profile_Sync_ACF_ACFE_Form_Address_Country( $this ); 209 | 210 | } 211 | 212 | /** 213 | * Check if ACF Extended Pro is present and active. 214 | * 215 | * The "ACFE_PRO" constant is only set after the "acf/include_field_types" 216 | * action at priority 10 - since this is when the "ACFE_Pro" class is included. 217 | * 218 | * We might be able to find out earlier based on the enclosing directory of 219 | * the ACF Extended plugin, because it should be "acf-extended-pro" but this 220 | * is not reliable. 221 | * 222 | * We might also be able to look for the "pro" directory in the root of the 223 | * plugin directory. This can be found by looking the "ACFE_PATH" constant. 224 | * This, too, may not be reliable. 225 | * 226 | * @since 0.5 227 | * 228 | * @return bool True if ACF Extended Pro is active, false otherwise. 229 | */ 230 | public function is_pro() { 231 | 232 | // Return boolean based the ACFE Pro constant. 233 | return ( defined( 'ACFE_PRO' ) && ACFE_PRO ) ? true : false; 234 | 235 | } 236 | 237 | } 238 | -------------------------------------------------------------------------------- /includes/acf/acfe/fields/cwps-acf-acfe-field-action-reference-case.php: -------------------------------------------------------------------------------- 1 | CIVICRM_WP_PROFILE_SYNC_VERSION, 126 | 'url' => CIVICRM_WP_PROFILE_SYNC_URL, 127 | 'path' => CIVICRM_WP_PROFILE_SYNC_PATH, 128 | ]; 129 | 130 | /** 131 | * Field Type translations. 132 | * 133 | * This must be populated in the class constructor because it is translatable. 134 | * 135 | * Array of strings that are used in JavaScript. This allows JS strings 136 | * to be translated in PHP and loaded via: 137 | * 138 | * var message = acf._e( 'civicrm_participant', 'error' ); 139 | * 140 | * @since 0.5 141 | * @access public 142 | * @var array 143 | */ 144 | public $l10n = []; 145 | 146 | /** 147 | * Sets up the Field Type. 148 | * 149 | * @since 0.5 150 | * 151 | * @param object $parent The parent object reference. 152 | */ 153 | public function __construct( $parent ) { 154 | 155 | // Store references to objects. 156 | $this->plugin = $parent->acf_loader->plugin; 157 | $this->acf_loader = $parent->acf_loader; 158 | $this->civicrm = $this->acf_loader->civicrm; 159 | $this->acf = $this->acf_loader->acf; 160 | $this->acfe = $parent; 161 | 162 | // Define label. 163 | $this->label = __( 'CiviCRM Form Action Reference: Case', 'civicrm-wp-profile-sync' ); 164 | 165 | // Define category. 166 | $this->category = __( 'CiviCRM ACFE Forms only', 'civicrm-wp-profile-sync' ); 167 | 168 | // Define translations. 169 | $this->l10n = [ 170 | // Example message. 171 | 'error' => __( 'Error! Please enter a higher value.', 'civicrm-wp-profile-sync' ), 172 | ]; 173 | 174 | // Call parent. 175 | parent::__construct(); 176 | 177 | // Remove this Field from the list of available Fields. 178 | add_filter( 'acf/get_field_types', [ $this, 'remove_field_type' ], 100, 1 ); 179 | 180 | } 181 | 182 | /** 183 | * Removes this Field Type from the list of available Field Types. 184 | * 185 | * @since 0.5 186 | * 187 | * @param array $groups The Field being rendered. 188 | */ 189 | public function remove_field_type( $groups ) { 190 | 191 | // Bail if the "CiviCRM" group is missing. 192 | if ( empty( $groups[ $this->category ] ) ) { 193 | return $groups; 194 | } 195 | 196 | // Remove this Field Type. 197 | if ( isset( $groups[ $this->category ][ $this->name ] ) ) { 198 | unset( $groups[ $this->category ][ $this->name ] ); 199 | } 200 | 201 | // --< 202 | return $groups; 203 | 204 | } 205 | 206 | /** 207 | * Creates the HTML interface for this Field Type. 208 | * 209 | * @since 0.5 210 | * 211 | * @param array $field The Field being rendered. 212 | */ 213 | public function render_field( $field ) { 214 | 215 | // Change Field into a select. 216 | $field['type'] = 'select'; 217 | $field['ui'] = 0; 218 | $field['ajax'] = 0; 219 | $field['allow_null'] = 1; 220 | $field['multiple'] = 0; 221 | $field['required'] = 0; 222 | $field['conditional_logic'] = 0; 223 | 224 | // Init choices array. 225 | $field['choices'] = []; 226 | 227 | // Overwrite with Field value. 228 | if ( ! empty( $field['value'] ) ) { 229 | $field['choices'][ $field['value'] ] = $field['value']; 230 | } 231 | 232 | // Render. 233 | acf_render_field( $field ); 234 | 235 | } 236 | 237 | /** 238 | * This method is called in the "admin_enqueue_scripts" action on the edit 239 | * screen where this Field is created. 240 | * 241 | * Use this action to add CSS and JavaScript to assist your render_field() 242 | * action. 243 | * 244 | * @since 0.5 245 | */ 246 | public function input_admin_enqueue_scripts() { 247 | 248 | // Enqueue our JavaScript. 249 | wp_enqueue_script( 250 | 'acf-input-' . $this->name, 251 | plugins_url( 'assets/js/acf/acfe/fields/cwps-field-action-reference-case.js', CIVICRM_WP_PROFILE_SYNC_FILE ), 252 | [ 'acf-input' ], 253 | CIVICRM_WP_PROFILE_SYNC_VERSION, // Version. 254 | true 255 | ); 256 | 257 | } 258 | 259 | } 260 | -------------------------------------------------------------------------------- /includes/acf/fields/cwps-acf-field-civicrm-contact-id.php: -------------------------------------------------------------------------------- 1 | CIVICRM_WP_PROFILE_SYNC_VERSION, 110 | 'url' => CIVICRM_WP_PROFILE_SYNC_URL, 111 | 'path' => CIVICRM_WP_PROFILE_SYNC_PATH, 112 | ]; 113 | 114 | /** 115 | * Field Type translations. 116 | * 117 | * This must be populated in the class constructor because it is translatable. 118 | * 119 | * Array of strings that are used in JavaScript. This allows JS strings 120 | * to be translated in PHP and loaded via: 121 | * 122 | * var message = acf._e( 'civicrm_contact', 'error' ); 123 | * 124 | * @since 0.4 125 | * @access public 126 | * @var array 127 | */ 128 | public $l10n = []; 129 | 130 | /** 131 | * Sets up the Field Type. 132 | * 133 | * @since 0.4 134 | * 135 | * @param object $parent The parent object reference. 136 | */ 137 | public function __construct( $parent ) { 138 | 139 | // Store references to objects. 140 | $this->plugin = $parent->acf_loader->plugin; 141 | $this->acf_loader = $parent->acf_loader; 142 | $this->acf = $parent->acf; 143 | 144 | // Define label. 145 | $this->label = __( 'CiviCRM Contact: Contact ID (Read Only)', 'civicrm-wp-profile-sync' ); 146 | 147 | // Define category. 148 | if ( function_exists( 'acfe' ) ) { 149 | $this->category = __( 'CiviCRM Post Type Sync only', 'civicrm-wp-profile-sync' ); 150 | } else { 151 | $this->category = __( 'CiviCRM Post Type Sync', 'civicrm-wp-profile-sync' ); 152 | } 153 | 154 | // Define translations. 155 | $this->l10n = []; 156 | 157 | // Call parent. 158 | parent::__construct(); 159 | 160 | } 161 | 162 | /** 163 | * Creates the HTML interface for this Field Type. 164 | * 165 | * @since 0.4 166 | * 167 | * @param array $field The Field being rendered. 168 | */ 169 | public function render_field( $field ) { 170 | 171 | // Change Field into a simple "number" Field. 172 | $field['type'] = 'number'; 173 | $field['readonly'] = 1; 174 | $field['allow_null'] = 0; 175 | $field['prepend'] = ''; 176 | $field['append'] = ''; 177 | $field['step'] = ''; 178 | 179 | // Populate Field. 180 | if ( ! empty( $field['value'] ) ) { 181 | 182 | // Cast value to an integer. 183 | $contact_id = (int) $field['value']; 184 | 185 | // Apply Contact ID to Field. 186 | $field['value'] = $contact_id; 187 | 188 | } 189 | 190 | // Render. 191 | acf_render_field( $field ); 192 | 193 | } 194 | 195 | /** 196 | * This filter is applied to the $value after it is loaded from the database. 197 | * 198 | * @since 0.4 199 | * 200 | * @param mixed $value The value found in the database. 201 | * @param integer|string $post_id The ACF "Post ID" from which the value was loaded. 202 | * @param array $field The Field array holding all the Field options. 203 | * @return mixed $value The modified value. 204 | */ 205 | public function load_value( $value, $post_id, $field ) { 206 | 207 | // Assign Contact ID for this Field if empty. 208 | if ( empty( $value ) ) { 209 | 210 | // Get Contact ID for this ACF "Post ID". 211 | $contact_id = $this->acf->field->query_contact_id( $post_id ); 212 | 213 | // Overwrite if we get a value. 214 | if ( false !== $contact_id ) { 215 | $value = $contact_id; 216 | } 217 | 218 | } 219 | 220 | // --< 221 | return $value; 222 | 223 | } 224 | 225 | /** 226 | * This filter is applied to the $value before it is saved in the database. 227 | * 228 | * @since 0.4 229 | * 230 | * @param mixed $value The value found in the database. 231 | * @param integer $post_id The Post ID from which the value was loaded. 232 | * @param array $field The Field array holding all the Field options. 233 | * @return mixed $value The modified value. 234 | */ 235 | public function update_value( $value, $post_id, $field ) { 236 | 237 | // Assign Contact ID for this Field if empty. 238 | if ( empty( $value ) ) { 239 | 240 | // Get Contact ID for this ACF "Post ID". 241 | $contact_id = $this->acf->field->query_contact_id( $post_id ); 242 | 243 | // Overwrite if we get a value. 244 | if ( false !== $contact_id ) { 245 | $value = $contact_id; 246 | } 247 | 248 | } 249 | 250 | // --< 251 | return $value; 252 | 253 | } 254 | 255 | } 256 | -------------------------------------------------------------------------------- /includes/acf/acfe/fields/cwps-acf-acfe-field-action-reference-contact.php: -------------------------------------------------------------------------------- 1 | CIVICRM_WP_PROFILE_SYNC_VERSION, 126 | 'url' => CIVICRM_WP_PROFILE_SYNC_URL, 127 | 'path' => CIVICRM_WP_PROFILE_SYNC_PATH, 128 | ]; 129 | 130 | /** 131 | * Field Type translations. 132 | * 133 | * This must be populated in the class constructor because it is translatable. 134 | * 135 | * Array of strings that are used in JavaScript. This allows JS strings 136 | * to be translated in PHP and loaded via: 137 | * 138 | * var message = acf._e( 'civicrm_participant', 'error' ); 139 | * 140 | * @since 0.5 141 | * @access public 142 | * @var array 143 | */ 144 | public $l10n = []; 145 | 146 | /** 147 | * Sets up the Field Type. 148 | * 149 | * @since 0.5 150 | * 151 | * @param object $parent The parent object reference. 152 | */ 153 | public function __construct( $parent ) { 154 | 155 | // Store references to objects. 156 | $this->plugin = $parent->acf_loader->plugin; 157 | $this->acf_loader = $parent->acf_loader; 158 | $this->civicrm = $this->acf_loader->civicrm; 159 | $this->acf = $this->acf_loader->acf; 160 | $this->acfe = $parent; 161 | 162 | // Define label. 163 | $this->label = __( 'CiviCRM Form Action Reference: Contact', 'civicrm-wp-profile-sync' ); 164 | 165 | // Define category. 166 | $this->category = __( 'CiviCRM ACFE Forms only', 'civicrm-wp-profile-sync' ); 167 | 168 | // Define translations. 169 | $this->l10n = [ 170 | // Example message. 171 | 'error' => __( 'Error! Please enter a higher value.', 'civicrm-wp-profile-sync' ), 172 | ]; 173 | 174 | // Call parent. 175 | parent::__construct(); 176 | 177 | // Remove this Field from the list of available Fields. 178 | add_filter( 'acf/get_field_types', [ $this, 'remove_field_type' ], 100, 1 ); 179 | 180 | } 181 | 182 | /** 183 | * Removes this Field Type from the list of available Field Types. 184 | * 185 | * @since 0.5 186 | * 187 | * @param array $groups The Field being rendered. 188 | */ 189 | public function remove_field_type( $groups ) { 190 | 191 | // Bail if the "CiviCRM" group is missing. 192 | if ( empty( $groups[ $this->category ] ) ) { 193 | return $groups; 194 | } 195 | 196 | // Remove this Field Type. 197 | if ( isset( $groups[ $this->category ][ $this->name ] ) ) { 198 | unset( $groups[ $this->category ][ $this->name ] ); 199 | } 200 | 201 | // --< 202 | return $groups; 203 | 204 | } 205 | 206 | /** 207 | * Creates the HTML interface for this Field Type. 208 | * 209 | * @since 0.5 210 | * 211 | * @param array $field The Field being rendered. 212 | */ 213 | public function render_field( $field ) { 214 | 215 | // Change Field into a select. 216 | $field['type'] = 'select'; 217 | $field['ui'] = 0; 218 | $field['ajax'] = 0; 219 | $field['allow_null'] = 1; 220 | $field['multiple'] = 0; 221 | $field['required'] = 0; 222 | $field['conditional_logic'] = 0; 223 | 224 | // Init choices array. 225 | $field['choices'] = []; 226 | 227 | // Overwrite with Field value. 228 | if ( ! empty( $field['value'] ) ) { 229 | $field['choices'][ $field['value'] ] = $field['value']; 230 | } 231 | 232 | // Render. 233 | acf_render_field( $field ); 234 | 235 | } 236 | 237 | /** 238 | * This method is called in the "admin_enqueue_scripts" action on the edit 239 | * screen where this Field is created. 240 | * 241 | * Use this action to add CSS and JavaScript to assist your render_field() 242 | * action. 243 | * 244 | * @since 0.5 245 | */ 246 | public function input_admin_enqueue_scripts() { 247 | 248 | // Enqueue our JavaScript. 249 | wp_enqueue_script( 250 | 'acf-input-' . $this->name, 251 | plugins_url( 'assets/js/acf/acfe/fields/cwps-field-action-reference-contact.js', CIVICRM_WP_PROFILE_SYNC_FILE ), 252 | [ 'acf-input' ], 253 | CIVICRM_WP_PROFILE_SYNC_VERSION, // Version. 254 | true 255 | ); 256 | 257 | } 258 | 259 | } 260 | -------------------------------------------------------------------------------- /includes/acf/acfe/fields/cwps-acf-acfe-field-action-reference-participant.php: -------------------------------------------------------------------------------- 1 | CIVICRM_WP_PROFILE_SYNC_VERSION, 126 | 'url' => CIVICRM_WP_PROFILE_SYNC_URL, 127 | 'path' => CIVICRM_WP_PROFILE_SYNC_PATH, 128 | ]; 129 | 130 | /** 131 | * Field Type translations. 132 | * 133 | * This must be populated in the class constructor because it is translatable. 134 | * 135 | * Array of strings that are used in JavaScript. This allows JS strings 136 | * to be translated in PHP and loaded via: 137 | * 138 | * var message = acf._e( 'civicrm_participant', 'error' ); 139 | * 140 | * @since 0.5 141 | * @access public 142 | * @var array 143 | */ 144 | public $l10n = []; 145 | 146 | /** 147 | * Sets up the Field Type. 148 | * 149 | * @since 0.5 150 | * 151 | * @param object $parent The parent object reference. 152 | */ 153 | public function __construct( $parent ) { 154 | 155 | // Store references to objects. 156 | $this->plugin = $parent->acf_loader->plugin; 157 | $this->acf_loader = $parent->acf_loader; 158 | $this->civicrm = $this->acf_loader->civicrm; 159 | $this->acf = $this->acf_loader->acf; 160 | $this->acfe = $parent; 161 | 162 | // Define label. 163 | $this->label = __( 'CiviCRM Form Action Reference: Participant', 'civicrm-wp-profile-sync' ); 164 | 165 | // Define category. 166 | $this->category = __( 'CiviCRM ACFE Forms only', 'civicrm-wp-profile-sync' ); 167 | 168 | // Define translations. 169 | $this->l10n = [ 170 | // Example message. 171 | 'error' => __( 'Error! Please enter a higher value.', 'civicrm-wp-profile-sync' ), 172 | ]; 173 | 174 | // Call parent. 175 | parent::__construct(); 176 | 177 | // Remove this Field from the list of available Fields. 178 | add_filter( 'acf/get_field_types', [ $this, 'remove_field_type' ], 100, 1 ); 179 | 180 | } 181 | 182 | /** 183 | * Removes this Field Type from the list of available Field Types. 184 | * 185 | * @since 0.5 186 | * 187 | * @param array $groups The Field being rendered. 188 | */ 189 | public function remove_field_type( $groups ) { 190 | 191 | // Bail if the "CiviCRM" group is missing. 192 | if ( empty( $groups[ $this->category ] ) ) { 193 | return $groups; 194 | } 195 | 196 | // Remove this Field Type. 197 | if ( isset( $groups[ $this->category ][ $this->name ] ) ) { 198 | unset( $groups[ $this->category ][ $this->name ] ); 199 | } 200 | 201 | // --< 202 | return $groups; 203 | 204 | } 205 | 206 | /** 207 | * Creates the HTML interface for this Field Type. 208 | * 209 | * @since 0.5 210 | * 211 | * @param array $field The Field being rendered. 212 | */ 213 | public function render_field( $field ) { 214 | 215 | // Change Field into a select. 216 | $field['type'] = 'select'; 217 | $field['ui'] = 0; 218 | $field['ajax'] = 0; 219 | $field['allow_null'] = 1; 220 | $field['multiple'] = 0; 221 | $field['required'] = 0; 222 | $field['conditional_logic'] = 0; 223 | 224 | // Init choices array. 225 | $field['choices'] = []; 226 | 227 | // Overwrite with Field value. 228 | if ( ! empty( $field['value'] ) ) { 229 | $field['choices'][ $field['value'] ] = $field['value']; 230 | } 231 | 232 | // Render. 233 | acf_render_field( $field ); 234 | 235 | } 236 | 237 | /** 238 | * This method is called in the "admin_enqueue_scripts" action on the edit 239 | * screen where this Field is created. 240 | * 241 | * Use this action to add CSS and JavaScript to assist your render_field() 242 | * action. 243 | * 244 | * @since 0.5 245 | */ 246 | public function input_admin_enqueue_scripts() { 247 | 248 | // Enqueue our JavaScript. 249 | wp_enqueue_script( 250 | 'acf-input-' . $this->name, 251 | plugins_url( 'assets/js/acf/acfe/fields/cwps-field-action-reference-participant.js', CIVICRM_WP_PROFILE_SYNC_FILE ), 252 | [ 'acf-input' ], 253 | CIVICRM_WP_PROFILE_SYNC_VERSION, // Version. 254 | true 255 | ); 256 | 257 | } 258 | 259 | } 260 | -------------------------------------------------------------------------------- /includes/acf/classes/cwps-acf-participant-cpt-term-html.php: -------------------------------------------------------------------------------- 1 | plugin = $parent->acf_loader->plugin; 95 | $this->acf_loader = $parent->acf_loader; 96 | $this->civicrm = $parent->civicrm; 97 | $this->participant = $parent->participant; 98 | $this->cpt = $parent; 99 | 100 | // Store Taxonomy name. 101 | $this->taxonomy_name = $parent->taxonomy_name; 102 | 103 | // Init when the Participant CPT object is loaded. 104 | add_action( 'cwps/acf/civicrm/participant-cpt/loaded', [ $this, 'initialise' ] ); 105 | 106 | } 107 | 108 | /** 109 | * Initialise object. 110 | * 111 | * @since 0.5 112 | */ 113 | public function initialise() { 114 | 115 | // Bail if CPT not enabled. 116 | if ( false === $this->cpt->enabled ) { 117 | return; 118 | } 119 | 120 | // Register hooks on admin init. 121 | add_action( 'admin_init', [ $this, 'register_hooks' ] ); 122 | 123 | } 124 | 125 | /** 126 | * Register hooks. 127 | * 128 | * @since 0.5 129 | */ 130 | public function register_hooks() { 131 | 132 | // Look for an existing WooDojo HTML Term Description install. 133 | if ( class_exists( 'WooDojo_HTML_Term_Description' ) ) { 134 | return; 135 | } 136 | 137 | // Bail if user doesn't have the "unfiltered_html" capability. 138 | if ( ! current_user_can( 'unfiltered_html' ) ) { 139 | return; 140 | } 141 | 142 | // Allow HTML in term descriptions. 143 | remove_filter( 'pre_term_description', 'wp_filter_kses' ); 144 | remove_filter( 'term_description', 'wp_kses_data' ); 145 | 146 | // Add TinyMCE to the Participant Role taxonomy. 147 | add_action( $this->taxonomy_name . '_edit_form_fields', [ $this, 'render_field_edit' ], 1, 2 ); 148 | add_action( $this->taxonomy_name . '_add_form_fields', [ $this, 'render_field_add' ], 1, 1 ); 149 | 150 | } 151 | 152 | // ----------------------------------------------------------------------------------- 153 | 154 | /** 155 | * Add the WYSIWYG editor to the "Edit" Field. 156 | * 157 | * @since 0.5 158 | * 159 | * @param object $term The WordPress Term. 160 | * @param string $taxonomy The WordPress Taxonomy. 161 | */ 162 | public function render_field_edit( $term, $taxonomy ) { 163 | 164 | $settings = [ 165 | 'textarea_name' => 'description', 166 | 'quicktags' => true, 167 | 'tinymce' => true, 168 | 'editor_css' => '', 169 | ]; 170 | 171 | ?> 172 | 173 | 174 | description ), 'html-description', $settings ); ?> 175 | 176 | 180 | 181 | 'description', 196 | 'quicktags' => true, 197 | 'tinymce' => true, 198 | // 'editor_css' => '', 199 | ]; 200 | 201 | ?> 202 |
203 | 204 | 205 |

206 | 221 |
222 | 12 | 29 | 30 |
31 | 32 |

33 | 34 |
35 | 36 | 46 |
47 | 48 |
49 | 50 | 60 |
61 | 62 |
63 | 64 | 74 |
75 | 76 |
77 | 78 | 88 |
89 | 90 |
91 | 92 | 102 |
103 | 104 |
105 | 106 | 120 |
121 | 122 |
123 | 124 | 138 |
139 | 140 |
141 |
142 |

143 |
144 |
145 | 146 |
147 | -------------------------------------------------------------------------------- /includes/acf/acfe/fields/cwps-acf-acfe-field-address-country.php: -------------------------------------------------------------------------------- 1 | CIVICRM_WP_PROFILE_SYNC_VERSION, 128 | 'url' => CIVICRM_WP_PROFILE_SYNC_URL, 129 | 'path' => CIVICRM_WP_PROFILE_SYNC_PATH, 130 | ]; 131 | 132 | /** 133 | * Field Type translations. 134 | * 135 | * This must be populated in the class constructor because it is translatable. 136 | * 137 | * Array of strings that are used in JavaScript. This allows JS strings 138 | * to be translated in PHP and loaded via: 139 | * 140 | * var message = acf._e( 'civicrm_contact', 'error' ); 141 | * 142 | * @since 0.5 143 | * @access public 144 | * @var array 145 | */ 146 | public $l10n = []; 147 | 148 | /** 149 | * Sets up the Field Type. 150 | * 151 | * @since 0.5 152 | * 153 | * @param object $parent The parent object reference. 154 | */ 155 | public function __construct( $parent ) { 156 | 157 | // Store references to objects. 158 | $this->plugin = $parent->acf_loader->plugin; 159 | $this->acf_loader = $parent->acf_loader; 160 | $this->acf = $parent->acf_loader->acf; 161 | $this->acfe = $parent; 162 | $this->civicrm = $this->acf_loader->civicrm; 163 | 164 | // Define label. 165 | $this->label = __( 'CiviCRM Address: Country', 'civicrm-wp-profile-sync' ); 166 | 167 | // Define category. 168 | $this->category = __( 'CiviCRM ACFE Forms only', 'civicrm-wp-profile-sync' ); 169 | 170 | // Define translations. 171 | $this->l10n = []; 172 | 173 | // Call parent. 174 | parent::__construct(); 175 | 176 | } 177 | 178 | /** 179 | * Create extra Settings for this Field Type. 180 | * 181 | * These extra Settings will be visible when editing a Field. 182 | * 183 | * @since 0.6.6 184 | * 185 | * @param array $field The Field being edited. 186 | */ 187 | public function render_field_settings( $field ) { 188 | 189 | // Only render Placeholder Setting Field here in ACF prior to version 6. 190 | if ( version_compare( ACF_MAJOR_VERSION, '6', '>=' ) ) { 191 | return; 192 | } 193 | 194 | // Get Placeholder Setting Field. 195 | $placeholder = $this->acf->field->field_setting_placeholder_get(); 196 | 197 | // Now add it. 198 | acf_render_field_setting( $field, $placeholder ); 199 | 200 | } 201 | 202 | /** 203 | * Renders the Field settings used in the "Presentation" tab. 204 | * 205 | * @since 0.6.6 206 | * 207 | * @param array $field The field settings array. 208 | */ 209 | public function render_field_presentation_settings( $field ) { 210 | 211 | // Get Placeholder Setting Field. 212 | $placeholder = $this->acf->field->field_setting_placeholder_get(); 213 | 214 | // Now add it. 215 | acf_render_field_setting( $field, $placeholder ); 216 | 217 | } 218 | 219 | /** 220 | * Creates the HTML interface for this Field Type. 221 | * 222 | * @since 0.5 223 | * 224 | * @param array $field The Field being rendered. 225 | */ 226 | public function render_field( $field ) { 227 | 228 | // Change Field into a "select" Field. 229 | $field['type'] = 'select'; 230 | 231 | // Render. 232 | acf_render_field( $field ); 233 | 234 | } 235 | 236 | /** 237 | * This filter is applied to the Field after it is loaded from the database. 238 | * 239 | * @since 0.5 240 | * 241 | * @param array $field The Field array holding all the Field options. 242 | * @return array $field The modified Field data. 243 | */ 244 | public function load_field( $field ) { 245 | 246 | // Try and init CiviCRM. 247 | if ( ! $this->civicrm->is_initialised() ) { 248 | return $field; 249 | } 250 | 251 | // Get CiviCRM config. 252 | $config = CRM_Core_Config::singleton(); 253 | 254 | $field['allow_null'] = 1; 255 | $field['multiple'] = 0; 256 | $field['ui'] = 1; 257 | $field['ajax'] = 0; 258 | $field['return_format'] = 'value'; 259 | $field['choices'] = CRM_Core_PseudoConstant::country(); 260 | // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 261 | $field['default_value'] = $config->defaultContactCountry; 262 | 263 | // --< 264 | return $field; 265 | 266 | } 267 | 268 | /** 269 | * This method is called in the "admin_enqueue_scripts" action on the edit 270 | * screen where this Field is created. 271 | * 272 | * Use this action to add CSS and JavaScript to assist your render_field() 273 | * action. 274 | * 275 | * @since 0.5 276 | */ 277 | public function input_admin_enqueue_scripts() { 278 | 279 | // Enqueue our JavaScript. 280 | wp_enqueue_script( 281 | 'acf-input-' . $this->name, 282 | plugins_url( 'assets/js/acf/acfe/fields/civicrm-address-country-field.js', CIVICRM_WP_PROFILE_SYNC_FILE ), 283 | [ 'acf-input' ], 284 | CIVICRM_WP_PROFILE_SYNC_VERSION, // Version. 285 | true 286 | ); 287 | 288 | } 289 | 290 | } 291 | -------------------------------------------------------------------------------- /includes/acf/classes/cwps-acf-civicrm-campaign.php: -------------------------------------------------------------------------------- 1 | plugin = $parent->acf_loader->plugin; 61 | $this->acf_loader = $parent->acf_loader; 62 | $this->civicrm = $parent; 63 | 64 | // Init when the ACF CiviCRM object is loaded. 65 | add_action( 'cwps/acf/civicrm/loaded', [ $this, 'register_hooks' ] ); 66 | 67 | } 68 | 69 | /** 70 | * Register WordPress hooks. 71 | * 72 | * @since 0.5 73 | */ 74 | public function register_hooks() { 75 | 76 | } 77 | 78 | // ----------------------------------------------------------------------------------- 79 | 80 | /** 81 | * Create a CiviCRM Campaign. 82 | * 83 | * If you want to "create" a Campaign, do not pass $data['id'] in. The presence 84 | * of an ID will cause an update to that Campaign. 85 | * 86 | * @since 0.5 87 | * 88 | * @param string $data The Campaign data. 89 | * @return array|bool $campaign The array of Campaign data, or false on failure. 90 | */ 91 | public function create( $data ) { 92 | 93 | // Init return. 94 | $campaign = false; 95 | 96 | // Try and init CiviCRM. 97 | if ( ! $this->civicrm->is_initialised() ) { 98 | return $campaign; 99 | } 100 | 101 | // Define params to create new Campaign. 102 | $params = [ 103 | 'version' => 3, 104 | ] + $data; 105 | 106 | // Call the API. 107 | $result = civicrm_api( 'Campaign', 'create', $params ); 108 | 109 | // Log and bail if there's an error. 110 | if ( ! empty( $result['is_error'] ) && 1 === (int) $result['is_error'] ) { 111 | $e = new Exception(); 112 | $trace = $e->getTraceAsString(); 113 | $log = [ 114 | 'method' => __METHOD__, 115 | 'params' => $params, 116 | 'result' => $result, 117 | 'backtrace' => $trace, 118 | ]; 119 | $this->plugin->log_error( $log ); 120 | return $campaign; 121 | } 122 | 123 | // Bail if there are no results. 124 | if ( empty( $result['values'] ) ) { 125 | return $campaign; 126 | } 127 | 128 | // The result set should contain only one item. 129 | $campaign = array_pop( $result['values'] ); 130 | 131 | // --< 132 | return $campaign; 133 | 134 | } 135 | 136 | /** 137 | * Update a CiviCRM Contact with a given set of data. 138 | * 139 | * This is an alias of `self::create()` except that we expect an ID to have 140 | * been set in the data. 141 | * 142 | * @since 0.5 143 | * 144 | * @param array $data The CiviCRM Campaign data. 145 | * @return array|bool The array of data from the CiviCRM API, or false on failure. 146 | */ 147 | public function update( $data ) { 148 | 149 | // Log and bail if there's no Campaign ID. 150 | if ( empty( $data['id'] ) ) { 151 | $e = new \Exception(); 152 | $trace = $e->getTraceAsString(); 153 | $log = [ 154 | 'method' => __METHOD__, 155 | 'message' => __( 'A numeric ID must be present to update a Campaign.', 'civicrm-wp-profile-sync' ), 156 | 'data' => $data, 157 | 'backtrace' => $trace, 158 | ]; 159 | $this->plugin->log_error( $log ); 160 | return false; 161 | } 162 | 163 | // Pass through. 164 | return $this->create( $data ); 165 | 166 | } 167 | 168 | // ----------------------------------------------------------------------------------- 169 | 170 | /** 171 | * Get the data for a Campaign. 172 | * 173 | * @since 0.5 174 | * 175 | * @param integer $campaign_id The numeric ID of the Campaign. 176 | * @return array $campaign The array of Campaign data, or empty if none. 177 | */ 178 | public function get_by_id( $campaign_id ) { 179 | 180 | // Init return. 181 | $campaign = []; 182 | 183 | // Try and init CiviCRM. 184 | if ( ! $this->civicrm->is_initialised() ) { 185 | return $campaign; 186 | } 187 | 188 | // Construct API query. 189 | $params = [ 190 | 'version' => 3, 191 | 'id' => $campaign_id, 192 | ]; 193 | 194 | // Get Campaign details via API. 195 | $result = civicrm_api( 'Campaign', 'get', $params ); 196 | 197 | // Bail if there's an error. 198 | if ( ! empty( $result['is_error'] ) && 1 === (int) $result['is_error'] ) { 199 | return $campaign; 200 | } 201 | 202 | // Bail if there are no results. 203 | if ( empty( $result['values'] ) ) { 204 | return $campaign; 205 | } 206 | 207 | // The result set should contain only one item. 208 | $campaign = (object) array_pop( $result['values'] ); 209 | 210 | // --< 211 | return $campaign; 212 | 213 | } 214 | 215 | // ----------------------------------------------------------------------------------- 216 | 217 | /** 218 | * Gets the currently-active CiviCRM Campaigns. 219 | * 220 | * @since 0.5 221 | * 222 | * @return array $campaigns The array of data for CiviCRM Campaigns. 223 | */ 224 | public function get_current() { 225 | 226 | // Return early if already calculated. 227 | static $campaigns; 228 | if ( isset( $campaigns ) ) { 229 | return $campaigns; 230 | } 231 | 232 | // Try and init CiviCRM. 233 | if ( ! $this->civicrm->is_initialised() ) { 234 | return []; 235 | } 236 | 237 | // Build params. 238 | $params = [ 239 | 'version' => 3, 240 | 'sequential' => 1, 241 | 'is_active' => 1, 242 | 'status_id' => [ 'NOT IN' => [ 'Completed', 'Cancelled' ] ], 243 | 'options' => [ 244 | 'sort' => 'name', 245 | 'limit' => 0, 246 | ], 247 | ]; 248 | 249 | // Call the CiviCRM API. 250 | $result = civicrm_api( 'Campaign', 'get', $params ); 251 | 252 | // Return early if something went wrong. 253 | if ( ! empty( $result['is_error'] ) && 1 === (int) $result['is_error'] ) { 254 | $e = new \Exception(); 255 | $trace = $e->getTraceAsString(); 256 | $log = [ 257 | 'method' => __METHOD__, 258 | 'params' => $params, 259 | 'result' => $result, 260 | 'backtrace' => $trace, 261 | ]; 262 | $this->plugin->log_error( $log ); 263 | return []; 264 | } 265 | 266 | // Bail if there are no results. 267 | if ( empty( $result['values'] ) ) { 268 | return []; 269 | } 270 | 271 | // Assign Campaign data. 272 | $campaigns = $result['values']; 273 | 274 | // --< 275 | return $campaigns; 276 | 277 | } 278 | 279 | /** 280 | * Gets the choices for the currently-active CiviCRM Campaigns. 281 | * 282 | * @since 0.5 283 | * 284 | * @return array $campaigns The array of choices for CiviCRM Campaigns. 285 | */ 286 | public function choices_get() { 287 | 288 | // Return early if already calculated. 289 | static $campaigns; 290 | if ( isset( $campaigns ) ) { 291 | return $campaigns; 292 | } 293 | 294 | // Get the currently-active Campaigns. 295 | $current = $this->get_current(); 296 | 297 | // Build return array. 298 | $campaigns = []; 299 | foreach ( $current as $key => $value ) { 300 | $campaigns[ $value['id'] ] = $value['title']; 301 | } 302 | 303 | // --< 304 | return $campaigns; 305 | 306 | } 307 | 308 | } 309 | --------------------------------------------------------------------------------