From 746919082a43ed6d56a7b58bf3365ace4f6ddc56 Mon Sep 17 00:00:00 2001 From: asus Date: Wed, 1 May 2024 19:34:51 +0200 Subject: [PATCH] wip newsletter, started by creating the acf field and the scheduled event --- plugins/cipf_plugin/cipf_plugin.php | 5 +- .../cipf_plugin/php/_actions_newsletter.php | 178 ++++++++++++++++++ 2 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 plugins/cipf_plugin/php/_actions_newsletter.php diff --git a/plugins/cipf_plugin/cipf_plugin.php b/plugins/cipf_plugin/cipf_plugin.php index 68e9cfc..8d3b690 100644 --- a/plugins/cipf_plugin/cipf_plugin.php +++ b/plugins/cipf_plugin/cipf_plugin.php @@ -4,7 +4,7 @@ Plugin Name: hggg_cipf Plugin URI: Description: Author: hugogogo -Version: 0.5.12 +Version: 0.5.13 Author URI: */ @@ -51,6 +51,7 @@ include_once(Plgntls::root_path() . 'php/_actions_payments.php'); include_once(Plgntls::root_path() . 'php/_actions_random_posts.php'); include_once(Plgntls::root_path() . 'php/_actions_scheduled_events.php'); include_once(Plgntls::root_path() . 'php/_actions_emails.php'); +include_once(Plgntls::root_path() . 'php/_actions_newsletter.php'); // admin include_once(Plgntls::root_path() . 'php/admin_hide_bar.php'); include_once(Plgntls::root_path() . 'php/admin_user_profil.php'); @@ -99,6 +100,8 @@ class Cipf { const ACF_PARTNER_OFFER_3_OUTPUT = ['_name'=>'afficher_offre_3', 'show'=>'Afficher', 'hide'=>'Masquer']; const ACF_READONLY_CLASS = 'readonly_acf'; const ACF_DATE_FORMAT = 'Ymd'; + const ACF_NEWSLETTER_RECEIVE = ['name' => 'recevoir_la_newsletter', 'true' => 'recevoir']; + const ACF_NEWSLETTER_ID = ['name' => 'identifiant_newsletter']; // META const META_PAYEMENT_STATUS = 'cipf_payement_status'; diff --git a/plugins/cipf_plugin/php/_actions_newsletter.php b/plugins/cipf_plugin/php/_actions_newsletter.php new file mode 100644 index 0000000..6f4f4b7 --- /dev/null +++ b/plugins/cipf_plugin/php/_actions_newsletter.php @@ -0,0 +1,178 @@ + array( + array( + 'key' => $acf_newsletter_receive['name'], + 'value' => $acf_newsletter_receive['true'], + 'compare' => 'LIKE', + ), + ), + 'fields' => array( + 'user_email', + ), + ); + + $users = get_users($args); + + /* + * transform the array of associatives arrays into an array of string : + * [['user_email' => ], ['user_email' => ]] -> [, ] + * + */ + $users_string = array_map(function($arr) { + return reset($arr); + }, $users); + + return $users_string; +} + +function get_all_partners_posts() { + Plgntls::debug_infos(); +} +function extract_ending_offers($all_posts) { + Plgntls::debug_infos(); +} +function extract_new_offers($all_posts) { + Plgntls::debug_infos(); +} +function extract_new_partners($all_posts) { + Plgntls::debug_infos(); +} +function extract_partners_if_less_than($all_posts, $total_count, $number) { + Plgntls::debug_infos(); +} + +function compose_newsletter_body_CIPF() { + Plgntls::debug_infos(); + + $all_posts = get_all_partners_posts(); + $ending_offers = extract_ending_offers($all_posts); // [ => , => ] + $new_offers = extract_new_offers($all_posts); // [ => , => ] + $new_partners = extract_new_partners($all_posts); // [, ] + $total = count($ending_offers) + count($new_offers) + count($new_partners); + $remaining_partners = extract_partners_if_less_than($all_posts, $total, 5); // [, ] + + ob_start(); + ?> +

newsletter cipf

+ + + $offer_number) { ?> + + $offer_number) { ?> + + + + + id; +// $old_body = $message->body; +////error_log("user_id: " . json_encode($user_id)); +////error_log("old_body: " . json_encode($old_body)); +// +// $pattern = '/\~\~(.*?)\~\~/'; +// +// $new_body = preg_replace_callback($pattern, 'newsletter_add_content_CIPF', $old_body); +// $message->body = $new_body; +// +// return $message; +//} +//add_filter("newsletter_message", "newsletter_filter_content_CIPF", 10, 3); +// +// +//function newsletter_add_content_CIPF($matches) { +// Plgntls::debug_infos(); +// error_log("matches: " . json_encode($matches)); +// +// $action = $matches[1].'_CIPF'; +// +// return $action(); +//} +// +//function nouveau_partenaire_CIPF() { +// Plgntls::debug_infos(); +// error_log("nouveau partenaire"); +// return "new partner"; +//} +// +//function nouvelle_offre_CIPF() { +// Plgntls::debug_infos(); +// error_log("nouvelle offre"); +// return "offre nouvelle"; +//} +// +//function fin_offre_CIPF() { +// Plgntls::debug_infos(); +// error_log("fin offre"); +// return "end offer"; +//} + + +?>