Skip to content

Commit

Permalink
General enhancements and improvements
Browse files Browse the repository at this point in the history
See ChangeLog for full details
  • Loading branch information
mattyrob committed Mar 14, 2021
1 parent 55f5db5 commit 5837219
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 299 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Fixed bug in One Click button functionality on the User Profile page
* Refactor plugin initialisation and hooking steps
* Strip out some legacy code for Block Editor
* Strip out some unnecessary comments
* Introduce global returning function
* Update styling to Reset button in Settings page

= 11.1 =

Expand Down
2 changes: 1 addition & 1 deletion admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@
echo '<h3>' . esc_html__( 'Reset to Default Settings', 'subscribe2-for-cp' ) . '</h3>' . "\r\n";
echo '<p>' . esc_html__( 'Use this to reset all options to their defaults. This WILL NOT modify your list of subscribers.', 'subscribe2-for-cp' ) . '</p>' . "\r\n";
echo '<p class="submit" style="text-align: center">';
echo '<input type="submit" id="deletepost" name="reset" value="' . esc_attr( __( 'RESET', 'subscribe2-for-cp' ) ) . '" /></p>';
echo '<input type="submit" class="button-secondary" style="color:red;" name="reset" value="' . esc_attr( __( 'RESET', 'subscribe2-for-cp' ) ) . '" /></p>';
}
echo '</form></div>' . "\r\n";

Expand Down
7 changes: 3 additions & 4 deletions classes/class-s2-counter-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ public function widget( $args, $instance ) {
if ( ! empty( $title ) ) {
echo wp_kses_post( $args['before_title'] ) . esc_html( $title ) . wp_kses_post( $args['after_title'] );
}
global $mysubscribe2;
$registered = $mysubscribe2->get_registered();
$confirmed = $mysubscribe2->get_public();
$registered = s2cp()->get_registered();
$confirmed = s2cp()->get_public();
$count = ( count( $registered ) + count( $confirmed ) );
echo wp_kses_post( '<ul><div style="text-align:center; background-color:' . $s2w_bg . '; color:' . $s2w_fg . '; width:' . $s2w_width . 'px; height:' . $s2w_height . 'px; font:' . $s2w_font . 'pt Verdana, Arial, Helvetica, sans-serif; vertical-align:middle; padding:3px; border:1px solid #444;">' );
echo esc_html( $count );
Expand Down Expand Up @@ -116,4 +115,4 @@ public function form( $instance ) {
echo '<td><input type="text" name="' . esc_attr( $this->get_field_name( 's2w_font' ) ) . '" id="' . esc_attr( $this->get_field_id( 's2w_font' ) ) . '" value="' . esc_attr( $s2w_font ) . '" /></td></tr>' . "\r\n";
echo '</table></fieldset></div>' . "\r\n";
}
}// end S2_Counter_widget class
}
10 changes: 5 additions & 5 deletions classes/class-s2-form-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function form( $instance ) {
$noantispam = htmlspecialchars( $instance['noantispam'], ENT_QUOTES );
$nowrap = htmlspecialchars( $instance['nowrap'], ENT_QUOTES );

global $wpdb, $mysubscribe2;
global $wpdb;
$sql = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type='page' AND post_status='publish'";

echo '<div>' . "\r\n";
Expand All @@ -154,13 +154,13 @@ public function form( $instance ) {
echo '<label for="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'complete"><input id="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'complete" name="' . esc_attr( $this->get_field_name( 'hidebutton' ) ) . '" type="radio" value="none"' . checked( 'none', $hidebutton, false ) . '/> ' . esc_html__( 'Show complete form', 'subscribe2-for-cp' ) . '</label>' . "\r\n";
echo '<br><label for="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'subscribe"><input id="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'subscribe" name="' . esc_attr( $this->get_field_name( 'hidebutton' ) ) . '" type="radio" value="subscribe"' . checked( 'subscribe', $hidebutton, false ) . '/> ' . esc_html__( 'Hide Subscribe button', 'subscribe2-for-cp' ) . '</label>' . "\r\n";
echo '<br><label for="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'unsubscribe"><input id="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'unsubscribe" name="' . esc_attr( $this->get_field_name( 'hidebutton' ) ) . '" type="radio" value="unsubscribe"' . checked( 'unsubscribe', $hidebutton, false ) . '/> ' . esc_html__( 'Hide Unsubscribe button', 'subscribe2-for-cp' ) . '</label>' . "\r\n";
if ( '1' === $mysubscribe2->subscribe2_options['ajax'] ) {
if ( '1' === s2cp()->subscribe2_options['ajax'] ) {
echo '<br><label for="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'ajax"><input id="' . esc_attr( $this->get_field_id( 'hidebutton' ) ) . 'ajax" name="' . esc_attr( $this->get_field_name( 'hidebutton' ) ) . '" type="radio" value="link"' . checked( 'link', $hidebutton, false ) . '/> ' . esc_html__( 'Show as link', 'subscribe2-for-cp' ) . '</label>' . "\r\n";
}
echo '</p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'postto' ) ) . '">' . esc_html__( 'Post form content to page', 'subscribe2-for-cp' ) . ':' . "\r\n";
echo '<select class="widefat" id="' . esc_attr( $this->get_field_id( 'postto' ) ) . '" name="' . esc_attr( $this->get_field_name( 'postto' ) ) . '">' . "\r\n";
echo '<option value="' . esc_attr( $mysubscribe2->subscribe2_options['s2page'] ) . '">' . esc_html__( 'Use Subscribe2 Default', 'subscribe2-for-cp' ) . '</option>' . "\r\n";
echo '<option value="' . esc_attr( s2cp()->subscribe2_options['s2page'] ) . '">' . esc_html__( 'Use Subscribe2 Default', 'subscribe2-for-cp' ) . '</option>' . "\r\n";
echo '<option value="home"';
if ( 'home' === $postto ) {
echo ' selected="selected"';
Expand All @@ -171,7 +171,7 @@ public function form( $instance ) {
echo ' selected="selected"';
}
echo '>' . esc_html__( 'Use Referring Page', 'subscribe2-for-cp' ) . '</option>' . "\r\n";
$mysubscribe2->pages_dropdown( $postto, true );
s2cp()->pages_dropdown( $postto, true );
echo '</select></label></p>' . "\r\n";
echo '<p><label for="' . esc_attr( $this->get_field_id( 'js' ) ) . '">' . esc_html__( 'Disable JavaScript', 'subscribe2-for-cp' ) . ':' . "\r\n";
echo '<input id="' . esc_attr( $this->get_field_id( 'js' ) ) . '" name ="' . esc_attr( $this->get_field_name( 'js' ) ) . '" value="true" type="checkbox"' . checked( 'true', $js, false ) . '/>';
Expand All @@ -184,4 +184,4 @@ public function form( $instance ) {
echo '</label></p>' . "\r\n";
echo '</div>' . "\r\n";
}
} // End S2_Form_widget class
}
87 changes: 43 additions & 44 deletions classes/class-s2-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,39 @@ public function s2_your_subscription_form( $userid ) {
if ( ! is_int( $userid ) ) {
return false;
}
global $mysubscribe2;

echo '<input type="hidden" name="s2_admin" value="user" />';
if ( 'never' === $mysubscribe2->subscribe2_options['email_freq'] ) {
if ( 'never' === s2cp()->subscribe2_options['email_freq'] ) {
echo esc_html__( 'Receive email as', 'subscribe2-for-cp' ) . ': &nbsp;&nbsp;';
echo '<label><input type="radio" name="s2_format" value="html"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true ), 'html', false ) . ' />';
echo '<label><input type="radio" name="s2_format" value="html"' . checked( get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_format' ), true ), 'html', false ) . ' />';
echo ' ' . esc_html__( 'HTML - Full', 'subscribe2-for-cp' ) . '</label>&nbsp;&nbsp;';
echo '<label><input type="radio" name="s2_format" value="html_excerpt"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true ), 'html_excerpt', false ) . ' />';
echo '<label><input type="radio" name="s2_format" value="html_excerpt"' . checked( get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_format' ), true ), 'html_excerpt', false ) . ' />';
echo ' ' . esc_html__( 'HTML - Excerpt', 'subscribe2-for-cp' ) . '</label>&nbsp;&nbsp;';
echo '<label><input type="radio" name="s2_format" value="post"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true ), 'post', false ) . ' />';
echo '<label><input type="radio" name="s2_format" value="post"' . checked( get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_format' ), true ), 'post', false ) . ' />';
echo ' ' . esc_html__( 'Plain Text - Full', 'subscribe2-for-cp' ) . '</label>&nbsp;&nbsp;';
echo '<label><input type="radio" name="s2_format" value="excerpt"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_format' ), true ), 'excerpt', false ) . ' />';
echo '<label><input type="radio" name="s2_format" value="excerpt"' . checked( get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_format' ), true ), 'excerpt', false ) . ' />';
echo ' ' . esc_html__( 'Plain Text - Excerpt', 'subscribe2-for-cp' ) . '</label><br><br>' . "\r\n";

if ( 'yes' === $mysubscribe2->subscribe2_options['show_autosub'] ) {
if ( 'yes' === s2cp()->subscribe2_options['show_autosub'] ) {
echo esc_html__( 'Automatically subscribe me to newly created categories', 'subscribe2-for-cp' ) . ': &nbsp;&nbsp;';
echo '<label><input type="radio" name="new_category" value="yes"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), true ), 'yes', false ) . ' />';
echo '<label><input type="radio" name="new_category" value="yes"' . checked( get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_autosub' ), true ), 'yes', false ) . ' />';
echo ' ' . esc_html__( 'Yes', 'subscribe2-for-cp' ) . '</label>&nbsp;&nbsp;';
echo '<label><input type="radio" name="new_category" value="no"' . checked( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), true ), 'no', false ) . ' />';
echo '<label><input type="radio" name="new_category" value="no"' . checked( get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_autosub' ), true ), 'no', false ) . ' />';
echo ' ' . esc_html__( 'No', 'subscribe2-for-cp' ) . '</label>';
echo '</p>';
}

if ( 'yes' === $mysubscribe2->subscribe2_options['one_click_profile'] ) {
if ( 'yes' === s2cp()->subscribe2_options['one_click_profile'] ) {
// One-click subscribe and unsubscribe buttons
echo '<h2>' . esc_html__( 'One Click Subscription / Unsubscription', 'subscribe2-for-cp' ) . "</h2>\r\n";
echo '<p class="submit"><input type="submit" class="button-primary" name="subscribe" value="' . esc_html__( 'Subscribe to All', 'subscribe2-for-cp' ) . '" />&nbsp;&nbsp;';
echo '<input type="submit" class="button-primary" name="unsubscribe" value="' . esc_html__( 'Unsubscribe from All', 'subscribe2-for-cp' ) . '" /></p>';
}

// subscribed categories
if ( $mysubscribe2->s2_mu ) {
if ( s2cp()->s2_mu ) {
global $blog_id;
$subscribed = get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
$subscribed = get_user_meta( $userid, s2cp()->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 ) );
Expand All @@ -86,34 +85,34 @@ public function s2_your_subscription_form( $userid ) {
} else {
echo '<h2>' . esc_html__( 'Subscribed Categories', 'subscribe2-for-cp' ) . '</h2>' . "\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 );
( '' === s2cp()->subscribe2_options['compulsory'] ) ? $compulsory = array() : $compulsory = explode( ',', s2cp()->subscribe2_options['compulsory'] );
$this->display_category_form( explode( ',', get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_subscribed' ), true ) ), s2cp()->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-for-cp' ) . ': &nbsp;&nbsp;';
echo '<label>';
echo '<input type="radio" name="category" value="digest"';
if ( get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) ) {
if ( get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_subscribed' ), true ) ) {
echo ' checked="checked"';
}
echo ' /> ' . esc_html__( 'Yes', 'subscribe2-for-cp' ) . '</label> <label><input type="radio" name="category" value="-1" ';
if ( ! get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true ) ) {
if ( ! get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_subscribed' ), true ) ) {
echo ' checked="checked"';
}
echo ' /> ' . esc_html__( 'No', 'subscribe2-for-cp' );
echo '</label></p>';
}

if ( count( $this->get_authors() ) > 1 && 'never' === $mysubscribe2->subscribe2_options['email_freq'] ) {
if ( count( $this->get_authors() ) > 1 && 'never' === s2cp()->subscribe2_options['email_freq'] ) {
echo '<div class="s2_admin" id="s2_authors">' . "\r\n";
echo '<h2>' . esc_html__( 'Do not send notifications for post made by these authors', 'subscribe2-for-cp' ) . '</h2>' . "\r\n";
$this->display_author_form( explode( ',', get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), true ) ) );
$this->display_author_form( explode( ',', get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_authors' ), true ) ) );
echo '</div>' . "\r\n";
}

// list of subscribed blogs on Multisite installs
if ( $mysubscribe2->s2_mu && ! isset( $_GET['email'] ) ) {
if ( s2cp()->s2_mu && ! isset( $_GET['email'] ) ) {
global $blog_id, $s2class_multisite;
$s2blog_id = $blog_id;
$current_user = wp_get_current_user();
Expand All @@ -136,7 +135,7 @@ public function s2_your_subscription_form( $userid ) {
}

// check if we're subscribed to the blog
$subscribed = get_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), true );
$subscribed = get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_subscribed' ), true );

$blogname = get_option( 'blogname' );
if ( strlen( $blogname ) > 30 ) {
Expand Down Expand Up @@ -207,80 +206,80 @@ public function s2_your_subscription_form( $userid ) {
* Process input from the form that allows Regsitered users to amend their subscription
*/
public function s2_your_subscription_submit() {
global $mysubscribe2, $user_ID;
global $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'] );
update_user_meta( $userid, s2cp()->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' );
update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_format' ), 'excerpt' );
}
if ( isset( $_POST['new_category'] ) ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), $_POST['new_category'] );
update_user_meta( $userid, s2cp()->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' );
if ( 'yes' === s2cp()->subscribe2_options['show_autosub'] && 'yes' === s2cp()->subscribe2_options['autosub_def'] ) {
update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_autosub' ), 'yes' );
} else {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_autosub' ), 'no' );
update_user_meta( $userid, s2cp()->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 ) );
$oldcats = explode( ',', get_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_subscribed' ), true ) );
if ( $oldcats ) {
foreach ( $oldcats as $cat ) {
delete_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_cat' ) . $cat );
delete_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_cat' ) . $cat );
}
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), '' );
update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_subscribed' ), '' );
} elseif ( 'digest' === $cats ) {
$all_cats = $mysubscribe2->all_cats( false, 'ID' );
$all_cats = s2cp()->all_cats( false, 'ID' );
$catids = '';
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, s2cp()->get_usermeta_keyname( 's2_cat' ) . $cat->term_id, $cat->term_id );
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), $catids );
update_user_meta( $userid, s2cp()->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 ) );
$old_cats = explode( ',', get_user_meta( $userid, s2cp()->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 );
delete_user_meta( $userid, s2cp()->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, s2cp()->get_usermeta_keyname( 's2_cat' ) . $id, $id );
}
}
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_subscribed' ), implode( ',', $cats ) );
update_user_meta( $userid, s2cp()->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 );
update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_authors' ), $authors );
} elseif ( empty( $authors ) ) {
update_user_meta( $userid, $mysubscribe2->get_usermeta_keyname( 's2_authors' ), '' );
update_user_meta( $userid, s2cp()->get_usermeta_keyname( 's2_authors' ), '' );
}
} elseif ( isset( $_POST['subscribe'] ) ) {
$mysubscribe2->one_click_handler( $userid, 'subscribe' );
s2cp()->one_click_handler( $userid, 'subscribe' );
} elseif ( isset( $_POST['unsubscribe'] ) ) {
$mysubscribe2->one_click_handler( $userid, 'unsubscribe' );
s2cp()->one_click_handler( $userid, 'unsubscribe' );
}

echo '<div id="message" class="updated fade"><p><strong>' . esc_html__( 'Subscription preferences updated.', 'subscribe2-for-cp' ) . '</strong></p></div>' . "\r\n";
Expand All @@ -291,12 +290,12 @@ public function s2_your_subscription_submit() {
* Optionally pre-select those categories specified
*/
public function display_category_form( $selected = array(), $override = 1, $compulsory = array(), $name = 'category' ) {
global $wpdb, $mysubscribe2;
global $wpdb;

if ( 0 === $override ) {
$all_cats = $mysubscribe2->all_cats( true );
$all_cats = s2cp()->all_cats( true );
} else {
$all_cats = $mysubscribe2->all_cats( false );
$all_cats = s2cp()->all_cats( false );
}

$half = ( count( $all_cats ) / 2 );
Expand Down
Loading

0 comments on commit 5837219

Please sign in to comment.