Skip to content

Instantly share code, notes, and snippets.

@verygoodplugins
Last active December 7, 2022 10:48
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/d1d400c48c52e11184a0676186b1e777 to your computer and use it in GitHub Desktop.
Save verygoodplugins/d1d400c48c52e11184a0676186b1e777 to your computer and use it in GitHub Desktop.
Makes WP Fusion inherit post access rules and redirects that were created in Memberium
<?php
function inherit_memberium_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'] ) ) {
$setting = get_post_meta( $post_id, '_is4wp_access_tags', true );
if ( ! empty( $setting ) ) {
$settings['lock_content'] = true;
$settings['allow_tags'] = array_filter( explode( ',', $setting ) );
}
}
if ( empty( $settings['redirect_url'] ) ) {
$settings['redirect_url'] = get_post_meta( $post_id, '_is4wp_redirect_url', true );
}
return $settings;
}
add_filter( 'wpf_post_access_meta', 'inherit_memberium_access_rules', 10, 2 );
add_filter( 'wpf_settings_for_meta_box', 'inherit_memberium_access_rules', 10, 2 );
// LearnDash course / lessson / topic complete tags.
function merge_complete_tags( $value, $object_id, $meta_key, $single ) {
if ( 'wpf-settings' === $meta_key && 0 === strpos( get_post_type( $object_id ), 'sfwd-' ) ) {
if ( empty( $value ) || empty( $value['apply_tags_ld'] ) ) {
$tags = get_post_meta( $object_id, '_is4wp_learndash_tags', true );
if ( ! empty( $tags ) ) {
$tags = array_values( array_filter( explode( ',', $tags ) ) );
if ( empty( $value ) ) {
$value = array();
}
$value['apply_tags_ld'] = $tags;
return array( $value );
}
}
}
return $value;
}
add_filter( 'get_post_metadata', 'merge_complete_tags', 100, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment