Support » Plugin: AddFunc Head & Footer Code » disable AddFunc Head & Footer Code for custom post types

  • Resolved xlan

    (@xlan)


    Hi there I have a WP site where I created 7 custom post types(cpts).
    Each of the cpt is saving meta information.
    When testing that all my meta was saving ok for each cpt, I realize I have aFhfc_head_code and aFhfc_footer_code all over the place in my postmeta table.

    I see that you are using save_post to save these two meta info, but is there a way to disable aFhfc_head_code and aFhfc_footer_code for custom post type where you never need your plugin feature, maybe with a hook that check what post_type are you saving and then return if is not a page or a regular post.
    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • xlan

    (@xlan)

    Another easy solution to avoid having these meta info, is just to check is there is actually any code on the AddFunc Head & Footer Code metabox, before saving.

    So instead of using

    if( isset( $_POST[‘aFhfc_head_code’] ) )
    update_post_meta( $post_id, ‘aFhfc_head_code’, $_POST[‘aFhfc_head_code’] );
    if( isset( $_POST[‘aFhfc_footer_code’] ) )
    update_post_meta( $post_id, ‘aFhfc_footer_code’, $_POST[‘aFhfc_footer_code’] );

    use this instead
    if( !empty( $_POST[‘aFhfc_head_code’] ) )
    update_post_meta( $post_id, ‘aFhfc_head_code’, $_POST[‘aFhfc_head_code’] );
    if( !empty( $_POST[‘aFhfc_footer_code’] ) )
    update_post_meta( $post_id, ‘aFhfc_footer_code’, $_POST[‘aFhfc_footer_code’] );

    So if the User never user AddFunc Head & Footer Code for a page or a post, you won’t save this meta info for that post, avoiding in this way creating garbage data in the postmeta table that it won’t ever be used.

    • This reply was modified 2 years ago by  xlan.
    • This reply was modified 2 years ago by  xlan.
    enfueggo

    (@enfueggo)

    I agree, it would be nice to choose which post types displayed your metabox, it seems to show up in odd places sometimes!

    And though it’s a separate issue, if @xlan is right about the plugin saving postmeta for every post/page/etc I would certainly appreciate using his suggestion there also.

    Thank you!

    Plugin Author joerhoney

    (@joerhoney)

    Thank you for this suggestion and tip! I had to do a little more than that, as leaving the custom field filled in would then cause the Head & Footer Code meta box to repopulate, so you’d have to delete if from the custom field as well, which would be a nuisance and would confuse most people. So I had to make it so AddFunc Head & Footer Code not only doesn’t save but DELETES its fields when empty. Fortunately, that means if you re-save/update any of your posts (pages, cpts, etc.) you won’t see them anymore unless you need them!

    So update to version 1.4 and you’re good to go!

    enfueggo

    (@enfueggo)

    Just updated and can confirm that updating a post with blank aFhfc_head_code or aFhfc_footer_code fields removes them from the postmeta table, thank you so much! Your plugin has been very helpful for adding to sites that needs a lot of per-page overriding.

    Any update on the original topic of this thread? Choosing which post types to allow the plugin to appear on? I realize it’s not a simple request but we’d just like to know if it’s on the roadmap. I currently use CSS in the admin to hide the metabox and reshow on only the post types I want (post and page in this case), though it would be nice to choose it in a settings page:

    
    #aFhfcMetaBox { display: none; }
    body.post-type-post #aFhfcMetaBox,
    body.post-type-page #aFhfcMetaBox { display: block; }
    
    • This reply was modified 2 years ago by  enfueggo.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘disable AddFunc Head & Footer Code for custom post types’ is closed to new replies.