' . esc_html__( 'Permission error! Your request cannot be completed.', 'subscribe2' ) . '
' );
}
if ( is_multisite() ) {
if ( ! is_user_member_of_blog( $_GET['id'], get_current_blog_id() ) ) {
die( '' . esc_html__( 'Permission error! Your request cannot be completed.', 'subscribe2' ) . '
' );
} else {
$userid = (int) $_GET['id'];
}
} else {
$userid = (int) $_GET['id'];
}
} else {
global $user_ID;
return $user_ID;
}
return $userid;
}
/**
* Display the form to allow Regsitered users to amend their subscription
*/
public function s2_your_subscription_form( $userid ) {
if ( ! is_int( $userid ) ) {
return false;
}
global $mysubscribe2;
echo ' ';
if ( 'never' === $mysubscribe2->subscribe2_options['email_freq'] ) {
echo esc_html__( 'Receive email as', 'subscribe2' ) . ': ';
echo ' get_usermeta_keyname( 's2_format' ), true ), 'html', false ) . ' />';
echo ' ' . esc_html__( 'HTML - Full', 'subscribe2' ) . ' ';
echo ' get_usermeta_keyname( 's2_format' ), true ), 'html_excerpt', false ) . ' />';
echo ' ' . esc_html__( 'HTML - Excerpt', 'subscribe2' ) . ' ';
echo ' get_usermeta_keyname( 's2_format' ), true ), 'post', false ) . ' />';
echo ' ' . esc_html__( 'Plain Text - Full', 'subscribe2' ) . ' ';
echo ' get_usermeta_keyname( 's2_format' ), true ), 'excerpt', false ) . ' />';
echo ' ' . esc_html__( 'Plain Text - Excerpt', 'subscribe2' ) . ' ' . "\r\n";
if ( 'yes' === $mysubscribe2->subscribe2_options['show_autosub'] ) {
echo esc_html__( 'Automatically subscribe me to newly created categories', 'subscribe2' ) . ': ';
echo ' get_usermeta_keyname( 's2_autosub' ), true ), 'yes', false ) . ' />';
echo ' ' . esc_html__( 'Yes', 'subscribe2' ) . ' ';
echo ' get_usermeta_keyname( 's2_autosub' ), true ), 'no', false ) . ' />';
echo ' ' . esc_html__( 'No', 'subscribe2' ) . ' ';
echo '';
}
if ( 'yes' === $mysubscribe2->subscribe2_options['one_click_profile'] ) {
// One-click subscribe and unsubscribe buttons
echo '' . esc_html__( 'One Click Subscription / Unsubscription', 'subscribe2' ) . " \r\n";
echo ' ';
echo '
';
}
// subscribed categories
if ( $mysubscribe2->s2_mu ) {
global $blog_id;
$subscribed = get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
// if we are subscribed to the current blog display an "unsubscribe" link
if ( ! empty( $subscribed ) ) {
$unsubscribe_link = esc_url( add_query_arg( 's2mu_unsubscribe', $blog_id ) );
echo '' . esc_html__( 'Unsubscribe me from this blog', 'subscribe2' ) . '
';
} else {
// else we show a "subscribe" link
$subscribe_link = esc_url( add_query_arg( 's2mu_subscribe', $blog_id ) );
echo '' . esc_html__( 'Subscribe to all categories', 'subscribe2' ) . '
';
}
echo '' . esc_html__( 'Subscribed Categories on', 'subscribe2' ) . ' ' . esc_html( get_option( 'blogname' ) ) . ' ' . "\r\n";
} else {
echo '' . esc_html__( 'Subscribed Categories', 'subscribe2' ) . ' ' . "\r\n";
}
('' === $mysubscribe2->subscribe2_options['compulsory']) ? $compulsory = array() : $compulsory = explode( ',', $mysubscribe2->subscribe2_options['compulsory'] );
$this->display_category_form( explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) ), $mysubscribe2->subscribe2_options['reg_override'], $compulsory );
} else {
// we're doing daily digests, so just show
// subscribe / unnsubscribe
echo esc_html__( 'Receive periodic summaries of new posts?', 'subscribe2' ) . ': ';
echo '';
echo ' get_usermeta_keyname( 's2_subscribed' ), true ) ) {
echo ' checked="checked"';
}
echo ' /> ' . esc_html__( 'Yes', 'subscribe2' ) . ' get_usermeta_keyname( 's2_subscribed' ), true ) ) {
echo ' checked="checked"';
}
echo ' /> ' . esc_html__( 'No', 'subscribe2' );
echo ' ';
}
if ( count( $this->get_authors() ) > 1 && 'never' === $mysubscribe2->subscribe2_options['email_freq'] ) {
echo '' . "\r\n";
echo '
' . esc_html__( 'Do not send notifications for post made by these authors', 'subscribe2' ) . ' ' . "\r\n";
$this->display_author_form( explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), true ) ) );
echo '' . "\r\n";
}
// list of subscribed blogs on WordPress mu
if ( $mysubscribe2->s2_mu && ! isset( $_GET['email'] ) ) {
global $blog_id, $s2class_multisite;
$s2blog_id = $blog_id;
$current_user = wp_get_current_user();
$blogs = $s2class_multisite->get_mu_blog_list();
$blogs_subscribed = array();
$blogs_notsubscribed = array();
foreach ( $blogs as $blog ) {
// switch to blog
switch_to_blog( $blog['blog_id'] );
// check that the Subscribe2 plugin is active on the current blog
$current_plugins = get_option( 'active_plugins' );
if ( ! is_array( $current_plugins ) ) {
$current_plugins = (array) $current_plugins;
}
if ( ! in_array( S2DIR . 'subscribe2.php', $current_plugins, true ) ) {
continue;
}
// check if we're subscribed to the blog
$subscribed = get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
$blogname = get_option( 'blogname' );
if ( strlen( $blogname ) > 30 ) {
$blog['blogname'] = wp_html_excerpt( $blogname, 30 ) . '..';
} else {
$blog['blogname'] = $blogname;
}
$blog['description'] = get_option( 'blogdescription' );
$blog['blogurl'] = get_option( 'home' );
$blog['subscribe_page'] = get_option( 'home' ) . '/wp-admin/admin.php?page=s2';
$key = strtolower( $blog['blogname'] . '-' . $blog['blog_id'] );
if ( ! empty( $subscribed ) ) {
$blogs_subscribed[ $key ] = $blog;
} else {
$blogs_notsubscribed[ $key ] = $blog;
}
restore_current_blog();
}
echo '' . "\r\n";
if ( ! empty( $blogs_subscribed ) ) {
ksort( $blogs_subscribed );
echo '
' . esc_html__( 'Subscribed Blogs', 'subscribe2' ) . ' ' . "\r\n";
echo '
' . "\r\n";
foreach ( $blogs_subscribed as $blog ) {
echo '' . esc_html( $blog['blogname'] ) . ' ' . "\r\n";
if ( $s2blog_id === $blog['blog_id'] ) {
echo '' . esc_html__( 'Viewing Settings Now', 'subscribe2' ) . ' ' . "\r\n";
} else {
echo '';
if ( is_user_member_of_blog( $current_user->id, $blog['blog_id'] ) ) {
echo '' . esc_html__( 'View Settings', 'subscribe2' ) . ' ' . "\r\n";
}
echo '' . esc_html__( 'Unsubscribe', 'subscribe2' ) . ' ' . "\r\n";
}
echo '' . esc_html( $blog['description'] ) . '
' . "\r\n";
echo ' ';
}
echo ' ' . "\r\n";
}
if ( ! empty( $blogs_notsubscribed ) ) {
ksort( $blogs_notsubscribed );
echo '
' . esc_html__( 'Subscribe to new blogs', 'subscribe2' ) . " \r\n";
echo '
';
foreach ( $blogs_notsubscribed as $blog ) {
echo '' . esc_html( $blog['blogname'] ) . ' ' . "\r\n";
if ( $s2blog_id === $blog['blog_id'] ) {
echo '' . esc_html__( 'Viewing Settings Now', 'subscribe2' ) . ' ' . "\r\n";
} else {
echo '';
if ( is_user_member_of_blog( $current_user->id, $blog['blog_id'] ) ) {
echo '' . esc_html__( 'View Settings', 'subscribe2' ) . ' ' . "\r\n";
}
echo '' . esc_html__( 'Subscribe', 'subscribe2' ) . ' ' . "\r\n";
}
echo '' . esc_html( $blog['description'] ) . '
' . "\r\n";
echo ' ';
}
echo ' ' . "\r\n";
}
echo '
' . "\r\n";
}
}
/**
* Process input from the form that allows Regsitered users to amend their subscription
*/
public function s2_your_subscription_submit() {
global $mysubscribe2, $user_ID;
$userid = $this->get_userid();
if ( isset( $_POST['submit'] ) ) {
if ( isset( $_POST['s2_format'] ) ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), $_POST['s2_format'] );
} else {
// value has not been set so use default
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), 'excerpt' );
}
if ( isset( $_POST['new_category'] ) ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), $_POST['new_category'] );
} else {
// value has not been passed so use Settings defaults
if ( 'yes' === $mysubscribe2->subscribe2_options['show_autosub'] && 'yes' === $mysubscribe2->subscribe2_options['autosub_def'] ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), 'yes' );
} else {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), 'no' );
}
}
$cats = ( isset( $_POST['category'] ) ) ? $_POST['category'] : '';
if ( empty( $cats ) || '-1' === $cats ) {
$oldcats = explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) );
if ( $oldcats ) {
foreach ( $oldcats as $cat ) {
delete_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $cat );
}
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), '' );
} elseif ( 'digest' === $cats ) {
$all_cats = $mysubscribe2->all_cats( false, 'ID' );
foreach ( $all_cats as $cat ) {
( '' === $catids ) ? $catids = "$cat->term_id" : $catids .= ",$cat->term_id";
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $cat->term_id, $cat->term_id );
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), $catids );
} else {
if ( ! is_array( $cats ) ) {
$cats = (array) $_POST['category'];
}
sort( $cats );
$old_cats = explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) );
$remove = array_diff( $old_cats, $cats );
$new = array_diff( $cats, $old_cats );
if ( ! empty( $remove ) ) {
// remove subscription to these cat IDs
foreach ( $remove as $id ) {
delete_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $id );
}
}
if ( ! empty( $new ) ) {
// add subscription to these cat IDs
foreach ( $new as $id ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $id, $id );
}
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), implode( ',', $cats ) );
}
$authors = ( isset( $_POST['author'] ) ) ? $_POST['author'] : '';
if ( is_array( $authors ) ) {
$authors = implode( ',', $authors );
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), $authors );
} elseif ( empty( $authors ) ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), '' );
}
} elseif ( isset( $_POST['subscribe'] ) ) {
$mysubscribe2->one_click_handler( $userid, 'subscribe' );
} elseif ( isset( $_POST['unsubscribe'] ) ) {
$mysubscribe2->one_click_handler( $userid, 'unsubscribe' );
}
echo '' . esc_html__( 'Subscription preferences updated.', 'subscribe2' ) . '
' . "\r\n";
}
/**
* Display a table of categories with checkboxes
* Optionally pre-select those categories specified
*/
public function display_category_form( $selected = array(), $override = 1, $compulsory = array(), $name = 'category' ) {
global $wpdb, $mysubscribe2;
if ( 0 === $override ) {
$all_cats = $mysubscribe2->all_cats( true );
} else {
$all_cats = $mysubscribe2->all_cats( false );
}
$half = ( count( $all_cats ) / 2 );
$i = 0;
$j = 0;
echo '' . "\r\n";
}
/**
* Display a table of authors with checkboxes
* Optionally pre-select those authors specified
*/
public function display_author_form( $selected = array() ) {
$all_authors = $this->get_authors();
$half = ( count( $all_authors ) / 2 );
$i = 0;
$j = 0;
echo '' . "\r\n";
}
/**
* Collect an array of all author level users and above
*/
public function get_authors() {
if ( '' === $this->all_authors ) {
$role = array(
'fields' => array( 'ID', 'display_name' ),
'role' => 'administrator',
);
$administrators = get_users( $role );
$role = array(
'fields' => array( 'ID', 'display_name' ),
'role' => 'editor',
);
$editors = get_users( $role );
$role = array(
'fields' => array( 'ID', 'display_name' ),
'role' => 'author',
);
$authors = get_users( $role );
$this->all_authors = array_merge( $administrators, $editors, $authors );
}
return apply_filters( 's2_authors', $this->all_authors );
}
/**
* Define some variables
*/
private $all_authors = '';
}