Skip to content

christophwolff/wp-ip-post-restrict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

IP Post Restrict

Adds a Meta Checkbox to the posteditor to hide the post.

Check with ipr_is_post_restricted(get_the_id()`, i.e.

<?php if (ipr_is_post_restricted(get_the_id())){

		echo "Access denied!"

	} else {

		echo "Access granted!"

	}
?>

Restrict posts to IPs or IP ranges. Can be configured in the WordPress Network Settings.

Check a clients IP with ipr_client_ip_is_allowed(), for example:

<?php
if (ipr_client_ip_is_allowed()) {
	echo "You are allowed to see this.";
} else {
	echo "Nothing to see here, please move along.";
}
?>

Warning: The client IP can be spoofed. Do not hide secure information using this technique.

Bringing it together i.e. in a loop:

<?php

while ( $index_query->have_posts() ) : $index_query->the_post(); ?>


	if (!ipr_is_post_restricted(get_the_id()) && !ipr_client_ip_is_allowed()){

			get_template_part( 'template-parts/content', 'post' );

	}

<?php endwhile; ?>

?>

About

Restrict Posts to specific IPs from visitors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages