Password Protection and metaboxes

Support General Password Protection and metaboxes

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #12574
    AleAle
    Participant

    Hello,

    Both password protected and private posts doesn't seem to work for metaboxes. Anything that is added in the editor (the_content) it is protected but all contents added by metaboxes is displayed.

    Am I doing something wrong?

    Thanks!

    #12576
    FarheenFarheen
    Participant

    Can you please show me your code so that I can take a look.

    #12577
    AleAle
    Participant

    This is my metabox

    The problem appears when I try to use metaboxes with a private or password protected post.

    Thanks!

    #12614
    Anh TranAnh Tran
    Keymaster

    Hi Ale,

    This depends on how you display custom fields' values in the front end. You need to change your code to check the post status, like this:

    if ( post_password_required() ) {
        echo 'Nothing here';
    } else {
        echo rwmb_meta( 'field_id' );
    }
    #12627
    AleAle
    Participant

    Thanks, it works well but I am looking for a way that password protection applies to all registered metaboxes, otherwise I need to add the conditionals in every place that I display a metabox field.

    Is there such a way?

    #12645
    Anh TranAnh Tran
    Keymaster

    WordPress hard-coded that in its function get_the_content, so there's no filter to do that automatically. Maybe you write a wrapper function for rwmb_meta like this:

    function your_meta( $field_id, $args = [], $post_id = null ) {
        if ( post_password_required ) {
            return 'This post is password protected.';
        }
        return rwmb_meta( $field_id, $args, $post_id );
    }

    Then use your_meta in replace for rwmb_meta.

    #35693
    TTI LicensingTTI Licensing
    Participant

    Is there a way to display a custom field only to authenticated users regardless of role? We have some fields in security docs that we would like to display to our employees but not to the world. Most of the other custom fields are OK for public display.

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