--- a/ays-popup-box/admin/partials/ays-pb-admin-display.php
+++ b/ays-popup-box/admin/partials/ays-pb-admin-display.php
@@ -11,16 +11,53 @@
* @package Ays_Pb
* @subpackage Ays_Pb/admin/partials
*/
+
+if (isset($_GET['error'])) {
+ if ($_GET['error'] === 'nonce') {
+ echo '<div class="notice notice-error ays-pb-notice"><p>' . __('Security check failed. Please try again.', 'ays-popup-box') . '</p></div>';
+ } elseif ($_GET['error'] === 'permissions') {
+ echo '<div class="notice notice-error ays-pb-notice"><p>' . __('You do not have sufficient permissions.', 'ays-popup-box') . '</p></div>';
+ }
+}
+
$action = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : '';
$id = isset($_GET['popupbox']) ? absint( intval($_GET['popupbox']) ) : null;
$popup_max_id = Ays_Pb_Data::get_max_id();
if ($action == 'duplicate') {
+
+ if (!current_user_can('manage_options')) {
+ wp_redirect(add_query_arg('error', 'permissions', admin_url('admin.php?page=' . sanitize_text_field($_REQUEST['page']))));
+ exit;
+ }
+
+ $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) ?? '';
+ if (!wp_verify_nonce( sanitize_text_field( wp_unslash( $nonce ) ), $this->plugin_name . '-duplicate-popupbox-' . $id)) {
+ wp_redirect(add_query_arg('error', 'nonce', admin_url('admin.php?page=' . sanitize_text_field($_REQUEST['page']))));
+ exit;
+ }
+
$this->popupbox_obj->duplicate_popupbox($id);
}
-if ($action == 'unpublish' || $action == 'publish') {
+if ($action == 'unpublish' || $action == 'publish') {
+
+ if (!current_user_can('manage_options')) {
+ wp_redirect(add_query_arg('error', 'permissions', admin_url('admin.php?page=' . sanitize_text_field($_REQUEST['page']))));
+ exit;
+ }
+
+ $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) ?? '';
+ if (!wp_verify_nonce( sanitize_text_field( wp_unslash( $nonce ) ), 'ays_pb_publish_unpublish_' . $id)) {
+ wp_redirect(add_query_arg('error', 'nonce', admin_url('admin.php?page=' . sanitize_text_field($_REQUEST['page']))));
+ exit;
+ }
+
$this->popupbox_obj->publish_unpublish_popupbox($id, $action);
+
+ wp_redirect(add_query_arg('success', 'status_changed', admin_url('admin.php?page=' . sanitize_text_field($_REQUEST['page']))));
+ exit;
+
}
$plus_icon_svg = "<span><img src='" . AYS_PB_ADMIN_URL . "/images/icons/plus-icon.svg'></span>";
--- a/ays-popup-box/ays-pb.php
+++ b/ays-popup-box/ays-pb.php
@@ -16,7 +16,7 @@
* Plugin Name: Popup Box
* Plugin URI: http://ays-pro.com/wordpress/popup-box
* Description: Pop up anything you want! Create informative and promotional popups all in one plugin. Boost your website traffic with eye-catching popups.
- * Version: 6.1.1
+ * Version: 6.1.2
* Author: Popup Box Team
* Author URI: http://ays-pro.com/
* License: GPL-2.0+
@@ -35,7 +35,7 @@
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
-define( 'AYS_PB_NAME_VERSION', '6.1.1' );
+define( 'AYS_PB_NAME_VERSION', '6.1.2' );
define( 'AYS_PB_NAME', 'ays-pb' );
if( ! defined( 'AYS_PB_ADMIN_URL' ) ) {
--- a/ays-popup-box/includes/lists/class-ays-pb-list-table.php
+++ b/ays-popup-box/includes/lists/class-ays-pb-list-table.php
@@ -380,36 +380,76 @@
*/
function column_title($item) {
- // Run a security check.
- if (empty($this->ays_pb_nonce) || ! wp_verify_nonce( $this->ays_pb_nonce, 'ays_pb_admin_popups_list_table_nonce' ) ) {
- // This nonce is not valid.
- wp_die('Nonce verification failed!');
- }
-
- if( !is_user_logged_in()){
- wp_die( esc_html__( 'Something went wrong', 'quiz-maker' ) );
- }
-
- // Verify unauthorized requests
- if( !current_user_can( 'manage_options' ) ){
- wp_die( esc_html__( 'Something went wrong', 'quiz-maker' ) );
- }
+ $duplicate_nonce = wp_create_nonce($this->plugin_name . "-duplicate-popupbox-" . absint($item["id"]));
- $delete_nonce = wp_create_nonce($this->plugin_name . "-delete-popupbox");
-
- $popup_name = ( isset($item["popup_name"]) && $item["popup_name"] != "" ) ? stripslashes( sanitize_text_field($item["popup_name"]) ) : stripslashes( sanitize_text_field($item["title"]) );
+ $popup_name = ( isset($item["popup_name"]) && $item["popup_name"] != "" )
+ ? stripslashes( sanitize_text_field($item["popup_name"]) )
+ : stripslashes( sanitize_text_field($item["title"]) );
$popup_title_length = intval($this->title_length);
-
$restitle = Ays_Pb_Admin::ays_pb_restriction_string("word", esc_attr($popup_name), $popup_title_length);
-
- $title = sprintf("<a href='?page=%s&action=%s&popupbox=%d' title='%s'>%s</a>", esc_attr($_REQUEST["page"]), "edit", absint($item["id"]), esc_attr($popup_name), $restitle);
-
+
+ $title = sprintf(
+ '<a href="?page=%s&action=%s&popupbox=%d" title="%s">%s</a>',
+ esc_attr($_REQUEST["page"]),
+ "edit",
+ absint($item["id"]),
+ esc_attr($popup_name),
+ $restitle
+ );
+
$actions = array(
- 'edit' => sprintf( "<a href='?page=%s&action=%s&popupbox=%d'>" . esc_html__('Edit', "ays-popup-box") . "</a>", esc_attr($_REQUEST["page"]), "edit", absint($item["id"]) ),
- 'duplicate' => sprintf( "<a href='?page=%s&action=%s&popupbox=%d'>" . esc_html__('Duplicate', "ays-popup-box") . '</a>', esc_attr($_REQUEST['page']), 'duplicate', absint($item['id']) ),
- 'delete' => sprintf( "<a class='ays_pb_confirm_del' data-message='%s' href='?page=%s&action=%s&popupbox=%d&_wpnonce=%s'>" . esc_html__('Delete', "ays-popup-box") . '</a>', $restitle, esc_attr($_REQUEST['page']), 'delete', absint($item['id']), $delete_nonce )
+ 'edit' => sprintf(
+ '<a href="?page=%s&action=%s&popupbox=%d">%s</a>',
+ esc_attr($_REQUEST["page"]),
+ "edit",
+ absint($item["id"]),
+ esc_html__('Edit', "ays-popup-box")
+ ),
+ 'duplicate' => sprintf(
+ '<a href="?page=%s&action=%s&popupbox=%d&_wpnonce=%s">%s</a>',
+ esc_attr($_REQUEST['page']),
+ 'duplicate',
+ absint($item['id']),
+ $duplicate_nonce,
+ esc_html__('Duplicate', "ays-popup-box")
+ ),
+ );
+
+ $delete_nonce = wp_create_nonce($this->plugin_name . "-delete-popupbox");
+ $actions['delete'] = sprintf(
+ '<a class="ays_pb_confirm_del" data-message="%s" href="?page=%s&action=%s&popupbox=%d&_wpnonce=%s">%s</a>',
+ $restitle,
+ esc_attr($_REQUEST['page']),
+ 'delete',
+ absint($item['id']),
+ $delete_nonce,
+ esc_html__('Delete', "ays-popup-box")
);
+
+ $status = isset($item['onoffswitch']) ? $item['onoffswitch'] : 'Off';
+
+ if ($status === 'On') {
+ $unpublish_url = add_query_arg([
+ 'page' => $_REQUEST['page'],
+ 'action' => 'unpublish',
+ 'popupbox' => absint($item['id'])
+ ], admin_url('admin.php'));
+
+ $unpublish_url = wp_nonce_url($unpublish_url, 'ays_pb_publish_unpublish_' . absint($item['id']));
+
+ $actions['unpublish'] = '<a href="' . esc_url($unpublish_url) . '">' . esc_html__('Unpublish', 'ays-popup-box') . '</a>';
+ } else {
+ $publish_url = add_query_arg([
+ 'page' => $_REQUEST['page'],
+ 'action' => 'publish',
+ 'popupbox' => absint($item['id'])
+ ], admin_url('admin.php'));
+
+ $publish_url = wp_nonce_url($publish_url, 'ays_pb_publish_unpublish_' . absint($item['id']));
+
+ $actions['publish'] = '<a href="' . esc_url($publish_url) . '">' . esc_html__('Publish', 'ays-popup-box') . '</a>';
+ }
return $title . $this->row_actions($actions);
}
@@ -711,25 +751,26 @@
if( !current_user_can( 'manage_options' ) ){
wp_die( esc_html__( 'Something went wrong', 'quiz-maker' ) );
}
-
- global $wpdb;
- $pb_table = $wpdb->prefix . "ays_pb";
-
+
if ($id == null) {
return false;
}
+ global $wpdb;
+ $pb_table = $wpdb->prefix . "ays_pb";
+
$onoffswitch = ($action == "unpublish") ? "Off" : "On";
$wpdb->update(
$pb_table,
- array(
- "onoffswitch" => $onoffswitch
- ),
+ array("onoffswitch" => $onoffswitch),
array("id" => intval($id)),
array("%s"),
array("%d")
);
+
+ // Optional: return true/false or the number of rows updated
+ return $wpdb->rows_affected > 0;
}
/**
@@ -1150,7 +1191,7 @@
if ($result >= 0) {
$message = "duplicated";
- $url = esc_url_raw( remove_query_arg(array('action', 'popupbox')) ) . '&status=' . $message;
+ $url = esc_url_raw( remove_query_arg(array('action', 'popupbox', '_wpnonce')) ) . '&status=' . $message;
wp_safe_redirect( $url );
exit;
}
@@ -2614,24 +2655,26 @@
if (empty($status)) return;
if ("created" == $status)
- $updated_message = esc_html( esc_html__("PopupBox created.", "ays-popup-box") );
+ $updated_message = esc_html__("PopupBox created.", "ays-popup-box");
elseif ("updated" == $status)
- $updated_message = esc_html( esc_html__("PopupBox saved.", "ays-popup-box") );
+ $updated_message = esc_html__("PopupBox saved.", "ays-popup-box");
elseif ("deleted" == $status)
- $updated_message = esc_html( esc_html__("PopupBox deleted.", "ays-popup-box") );
+ $updated_message = esc_html__("PopupBox deleted.", "ays-popup-box");
elseif ("duplicated" == $status)
- $updated_message = esc_html( esc_html__("PopupBox duplicated.", "ays-popup-box") );
+ $updated_message = esc_html__("PopupBox duplicated.", "ays-popup-box");
elseif ("published" == $status)
- $updated_message = esc_html( esc_html__("PopupBox published.", "ays-popup-box") );
+ $updated_message = esc_html__("PopupBox published.", "ays-popup-box");
elseif ("unpublished" == $status)
- $updated_message = esc_html( esc_html__("PopupBox unpublished.", "ays-popup-box") );
+ $updated_message = esc_html__("PopupBox unpublished.", "ays-popup-box");
+ elseif ("status_changed" == $status)
+ $updated_message = esc_html__("Popup status updated successfully.", "ays-popup-box");
elseif ("error" == $status)
$updated_message = esc_html__( "You're not allowed to add popupbox for more popupboxes please checkout to ", "ays-popup-box")."<a href='https://ays-pro.com/wordpress/popup-box' target='_blank'>PRO ".esc_html__("version", "ays-popup-box")."</a>.";
if (empty($updated_message)) return;
?>
- <div class="notice notice-<?php echo esc_attr($type); ?> is-dismissible">
+ <div class="ays-pb-notice notice notice-<?php echo esc_attr($type); ?> is-dismissible">
<p> <?php echo $updated_message; ?> </p>
</div>
<?php