Skip to content

Commit

Permalink
Merge pull request #6 from vidmantaskiro/1.0.3-update
Browse files Browse the repository at this point in the history
1.0.3 update
  • Loading branch information
greta-mik authored Oct 22, 2024
2 parents f338876 + 926aa4b commit 92a12ac
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions omnisend-for-lifterlms/class-omnisend-lifterlmsaddon.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Omnisend for LifterLMS Add-On
* Description: A LifterLMS add-on to sync contacts with Omnisend. In collaboration with LifterLMS plugin it enables better customer tracking
* Version: 1.0.2
* Version: 1.0.3
* Author: Omnisend
* Author URI: https://www.omnisend.com
* Developer: Omnisend
Expand All @@ -26,7 +26,7 @@
}

define( 'OMNISEND_LIFTERLMS_ADDON_NAME', 'Omnisend for Lifter LMS Add-On' );
define( 'OMNISEND_LIFTERLMS_ADDON_VERSION', '1.0.2' );
define( 'OMNISEND_LIFTERLMS_ADDON_VERSION', '1.0.3' );

spl_autoload_register( array( 'Omnisend_LifterLMSAddOn', 'autoloader' ) );
add_action( 'plugins_loaded', array( 'Omnisend_LifterLMSAddOn', 'check_plugin_requirements' ) );
Expand Down
21 changes: 12 additions & 9 deletions omnisend-for-lifterlms/includes/Mapper/class-contactmapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function update_contact( array $mapped_fields ): Contact {
$contact->set_city( $mapped_fields['llms_billing_city'] ?? '' );
$contact->set_welcome_email( true );

if ( ! isset( $options['filter_lms_consent_setting'] ) ) {
if ( isset( $options['filter_lms_consent_setting'] ) ) {
if ( isset( $mapped_fields['llmsconsentEmail'] ) ) {
$contact->set_email_subscriber();
$contact->set_email_consent( self::CONSENT_PREFIX );
Expand Down Expand Up @@ -158,15 +158,16 @@ public function create_contact_from_user_info( array $user_info ): Contact {
/**
* Custom function to add/remove memberships depending on current saved courses
*
* @param array $contract_data
* @param Contact $contract_data
* @param int $course_id
* @param string $action
*
* @return Contact object
*/
public function update_courses_omnisend_contract( array $contract_data, int $course_id = 0, string $action = 'add' ): Contact {
$current_contract_courses = $contract_data['customProperties']['courses'] ?? array();
$user_email = $contract_data['email'];
public function update_courses_omnisend_contract( Contact $contract_data, int $course_id = 0, string $action = 'add' ): Contact {
$custom_properties = $contract_data->get_custom_properties();
$current_contract_courses = isset( $custom_properties['courses'] ) ? $custom_properties['courses'] : array();
$user_email = $contract_data->get_email();

$course_name = get_the_title( $course_id );
if ( ! in_array( $course_name, $current_contract_courses ) && '' != $course_name ) {
Expand All @@ -183,6 +184,7 @@ public function update_courses_omnisend_contract( array $contract_data, int $cou
if ( empty( $current_contract_courses ) || null ) {
$current_contract_courses = '';
}

$contact->add_custom_property( 'courses', $current_contract_courses );
$contact->add_tag( self::CUSTOM_PREFIX );

Expand All @@ -192,15 +194,16 @@ public function update_courses_omnisend_contract( array $contract_data, int $cou
/**
* Custom function to add/remove memberships depending on current saved memberships
*
* @param array $contract_data
* @param Contact $contract_data
* @param int $membership_id
* @param string $action
*
* @return Contact object
*/
public function update_memberships_omnisend_contract( array $contract_data, int $membership_id = 0, string $action = 'add' ): Contact {
$current_contract_memberships = $contract_data['customProperties']['memberships'] ?? array();
$user_email = $contract_data['email'];
public function update_memberships_omnisend_contract( Contact $contract_data, int $membership_id = 0, string $action = 'add' ): Contact {
$custom_properties = $contract_data->get_custom_properties();
$current_contract_memberships = isset( $custom_properties['memberships'] ) ? $custom_properties['memberships'] : array();
$user_email = $contract_data->get_email();

$membership_name = get_the_title( $membership_id );
if ( ! in_array( $membership_name, $current_contract_memberships ) && '' != $membership_name ) {
Expand Down
17 changes: 13 additions & 4 deletions omnisend-for-lifterlms/includes/Service/class-consentservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function add_consent_llms_form_fields( $html ): string {
$contract_data = $omnisend_api->get_omnisend_contact_consent();

$email_consent = '';
if ( $contract_data['email'] ) {
if ( $contract_data['email'] == 'subscribed' ) {
$email_consent = 'checked';
}

$sms_consent = '';
if ( $contract_data['sms'] ) {
if ( $contract_data['sms'] == 'subscribed' ) {
$sms_consent = 'checked';
}

Expand Down Expand Up @@ -106,13 +106,18 @@ public function add_omnisend_memberships_data( int $user_id, int $membership_id
$omnisend_api->update_omnisend_memberships_data( $user_email, $membership_id, 'add' );
}

/**
* phpcs:disable WordPress.Security.NonceVerification.Missing
*/

/**
* Custom function to trigger when a user just registered for first time.
*
* @param int $user_id The ID of the user being removed.
*/
public function omnisend_save_register_fields( $user_id ): void {
if ( isset( $user_id ) && isset( $_POST['_llms_register_person_nonce'] ) && check_admin_referer( 'llms_register_person', '_llms_register_person_nonce' ) ) {

if ( isset( $user_id ) && isset( $_POST['_llms_register_person_nonce'] ) ) {

$register_fields = array();
$register_fields['email_address'] = sanitize_email( wp_unslash( $_POST['email_address'] ?? '' ) );
Expand Down Expand Up @@ -145,7 +150,7 @@ public function omnisend_save_register_fields( $user_id ): void {
* @param int $user_id The ID of the user profile.
*/
public function omnisend_update_register_fields( $user_id ): void {
if ( isset( $user_id ) && isset( $_POST['_llms_update_person_nonce'] ) && check_admin_referer( 'llms_update_person', '_llms_update_person_nonce' ) ) {
if ( isset( $user_id ) && isset( $_POST['_llms_update_person_nonce'] ) ) {
$update_register_fields = array();
$update_register_fields['email_address'] = sanitize_email( wp_unslash( $_POST['email_address'] ?? '' ) );
$update_register_fields['llms_phone'] = sanitize_text_field( wp_unslash( $_POST['llms_phone'] ?? '' ) );
Expand All @@ -171,6 +176,10 @@ public function omnisend_update_register_fields( $user_id ): void {
}
}

/**
* phpcs:enable WordPress.Security.NonceVerification.Missing
*/

/**
* Custom function to trigger when a user just enrolled to course.
*
Expand Down
2 changes: 1 addition & 1 deletion omnisend-for-lifterlms/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: LifterLMS, form, email marketing, web tracking, subscriber collection
Requires at least: 4.7.0
Tested up to: 6.6
Requires PHP: 7.4
Stable tag: 1.0.2
Stable tag: 1.0.3
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down

0 comments on commit 92a12ac

Please sign in to comment.