Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/subscribe2-settings-relevant-issues #18

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions admin/send-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@
}
} else {
global $phpmailer;
$message = '<p class="s2_error">' . __( 'Message failed!', 'subscribe2' ) . '</p>' . $error_message . $phpmailer->ErrorInfo;

$mailer_error = ! empty( $phpmailer->ErrorInfo ) ? $phpmailer->ErrorInfo : '';
$message = '<p class="s2_error">' . __( 'Message failed!', 'subscribe2' ) . '</p>' . $error_message . $mailer_error;
}
echo '<div id="message" class="updated"><strong><p>' . wp_kses_post( $message ) . '</p></strong></div>' . "\r\n";

echo '<div id="message" class="' . ( $success ? 'updated' : 'error' ) . '"><strong><p>' . wp_kses_post( $message ) . '</p></strong></div>' . "\r\n";
}

// show our form
Expand All @@ -118,7 +121,7 @@

echo '<p>' . esc_html__( 'Subject', 'subscribe2' ) . ': <input type="text" size="69" name="subject" value="' . esc_attr( $subject ) . '" /> <br><br>';
echo '<textarea rows="12" cols="75" name="content">' . $body . '</textarea>';
echo "<br><div id=\"upload_files\"><input type=\"file\" name=\"file[]\"></div>\r\n";
echo "<br><div id=\"upload_files\"><input type=\"file\" name=\"file[]\" onChange=\"remove_selected_image()\"></div>\r\n";
echo '<input type="button" class="button-secondary" name="addmore" value="' . esc_attr( __( 'Add More Files', 'subscribe2' ) ) . "\" onClick=\"add_file_upload();\" />\r\n";
echo "<br><br>\r\n";
echo esc_html__( 'Recipients:', 'subscribe2' ) . ' ';
Expand All @@ -128,16 +131,58 @@
echo '</form></div>' . "\r\n";
echo '<div style="clear: both;"><p>&nbsp;</p></div>';
?>
<script type="text/javascript">
//<![CDATA[
function add_file_upload() {
var div = document.getElementById( 'upload_files' );
var field = div.getElementsByTagName( 'input' )[0];
div.appendChild( document.createElement( 'br' ) );
div.appendChild( field.cloneNode( false ) );
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
function add_file_upload() {
const fileUploadContainer = document.getElementById('upload_files'),
fileNode = document.createElement('input'),
spanNode = document.createElement('span'),
lineBreak = document.createElement('br');

// Insert multiple file.
if (!Boolean(fileNode.value)) {
fileNode.type = 'file';
fileNode.name = 'file[]';
spanNode.classList.add('dashicons', 'dashicons-no-alt');
spanNode.style.marginTop = '4px';

fileUploadContainer.appendChild(lineBreak);
fileUploadContainer.appendChild(fileNode);
fileUploadContainer.appendChild(spanNode);
}

// Remove uploaded image if selected otherwise remove field.
spanNode.addEventListener('click', function () {
if (Boolean(fileNode.value)) {
fileNode.value = '';
return;
}

fileNode.remove();
spanNode.remove();
lineBreak.remove();
});
}

// Handle first selected image.
function remove_selected_image() {
const fileUploadContainer = document.getElementById('upload_files'),
firstFile = fileUploadContainer.getElementsByTagName('input')[0],
spanNode = document.createElement('span');

if (!Boolean(firstFile.nextSibling)) {
spanNode.style.marginTop = '4px';
spanNode.classList.add('dashicons', 'dashicons-no-alt');
firstFile.after(spanNode);
}

spanNode.addEventListener('click', function () {
firstFile.value = '';
this.remove();
});
}
//]]>
</script>
<?php
require ABSPATH . 'wp-admin/admin-footer.php';
// just to be sure
Expand Down
2 changes: 1 addition & 1 deletion admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
}
} elseif ( in_array( $key, array( 'notification_subject', 'mailtext', 'confirm_subject', 'confirm_email', 'remind_subject', 'remind_email' ), true ) && ! empty( $_POST[ $key ] ) ) {
// Email subject and body templates.
$this->subscribe2_options[ $key ] = sanitize_text_field( trim( $_POST[ $key ] ) );
$this->subscribe2_options[ $key ] = in_array( $key, array( 'notification_subject', 'confirm_subject', 'remind_subject' ) ) ? sanitize_text_field( trim( $_POST[ $key ] ) ) : sanitize_textarea_field( trim( $_POST[ $key ] ) );
} elseif ( in_array( $key, array( 'compulsory', 'exclude', 'format' ), true ) ) {
sort( $_POST[ $key ] );

Expand Down
2 changes: 1 addition & 1 deletion classes/class-s2-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public function s2_meta_handler( $post_id ) {
}
}

$subscribe_meta_field = ! empty( $_POST['s2_meta_field'] ) ? sanitize_text_field( $_POST['s2_meta_field'] ) : 'no';
$subscribe_meta_field = ! empty( $_POST['s2_meta_field'] ) ? sanitize_text_field( $_POST['s2_meta_field'] ) : 'yes';
if ( ! empty( $subscribe_meta_field ) && 'no' === $subscribe_meta_field ) {
update_post_meta( $post_id, '_s2mail', $subscribe_meta_field );
} else {
Expand Down
20 changes: 9 additions & 11 deletions classes/class-s2-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ public function substitute( $string = '', $digest_post_ids = array() ) {

if ( strstr( $string, '{TINYLINK}' ) ) {
$response = wp_safe_remote_get( 'http://tinyurl.com/api-create.php?url=' . rawurlencode( $this->get_tracking_link( $this->permalink ) ) );
if ( ! is_wp_error( $response ) ) {
$tinylink = wp_remote_retrieve_body( $response );
}
$tinylink = ! is_wp_error( $response ) ? wp_remote_retrieve_body( $response ) : '';

if ( false !== $tinylink ) {
$tlink = '<a href="' . $tinylink . '">' . $tinylink . '</a>';
Expand Down Expand Up @@ -2204,7 +2202,7 @@ public function s2init() {
}

// Load our translations.
add_action( 'init', array( &$this, 'load_translations' ) );
add_action( 'init', array( $this, 'load_translations' ) );

// Define and register table name.
$s2_table = $wpdb->prefix . 'subscribe2';
Expand Down Expand Up @@ -2270,25 +2268,25 @@ public function s2init() {

// Add actions for comment subscribers.
if ( 'no' !== $this->subscribe2_options['comment_subs'] ) {
add_filter( 'jetpack_get_available_modules', array( &$this, 's2_hide_jetpack_comments' ) );
add_filter( 'comment_form_submit_field', array( &$this, 's2_comment_meta_form' ) );
add_action( 'comment_post', array( &$this, 's2_comment_meta' ), 1, 2 );
add_action( 'wp_set_comment_status', array( &$this, 'comment_status' ) );
add_filter( 'jetpack_get_available_modules', array( $this, 's2_hide_jetpack_comments' ) );
add_filter( 'comment_form_submit_field', array( $this, 's2_comment_meta_form' ) );
add_action( 'comment_post', array( $this, 's2_comment_meta' ), 1, 2 );
add_action( 'wp_set_comment_status', array( $this, 'comment_status' ) );
}

// Add action to display widget if option is enabled.
if ( '1' === $this->subscribe2_options['widget'] ) {
add_action( 'widgets_init', array( &$this, 'subscribe2_widget' ) );
add_action( 'widgets_init', array( $this, 'subscribe2_widget' ) );
}

// Add action to display counter widget if option is enabled.
if ( '1' === $this->subscribe2_options['counterwidget'] ) {
add_action( 'widgets_init', array( &$this, 'counter_widget' ) );
add_action( 'widgets_init', array( $this, 'counter_widget' ) );
}

// Add action to 'clean' unconfirmed Public Subscribers.
if ( is_int( $this->clean_interval ) && $this->clean_interval > 0 ) {
add_action( 'wp_scheduled_delete', array( &$this, 's2cleaner_task' ) );
add_action( 'wp_scheduled_delete', array( $this, 's2cleaner_task' ) );
}

// Add ajax class if enabled.
Expand Down
1 change: 0 additions & 1 deletion classes/class-s2-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class S2_Frontend extends S2_Core {
public function unsubscribe( $email ) {
global $wpdb;

$email = base64_decode( $email );
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion traits/ShortcodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function load_strings() {
$this->unsubscribe = __( 'unsubscribe', 'subscribe2' ); //ACTION replacement in unsubscribing in confirmation email

if ( ! empty( $_GET['s2_unsub'] ) ) {
$this->unsubscribe( sanitize_email( $_GET['s2_unsub'] ) );
$this->unsubscribe( sanitize_email( base64_decode( $_GET['s2_unsub'] ) ) );
}
}

Expand Down
4 changes: 3 additions & 1 deletion uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
return;
}

$s2_mu = false;

// Is this WordPressMU or not?
if ( isset( $wpmu_version ) || strpos( $wp_version, 'wordpress-mu' ) ) {
if ( isset( $wpmu_version ) || ( isset( $wp_version ) && strpos( $wp_version, 'wordpress-mu' ) ) ) {
$s2_mu = true;
}

Expand Down