WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Setting new Posts Privacy to Protected by Default (8 posts)

  1. henshall
    Member
    Posted 2 years ago #

    There's a great answer to how to set new post visibility to private by default. I found it here. However, this appears to apply to a single user site. I am running a multi-site.

    http://wordpress.org/support/topic/how-to-set-new-post-visibility-to-private-by-default?replies=14

    Is there a way to make this optional on a multiuser site by blog? I presume if I insert this code it will make all sites in this network perform this way from here on out. How would I amend the code for a multiuser site? What will be the impact on blogs that were already created on this network? Presume new posts will go to protected?

    Application/User Case. I have multiple registered users. Some are respondents which are submitting data via forms (contributors) I would like them to be able to read their posts only. A subscriber may only be able to see a few pages. Other... example authors can read all posts when logged in. Ie they have access to all protected posts.

    I don't know of a plug-in that helps me manage this. Any solutions?

    Thank you.

  2. That very last answer - http://wordpress.org/support/topic/how-to-set-new-post-visibility-to-private-by-default?replies=14#post-2074408

    That can be applied to a plugin and put in your mu-plugins folder, which would activate for all sites.

  3. henshall
    Member
    Posted 2 years ago #

    Ok... sort of. I see the code referenced although I'm not quite sure where to go from there. Do I just create a new plug-in from that code? Is there anything else that needs to go in this plug-in? I probably don't understand enough. Thanks.

  4. Make a file called 'private-by-default.php'

    In that file, you put this:

    <?php
    /*
    Plugin Name: Name Of The Plugin
    Description: A brief description of the Plugin.
    */
    
    [all the code from that post]
    
    ?>

    Put that file into the /wp-content/mu-plugins/ folder.

  5. henshall
    Member
    Posted 2 years ago #

    Thank you much appreciated. I checked out the plug-in codex in the meantime. I will give it a go.

  6. henshall
    Member
    Posted 2 years ago #

    The plug-in worked. Posts are on the activated blog are now auto posted as private. This is very useful where I am using forms and want the form fillers to see their posts only (and not protected), while others can be given the permissions to see all posts. In this instance it would be useful to remove the "private: hello world" as a notation.

    I note in the previous thread this:

    To remove the "Private: " part from the title of the post, change the following line of code in your code above:
    $private_title_format = apply_filters('private_title_format', __('Private: %s'));

    To this:
    $private_title_format = apply_filters('private_title_format', __('%s'));

    Anyway I can incorporate this into the same solution? Thanks for your time much appreciated.

  7. Not exactly, since the fix that post provides tells you to edit core, which you don't want to do. You'll hate it.

    Put this in your plugin though:

    function the_title_trim($title) {
    	// Might as well make use of this function to escape attributes
    	$title = attribute_escape($title);
    	// What to find in the title
    	$findthese = array(
    		'#Protected:#', // # is just the delimiter
    		'#Private:#'
    	);
    	// What to replace it with
    	$replacewith = array(
    		'a', // What to replace protected with
    		'b' // What to replace private with
    	);
    	// Items replace by array key
    	$title = preg_replace($findthese, $replacewith, $title);
    	return $title;
    }
    add_filter('the_title', 'the_title_trim');

    Put it ABOVE the ?> at the end :)

  8. henshall
    Member
    Posted 2 years ago #

    Brilliant! Thank you. Worked like a charm.

Topic Closed

This topic has been closed to new replies.

About this Topic