Add some AJAX actions in your plugin file, something like this… The first one (without _nopriv
) will already only be executed for logged in users, and the second will only be executed for logged out users, so there is no need to retest is_user_logged_in()
here:
add_action('wp_ajax_show_popup_contents', 'show_popup_contents');
function show_popup_contents() {
$filepath = dirname(__FILE__).'/popup.php';
include($filepath); exit;
}
add_action('wp_ajax_nopriv_show_popup_contents', 'deny_popup_contents');
function deny_popup_contents() {
wp_die("You need to be logged in to view these contents.");
}
Then set the popup URL to /wp-admin/admin-ajax.php?action=show_popup_contents
You probably want to also add if (!defined('ABSPATH')) {exit;}
at the top of the included popup.php
file so it cannot be accessed directly that way.
Related Posts:
- What are the common security flaws I need to look for? [closed]
- WordPress Capabilities: edit_user vs edit_users
- Where should my plugin POST to?
- Security error WP 4.0 + WP phpBB Bridge [closed]
- Should I use RIPS tool to test my themes and plugins?
- Escape when echoed
- wp_create_nonce function doesn’t work inside a plugin?
- I should enable automatic updates?
- Prevent direct access to WordPress plugin assets?
- How to prevent plugins from sniffing/stealing other plugins’ options?
- Security of a WordPress Plugin
- Help to Create a Simple Plugin to make a post
- Content-Security-Policy implementation with WordPress W3Total Cache plugin installed
- wp_verify_nonce fails always
- Validating values using Settings API?
- Loading external page template and enqueue script from plugin causes 403 forbidden error
- Where the Nickname is being used in WordPress
- WordPress plugin from own server
- How to avoid plugin name conflicts from the upgrade notifier?
- Is their any way to Extend WPDB class and Overwrite the Default Query Function
- Add content to /wp-admin/plugin-install.php admin screens
- How to check plugins for malicious code?
- How to properly secure my WordPress installation?
- How do I only load a plugin js on it’s settings pages?
- Need a function for changing saved post_date or post_date_gmt to relative time in wordpress
- How can I include a setting that has a variable number of values in a settings page using register_setting?
- Activate Plugin which is in subfolder?
- Adding dynamic section to WordPress
- Use functionality of 2 wordpress plugins
- Autoload via composer in plugin interference
- Yoast SEO blocking/re-initialising longer running process
- Add Fields with Sub-Fields to WP Job Manager
- template_redirect not being called when using ajax
- Can WordPress plugins “Talk to each other”?
- How do I store information in a dynamic block in WordPress?
- Is there a way to alter the order in which the plugins appear in the page?
- How to correctly detect accessing wp-content/uploads?
- How to create custom embed block in gutenberg wordpress
- Plugin exceeds memory limit
- Find the URL of the current plugin directory
- How can sanitize $_FILES[‘haq_slider’] field
- How to trigger $_GET request within admin plugin page?
- Plugin Paths Issue
- How to generate video out of images via WordPress plugin
- WordPress plugin – Error “Plugin generate 2890 characters of unexpected output when activated”
- Woocommerce plugin for minimum order and add-to-card-step
- UnInstallation of a Plugin from a developers perspective – The correct and clean method
- Using a post-signup hook to get user details
- How to apply a patch via plugin?
- wp_remote_get() returns 403 while file_get_contents() does not
- How to set add question capability for author role in wp pro quiz plugin
- Malware installation during plugin update?
- Unable to delete custom post types, confusion around capabilities
- Getting wp.me shortlink for wordpress custom post type
- where is the main file in this plugin?
- Remove .htaccess portion upon plugin deactivation?
- Insert Array in Plugin Database
- First plugin, problem with get_pages
- Plugin onclick button activate other plugin
- Translation issue with global variables
- what is the point of telling add_filter how many parameters you want passed to the function?
- How to add category and subcategory in WordPress custom code?
- Structuring function with registration_errors hook
- Yoast SEO Plug In and my Theme duplicating code. Need some feedback on what to do? [closed]
- Should I use the action in the plugin’s main file?
- wp_query ‘s’ parameter does not work with WC_AJAX
- Monitor all the queriers executed by my website
- Dotenv file in custom plugin
- Allow a particular user to access a particular plugin?
- wordpress plugin add page when activate
- Validating ajax search
- Add style to body based on url
- Getting the same post on my related post
- I want to schedule email (date, time is in database->table) wp_schedule_event() not working
- How to remove WordPress Default Comment? not Facebook
- How to use Datatable with Ajax when creating plugin on WordPress?
- Loading plugin script only on required page?
- Create survey that redirects to sidebar menu customized to answers
- Hook to display element as product on category page
- Missing files in enqueue actions causes WordPress to reload
- I can’t use WP_Query
- Adding/ Removing actions for plugins
- Get input form data posted by users
- WP Plugin: Print javascript in header
- Custom Plugin: Point to `template_directory`
- Adding list of Indexes in wordpress document
- WP internationalization not loaded
- Plugin options not appearing on options page using tabbed navigation
- Create plugin with form in post and submit it to specific form
- Storing values in Post Meta vs new tables
- Add custom fields in the new and edit the site forms without touching the WP core
- Extend WordPress REST API with Scheme Pro Plugin
- How to submit the custom form data in database in WordPress without plugin?
- My WP site and password was hacked, what to do? [closed]
- map urls to plugins
- Embed php code in custom field of a plugin [closed]
- Why haven’t I see plugins using get_file_data to handle retrieving plugin version?
- How to add custom html to the Media > Attachment Details modal?
- manage_{taxonomy}_custom_column not working
- How to be Variables and options must be escaped when echo’d?