WordPress Access Control - Version 3.0.3

Version Description

  • June 5, 2011 =

  • Added an option to apply members settings to all children of a page

  • Fixed a bug where the page navigation for posts/archives was broken

  • Fixed a bug where themes that used the_content on archive/search pages could show all the contents of a post instead of the no excerpt message

Download this release

Release Info

Developer brandon.wamboldt
Plugin Icon wp plugin WordPress Access Control
Version 3.0.3
Comparing to
See all releases

Code changes from version 3.0.2 to 3.0.3

public/css/wpac.css CHANGED
File without changes
public/images/lock.png CHANGED
File without changes
public/images/unlock.png CHANGED
File without changes
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: members, only, plugin, restricted, access, menus, 3.0, wp_nav_menu, nonmembers
5
  Requires at least: 2.9
6
  Tested up to: 3.2
7
- Stable tag: 3.0.2
8
 
9
  Restrict pages, posts and custom post types to members, nonmembers or specific roles and still add to navigation
10
 
@@ -50,6 +50,12 @@ Please leave a comment at http://brandonwamboldt.ca/plugins/members-only-menu-pl
50
 
51
  == Changelog ==
52
 
 
 
 
 
 
 
53
  = 3.0.2 - June 2, 2011 =
54
 
55
  * Added do_shortcode commands to allow nested shortcodes in the [members] and [nonmembers] shortcodes
4
  Tags: members, only, plugin, restricted, access, menus, 3.0, wp_nav_menu, nonmembers
5
  Requires at least: 2.9
6
  Tested up to: 3.2
7
+ Stable tag: 3.0.3
8
 
9
  Restrict pages, posts and custom post types to members, nonmembers or specific roles and still add to navigation
10
 
50
 
51
  == Changelog ==
52
 
53
+ = 3.0.3 - June 5, 2011 =
54
+
55
+ * Added an option to apply members settings to all children of a page
56
+ * Fixed a bug where the page navigation for posts/archives was broken
57
+ * Fixed a bug where themes that used the_content on archive/search pages could show all the contents of a post instead of the no excerpt message
58
+
59
  = 3.0.2 - June 2, 2011 =
60
 
61
  * Added do_shortcode commands to allow nested shortcodes in the [members] and [nonmembers] shortcodes
screenshot-1.png CHANGED
File without changes
screenshot-2.png CHANGED
File without changes
templates/meta_box.php CHANGED
@@ -3,8 +3,10 @@
3
  ?><input type="hidden" name="members_only_nonce" id="members_only_nonce" value="<?php echo wp_create_nonce( 'members_only' ); ?>" />
4
 
5
  <div id="members_only_container">
6
- <input type="checkbox" name="members_only" id="members_only" value="true" <?php echo $is_members_only; ?> />
7
- <?php _e( 'Only accessible by members?', 'wpac' ); ?>
 
 
8
 
9
  <div id="members_only_options" class="hide-if-js">
10
  <br /><strong><?php _e( 'Only Accessible By (Defaults to everyone):', 'wpac' ); ?></strong><br />
@@ -48,14 +50,16 @@
48
  $wpac_show_excerpt_in_search = get_option( 'wpac_show_page_excerpts_in_search', 0 );
49
  }
50
  ?>
51
- <input type="checkbox" name="wpac_show_in_search" value="yes" <?php checked( $wpac_show_in_search, 1 ); ?> /> <?php _e( 'Show in search results?', 'wpac' ); ?><br />
52
- <input type="checkbox" name="wpac_show_excerpt_in_search" value="yes"<?php checked( $wpac_show_excerpt_in_search, 1 ); ?> /> <?php _e( 'Show excerpt in search?', 'wpac' ); ?><br />
53
  </div>
54
  </div>
55
 
56
  <div id="nonmembers_only_container">
57
- <input type="checkbox" name="nonmembers_only" id="nonmembers_only" value="true" <?php echo $is_nonmembers_only; ?> />
58
- <?php _e( 'Only accessible by non-members?', 'wpac' ); ?>
 
 
59
 
60
  <div id="nonmembers_only_options" class="hide-if-js">
61
  <?php $redirect_to = get_post_meta( $post->ID, '_wpac_nonmembers_redirect_to', true ); ?>
@@ -65,6 +69,12 @@
65
  </div>
66
  </div>
67
 
 
 
 
 
 
 
68
  <script>
69
  //$j = jQuery.noConflict();
70
 
3
  ?><input type="hidden" name="members_only_nonce" id="members_only_nonce" value="<?php echo wp_create_nonce( 'members_only' ); ?>" />
4
 
5
  <div id="members_only_container">
6
+ <label>
7
+ <input type="checkbox" name="members_only" id="members_only" value="true" <?php echo $is_members_only; ?> />
8
+ <?php _e( 'Only accessible by members?', 'wpac' ); ?>
9
+ </label>
10
 
11
  <div id="members_only_options" class="hide-if-js">
12
  <br /><strong><?php _e( 'Only Accessible By (Defaults to everyone):', 'wpac' ); ?></strong><br />
50
  $wpac_show_excerpt_in_search = get_option( 'wpac_show_page_excerpts_in_search', 0 );
51
  }
52
  ?>
53
+ <label><input type="checkbox" name="wpac_show_in_search" value="yes" <?php checked( $wpac_show_in_search, 1 ); ?> /> <?php _e( 'Show in search results?', 'wpac' ); ?><br /></label>
54
+ <label><input type="checkbox" name="wpac_show_excerpt_in_search" value="yes"<?php checked( $wpac_show_excerpt_in_search, 1 ); ?> /> <?php _e( 'Show excerpt in search?', 'wpac' ); ?><br /></label>
55
  </div>
56
  </div>
57
 
58
  <div id="nonmembers_only_container">
59
+ <label>
60
+ <input type="checkbox" name="nonmembers_only" id="nonmembers_only" value="true" <?php echo $is_nonmembers_only; ?> />
61
+ <?php _e( 'Only accessible by non-members?', 'wpac' ); ?>
62
+ </label>
63
 
64
  <div id="nonmembers_only_options" class="hide-if-js">
65
  <?php $redirect_to = get_post_meta( $post->ID, '_wpac_nonmembers_redirect_to', true ); ?>
69
  </div>
70
  </div>
71
 
72
+ <?php if ( $post->post_type == 'page' ) { ?>
73
+ <label>
74
+ <input type="checkbox" name="pass_to_children" id="pass_to_children" value="true" <?php checked( $pass_to_children, 'true' ); ?> /> <?php _e( 'Apply options to children?', 'wpac' ); ?>
75
+ </label>
76
+ <?php } ?>
77
+
78
  <script>
79
  //$j = jQuery.noConflict();
80
 
wordpress-access-control.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: http://brandonwamboldt.ca/plugins/members-only-menu-plugin/
5
  * Author: Brandon Wamboldt
6
  * Author URI: http://brandonwamboldt.ca/
7
- * Version: 3.0.2
8
  * Description: This plugin is a powerful tool which gives you fine grained control over your pages and posts (and custom post types), allowing you to restrict a page, post, or custom post type to members, non-members, or even specific roles. You can customize how these pages and posts show up in search results, where users are directed when they visit them, and much more. <strong>You can even make your entire blog members only!</strong>.
9
  */
10
 
@@ -19,8 +19,10 @@ add_action( 'manage_pages_custom_column', array( 'WordPressAccessControl', 'show
19
  add_filter( 'get_pages', array( 'WordPressAccessControl', 'get_pages' ) );
20
  add_filter( 'manage_edit-page_columns', array( 'WordPressAccessControl', 'add_column' ) );
21
  add_filter( 'the_excerpt', array( 'WordPressAccessControl', 'remove_excerpt' ) );
22
- add_filter( 'the_posts', array( 'WordPressAccessControl', 'remove_restricted_posts' ), 100, 2 );
23
  add_filter( 'plugin_row_meta', array( 'WordPressAccessControl', 'plugin_row_meta' ), 10, 5 );
 
 
24
 
25
  add_shortcode( 'member', array( 'WordPressAccessControl', 'shortcode_members' ) );
26
  add_shortcode( 'members', array( 'WordPressAccessControl', 'shortcode_members' ) );
@@ -247,9 +249,9 @@ class WordPressAccessControl
247
 
248
  // Make the blog members only
249
  if ( isset( $_REQUEST['wpac_members_only_blog'] ) && $_REQUEST['wpac_members_only_blog'] == 'yes' ) {
250
- update_option( 'wpac_members_only_blog', TRUE );
251
  } else {
252
- update_option( 'wpac_members_only_blog', FALSE );
253
  }
254
 
255
  // Members blog redirect link
@@ -310,27 +312,27 @@ class WordPressAccessControl
310
 
311
  // Search Options
312
  if ( isset( $_REQUEST['show_posts_in_search'] ) && $_REQUEST['show_posts_in_search'] == 'yes' ) {
313
- update_option( 'wpac_show_posts_in_search', TRUE );
314
  } else {
315
- update_option( 'wpac_show_posts_in_search', FALSE );
316
  }
317
 
318
  if ( isset( $_REQUEST['show_post_excerpts_in_search'] ) && $_REQUEST['show_post_excerpts_in_search'] == 'yes' ) {
319
- update_option( 'wpac_show_post_excerpts_in_search', TRUE );
320
  } else {
321
- update_option( 'wpac_show_post_excerpts_in_search', FALSE );
322
  }
323
 
324
  if ( isset( $_REQUEST['show_pages_in_search'] ) && $_REQUEST['show_pages_in_search'] == 'yes' ) {
325
- update_option( 'wpac_show_pages_in_search', TRUE );
326
  } else {
327
- update_option( 'wpac_show_pages_in_search', FALSE );
328
  }
329
 
330
  if ( isset( $_REQUEST['show_page_excerpts_in_search'] ) && $_REQUEST['show_page_excerpts_in_search'] == 'yes' ) {
331
- update_option( 'wpac_show_page_excerpts_in_search', TRUE );
332
  } else {
333
- update_option( 'wpac_show_page_excerpts_in_search', FALSE );
334
  }
335
 
336
  // Custom excerpts
@@ -378,7 +380,7 @@ class WordPressAccessControl
378
  if ( is_user_logged_in() ) {
379
  get_currentuserinfo();
380
 
381
- $allowed_roles = maybe_unserialize( get_post_meta( $page_id, '_wpac_restricted_to', TRUE ) );
382
 
383
  if ( empty( $allowed_roles ) ) {
384
  $allowed_roles_tmp = $wp_roles->get_names();
@@ -392,21 +394,21 @@ class WordPressAccessControl
392
  $intersections = array_intersect( $current_user->roles, $allowed_roles );
393
 
394
  if ( empty( $intersections ) ) {
395
- $role = FALSE;
396
  } else {
397
- $role = TRUE;
398
  }
399
  } else {
400
- $role = TRUE;
401
  }
402
 
403
- $is_members_only = get_post_meta( $page_id, '_wpac_is_members_only', TRUE );
404
- $is_nonmembers_only = get_post_meta( $page_id, '_wpac_is_nonmembers_only', TRUE );
405
 
406
  if ( ( is_user_logged_in() && $is_members_only && $role ) || ( ! is_user_logged_in() && $is_nonmembers_only ) || ( ! $is_members_only && ! $is_nonmembers_only ) ) {
407
- return TRUE;
408
  } else {
409
- return FALSE;
410
  }
411
  }
412
 
@@ -417,7 +419,7 @@ class WordPressAccessControl
417
  if ( is_admin() ) return;
418
 
419
  // Check for a members only blog
420
- $blog_is_members_only = get_option( 'wpac_members_only_blog', FALSE );
421
 
422
  if ( $blog_is_members_only && ! is_user_logged_in() ) {
423
  if ( is_home() || is_archive() || is_search() || is_feed() ) {
@@ -468,7 +470,7 @@ class WordPressAccessControl
468
 
469
  function remove_excerpt( $excerpt )
470
  {
471
- if ( is_admin() ) return $excerpt;
472
 
473
  global $post;
474
 
@@ -491,8 +493,41 @@ class WordPressAccessControl
491
  return $excerpt;
492
  }
493
 
494
- function remove_restricted_posts( $posts, $query = FALSE )
495
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
  if ( ! is_singular() && ! is_admin() ) {
497
  $new_posts = array();
498
 
@@ -522,7 +557,7 @@ class WordPressAccessControl
522
 
523
  $new_posts[] = $post;
524
  }
525
-
526
  $query->found_posts = count( $new_posts );
527
  $query->max_num_pages = ceil( count( $new_posts ) / $query->query_vars['posts_per_page'] );
528
  $query->posts = $new_posts;
@@ -567,13 +602,14 @@ class WordPressAccessControl
567
 
568
  $wpac_show_in_search = get_post_meta( $post->ID, '_wpac_show_in_search', true );
569
  $wpac_show_excerpt_in_search = get_post_meta( $post->ID, '_wpac_show_excerpt_in_search', true );
 
570
 
571
  include( dirname( __FILE__ ) . '/templates/meta_box.php' );
572
  }
573
 
574
  function save_postdata( $post_id )
575
  {
576
- if ( ! isset($_POST['members_only_nonce'] ) ) {
577
  return $post_id;
578
  }
579
 
@@ -584,7 +620,7 @@ class WordPressAccessControl
584
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
585
  return $post_id;
586
  }
587
-
588
  if ( isset( $_POST['members_only'] ) && $_POST['members_only'] == 'true' ) {
589
  update_post_meta( $post_id, '_wpac_is_members_only', 'true' );
590
 
@@ -623,6 +659,25 @@ class WordPressAccessControl
623
  update_post_meta( $post_id, '_wpac_nonmembers_redirect_to', $_POST['wpac_nonmembers_redirect_to'] );
624
  }
625
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
626
  return $post_id;
627
  }
628
 
@@ -651,6 +706,8 @@ class WordPressAccessControl
651
  */
652
  function get_pages( $pages )
653
  {
 
 
654
  $auth = is_user_logged_in();
655
 
656
  foreach ( $pages as $key => $page ) {
4
  * Plugin URI: http://brandonwamboldt.ca/plugins/members-only-menu-plugin/
5
  * Author: Brandon Wamboldt
6
  * Author URI: http://brandonwamboldt.ca/
7
+ * Version: 3.0.3
8
  * Description: This plugin is a powerful tool which gives you fine grained control over your pages and posts (and custom post types), allowing you to restrict a page, post, or custom post type to members, non-members, or even specific roles. You can customize how these pages and posts show up in search results, where users are directed when they visit them, and much more. <strong>You can even make your entire blog members only!</strong>.
9
  */
10
 
19
  add_filter( 'get_pages', array( 'WordPressAccessControl', 'get_pages' ) );
20
  add_filter( 'manage_edit-page_columns', array( 'WordPressAccessControl', 'add_column' ) );
21
  add_filter( 'the_excerpt', array( 'WordPressAccessControl', 'remove_excerpt' ) );
22
+ add_filter( 'the_content', array( 'WordPressAccessControl', 'remove_excerpt' ) );
23
  add_filter( 'plugin_row_meta', array( 'WordPressAccessControl', 'plugin_row_meta' ), 10, 5 );
24
+ add_filter( 'posts_join_paged', array( 'WordPressAccessControl', 'posts_join_paged' ) );
25
+ add_filter( 'posts_where_paged', array( 'WordPressAccessControl', 'posts_where_paged' ) );
26
 
27
  add_shortcode( 'member', array( 'WordPressAccessControl', 'shortcode_members' ) );
28
  add_shortcode( 'members', array( 'WordPressAccessControl', 'shortcode_members' ) );
249
 
250
  // Make the blog members only
251
  if ( isset( $_REQUEST['wpac_members_only_blog'] ) && $_REQUEST['wpac_members_only_blog'] == 'yes' ) {
252
+ update_option( 'wpac_members_only_blog', true );
253
  } else {
254
+ update_option( 'wpac_members_only_blog', false );
255
  }
256
 
257
  // Members blog redirect link
312
 
313
  // Search Options
314
  if ( isset( $_REQUEST['show_posts_in_search'] ) && $_REQUEST['show_posts_in_search'] == 'yes' ) {
315
+ update_option( 'wpac_show_posts_in_search', true );
316
  } else {
317
+ update_option( 'wpac_show_posts_in_search', false );
318
  }
319
 
320
  if ( isset( $_REQUEST['show_post_excerpts_in_search'] ) && $_REQUEST['show_post_excerpts_in_search'] == 'yes' ) {
321
+ update_option( 'wpac_show_post_excerpts_in_search', true );
322
  } else {
323
+ update_option( 'wpac_show_post_excerpts_in_search', false );
324
  }
325
 
326
  if ( isset( $_REQUEST['show_pages_in_search'] ) && $_REQUEST['show_pages_in_search'] == 'yes' ) {
327
+ update_option( 'wpac_show_pages_in_search', true );
328
  } else {
329
+ update_option( 'wpac_show_pages_in_search', false );
330
  }
331
 
332
  if ( isset( $_REQUEST['show_page_excerpts_in_search'] ) && $_REQUEST['show_page_excerpts_in_search'] == 'yes' ) {
333
+ update_option( 'wpac_show_page_excerpts_in_search', true );
334
  } else {
335
+ update_option( 'wpac_show_page_excerpts_in_search', false );
336
  }
337
 
338
  // Custom excerpts
380
  if ( is_user_logged_in() ) {
381
  get_currentuserinfo();
382
 
383
+ $allowed_roles = maybe_unserialize( get_post_meta( $page_id, '_wpac_restricted_to', true ) );
384
 
385
  if ( empty( $allowed_roles ) ) {
386
  $allowed_roles_tmp = $wp_roles->get_names();
394
  $intersections = array_intersect( $current_user->roles, $allowed_roles );
395
 
396
  if ( empty( $intersections ) ) {
397
+ $role = false;
398
  } else {
399
+ $role = true;
400
  }
401
  } else {
402
+ $role = true;
403
  }
404
 
405
+ $is_members_only = get_post_meta( $page_id, '_wpac_is_members_only', true );
406
+ $is_nonmembers_only = get_post_meta( $page_id, '_wpac_is_nonmembers_only', true );
407
 
408
  if ( ( is_user_logged_in() && $is_members_only && $role ) || ( ! is_user_logged_in() && $is_nonmembers_only ) || ( ! $is_members_only && ! $is_nonmembers_only ) ) {
409
+ return true;
410
  } else {
411
+ return false;
412
  }
413
  }
414
 
419
  if ( is_admin() ) return;
420
 
421
  // Check for a members only blog
422
+ $blog_is_members_only = get_option( 'wpac_members_only_blog', false );
423
 
424
  if ( $blog_is_members_only && ! is_user_logged_in() ) {
425
  if ( is_home() || is_archive() || is_search() || is_feed() ) {
470
 
471
  function remove_excerpt( $excerpt )
472
  {
473
+ if ( is_admin() || is_single() ) return $excerpt;
474
 
475
  global $post;
476
 
493
  return $excerpt;
494
  }
495
 
496
+ function posts_join_paged( $join, $query )
497
  {
498
+ global $wpdb;
499
+
500
+ if ( is_admin() ) return $join;
501
+
502
+ if ( ! is_singular() && ! is_admin() ) {
503
+ $join .= " LEFT JOIN {$wpdb->postmeta} PMWPAC3 ON PMWPAC3.post_id = {$wpdb->posts}.ID AND PMWPAC3.meta_key = '_wpac_show_in_search' LEFT JOIN {$wpdb->postmeta} PMWPAC ON PMWPAC.post_id = {$wpdb->posts}.ID AND PMWPAC.meta_key = '_wpac_is_members_only' LEFT JOIN {$wpdb->postmeta} PMWPAC2 ON PMWPAC2.post_id = {$wpdb->posts}.ID AND PMWPAC2.meta_key = '_wpac_is_nonmembers_only' ";
504
+ }
505
+
506
+ return $join;
507
+ }
508
+
509
+ function posts_where_paged( $where, $query )
510
+ {
511
+ global $wpdb;
512
+
513
+ if ( is_admin() ) return $where;
514
+
515
+ if ( ! is_singular() && ! is_admin() ) {
516
+ if ( ! is_user_logged_in() ) {
517
+ $where .= " AND ( PMWPAC.meta_value IS NULL OR PMWPAC3.meta_value = '1' OR PMWPAC.meta_value != 'true' ) ";
518
+ } else {
519
+ $where .= " AND ( PMWPAC2.meta_value IS NULL OR PMWPAC2.meta_value != 'true' ) ";
520
+ }
521
+ }
522
+
523
+ return $where;
524
+ }
525
+
526
+ function remove_restricted_posts( $posts, $query = false )
527
+ {
528
+ return $posts;
529
+ echo $query->request;exit();
530
+
531
  if ( ! is_singular() && ! is_admin() ) {
532
  $new_posts = array();
533
 
557
 
558
  $new_posts[] = $post;
559
  }
560
+
561
  $query->found_posts = count( $new_posts );
562
  $query->max_num_pages = ceil( count( $new_posts ) / $query->query_vars['posts_per_page'] );
563
  $query->posts = $new_posts;
602
 
603
  $wpac_show_in_search = get_post_meta( $post->ID, '_wpac_show_in_search', true );
604
  $wpac_show_excerpt_in_search = get_post_meta( $post->ID, '_wpac_show_excerpt_in_search', true );
605
+ $pass_to_children = get_post_meta( $post->ID, '_wpac_pass_to_children', true );
606
 
607
  include( dirname( __FILE__ ) . '/templates/meta_box.php' );
608
  }
609
 
610
  function save_postdata( $post_id )
611
  {
612
+ if ( ! isset( $_POST['members_only_nonce'] ) ) {
613
  return $post_id;
614
  }
615
 
620
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
621
  return $post_id;
622
  }
623
+
624
  if ( isset( $_POST['members_only'] ) && $_POST['members_only'] == 'true' ) {
625
  update_post_meta( $post_id, '_wpac_is_members_only', 'true' );
626
 
659
  update_post_meta( $post_id, '_wpac_nonmembers_redirect_to', $_POST['wpac_nonmembers_redirect_to'] );
660
  }
661
 
662
+ if ( isset( $_POST['pass_to_children'] ) && $_POST['pass_to_children'] == 'true' ) {
663
+ update_post_meta( $post_id, '_wpac_pass_to_children', 'true' );
664
+
665
+ $original_id = $post_id;
666
+ $is_revision = wp_is_post_revision( $original_id );
667
+
668
+ if ( $is_revision ) {
669
+ $original_id = $is_revision;
670
+ }
671
+
672
+ $children = get_pages( array( 'child_of' => $original_id ) );
673
+
674
+ foreach ( $children as $child ) {
675
+ WordPressAccessControl::save_postdata( $child->ID );
676
+ }
677
+ } else {
678
+ delete_post_meta( $post_id, '_wpac_pass_to_children' );
679
+ }
680
+
681
  return $post_id;
682
  }
683
 
706
  */
707
  function get_pages( $pages )
708
  {
709
+ if ( is_admin() ) return $pages;
710
+
711
  $auth = is_user_logged_in();
712
 
713
  foreach ( $pages as $key => $page ) {