| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPFunnels\Integrations; |
| 4 |
|
| 5 |
use MRM\Common\MrmCommon; |
| 6 |
use Mint\MRM\DataBase\Models\ContactGroupModel; |
| 7 |
|
| 8 |
/** |
| 9 |
* Helper class for WP Funnels integrations. |
| 10 |
* |
| 11 |
* @since 3.2.0 |
| 12 |
*/ |
| 13 |
|
| 14 |
class Helper { |
| 15 |
|
| 16 |
|
| 17 |
/** |
| 18 |
* Get contact status based on the parameters provided. |
| 19 |
* |
| 20 |
* This method checks if double opt-in is enabled and sets the status accordingly. |
| 21 |
* |
| 22 |
* @param array $params Parameters containing contact status. |
| 23 |
* @return array|false Updated parameters with contact status or false if not enabled. |
| 24 |
* |
| 25 |
* @since 3.2.0 |
| 26 |
*/ |
| 27 |
public static function get_contact_status( $params ) { |
| 28 |
if( !self::maybe_enabled() ){ |
| 29 |
return false; |
| 30 |
} |
| 31 |
|
| 32 |
$is_enable = MrmCommon::is_double_optin_enable(); |
| 33 |
if( ! $is_enable && empty( $params[ 'status' ][ 0 ] ) ) { |
| 34 |
$params['status'] = 'subscribed'; |
| 35 |
} elseif( !is_array( $params['status'] ) ) { |
| 36 |
$params['status'] = isset( $params[ 'status' ] ) && in_array( $params[ 'status' ], array( 'subscribed', 'unsubscribed', 'pending' ), true ) ? $params[ 'status' ] : 'pending'; |
| 37 |
} else { |
| 38 |
$params['status'] = isset( $params[ 'status' ][ 0 ] ) && ! empty( $params[ 'status' ][ 0 ] ) ? $params[ 'status' ][ 0 ] : 'pending'; |
| 39 |
} |
| 40 |
return $params; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
/** |
| 46 |
* Retrieve all lists. |
| 47 |
* |
| 48 |
* This method returns an array of lists. If the feature is not enabled, it returns a default list with a "Select list" option. |
| 49 |
* |
| 50 |
* @return array Array of lists. |
| 51 |
* |
| 52 |
* @since 3.2.0 |
| 53 |
*/ |
| 54 |
public static function get_lists() { |
| 55 |
$lists = [ |
| 56 |
'' => __( 'Select list', 'wpfnl'), |
| 57 |
]; |
| 58 |
if( !self::maybe_enabled() ){ |
| 59 |
return $lists; |
| 60 |
} |
| 61 |
$data = ContactGroupModel::get_all( 'lists', 0, 0, '','title','ASC' ); |
| 62 |
|
| 63 |
if( !empty($data['data']) ){ |
| 64 |
foreach ($data['data'] as $key => $value) { |
| 65 |
$lists[$value['id']] = $value['title']; |
| 66 |
} |
| 67 |
} |
| 68 |
return $lists; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
/** |
| 73 |
* Retrieve all tags. |
| 74 |
* |
| 75 |
* This method returns an array of tags. If the feature is not enabled, it returns a default list with a "Select list" option. |
| 76 |
* |
| 77 |
* @return array Array of lists. |
| 78 |
* |
| 79 |
* @since 3.2.0 |
| 80 |
*/ |
| 81 |
public static function get_tags() { |
| 82 |
$lists = [ |
| 83 |
'' => __( 'Select tag', 'wpfnl'), |
| 84 |
]; |
| 85 |
if( !self::maybe_enabled() ){ |
| 86 |
return $lists; |
| 87 |
} |
| 88 |
$data = ContactGroupModel::get_all( 'tags', 0, 0, '','title','ASC' ); |
| 89 |
|
| 90 |
if( !empty($data['data']) ){ |
| 91 |
foreach ($data['data'] as $key => $value) { |
| 92 |
$lists[$value['id']] = $value['title']; |
| 93 |
} |
| 94 |
} |
| 95 |
return $lists; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
/** |
| 101 |
* Retrieve all lists for gutenberg. |
| 102 |
* |
| 103 |
* This method returns an array of lists. If the feature is not enabled, it returns a default list with a "Select list" option. |
| 104 |
* |
| 105 |
* @return array Array of lists. |
| 106 |
* |
| 107 |
* @since 3.2.0 |
| 108 |
*/ |
| 109 |
public static function get_lists_for_gutenberg() { |
| 110 |
$lists = [ |
| 111 |
[ |
| 112 |
'label' => __( 'Select list', 'wpfnl'), |
| 113 |
'value' => '' |
| 114 |
] |
| 115 |
]; |
| 116 |
if( !self::maybe_enabled() ){ |
| 117 |
return $lists; |
| 118 |
} |
| 119 |
$data = ContactGroupModel::get_all( 'lists', 0, 0, '','title','ASC' ); |
| 120 |
|
| 121 |
if( !empty($data['data']) ){ |
| 122 |
foreach ($data['data'] as $key => $value) { |
| 123 |
$lists[] = [ |
| 124 |
'label' => $value['title'], |
| 125 |
'value' => $value['id'] |
| 126 |
]; |
| 127 |
} |
| 128 |
} |
| 129 |
return $lists; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
/** |
| 134 |
* Retrieve all tags for gutenberg. |
| 135 |
* |
| 136 |
* This method returns an array of contact tags. If the feature is not enabled, it returns a default tag with a "Select tag" option. |
| 137 |
* |
| 138 |
* @return array Array of tags. |
| 139 |
* |
| 140 |
* @since 3.2.0 |
| 141 |
*/ |
| 142 |
public static function get_tags_for_gutenberg() { |
| 143 |
$tags = [ |
| 144 |
[ |
| 145 |
'label' => __( 'Select tag', 'wpfnl'), |
| 146 |
'value' => '' |
| 147 |
] |
| 148 |
]; |
| 149 |
if( !self::maybe_enabled() ){ |
| 150 |
return $tags; |
| 151 |
} |
| 152 |
$data = ContactGroupModel::get_all( 'tags', 0, 0,'','title','ASC'); |
| 153 |
|
| 154 |
if( !empty($data['data']) ){ |
| 155 |
foreach ($data['data'] as $key => $value) { |
| 156 |
$tags[] = [ |
| 157 |
'label' => $value['title'], |
| 158 |
'value' => $value['id'] |
| 159 |
]; |
| 160 |
} |
| 161 |
} |
| 162 |
return $tags; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
/** |
| 167 |
* Retrieve a list by its ID. |
| 168 |
* |
| 169 |
* This method returns the details of a specific list based on its ID. |
| 170 |
* |
| 171 |
* @param int $id The ID of the list. |
| 172 |
* @return array|false The list details or false if not enabled. |
| 173 |
* |
| 174 |
* @since 3.2.0 |
| 175 |
*/ |
| 176 |
public static function get_list_by_id( $id ) { |
| 177 |
if( !self::maybe_enabled() ){ |
| 178 |
return false; |
| 179 |
} |
| 180 |
$data = ContactGroupModel::get( $id ); |
| 181 |
return $data; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
/** |
| 186 |
* Retrieve a contact tag by its ID. |
| 187 |
* |
| 188 |
* This method returns the details of a specific contact tag based on its ID. |
| 189 |
* |
| 190 |
* @param int $id The ID of the contact tag. |
| 191 |
* @return array|false The contact tag details or false if not enabled. |
| 192 |
* |
| 193 |
* @since 3.2.0 |
| 194 |
*/ |
| 195 |
public static function get_tag_by_id( $id ) { |
| 196 |
if( !self::maybe_enabled() ){ |
| 197 |
return false; |
| 198 |
} |
| 199 |
$data = ContactGroupModel::get( $id ); |
| 200 |
return $data; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
/** |
| 205 |
* Check if the MailMint feature is enabled. |
| 206 |
* |
| 207 |
* This method checks if the MAILMINT constant is defined to determine if the feature is enabled. |
| 208 |
* |
| 209 |
* @return bool True if enabled, false otherwise. |
| 210 |
* |
| 211 |
* @since 3.2.0 |
| 212 |
*/ |
| 213 |
public static function maybe_enabled(){ |
| 214 |
return defined('MAILMINT'); |
| 215 |
} |
| 216 |
} |
| 217 |
|