Custom Fields
Re-Envisioned
Support General Password Protection and metaboxes

This topic contains 5 replies, has 3 voices, and was last updated by  Anh Tran 11 months, 1 week ago.

  • Creator
    Topic
  • #12574

    Ale
    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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #12576

    Farheen
    Participant

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

    #12577

    Ale
    Participant

    This is my metabox

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

    Thanks!

    #12614

    Anh 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

    Ale
    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 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.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.