Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. <?php
  2.  
  3. // leaky paywall restriction functionality for custom fields
  4. function is_restricted_zeen101_post( $post_id ) {
  5.  
  6. if ( current_user_can( 'edit_posts' ) ) { // show content to contributors and up
  7. return false;
  8. }
  9.  
  10. $settings = get_leaky_paywall_settings();
  11. $site = '';
  12. $level_ids = leaky_paywall_subscriber_current_level_ids();
  13.  
  14. $restrictions = leaky_paywall_subscriber_restrictions();
  15.  
  16.  
  17.  
  18. foreach( $restrictions as $key => $restriction ) {
  19.  
  20. if ( is_singular( $restriction['post_type'] ) ) {
  21.  
  22. if ( 0 <= $restriction['allowed_value'] ) {
  23.  
  24. $post_type_id = $key;
  25. $restricted_post_type = $restriction['post_type'];
  26. break;
  27.  
  28. } else if ( -1 == $restriction['allowed_value'] ) {
  29. return false; // content is not restricted because user has unlimted access to this post type
  30. }
  31.  
  32. }
  33.  
  34. }
  35.  
  36. switch ( $settings['cookie_expiration_interval'] ) {
  37. case 'hour':
  38. $multiplier = 60 * 60; //seconds in an hour
  39. break;
  40. case 'day':
  41. $multiplier = 60 * 60 * 24; //seconds in a day
  42. break;
  43. case 'week':
  44. $multiplier = 60 * 60 * 24 * 7; //seconds in a week
  45. break;
  46. case 'month':
  47. $multiplier = 60 * 60 * 24 * 7 * 4; //seconds in a month (4 weeks)
  48. break;
  49. case 'year':
  50. $multiplier = 60 * 60 * 24 * 7 * 52; //seconds in a year (52 weeks)
  51. break;
  52. }
  53.  
  54. $expiration = time() + ( $settings['cookie_expiration'] * $multiplier );
  55.  
  56. if ( !empty( $_COOKIE['issuem_lp' . $site] ) )
  57. $available_content = maybe_unserialize( stripslashes( $_COOKIE['issuem_lp' . $site] ) );
  58.  
  59. if ( empty( $available_content[$restricted_post_type] ) )
  60. $available_content[$restricted_post_type] = array();
  61.  
  62. foreach ( $available_content[$restricted_post_type] as $key => $restriction ) {
  63.  
  64. if ( time() > $restriction || 7200 > $restriction ) {
  65. //this post view has expired
  66. //Or it is very old and based on the post ID rather than the expiration time
  67. unset( $available_content[$restricted_post_type][$key] );
  68.  
  69. }
  70.  
  71. }
  72.  
  73. if( -1 != $restrictions[$post_type_id]['allowed_value'] ) { //-1 means unlimited
  74.  
  75. if ( $restrictions[$post_type_id]['allowed_value'] > count( $available_content[$restricted_post_type] ) ) {
  76.  
  77. if ( !array_key_exists( $post_id, $available_content[$restricted_post_type] ) ) {
  78.  
  79. $available_content[$restricted_post_type][$post_id] = $expiration;
  80.  
  81. }
  82.  
  83. } else {
  84.  
  85. if ( !array_key_exists( $post_id, $available_content[$restricted_post_type] ) ) {
  86.  
  87. return true; // content is restricted for this post
  88.  
  89. }
  90.  
  91. }
  92.  
  93. }
  94.  
  95. return false; // content is not restricted for this post
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement