/** Load all our strings */ function load_strings() { // adjust the output of Subscribe2 here $this->please_log_in = "<p class=\"s2_message\">" . __('To manage your subscription options please', 'subscribe2') . " <a href=\"" . get_option('siteurl') . "/wp-login.php\">" . __('login', 'subscribe2') . "</a>.</p>"; $this->profile = "<p class=\"s2_message\">" . __('You may manage your subscription options from your', 'subscribe2') . " <a href=\"" . get_option('siteurl') . "/wp-admin/admin.php?page=s2\">" . __('profile', 'subscribe2') . "</a>.</p>"; if ($this->s2_mu === true) { global $blog_id, $user_ID; if (!is_blog_user($blog_id)) { // if we are on multisite and the user is not a member of this blog change the link $this->profile = "<p class=\"s2_message\"><a href=\"" . get_option('siteurl') . "/wp-admin/?s2mu_subscribe=" . $blog_id . "\">" . __('Subscribe', 'subscribe2') . "</a> " . __('to email notifications when this blog posts new content', 'subscribe2') . ".</p>"; } } $this->confirmation_sent = "<p class=\"s2_message\">" . __('A confirmation message is on its way!', 'subscribe2') . "</p>"; $this->already_subscribed = "<p class=\"s2_error\">" . __('That email address is already subscribed.', 'subscribe2') . "</p>"; $this->not_subscribed = "<p class=\"s2_error\">" . __('That email address is not subscribed.', 'subscribe2') . "</p>"; $this->not_an_email = "<p class=\"s2_error\">" . __('Sorry, but that does not look like an email address to me.', 'subscribe2') . "</p>"; $this->barred_domain = "<p class=\"s2_error\">" . __('Sorry, email addresses at that domain are currently barred due to spam, please use an alternative email address.', 'subscribe2') . "</p>"; $this->error = "<p class=\"s2_error\">" . __('Sorry, there seems to be an error on the server. Please try again later.', 'subscribe2') . "</p>"; $this->no_page = __('You must to create a WordPress page for this plugin to work correctly.', 'subscribe2'); $this->mail_sent = "<p class=\"s2_message\">" . __('Message sent!', 'subscribe2') . "</p>"; $this->mail_failed = "<p class=\"s2_error\">" . __('Message failed! Check your settings and check with your hosting provider', 'subscribe2') . "</p>"; // confirmation messages $this->no_such_email = "<p class=\"s2_error\">" . __('No such email address is registered.', 'subscribe2') . "</p>"; $this->added = "<p class=\"s2_message\">" . __('You have successfully subscribed!', 'subscribe2') . "</p>"; $this->deleted = "<p class=\"s2_message\">" . __('You have successfully unsubscribed.', 'subscribe2') . "</p>"; $this->subscribe = __('subscribe', 'subscribe2'); //ACTION replacement in subscribing confirmation email $this->unsubscribe = __('unsubscribe', 'subscribe2'); //ACTION replacement in unsubscribing in confirmation email // menu strings $this->options_saved = __('Options saved!', 'subscribe2'); $this->options_reset = __('Options reset!', 'subscribe2'); }
function widget_suscribe() { global $wpdb, $current_user; $options = get_option('widget_suscribe'); $before_widget = "<li id='subscribe'>"; $before_title = "<h2>"; $title = empty($options['title']) ? 'Suscríbete a este blog' : $options['title']; $after_title = "</h2>"; $content = ""; $after_widget = "</li>"; //error_log("[widget subscribe] current blog: ". $wpdb->blogid); //error_log("[widget subscribe] current user: "******"[widget subscribe] is blog user"); // User wants to unsubscribe if (isset($_POST['unsuscribe'])) { //error_log("[widget subscribe] POST[unsuscribe]"); remove_user_from_blog($current_user->ID, $wpdb->blogid); $content .= '<p>Te has desuscrito de este blog</p>'; $content .= widget_subscribe_form(); } elseif ($current_user->has_cap('subscriber')) { //error_log("[widget subscribe] has_cap('subscriber')"); $content .= widget_unsubscribe_form(); } elseif ($current_user->has_cap('edit_posts')) { $content .= "<p>Este blog tiene activado el widget de suscripción</p>"; } } else { //error_log("[widget subscribe] not in log"); // User wants to subscribe if (isset($_POST['suscribe'])) { //error_log("[widget subscribe] POST[suscribe]"); add_user_to_blog($wpdb->blogid, $current_user->ID, 'subscriber'); $content .= '<p>Te has suscrito a este blog</p>'; $content .= widget_unsubscribe_form(); } else { //error_log("[widget subscribe] subscribe form"); $content .= widget_subscribe_form(); } } echo $before_widget . $before_title . $title . $after_title . $content . $after_widget; }
/** * @expectedDeprecated is_blog_user */ function test_is_blog_user() { global $wpdb; $user1_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); $old_current = get_current_user_id(); wp_set_current_user( $user1_id ); $this->assertTrue( is_blog_user() ); $this->assertTrue( is_blog_user( $wpdb->blogid ) ); $blog_ids = array(); $blog_ids = $this->factory->blog->create_many( 5 ); foreach ( $blog_ids as $blog_id ) { $this->assertInternalType( 'int', $blog_id ); $this->assertTrue( is_blog_user( $blog_id ) ); $this->assertTrue( remove_user_from_blog( $user1_id, $blog_id ) ); $this->assertFalse( is_blog_user( $blog_id ) ); } wp_set_current_user( $old_current ); }
/** Handles subscriptions and unsubscriptions for different blogs on WPMU installs */ function wpmu_subscribe() { global $mysubscribe2; // subscribe to new blog if (!empty($_GET['s2mu_subscribe'])) { $sub_id = intval($_GET['s2mu_subscribe']); if ($sub_id >= 0) { switch_to_blog($sub_id); $user_ID = get_current_user_id(); // if user is not a user of the current blog if (!is_blog_user($sub_id)) { // add user to current blog as subscriber add_user_to_blog($sub_id, $user_ID, 'subscriber'); // add an action hook for external manipulation of blog and user data do_action_ref_array('subscribe2_wpmu_subscribe', array($user_ID, $sub_id)); } // get categories, remove excluded ones if override is off if (0 == $mysubscribe2->subscribe2_options['reg_override']) { $all_cats = $mysubscribe2->all_cats(true, 'ID'); } else { $all_cats = $mysubscribe2->all_cats(false, 'ID'); } $cats_string = ''; foreach ($all_cats as $cat) { '' == $cats_string ? $cats_string = "{$cat->term_id}" : ($cats_string .= ",{$cat->term_id}"); update_user_meta($user_ID, $mysubscribe2->get_usermeta_keyname('s2_cat') . $cat->term_id, $cat->term_id); } if (empty($cats_string)) { delete_user_meta($user_ID, $mysubscribe2->get_usermeta_keyname('s2_subscribed')); } else { update_user_meta($user_ID, $mysubscribe2->get_usermeta_keyname('s2_subscribed'), $cats_string); } } } elseif (!empty($_GET['s2mu_unsubscribe'])) { // unsubscribe from a blog $unsub_id = intval($_GET['s2mu_unsubscribe']); if ($unsub_id >= 0) { switch_to_blog($unsub_id); $user_ID = get_current_user_id(); // delete subscription to all categories on that blog $cats = get_user_meta($user_ID, $mysubscribe2->get_usermeta_keyname('s2_subscribed'), true); $cats = explode(',', $cats); if (!is_array($cats)) { $cats = array($cats); } foreach ($cats as $id) { delete_user_meta($user_ID, $mysubscribe2->get_usermeta_keyname('s2_cat') . $id); } delete_user_meta($user_ID, $mysubscribe2->get_usermeta_keyname('s2_subscribed')); // add an action hook for external manipulation of blog and user data do_action_ref_array('subscribe2_wpmu_unsubscribe', array($user_ID, $unsub_id)); restore_current_blog(); } } if (!is_user_member_of_blog($user_ID)) { $user_blogs = get_active_blog_for_user($user_ID); if (is_array($user_blogs)) { switch_to_blog(key($user_blogs)); } else { // no longer a member of a blog wp_redirect(get_option('siteurl')); // redirect to front page exit(0); } } // redirect to profile page $url = get_option('siteurl') . '/wp-admin/admin.php?page=s2'; wp_redirect($url); exit(0); }
/** Our profile menu */ function user_menu() { global $user_ID, $s2nonce; if (isset($_GET['email'])) { global $wpdb; $user_ID = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE user_email = '" . $_GET['email'] . "'"); } else { get_currentuserinfo(); } // was anything POSTed? if (isset($_POST['s2_admin']) && 'user' == $_POST['s2_admin']) { check_admin_referer('subscribe2-user_subscribers' . $s2nonce); echo "<div id=\"message\" class=\"updated fade\"><p><strong>" . __('Subscription preferences updated.', 'subscribe2') . "</strong></p></div>\n"; $format = 'text'; $post = 'post'; if ('html' == $_POST['s2_format']) { $format = 'html'; } if ('excerpt' == $_POST['s2_excerpt']) { $post = 'excerpt'; } update_usermeta($user_ID, 's2_excerpt', $post); update_usermeta($user_ID, 's2_format', $format); update_usermeta($user_ID, 's2_autosub', $_POST['new_category']); $cats = $_POST['category']; if (empty($cats) || $cats == '-1') { $oldcats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'))); if ($oldcats) { foreach ($oldcats as $cat) { delete_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat); } } update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), ''); } elseif ($cats == 'digest') { $all_cats = get_categories(array('hide_empty' => false)); foreach ($all_cats as $cat) { '' == $catids ? $catids = "{$cat->term_id}" : ($catids .= ",{$cat->term_id}"); update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $cat->term_id, $cat->term_id); } update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), $catids); } else { if (!is_array($cats)) { $cats = array($_POST['category']); } $old_cats = explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'))); $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_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id); } } if (!empty($new)) { // add subscription to these cat IDs foreach ($new as $id) { update_usermeta($user_ID, $this->get_usermeta_keyname('s2_cat') . $id, $id); } } update_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'), implode(',', $cats)); } } // show our form echo "<div class=\"wrap\">"; echo "<h2>" . __('Notification Settings', 'subscribe2') . "</h2>\r\n"; if (isset($_GET['email'])) { $user = get_userdata($user_ID); echo "<span style=\"color: red;line-height: 300%;\">" . __('Editing Subscribe2 preferences for user', 'subscribe2') . ": " . $user->display_name . "</span>"; } echo "<form method=\"post\" action=\"\">"; echo "<p>"; if (function_exists('wp_nonce_field')) { wp_nonce_field('subscribe2-user_subscribers' . $s2nonce); } echo "<input type=\"hidden\" name=\"s2_admin\" value=\"user\" />"; if ($this->subscribe2_options['email_freq'] == 'never') { echo __('Receive email as', 'subscribe2') . ": "; echo "<label><input type=\"radio\" name=\"s2_format\" value=\"html\""; if ('html' == get_usermeta($user_ID, 's2_format')) { echo "checked=\"checked\" "; } echo "/> " . __('HTML', 'subscribe2') . "</label> "; echo "<label><input type=\"radio\" name=\"s2_format\" value=\"text\" "; if ('text' == get_usermeta($user_ID, 's2_format')) { echo "checked=\"checked\" "; } echo "/> " . __('Plain Text', 'subscribe2') . "</label><br /><br />\r\n"; echo __('Email contains', 'subscribe2') . ": "; $amount = array('excerpt' => __('Excerpt Only', 'subscribe2'), 'post' => __('Full Post', 'subscribe2')); foreach ($amount as $key => $value) { echo "<label><input type=\"radio\" name=\"s2_excerpt\" value=\"" . $key . "\""; if ($key == get_usermeta($user_ID, 's2_excerpt')) { echo " checked=\"checked\""; } echo " /> " . $value . "</label> "; } echo "<br /><span style=\"color: red;line-height: 300%;\">" . __('Note: HTML format will always deliver the full post', 'subscribe2') . ".</span><br />\r\n"; if ($this->subscribe2_options['show_autosub'] == 'yes') { echo __('Automatically subscribe me to newly created categories', 'subscribe2') . ': '; echo "<label><input type=\"radio\" name=\"new_category\" value=\"yes\" "; if ('yes' == get_usermeta($user_ID, 's2_autosub')) { echo "checked=\"checked\" "; } echo "/> " . __('Yes', 'subscribe2') . "</label> "; echo "<label><input type=\"radio\" name=\"new_category\" value=\"no\" "; if ('no' == get_usermeta($user_ID, 's2_autosub')) { echo "checked=\"checked\" "; } echo "/> " . __('No', 'subscribe2') . "</label><br /><br />"; echo "</p>"; } // subscribed categories if ($this->s2_mu) { global $blog_id; $subscribed = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')); // if we are subscribed to the current blog display an "unsubscribe" link if (!empty($subscribed)) { $unsubscribe_link = get_bloginfo('url') . "/wp-admin/?s2mu_unsubscribe=" . $blog_id; echo "<p><a href=\"" . $unsubscribe_link . "\" class=\"button\">" . __('Unsubscribe me from this blog', 'subscribe2') . "</a></p>"; } else { // else we show a "subscribe" link $subscribe_link = get_bloginfo('url') . "/wp-admin/?s2mu_subscribe=" . $blog_id; echo "<p><a href=\"" . $subscribe_link . "\" class=\"button\">" . __('Subscribe to all categories', 'subscribe2') . "</a></p>"; } echo "<h2>" . __('Subscribed Categories on', 'subscribe2') . " " . get_bloginfo('name') . " </h2>\r\n"; } else { echo "<h2>" . __('Subscribed Categories', 'subscribe2') . "</h2>\r\n"; } $this->display_category_form(explode(',', get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'))), $this->subscribe2_options['reg_override']); } else { // we're doing daily digests, so just show // subscribe / unnsubscribe echo __('Receive periodic summaries of new posts?', 'subscribe2') . ': '; echo "<p><label>"; echo "<input type=\"radio\" name=\"category\" value=\"digest\" "; if (get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'))) { echo "checked=\"yes\" "; } echo "/> " . __('Yes', 'subscribe2') . "</label> <label><input type=\"radio\" name=\"category\" value=\"-1\" "; if (!get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed'))) { echo "checked=\"yes\" "; } echo "/> " . __('No', 'subscribe2'); echo "</label></p>"; } // submit echo "<p class=\"submit\"><input type=\"submit\" class=\"button-primary\" name=\"submit\" value=\"" . __("Update Preferences", 'subscribe2') . " »\" /></p>"; echo "</form>\r\n"; // list of subscribed blogs on wordpress mu if ($this->s2_mu) { global $blog_id; $blogs = get_blog_list(0, 'all'); $blogs_subscribed = array(); $blogs_notsubscribed = array(); foreach ($blogs as $key => $blog) { // switch to blog switch_to_blog($blog['blog_id']); // check that the 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('subscribe2/subscribe2.php', $current_plugins)) { continue; } // check if we're subscribed to the blog $subscribed = get_usermeta($user_ID, $this->get_usermeta_keyname('s2_subscribed')); $blogname = get_bloginfo('name'); if (strlen($blogname) > 30) { $blog['blogname'] = wp_html_excerpt($blogname, 30) . ".."; } else { $blog['blogname'] = $blogname; } $blog['description'] = get_bloginfo('description'); if (defined('AUTHOR_AVATARS_VERSION')) { if (!class_exists('UserList')) { include_once ABSPATH . 'wp-content/plugins/author-avatars/lib/UserList.class.php'; } $userlist = new UserList(); $userlist->roles = array('Administrator', 'Editor', 'Subscriber'); $userlist->blogs = array($blog['blog_id']); $userlist->avatar_size = 30; $userlist->use_list_template(); $blog['users'] = $userlist->get_output(); } $blog['blogurl'] = get_bloginfo('url'); $blog['subscribe_page'] = get_bloginfo('url') . "/wp-admin/users.php?page=subscribe2/subscribe2.php"; $key = strtolower($blog['blogname'] . "-" . $blog['blog_id']); if (!empty($subscribed)) { $blogs_subscribed[$key] = $blog; } else { $blogs_notsubscribed[$key] = $blog; } restore_current_blog(); } if (!empty($blogs_subscribed)) { ksort($blogs_subscribed); echo '<h2>' . __('Subscribed Blogs', 'subscribe2') . '</h2>' . "\r\n"; echo "<ul class=\"s2_blogs\">\r\n"; foreach ($blogs_subscribed as $blog) { echo "<li><span class=\"name\"><a href=\"" . $blog['blogurl'] . "\" title=\"" . $blog['description'] . "\">" . $blog['blogname'] . "</a></span>\r\n"; if ($blog_id == $blog['blog_id']) { echo "<span class=\"buttons\">" . __('Viewing Settings Now', 'subscribe2') . "</span>\r\n"; } else { echo "<span class=\"buttons\">"; if (is_blog_user($blog['blog_id'])) { echo "<a href=\"" . $blog['subscribe_page'] . "\">" . __('View Settings', 'subscribe2') . "</a>\r\n"; } echo "<a href=\"" . $blog['blogurl'] . "/wp-admin/?s2mu_unsubscribe=" . $blog['blog_id'] . "\">" . __('Unsubscribe', 'subscribe2') . "</a></span>\r\n"; } echo "<div class=\"additional_info\"><span class=\"description\">" . $blog['description'] . "</span>" . $blog['users'] . "</div>\r\n"; echo "</li>"; } echo "</ul>\r\n"; } if (!empty($blogs_notsubscribed)) { ksort($blogs_notsubscribed); echo "<h2>" . __('Subscribe to new blogs', 'subscribe2') . "</h2>\r\n"; echo "<ul class=\"s2_blogs\">"; foreach ($blogs_notsubscribed as $blog) { echo "<li><span class=\"name\"><a href=\"" . $blog['blogurl'] . "\" title=\"" . $blog['description'] . "\">" . $blog['blogname'] . "</a></span>\r\n"; if ($blog_id == $blog['blog_id']) { echo "<span class=\"buttons\">" . __('Viewing Settings Now', 'subscribe2') . "</span>\r\n"; } else { echo "<span class=\"buttons\">"; if (is_blog_user($blog['blog_id'])) { echo "<a href=\"" . $blog['subscribe_page'] . "\">" . __('View Settings', 'subscribe2') . "</a>\r\n"; } echo "<a href=\"" . $blog['blogurl'] . "/wp-admin/?s2mu_subscribe=" . $blog['blog_id'] . "\">" . __('Subscribe', 'subscribe2') . "</a></span>\r\n"; } echo "<div class=\"additional_info\"><span class=\"description\">" . $blog['description'] . "</span>" . $blog['users'] . "</div>\r\n"; echo "</li>"; } echo "</ul>\r\n"; } } echo "</div>\r\n"; include ABSPATH . 'wp-admin/admin-footer.php'; // just to be sure die; }