Skip to content

Instantly share code, notes, and snippets.

@verygoodplugins
Created July 13, 2023 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verygoodplugins/298415e3eaefffc834e4828344d106cc to your computer and use it in GitHub Desktop.
Save verygoodplugins/298415e3eaefffc834e4828344d106cc to your computer and use it in GitHub Desktop.
Inherit access rules from ActiveMember360
<?php
/**
* Inherits access rules and redirects from ActiveMember360 for posts and pages.
*
* @param array $settings The WP Fusion settings on the post.
* @param WP_Post|int $post_id The post or post ID.
* @return array The settings.
*/
function inherit_am360_access_rules( $settings, $post_id ) {
if ( is_object( $post_id ) ) {
$post_id = $post_id->ID; // wpf_settings_for_meta_box passes a WP_Post.
}
if ( empty( $settings['allow_tags'] ) ) {
$am360_setting = get_post_meta( $post_id, 'mbr_permissions', true );
if ( ! empty( $am360_setting ) ) {
if ( ! empty( $am360_setting['tag_pos_list'] ) ) {
$settings['lock_content'] = true;
$settings['allow_tags'] = $am360_setting['tag_pos_list'];
}
if ( ! empty( $am360_setting['tag_neg_list'] ) ) {
$settings['allow_tags_not'] = $am360_setting['tag_neg_list'];
}
}
}
if ( empty( $settings['redirect'] ) ) {
$settings['redirect'] = get_post_meta( $post_id, 'mbr_no_access_redirect', true );
}
if ( empty( $settings['redirect_url'] ) ) {
$settings['redirect_url'] = get_post_meta( $post_id, 'mbr_no_access_redirect_url', true );
}
return $settings;
}
add_filter( 'wpf_post_access_meta', 'inherit_am360_access_rules', 10, 2 );
add_filter( 'wpf_settings_for_meta_box', 'inherit_am360_access_rules', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment