Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/c3acb3e2858a391c2cd0714061e7636e to your computer and use it in GitHub Desktop.
Save kimwhite/c3acb3e2858a391c2cd0714061e7636e to your computer and use it in GitHub Desktop.
Default new WP posts to require level 1 with Paid Memberships Pro.
<?php // do not copy this line.
/**
* This recipe does will Check to require level 1 by default (or whatever level you choose).
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/*
Check to require level 1 by default.
Add this code to a custom plugin or
your active theme's functions.php.
Change #in-membership-level-1 in the JS code to check a different level.
*/
function default_new_posts_to_level1()
{
$screen = get_current_screen();
if(!empty($screen) && $screen->action == "add" && $screen->base == "post" && in_array($screen->post_type, array("post", "page")))
{
?>
<script>
//change the -1 there to -2 or -3 etc to check a different membership level
jQuery('#in-membership-level-1').prop('checked', true);
</script>
<?php
}
}
add_action('admin_footer', 'default_new_posts_to_level1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment