• Resolved Nikki Blight

    (@kionae)


    Attempted to update to 2.0.4, and am now getting the error “2023-9-18 08:33:41 – ERROR: Rule content_is_page_with_category has no callback.” in the log, and my rules no longer work. Categories are enabled on Pages through my theme’s functions.php file.

    Category is pretty much the basis for determining who sees what content on my site, so without this functionality, I’m dead in the water. Had to downgrade to previously installed version (1.1.10).

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author Daniel Iser

    (@danieliser)

    @kionae – Sorry to hear that, happy to help.

    Can you copy/paste the custom code used to register the categories functionality from your theme here?

    I need to determine why it shows up some times and not others in our systems.

    Further if you’d like you can follow the guide?here, and send a token via the?support?form I will be happy to check out the site directly.

    Thread Starter Nikki Blight

    (@kionae)

    /*
     * Allow Pages to use the Category Taxonomy
     */
    function add_taxonomies_to_pages() {
    	register_taxonomy_for_object_type( 'category', 'page' );
    }
    add_action( 'init', 'add_taxonomies_to_pages' );

    For network reasons, I unfortunately cannot grant support access to the site. It’s a private employees only website on an internal server that you can only access via our in-office network or company VPN.

    • This reply was modified 1 year, 2 months ago by Nikki Blight.
    Plugin Author Daniel Iser

    (@danieliser)

    Understandable. This isn’t the only report of similar nature, so I’m trying to track it down quickly. Strangely we should support that out of the box as our rules are dynamically generated based on the existing post types & taxonomies.

    I’m wondering if this is happening in a scenario where the code you have to add tags to pages isn’t running or is running too late (or ours is running too early).

    Can you install a plugin by chance?

    This is a tool we built for testing & troubleshooting migration issues during the build of v2.

    https://github.com/code-atlantic/content-control-migration-tester/releases/tag/v1.1.0

    Specifically it adds an menu to the admin toolbar with options to Export v1 Data and Import v1 Data. You can uninstall it right after, and you can see the source on github.

    It might help you can export the settings your using so I can try to replicate as closely as possible.

    You could either paste the contents here, or submit a ticket at https://contentcontrolplugin.com/support/ with the contents of the file or attaching it.

    Thread Starter Nikki Blight

    (@kionae)

    {"settings":{"restrictions":[{"index":"0","title":"Westgate Users","who":"logged_in","roles":{"administrator":"administrator","westgate":"westgate"},"conditions":[[{"target":"page_w_category","settings":{"selected":["17"]}}],[{"target":"page_selected","settings":{"selected":["3082"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"1","title":"Forest Park Users","who":"logged_in","roles":{"administrator":"administrator","forestpart":"forestpart"},"conditions":[[{"target":"page_w_category","settings":{"selected":["20"]}}],[{"target":"page_selected","settings":{"selected":["3082"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"2","title":"Glenbrook Users","who":"logged_in","roles":{"administrator":"administrator","glenbrook":"glenbrook"},"conditions":[[{"target":"page_w_category","settings":{"selected":["13"]}}],[{"target":"page_selected","settings":{"selected":["3082"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"3","title":"Baytowne Users","who":"logged_in","roles":{"administrator":"administrator","baytowne":"baytowne"},"conditions":[[{"target":"page_w_category","settings":{"selected":["18"]}}],[{"target":"page_selected","settings":{"selected":["3082"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"4","title":"TAG Users","who":"logged_in","roles":{"administrator":"1","tag":"1"},"conditions":[[{"target":"page_w_category","settings":{"selected":["19"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"5","title":"Property Manager","who":"logged_in","roles":{"administrator":"1","propertymanager":"1"},"conditions":[[{"target":"page_w_category","settings":{"selected":["38"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"6","title":"Admin only","who":"logged_in","roles":{"administrator":"1"},"conditions":[[{"target":"page_selected","settings":{"selected":["109"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"7","title":"Only Logged In","who":"logged_in","roles":{"administrator":"administrator","editor":"editor","author":"author","contributor":"contributor","subscriber":"subscriber","westgate":"westgate","baytowne":"baytowne","forestpart":"forestpart","falconway":"falconway","tag":"tag","glenbrook":"glenbrook","ai1ec_event_assistant":"ai1ec_event_assistant","propertymanager":"propertymanager","breakshot":"breakshot","leasingagent":"leasingagent"},"conditions":[[{"target":"page_selected","settings":{"selected":["348"]}},{"target":"page_selected","settings":{"selected":["1335"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"8","title":"Break Shot Users","who":"logged_in","roles":{"administrator":"administrator","breakshot":"breakshot"},"conditions":[[{"target":"page_w_category","settings":{"selected":["39"]}}],[{"target":"page_selected","settings":{"selected":["3082"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""},{"index":"9","title":"Leasing Agent Users","who":"logged_in","roles":{"administrator":"administrator","leasingagent":"leasingagent"},"conditions":[[{"target":"page_w_category","settings":{"selected":["41"]}}],[{"target":"page_selected","settings":{"selected":["3336"]}}]],"protection_method":"redirect","custom_message":"","redirect_type":"home","redirect_url":"","meta":""}]},"user_meta":{"_jp_cc_reviews_dismissed_triggers":"","_jp_cc_reviews_last_dismissed":"","_jp_cc_reviews_already_did":""},"plugin_meta":{"jp_cc_reviews_installed_on":"2020-03-03 14:38:58"}}

    Here’s the output from the tester plugin.

    Plugin Author Daniel Iser

    (@danieliser)

    Ok perfect, off to test this all. Will keep you posted.

    Plugin Author Daniel Iser

    (@danieliser)

    Can you confirm something for me, does changing this line in your code make it work?
    add_action( 'init', 'add_taxonomies_to_pages', 9 );

    If so I have a fix coming that should hopefully fix it.

    As I suspected it seems to have been all about timing.

    Plugin Author Daniel Iser

    (@danieliser)

    @kionae – Ok so for another user I found that they had a theme/plugin that was making post queries before init action. This effectively made our rules init run earlier than your tags are being added to the pages.

    The temporary fix while I investigate why those other plugins do what they do was to remove our filters early on and readd them back just before we normally would expect them. This may result in some content not protected on some sites, but that is unlikely for most simpler setups:

    remove_filter( 'the_posts', [ \ContentControl\plugin('Frontend\Restrictions\QueryPosts'), 'restrict_query_posts' ], 10, 2 );
    
    add_action( 'init', function () {
    	add_filter( 'the_posts', [ \ContentControl\plugin('Frontend\Restrictions\QueryPosts'), 'restrict_query_posts' ], 10, 2 );
    } );

    If this works for you, it likely also means you have similar. Can you tell me what plugins your using, would BuddyBoss be one of them by chance?

    I have similar error and I suspect similar reason. The plugin “pages with tags and categories” does stuff on init with prio 10. The other plugin (cooked pro in my case) does get_posts on init ALSO with prio 10. So think what happens is a racing condition even though the call is in the init and not before it. Already mentioned that to the developer of “pages with tags and categories”, but have no feedback yet.

    Thread Starter Nikki Blight

    (@kionae)

    Can confirm that dropping the priority to 9 when adding categories/tags to pages did fix the issue for me. Removing/re-adding your filters (with no changes to aforementioned priority) did nothing on my install.

    Plugins in use on the site:

    Advanced Custom Fields
    Content Control
    iThemes Security
    NextGEN Gallery
    User Menus
    WP MAIL SMTP

    I also have a few of my own in-house plugins, but I’ve already tried disabling them for testing and it had no effect. I think you’re right and it’s a timing issue.

    @kionae Yeah, I think so, but if that’s the case – it is an issue for the “Pages with category and tag” plugin, I think. I somewhat raised the question here : Doesn’t play well with Content Control 2.0 plugin | www.ads-software.com but still no feedback from the developer, although he reacted quite quickly initially. You can join me in the discussion there, if you want.

    Thread Starter Nikki Blight

    (@kionae)

    @joroabv It’s not specific to that plugin. I’m not using it. I’m enabling categories for Pages directly in my theme’s functions.php file.

    @kionae Ah, of course not. It is a racing condition on init. I just thought you’re using it, since you mentioned pages tags. But anyway – it is the same principle and I think the plugin I use has the same problem.

    Plugin Author Daniel Iser

    (@danieliser)

    @kionae, @joroabv – Thanks for the testing and insights.

    Yeah, I think so, but if that’s the case – it is an issue for the “Pages with category and tag” plugin, I think. I somewhat raised the question here :?Doesn’t play well with Content Control 2.0 plugin | www.ads-software.com?

    So I’m not gonna lay the blame there. We need our plugin to “just work” on any commercialized site for it to succeed. As such this is likely not the only scenario where early calls and late registered hooks are gonna be a problem.

    Though they could solve it for their one use case, from our perspective we need to focus on a solution that will work properly solve it for any user case.

    Can confirm that dropping the priority to 9 when adding categories/tags to pages did fix the issue for me. Removing/re-adding your filters (with no changes to aforementioned priority) did nothing on my install.

    @kionae – Great, I patched ours to run the registration as late as possible by default. We use them in the_posts, template_redirect & wp_enqueue_scripts.

    What i’ve deduced is that there are 2 scenarios where issues will arise:

    1. Post types or other things that generate dynamic rules get registered after our first use (the_posts). But I’ve patched it so that in normal circumstances if they do it by or duringinit they are good to go.
    2. Some other plugin/theme makes queries long before init , BuddyBoss is one I came across for example that prequeries lots of data for the logged in user at plugins_loaded or similar
      • I have a debug snippet that tries to detect when this occurs and log it when I come across it.
      • We also built in mechanisms to filter whether we try to apply restrictions to any given query, we may need to simply exclude queries before specific actions like init or with specific parameters (CPT names for example).

    I just thought you’re using it, since you mentioned pages tags. But anyway – it is the same principle and I think the plugin I use has the same problem.

    Her code was near identical to what the plugin you mentioned uses. Tested both pretty extensively, even filtered the order plugins were loaded which did seem to work (when you load their init action on the same priority before ours). But now that doesn’t matter as we do it even later.

    Only concern now is plugins making post queries before init, because I can’t control all the other plugins & custom code that do things properly and register their changes by init, I have to develop the WP way, and make adjustments to compensate for those that don’t.

    Let me know if your still having trouble after the latest changes, if so I’ll give you the debug code to find the plugin that is making early queries so we can at least get it on the list.

    Otherwise if its solved, please take a moment to?rate & review?the plugin and or support to spread the word.

    Plugin Author Daniel Iser

    (@danieliser)

    @kionae, @joroabv

    For the record, we added a filter in v2.0.9 that will allow delaying our query filtering. This will allow you to bypass these types of issues by effectively ignore any queries made before init using the example below. You can use setup_theme, after_theme_setup, init or wp_loaded

    add_filter( 'content_control/query_filter_init_hook', function () {
        return 'init'; // Try setup_theme, after_theme_setup, init or wp_loaded
    } );
    
    

    That should hopefully at least allow quickly resolving any issues like this in the future from plugins we don’t control.

    Marking this resolved for now. Please take a moment to rate & review the plugin and or support to spread the word.

    If you have any further issues please open a new thread for those.

    • This reply was modified 1 year, 2 months ago by Daniel Iser.

    @danieliser thanks, I’ll try to use this if something breaks up. Thank you for being responsive and willing to help.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘2023-9-18 08:33:41 – ERROR: Rule `content_is_page_with_category` has no callback’ is closed to new replies.