Created
August 29, 2022 05:06
-
-
Save wp126/0548701676b66be2f7d91770048f4437 to your computer and use it in GitHub Desktop.
Create Situations in BuddyPress Email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Run Action User | |
* Description: | |
* Version: 1.0 | |
* Copyright: 2022 | |
* Text Domain: run-action-user | |
* Domain Path: /languages | |
*/ | |
add_action('exp_passport','runuser_data'); | |
//add_action('init','runuser_data'); | |
function runuser_data(){ | |
//if ($_REQUEST['action'] == 'runuser') { | |
/*$args = array( | |
'orderby' => 'user_nicename', | |
'order' => 'ASC', | |
); | |
$users = BP_XProfile_Query ( $args );*/ | |
$extradate = strtotime("+7 day"); | |
$date = date('Y-m-d',$extradate); | |
$args12 = array( | |
'xprofile_query' => array( | |
'relation' => 'AND', | |
array( | |
'field' => 623, | |
'value' => $date, | |
'compare' => '<=', | |
'type' => 'DATE', | |
), | |
/*array( | |
'field_name' => 'Number of Sisters', | |
'value' => '3', | |
'compare' => '>', | |
'type' => 'NUMERIC', | |
),*/ | |
), | |
); | |
$user_query12 = new BP_User_Query( $args12 ); | |
//echo "<pre>"; | |
//print_r($user_query12->results); | |
foreach ($user_query12->results as $uservalue) { | |
$user_email = $uservalue->user_email; | |
$user_id = $uservalue->ID; | |
//print_r($user_email); | |
//$to = '[email protected]'; | |
//$subject = 'Passport Expired'; | |
//$body = 'Your Passport Is a Expired. Please Renewal Your Passport'; | |
//$headers = array('Content-Type: text/html; charset=UTF-8'); | |
//wp_mail( $user_email, $subject, $body, $headers ); | |
//echo "sss"; | |
$emails = [ | |
$user_email, | |
]; | |
$email_type = 'post_passport_expired'; | |
$bpargs = array( | |
'tokens' => array('post.name'=>'customtoken') | |
); | |
bp_send_email( $email_type,$emails, $bpargs ); | |
} | |
$argsvisa = array( | |
'xprofile_query' => array( | |
'relation' => 'AND', | |
array( | |
'field' => 624, | |
'value' => $date, | |
'compare' => '<=', | |
'type' => 'DATE', | |
), | |
/*array( | |
'field_name' => 'Number of Sisters', | |
'value' => '3', | |
'compare' => '>', | |
'type' => 'NUMERIC', | |
),*/ | |
), | |
); | |
$user_queryvisa = new BP_User_Query( $argsvisa ); | |
foreach ($user_queryvisa->results as $visavalue) { | |
$user_email2 = $visavalue->user_email; | |
$user_id = $visavalue->ID; | |
//print_r($user_email); | |
//$to = '[email protected]'; | |
/*$subject2 = 'Visa Expired'; | |
$body2 = 'Your Visa Is a Expired. Please Renewal Your Visa'; | |
$headers2 = array('Content-Type: text/html; charset=UTF-8'); | |
wp_mail( $user_email2, $subject2, $body2, $headers2 );*/ | |
$emails = [ | |
$user_email2, | |
]; | |
$email_type = 'post_visa_expired'; | |
$bpargs = array( | |
'tokens' => array('post.name'=>'customtoken') | |
); | |
bp_send_email( $email_type,$emails, $bpargs ); | |
} | |
//exit(); | |
//} | |
} | |
function codex15766_custom_email_message() { | |
//exit; | |
// Do not create if it already exists and is not in the trash | |
$post_exists = post_exists( '[{{{site.name}}}] Visa Expired.' ); | |
if ( $post_exists != 0 && get_post_status( $post_exists ) == 'publish' ) | |
return; | |
// Create post object | |
$my_post = array( | |
'post_title' => __( '[{{{site.name}}}] Visa Expired', 'buddypress' ), | |
'post_content' => __( 'Visa Expired', 'buddypress' ), // HTML email content. | |
'post_excerpt' => __( 'Visa Expired commented on your blog post.', 'buddypress' ), // Plain text email content. | |
'post_status' => 'publish', | |
'post_type' => bp_get_email_post_type() // this is the post type for emails | |
); | |
// Insert the email post into the database | |
$post_id = wp_insert_post( $my_post ); | |
if ( $post_id ) { | |
// add our email to the taxonomy term 'post_received_comment' | |
// Email is a custom post type, therefore use wp_set_object_terms | |
$tt_ids = wp_set_object_terms( $post_id, 'post_visa_expired', bp_get_email_tax_type() ); | |
foreach ( $tt_ids as $tt_id ) { | |
$term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() ); | |
wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array( | |
'description' => 'Visa Expired', | |
) ); | |
} | |
} | |
} | |
//add_action( 'init', 'codex15766_custom_email_message' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment