Skip to content

Instantly share code, notes, and snippets.

@ejntaylor
Created November 28, 2016 11:50
Show Gist options
  • Save ejntaylor/17e57555104ed9e796087418b6fda280 to your computer and use it in GitHub Desktop.
Save ejntaylor/17e57555104ed9e796087418b6fda280 to your computer and use it in GitHub Desktop.
<?php
function ss_list_array() {
// Set Vars
$current_user = get_current_user();
$username = $current_user->user_login;
$post = get_the_ID();
$final_arr = array();
$user_array = array();
$email_addresses = array();
$n = 0;
// p2p site owners
$posts = get_posts( array(
'connected_type' => 'site_owners',
'connected_items' => $username,
'suppress_filters' => false,
'nopaging' => true
) );
// Add to array
$user_array['current_user'] = $current_user;
foreach ($posts as $post) {
// Set Vars
$post_id = $post->ID;
$post_title = $post->post_title;
$user_array['sites'][$n]['post_id'] = $post_id;
$user_array['sites'][$n]['post_title'] = $post_title;
/*
* Show assigned emails
*/
$emails = get_users( array(
'connected_type' => 'user_following',
'connected_items' => $post_id,
'suppress_filters' => false,
'nopaging' => true
) );
// create JSON array
foreach ($emails as $email) {
// get subscription field and make boolean
$connection_field = p2p_get_meta($email->p2p_id, 'special', true);
$connection_field = filter_var($connection_field, FILTER_VALIDATE_BOOLEAN);
$user_array['sites'][$n]['emails_followed'][] = array (
'email' => $email->user_email,
'subscribed' => $connection_field
);
}
$n++;
}
// var_dump($user_array);
return $user_array;
}
function user_loop_sites_new() {
$user_array = ss_list_array();
//vars
$n = 0;
foreach ($user_array['sites'] as $site) {
//var_dump($site);
echo '<h4>'.$site['post_title'].' <span>('. $site['post_id'] .')</span></h4>';
//var_dump($site['emails_followed']);
?>
<table id="account_emails" class="uk-table-hover uk-table uk-table-striped uk-table-condense account_emails account_emails_<?php echo $n; ?>">
<thead>
<th>Email</th>
<th>Subscribed</th>
</thead>
<?php
foreach ($site['emails_followed'] as $email) {
?>
<tr>
<td><?php echo $email['email']; ?></td>
<td><?php echo $email['subscribed'] ? 'Subscribed' : 'Unsubscribed'; ?></td>
</tr>
<?php
}
echo '</table>';
$n++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment