Posted on

User Access Manager

Relevanssi has a conflict with User Access Manager plugin. Both plugins attach to the same `the_posts` filter hook with the same priority, and if UAM runs after Relevanssi, it may cause some issues, like missing excerpts or even broken search results pages.

The solution seems simple, however: at least in the one case I’ve run into so far, things started working after I moved Relevanssi to a slightly later priority, so it runs after UAM. That’s easy to do, just add the following code to your theme functions.php:

add_filter('after_setup_theme', 'rlv_move_to_later_priority');
function rlv_move_to_later_priority($priority) {
	remove_filter('the_posts', 'relevanssi_query');
	add_filter('the_posts', 'relevanssi_query', 11);
}

Update 19.1.2021: This is no longer necessary, as Relevanssi runs on `posts_pre_query` hook now.

5 comments User Access Manager

  1. We are still having the same issue over UAM vs Relevanssi after we tried the above solution. Is there any other way to rectify this?

    1. That fix doesn’t even do anything anymore, Relevanssi is now already by default on priority 99.

      What kind of problems you are having with UAM and Relevanssi? I tried it now and everything seems to work without problems. Relevanssi doesn’t respect the UAM restrictions and will show the posts in search results (but of course you can’t see the actual post), but I’ll fix that in the next version.

        1. Ok, that isn’t even supposed to work in the current version, the current version doesn’t have any UAM compatibility built in.

          This will be fixed in the next version, but meanwhile you can add this to your theme functions.php:

          add_filter( 'relevanssi_post_ok', 'rlv_uam_post_ok', 11, 2 );
          function rlv_uam_post_ok( $post_ok, $post_id ) {
          	// User Access Manager.
          	global $userAccessManager; // phpcs:ignore WordPress.NamingConventions.ValidVariableName
          	if ( isset( $userAccessManager ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName
          		$type    = relevanssi_get_post_type( $post_id );
          		$post_ok = $userAccessManager->getAccessHandler()->checkObjectAccess( $type, $post_id ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName
          	}
          	return $post_ok;
          }

          This should fix the problem.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *