4

Is there a way to disable the public vs private vs password-protected visibility UI when editing or quick-editing a post?

A quick scan in the code yields #visibility, which I could hide using jQuery, but I was wondering if there was a documented way to do this "properly".

2

Quick hack to get the job done, in case anyone else needs to do this:

add_action('add_meta_boxes', function() {
    add_action('admin_head', function() {
        echo <<<EOS
<style type="text/css">
#visibility {
    display: none;
}
</style>

EOS;
    });
});

add_action('restrict_manage_posts', function() {
    echo <<<EOS
<script type="text/javascript">
jQuery(document).ready(function($) {
    $("input[name='keep_private']").parents("div.inline-edit-group:first").hide();
});
</script>

EOS;
});

(Still curious to know if there's a better way.)

| improve this answer | |
  • 1
    I don't see any other better way at the moment other than a jQuery hack ;-) – birgire Nov 12 '13 at 12:18
  • yes, why jquery is "improper"? unless you want to block it from being processed by the server then I don't see much difference between an HTML generation solution or hiding with JS or CSS – Mark Kaplun Nov 13 '13 at 7:40
  • @MarkKaplun: I was hoping there was a means to disable the functionality altogether, rather than sweep it under the rug. – Denis de Bernardy Nov 13 '13 at 7:57
  • 1
    @MarkKaplun, because code that shouldn't be seen by the user shouldn't be sent from the server at all. Ideally things hidden from the user should be removed in (or by) the PHP, and not "kinda hidden" by CSS or JS in the browser. Not only is it cleaner, but in some cases there are security reasons for wanting to prevent options from being sent/read by the server. – thirdender Aug 20 '16 at 23:49
  • @thirdender, yes you probably have in your CSS and JS files only code that is applied only on the specific page it is loaded for and nothing more, no comments in the HTML and no spaces .... On this site we usually have a practical approach to programming and, not a religious ones, unless it is a truly horrible practice. With the way wordpress code in this area is structured, jQuery solution is the cleanest and more maintainable approach, when it is compared to buffering and filtering the HTML.when it is generated. You will not get a A+ grade for this code but in the real world it is better – Mark Kaplun Aug 21 '16 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.