GithubHelp home page GithubHelp logo

strangerstudios / pmpro-cpt Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 18.0 58 KB

Adds the 'Require Membership' meta box to all CPTs selected and redirects non-members to the selected page.

Home Page: https://www.paidmembershipspro.com/add-ons/custom-post-type-membership-access/

PHP 92.41% Shell 7.59%
wordpress wordpress-plugin paid-memberships-pro strangerstudios-product

pmpro-cpt's Introduction

=== Paid Memberships Pro - Custom Post Type Add On ===
Contributors: strangerstudios
Tags: pmpro, paid memberships pro, members, custom post type, cpt, redirect
Requires at least: 3.5
Tested up to: 6.2
Stable tag: 1.0.1

Adds the 'Require Membership' meta box to all CPTs selected and redirects non-members to the selected page.

== Description ==

This plugin will add the PMPro "Require Membership" meta box to all CPTs selected. If a non-member visits that single CPT (either a logged out visitor or a logged in user without membership access) they will be redirected to the selected page.

== Settings == 
Navigate to Memberships > CPT Access in the WordPress Admin to select custom post types and set redirection rules.

== Changelog ==
= 1.0.1 - 2023-08-11 =
* ENHANCEMENT: Added compatibility with enhanced "Require Membership" block editor panel in PMPro 3.0. #23 (@dparker1005)
* BUG FIX: Fixed error where the "redirect to" setting may not be saved correctly. #24 (@MaximilianoRicoTabo)
* BUG FIX: Fixed PHP warning when using PHP 8+. #22 (@ipokkel)
* BUG FIX: Fixed text domain on for some strings. #18 (@dparker1005)

= 1.0 - 2021-06-10 =
* SECURITY: Improved escaping of text strings.
* ENHANCEMENT: Wrapped strings for localization and generated a .pot file.
* ENHANCEMENT: Moved the PMPro CPT settings menu to show up under the Memberships menu.
* ENHANCEMENT: Better hint text on the settings page.
* BUG FIX: Avoiding fatal errors if PMPro is not active.
* BUG FIX: Fixed issue where users were redirected to the PMPro levels page even if the "Do Not Redirect" setting was chosen.

= .2.1 =
* BUG FIX: Fixed redirect issue when no CPTs were selected on the settings page but the is_singular check was still returning true.
* ENHANCEMENT: WordPress Coding Standards and Improved PHPDoc Blocs

= .2 =
* BUG FIX: Fixed a warning when getting the redirect_to setting. (Thanks, Sarah Hines on GitHub)
* ENHANCEMENT: Added a pmprocpt_redirect_to filter that can be used to change what page the user is redirected to when accessing a restricted CPT they don't have the appropriate membership level for. See here for an example on how to use this filter: https://gist.github.com/strangerstudios/dd213f75c67935a447146ec430498c6d

= .1 =
* Initial commit.

pmpro-cpt's People

Contributors

andrewlimaza avatar dparker1005 avatar femiyb avatar github-actions[bot] avatar ideadude avatar ipokkel avatar jarrydlong avatar kimcoleman avatar maximilianoricotabo avatar pbrocks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pmpro-cpt's Issues

Doesn't work with MMPU

The code to redirect always redirects away even when you should have access.

Create 2 levels. Give yourself both levels. Mark one CPT post to require one level. Mark another CPT post to require the other level. Navigate to either CPT page.

The the_content filter still works well on archive views (probably because it's just core PMPro and MMPU).

Error on PHP 8.0+

Describe the bug
A customer ran into an error on PHP 8.0+.

To Reproduce
Steps to reproduce the behavior:

  1. Set PHP version to PHP 8.0+
  2. Activate Paid Memberships Pro, and Custom Post Type Add On. See this error:
Error Details
=============
An error of type E_ERROR was caused in line 194 of the file /nas/content/live/wp-content/plugins/pmpro-cpt/pmpro-cpt.php. Error message: Uncaught TypeError: trim(): Argument #1 ($string) must be of type string, array given in /nas/content/live/wp-content/plugins/pmpro-cpt/pmpro-cpt.php:194
Stack trace:
#0 /nas/content/live/wp-content/plugins/pmpro-cpt/pmpro-cpt.php(194): trim(Array)
#1 /nas/content/live/wp-includes/class-wp-hook.php(310): pmprocpt_options_validate(Array)
#2 /nas/content/live/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
#3 /nas/content/live/wp-includes/formatting.php(5000): apply_filters(‘sanitize_option…’, Array, ‘pmprocpt_option…’, Array)
#4 /nas/content/live/wp-includes/option.php(638): sanitize_option(‘pmprocpt_option…’, Array)
#5 /nas/content/live/wp-includes/option.php(496): add_option(‘pmprocpt_option…’, Array, ”, ‘yes’)
#6 /nas/content/live/wp-admin/options.php(322): update_option(‘pmprocpt_option…’, Array)
#7 {main}
thrown

Expected behavior
There should not be an error.

Isolating the problem:

  • Deactivated other plugins and confirmed this bug occurs when only Paid Memberships Pro 2.9.12, and Custom Post Type Add On 1.0 is active.
  • This bug happens with a default WordPress theme active, or Memberlite.

This came up in ticket 465372 on PHP 8.0.26, and this error happened in my test with PHP 8.0.22.

WordPress Environment

Paid Memberships Pro 2.9.12, and Custom Post Type Add On 1.0, WordPress 6.1.1, PHP 8.0.22

Very minor: Php Warning line 24

Howdy,

If you don't have a redirect enabled for your CPT, yet wish to use the metabox, you get a php undefined index for line 24. Doesn't hurt much, but I try to remove them for cleaner troubleshooting. Here's the fix if you want it!

$redirect_to = isset($options['redirect_to'][0]) ? intval($options['redirect_to'][0]) : '';

Best,
Sarah

Fatal Error

Just spotted that if I select a CPT to restrict access to, then save settings, then deselect all CPTs and save settings again, when I hit the front end, I get:

Fatal error: Cannot use string offset as an array in [...]/wp-content/plugins/pmpro-cpt/pmpro-cpt.php on line 24

Easy enough to work around, by selecting any CPT in the backend again, but could be a bit worrying for people.
(Unless my theme has somehow caused this - I haven't got any others installed atm so haven't checked.)

Feature Request: Allow users to choose which CPTs are redirected away from vs filtered

The PMPro CPT add on redirects non-members away from member content because we can't be sure how a CPT is displayed and if our basic the_content filter will properly protect the member content.

However, sometimes you know the content will be protected enough and would rather have the content filter and links to checkout/etc like we do for posts and pages by default.

This code disables the redirect entirely: https://gist.github.com/ideadude/76872d4ee982f7add05dafb69cf00d13

We could perhaps add a filter to the redirect code to disable it for specific CPTs.

We could then also consider adding UI to the settings to select some CPTs to redirect away from entirely and some to just filter. That probably needs a lot of thought because the concept is pretty hard to get I think. I'd like a solution that is not too complicated for users to manage and understand what is happening.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.