Upgraded to AIO, now meta fields won't display unless free MB is activated

Support Meta Box AIO Upgraded to AIO, now meta fields won't display unless free MB is activatedResolved

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #48221
    Max ElmanMax Elman
    Participant

    This happened across many sites today. Changed from the free plugin and a few premium extensions to AIO but now custom fields no longer show on the frontend templates where I had them coded with rwmb_meta. Activating the free plugin restores everything and the content shows again.

    Why would I need both plugins installed for custom fields to display?

    #48225
    PeterPeter
    Moderator

    Hello Max,

    Thanks for reaching out.

    Basically, you can use only one plugin Meta Box AIO to get all features of Meta Box plugins, including Meta Box single (free) plugin.

    Please ensure that you have the latest version of Meta Box AIO 2.1.1 on your site and recheck the issue.

    #48226
    Max ElmanMax Elman
    Participant

    Yes, I am using Meta Box AIO 2.2.0

    #48230
    PeterPeter
    Moderator

    Please share your site credentials by submitting this form https://metabox.io/contact/
    I will take a look.

    Thank you.

    #48231
    Max ElmanMax Elman
    Participant

    I now see the problem - we had this legacy code in a helper plugin:

    // Avoid Undefined Function Error when Meta Box is not active.
    if ( ! function_exists( 'rwmb_meta' ) ) {
        function rwmb_meta( $key, $args = '', $post_id = null ) {
            return false;
        }
    }

    Removing the code fixed the problem.

    I see many mentions of that snippet still online - perhaps AIO can be edited to better deal with that code if present.

    #48254
    PeterPeter
    Moderator

    Thanks for sharing the solution. That issue is noted in the documentation https://docs.metabox.io/functions/rwmb-meta/#why-does-my-site-crash-when-i-deactivate-meta-box

    Have a nice day!

    #48257
    Max ElmanMax Elman
    Participant

    Ok. Is there a version of this code that works with the AIO plugin? This fallback function only works with the base plugin.

    Ideally I’d like a function that works with AIO and also protects the site if AIO is deactivated.

    #48300
    Max ElmanMax Elman
    Participant

    Hello - I'd like a fallback function that still works with AIO. Would this work?

    if ( !function_exists( 'rwmb_meta' ) && !in_array( 'meta-box-aio/meta-box-aio.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    	function rwmb_meta( $field_id, $args = '', $object_id = null ) {
    		if ( null === $object_id ) {
    			$object_id = get_the_ID();
    		}
    		return get_post_meta( $object_id, $field_id, true );
    	}
    }
    #48302
    Anh TranAnh Tran
    Keymaster

    The problem is that Meta Box AIO loads Meta Box at init hook (with priority -5). If you put the snippet to define rwmb_meta function in your theme's functions.php, then it will load **before**, which defines an empty rwmb_meta function.

    This method was usually used for themes that are sold like on ThemeForest, to prevent errors of undefined function rwmb_meta when they haven't installed Meta Box yet.

    In your case, I'd recommend removing that snippet, and it will work fine.

    #48304
    Max ElmanMax Elman
    Participant

    OK. I'm still interested in a fallback function if AIO is disabled - so that CPT data is still displayed. Should my function above work for that?

    #48331
    Max ElmanMax Elman
    Participant

    Can you reply regarding my snippet above please? Thank you

    #48338
    PeterPeter
    Moderator

    Hello Max,

    The plugin Meta Box is now included in the Meta Box AIO source, so I think you don't need to use the snippet code to get the fallback function. If you prefer to use the custom code, you are welcome to add it to your site, but we won't support the custom code if it causes any issues there.

    I hope that makes sense.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.