Automatically set default password to all posts in a specific category

This should do what you want: add_filter(‘save_post’, ‘wpse_135377_protect_post’); function wpse_135377_protect_post($post_ID) { if (in_array( ‘protected_category’, wp_get_post_categories($post_ID, array(‘fields’ => ‘slugs’)) )) { // we have to remove the function // as it will be called by `wp_update_post` (=> infinite loop) remove_filter(‘save_post’, ‘wpse_135377_protect_post’); wp_update_post(array( ‘ID’ => $post_ID, ‘post_password’ => ‘123123’, )); // now we add it again add_filter(‘save_post’, … Read more

Personalized message for each unique password-protected page

You should probably add in more checks, but this should get you started. function change_pw_text($content) { // Just to save processing other pages. if ( !is_page(‘page-slug-one’) && !is_page(‘page-slug-two’) ) return $content; $find = ‘This post is password protected. To view it please enter your password below:’; if ( is_page(‘page-slug-one’) ) $replace=”Hint: Tell our system to … Read more

Password protect a single site on network

You can either use a powerful plugin such as Multisite Privacy by WPMUDEV, or you can use the following code which I developed for a project of my own. To use this code, either create a plugin with it that you only activate on the site to protect, or if that sounds too difficult, you … Read more

How to delete Passwrd Protected posts cookies when a user logged out from the site

The post password cookie is set with: setcookie( ‘wp-postpass_’ . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST[‘post_password’] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure ); in the wp-login.php file. We can then use the clear_auth_cookie hook, in the wp_clear_auth_cookie() function, to clear it on logout: /** * Clear the Post Password Cookie on logout. * * @link http://wordpress.stackexchange.com/a/198890/26350 */ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)