Advertisement
YordanSoares

WordPress: Protect custom post type with a predefined password

Mar 12th, 2024
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.29 KB | Software | 0 0
  1. <?php
  2. /**
  3.  * WordPress:
  4.  * Protect custom post type with a predefined password
  5.  */
  6. add_action( 'the_post', function( $post ){
  7.     if ( $post->post_type == 'gallery' ) { // Write the custom post type ID here
  8.         $post->post_password = 'MyP@sSW0rD'; // The predefined password goes here
  9.     }
  10. } );
Tags: wordpress CPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement