Skip to content
Merged
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
69 changes: 69 additions & 0 deletions includes/admin/feedzy-rss-feeds-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,7 @@ private function setup_wizard_subscribe_process() {
if ( ! is_wp_error( $request_res ) ) {
$body = json_decode( wp_remote_retrieve_body( $request_res ) );
if ( 'success' === $body->code ) {
update_option( 'feedzy_onboarding_user_subscribed', 'yes' );
$this->feedzy_dismiss_wizard( false );
wp_send_json( $response );
}
Expand All @@ -2177,6 +2178,74 @@ private function setup_wizard_subscribe_process() {
}
}

/**
* AJAX method to subscribe user to Feedzy newsletter via dashboard notice.
*
* @since 5.1.0
* @access public
* @return void
*/
public function feedzy_dashboard_subscribe() {
check_ajax_referer( 'feedzy_subscribe_nonce', '_wpnonce' );

Copilot AI Aug 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct access to $_POST without proper sanitization. Consider using sanitize_text_field() or wp_unslash() before casting to boolean for consistency with WordPress security practices.

Suggested change
$with_subscribe = !empty($_POST['with_subscribe']) ? (bool) sanitize_text_field(wp_unslash($_POST['with_subscribe'])) : false;

Copilot uses AI. Check for mistakes.
$email = ! empty( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : '';
$skip = ! empty( $_POST['skip'] ) ? sanitize_text_field( wp_unslash( $_POST['skip'] ) ) : '';

if ( 'yes' === $skip ) {
$this->dismiss_subscribe_notice();
wp_send_json_success();
}

if ( empty( $email ) || ! is_email( $email ) ) {
wp_send_json_error(
array(
'message' => __( 'Validation failed', 'feedzy-rss-feeds' ),
)
);
}

update_option( 'feedzy_rss_feeds_logger_flag', 'yes' );

$request_res = wp_remote_post(
FEEDZY_SUBSCRIBE_API,
array(
'timeout' => 100, // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
'headers' => array(
'Content-Type' => 'application/json',
),
'body' => wp_json_encode(
array(
'slug' => 'feedzy-rss-feeds',
'site' => home_url(),
'email' => $email,
'data' => array( 'source' => 'dashboard-notice' ),
)
),
)
);

if ( ! is_wp_error( $request_res ) ) {
$this->dismiss_subscribe_notice();
wp_send_json_success();
} else {
wp_send_json_error(
array(
'message' => $request_res->get_error_message(),
)
);
}
}

Copilot AI Aug 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dismiss_subscribe_notice() method is missing a docblock comment. Public methods should have proper documentation including @SInCE, @access, and description.

Suggested change
}
/**
* Dismisses the subscribe notice by updating the relevant option.
*
* @since 5.1.0
* @access public
*/

Copilot uses AI. Check for mistakes.

/**
* Dismiss subscribe notice.
*
* @since 5.1.0
* @return void
*/
public function dismiss_subscribe_notice() {
update_option( 'feedzy_dismiss_subscribe_notice_dashboard', 'yes' );
}

/**
* Create draft page.
*
Expand Down
1 change: 1 addition & 0 deletions includes/feedzy-rss-feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private function define_admin_hooks() {
self::$instance->loader->add_action( 'current_screen', self::$instance->admin, 'handle_legacy' );
self::$instance->loader->add_action( 'init', self::$instance->admin, 'register_settings' );
self::$instance->loader->add_action( 'wp_ajax_feedzy_validate_feed', self::$instance->admin, 'validate_feed' );
self::$instance->loader->add_action( 'wp_ajax_feedzy_dashboard_subscribe', self::$instance->admin, 'feedzy_dashboard_subscribe' );

// do not load this with the loader as this will need a corresponding remove_filter also.
add_filter( 'update_post_metadata', array( self::$instance->admin, 'validate_category_feeds' ), 10, 5 );
Expand Down
232 changes: 232 additions & 0 deletions includes/layouts/feedzy-subscribe-notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
<?php
/**
* Subscribe notice layout.
*
* @package Feedzy
* @since 5.1.0
*/

?>
<div class="feedzy-container">
<div class="feedzy-helper-notice" style="padding: 30px; position: relative">
<button
type="button"
class="feedzy-notice-dismiss"
aria-label="<?php esc_attr_e( 'Dismiss this notice', 'feedzy-rss-feeds' ); ?>"
>
&times;
</button>

<h2 class="feedzy-notice-title">
<?php esc_html_e( 'Welcome to Feedzy!', 'feedzy-rss-feeds' ); ?>
</h2>

<p class="feedzy-notice-subtitle">
<?php
$users_number = number_format_i18n( 50000 );
echo esc_html(
sprintf(
// translators: %s is the number of users.
__( 'Join %s+ users aggregating RSS feeds effortlessly', 'feedzy-rss-feeds' ),
$users_number
)
);
?>
</p>

<form id="feedzy-subscribe-form" method="post" action="">
<?php wp_nonce_field( 'feedzy_subscribe_nonce', 'feedzy_subscribe_nonce_field' ); ?>

<input
type="email"
id="fz_subscribe_email"
name="feedzy_email"
value="<?php echo esc_attr( get_option( 'admin_email' ) ); ?>"
class="feedzy-helper-subscribe"
required
>

<div class="mb-20">
<div class="feedzy-helper-info">
<?php esc_html_e( 'Get tips, updates & unlock exclusive guides', 'feedzy-rss-feeds' ); ?>
</div>
<div style="font-size: 16px;">
<?php esc_html_e( 'Help improve Feedzy with anonymous usage insights', 'feedzy-rss-feeds' ); ?>
</div>
</div>

<button
type="button"
name="feedzy_subscribe_button"
class="feedzy-subscribe"
>
<?php esc_html_e( 'Get Started', 'feedzy-rss-feeds' ); ?> →
</button>
</form>

<div class="feedzy-notice-error"></div>
</div>
</div>
<style>
.feedzy-notice-dismiss {
position: absolute;
top: 10px;
right: 10px;
background: transparent;
border: none;
cursor: pointer;
font-size: 24px;
}

.feedzy-notice-title {
font-size: clamp(28px, 5vw, 42px);
margin: 0 0 10px 0;
}

.feedzy-helper-notice .feedzy-notice-subtitle {
font-size: 20px;
margin-bottom: 20px;
}

.feedzy-wrap .feedzy-helper-subscribe {
width: 100%;
max-width: 600px;
padding: 15px;
font-size: 16px;
border: none;
border-radius: 5px;
margin-bottom: 20px;
}

.feedzy-helper-info {
font-size: 18px;
font-weight: 600;
margin-bottom: 8px;
}

.feedzy-helper-notice .feedzy-subscribe{
background: white;
padding: 12px 30px;
font-size: 18px;
font-weight: 600;
border: none;
border-radius: 5px;
cursor: pointer;
}

.feedzy-notice-error {
display: none;
color: #d63638;
margin-top: 10px;
padding: 8px;
background-color: #fcf0f1;
border: 1px solid #d63638;
border-radius: 4px;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
const showError = (message) => {
const errorDiv = document.querySelector('.feedzy-notice-error');
errorDiv.textContent = message;
errorDiv.style.display = 'block';
};

const hideError = () => {
const errorDiv = document.querySelector('.feedzy-notice-error');
errorDiv.style.display = 'none';
errorDiv.textContent = '';
};

const send = async (formData) => {
return await fetch(window.ajaxurl, {
method: 'POST',
body: formData,
credentials: 'same-origin'
});
}

const dismissNotice = async (button) => {
const notice = button.closest('.feedzy-helper-notice');
try {
button.disabled = true;
const nonceField = document.getElementById('feedzy_subscribe_nonce_field');

const formData = new FormData();
formData.append('action', 'feedzy_dashboard_subscribe');
formData.append('_wpnonce', nonceField.value);
formData.append('skip', 'yes');

await send(formData);
} catch (error) {
console.error('Error dismissing notice:', error);
} finally {
button.disabled = false;
jQuery(notice).fadeOut(400, function() {
jQuery(this).remove();
});
}
};

const handleSubscription = async (button) => {
try {
hideError();
const subscriptionForm = document.getElementById('feedzy-subscribe-form');

if ( !subscriptionForm.checkValidity() ) {
subscriptionForm.reportValidity();
return;
}

const emailElement = document.getElementById('fz_subscribe_email');
const nonceField = document.getElementById('feedzy_subscribe_nonce_field');

button.disabled = true;

const formData = new FormData();
formData.append('action', 'feedzy_dashboard_subscribe');
formData.append('_wpnonce', nonceField.value);
formData.append('with_subscribe', '1');
formData.append('email', emailElement.value);

const response = await send(formData);
const result = await response.json();

if (result.success) {
const notice = document.querySelector('.feedzy-helper-notice');
jQuery(notice).fadeOut(400, function() {
jQuery(this).remove();
});

if (result.data?.redirect_to) {
window.location.href = result.data.redirect_to;
}
} else {
const errorMessage = result.data?.message || 'Unknown';
showError(errorMessage);
}
} catch (error) {
showError(error);
} finally {
button.disabled = false;
}
};

const dismissButton = document.querySelector('.feedzy-notice-dismiss');
const subscribeButton = document.querySelector('.feedzy-subscribe');

if (dismissButton) {
dismissButton.addEventListener('click', (event) => {
event.preventDefault();
dismissNotice(event.target);
});
}

if (subscribeButton) {
subscribeButton.addEventListener('click', (event) => {
event.preventDefault();
handleSubscription(event.target);
});
}
});
</script>
Loading
Loading