[insert_php]
date_default_timezone_set(‚Europe/Vienna‘);
if ($_SERVER[‚REMOTE_ADDR‘] == ‚91.118.154.57‘) {
$change = get_the_modified_date( „Y-m-d“, „2040“ );
$date_now = date(„Y-m-d“); // this format is string comparable
if ($date_now > $change and date(„H“) >= „14“) {
// the message
$msg = „Sie haben die Wochenkarte noch nicht aktualisiert! Bitte aktualisieren Sie diese bis 16:00!“;
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
// send email
mail(„ahoi@spelunke.at“,“Spelunke Wochenkarte Aussendung Hinweis!“,$msg);
} else if ($date_now > $change and date(„H“) >= „15“) {
// the message
$msg = „Die Wochenkarte wurde nicht versendet!“;
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
// send email
mail(„ahoi@spelunke.at“,“Spelunke Wochenkarte Aussendung Hinweis!“,$msg);
} else if (date(„H“) >= „15“) {
/**
* Make a request to MailChimp API v3
*
* @param string $endpoint The MailChimp API endpoint for this request WITHOUT starting slash
* @param string $type Type of request, whether GET, POST, PATCH, PUT, or DELETE
* @param array $body The request body parameters
*
* @return $response object The response object
*
*/
function isa_mailchimp_api_request( $endpoint, $type = ‚POST‘, $body = “ ) {
// Configure ————————————–
$api_key = ’83d963e00370fcdeb9c0a95545997ce4-us18′;
// STOP Configuring ——————————-
$core_api_endpoint = ‚https://.api.mailchimp.com/3.0/‘;
list(, $datacenter) = explode( ‚-‚, $api_key );
$core_api_endpoint = str_replace( “, $datacenter, $core_api_endpoint );
$url = $core_api_endpoint . $endpoint;
$request_args = array(
‚method‘ => $type,
‚timeout‘ => 20,
‚headers‘ => array(
‚Content-Type‘ => ‚application/json‘,
‚Authorization‘ => ‚apikey ‚ . $api_key
)
);
if ( $body ) {
$request_args[‚body‘] = json_encode( $body );
}
$request = wp_remote_post( $url, $request_args );
$response = is_wp_error( $request ) ? false : json_decode( wp_remote_retrieve_body( $request ) );
return $response;
}
$woche = get_field( „menuMainHeadline“,2040);
$essen = get_field( „menuGroupe“,2040);
$datum = get_field( „menuMain_datum“,2040);
$uhrzeit = get_field( „menuMain_uhrzeit“,2040);
$woche_u =get_field( „menuMainSubheadline“,2040);
/* Test */
$body_test = array(
’name‘ => ‚Wochenkarte_Template‘,
‚html‘ => ‚
|
|||||||||||||||
|
‚
);
$load_campaign_content = isa_mailchimp_api_request( „/templates/53441″, ‚Patch‘, $body_test);
/**
* Create a MailChimp campaign with MailChimp API v3
*
* @param $list_id string Your List ID for this campaign
* @param $subject string The email subject line for this campaign
* @return mixed The campaign ID if it was successfully created, otherwise false.
*/
function isa_create_mailchimp_campaign( $list_id, $subject ) {
// Configure ————————————–
$reply_to = ‚ahoi@spelunke.at‘;
$from_name = ‚Spelunke‘;
// STOP Configuring ——————————-
$campaign_id = “;
$segment = 32517;
$body = array(
‚recipients‘ => array(‚list_id‘ => $list_id, ’segment_opts‘ => array(’saved_segment_id‘ => $segment,)),
‚type‘ => ‚regular‘,
’settings‘ => array(’subject_line‘ => $subject,
‚reply_to‘ => $reply_to,
‚from_name‘ => $from_name
)
);
$create_campaign = isa_mailchimp_api_request( ‚campaigns‘, ‚POST‘, $body );
if ( $create_campaign ) {
if ( ! empty( $create_campaign->id ) && isset( $create_campaign->status ) && ’save‘ == $create_campaign->status ) {
// The campaign id:
$campaign_id = $create_campaign->id;
}
}
return $campaign_id ? $campaign_id : false;
}
/**
* Set the HTML content for MailChimp campaign, given template sections, with MailChimp API v3
*
* @param $campaign_id string The Campaign ID
* @param $template_content array Template Content including the Template ID and Sections
*
* @return bool True if the content was set, otherwise false.
*/
function isa_set_mail_campaign_content( $campaign_id, $template_content ) {
$set_content = “;
$set_campaign_content = isa_mailchimp_api_request( „campaigns/$campaign_id/content“, ‚PUT‘, $template_content );
if ( $set_campaign_content ) {
if ( ! empty( $set_campaign_content->html ) ) {
$set_content = true;
}
}
return $set_content ? true : false;
}
/************************************************************
*
* Create a MailChimp campaign, set the content, and SEND the campaign
*
************************************************************/
$woche = „Wochenkarte „.$datum;
$campaign_id = isa_create_mailchimp_campaign(„a425972ddb“, $woche );
if ( $campaign_id ) {
// Set the content for this campaign
$template_content = array(
‚template‘ => array(
// The id of the template to use.
‚id‘ => 53441, // INTEGER
// Content for the sections of the template. Each key should be the unique mc:edit area name from the template.
’sections‘ => array(
’std_content00′ => ‚THIS IS THE CONTENT BODY OF MY EMAIL MESSAGE.‘
)
)
);
$set_campaign_content = isa_set_mail_campaign_content( $campaign_id, $template_content );
// Send the Campaign if the content was set.
// NOTE: Campaign will send immediately.
if ( $set_campaign_content ) {
$send_campaign = isa_mailchimp_api_request( „campaigns/$campaign_id/actions/send“, ‚POST‘ );
if ( empty( $send_campaign ) ) {
// Campaign was sent!
} elseif( isset( $send_campaign->detail ) ) {
$error_detail = $send_campaign->detail;
}
}
}
}
} else {echo ‚Die Seite ist leider nicht verfügbar!‘;}
[/insert_php]