Skip to content

Instantly share code, notes, and snippets.

@wp126
Created August 29, 2022 05:06
Show Gist options
  • Save wp126/0548701676b66be2f7d91770048f4437 to your computer and use it in GitHub Desktop.
Save wp126/0548701676b66be2f7d91770048f4437 to your computer and use it in GitHub Desktop.
Create Situations in BuddyPress Email
<?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 = 'sendto@example.com';
//$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 = 'sendto@example.com';
/*$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