Categories
Package/plugin/module WordPress

Plugin: Hide or Cut Post Text

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:
coffee2code.com/wp-plugins/hide-or-cut-post-text
Name:
Hide or Cut Post Text
Author:
Scott Reilly
Version:
1.2
Last updated:
11 April 2005
Description:

Hide (so no one, or only users above a certain userlevel, can see) or cut (so only viewable on post’s permalink page) portion(s) of a post’s text. Link text for cuts can be defined per-cut or omitted, and if used, cut links are uniquely anchored. Quicktag buttons for the new tags are automatically created (but can be disabled).

Notes:

This plugin gets you four basic features (actual two plus a pair of worthwhile variations):

1.) Hide portion(s) of post text
Any text falling between <!–hide–> and <!–/hide–> will be hidden from visitors, with no indication any text was hidden. Why? Maybe you want to leave yourself a note that no one else (who doesn’t have the ability to edit your post) can ever see. Maybe you want to remove section(s) of a post without removing the post entirely, and you don’t want to lose the original text, or lose track of it by pasting the text elsewhere. I’ve used it to remove documentation for a deprecated plugin. You can include comments to yourself about the hide via <!–hide=PUT YOUR NOTES HERE–>. *NEW* You can also hide text for users below a given user level while showing the text for those at or above the user level: in this manner : <!–hide=”Only high level users should see this” userlevel=9–>Secret stuff here…<!–/hide–>.

2.) Cut portion(s) of post text
While there are various cut plugins already, this was a fallout of my needing the hide feature, and just as well, I like the way this works. Basically, sections of post text falling between <!–cut–> and <!–/cut–> will only be displayed on the post’s permalink page. In place of the cut text in non-single pages is a link (by default it says “Read more…”). Customize the cut link text like so <!–cut=Read what I just cut…–>. Each cut link links to a unique anchor in the individual archive page.

3.) Single/individual archive only
This is a variation of the previous feature. Any text falling between <!–show=single–> and <!–/single–> will only appear in the post’s permalink page, but unlike a typical cut, non-permalink pages will not in any way reflect that text had been cut. I use this on coffee2code.com for each of my plugin announcements; on the permalink page, at the top of the post, you’ll notice there is a navigation bar that links down into the different sections of the post, but on the front page you don’t see the navigation bar.

4.) Non-single pages only
Any text falling between <!–show=nonsingle–> and <!–/show–> will only be visible in non-single pages (any page that the post would appear alongside other posts… i.e. the main page, yearly archive, monthly archive, daily archive, etc). The permalink page for the post will not in any way reflect that text had been cut.

Note: Users who have installed v0.9 of this plugin may want to undo the manually edits to quicktags.js that created the
“cut” and “hide” buttons so that the preferred method for dynamic button creation implemented by this version can be used.
If not, no biggie.

Note: The <!–cut=none–> tag is being phased out in favor of <!–show=single–>

Installation:
  1. Download the file hide-or-cut-text.zip and unzip it into your /wp-content/plugins/ directory.
    -OR-
    Copy and paste the the code ( hide-or-cut-text.phps ) into a file called hide-or-cut-text.php, and put that file into your /wp-content/plugins/ directory. Please ensure you do not introduce any spaces or other characters before the <?php or after the ?>
  2. Optional: Change configuration options in the file to your liking
    • In the arguments to function hide_or_cut_text(), $allowed_types is a space-separated list that can include ‘cut’, ‘hide’, and/or ‘show’ (to indicate which you wish to use); the default is ‘cut hide show’; you probably don’t need to change this because you could simply not make use of the tags in your post if you don’t want to
    • In the arguments to function cut_link_handler(), change $default_linktext to be the string used for the link for cut text when no per-cut link text is defined
    • If you don’t want ANY quicktags created for you in the Post Edit admin page, find and comment out the following line in the code (by putting two forward slashes before it, i.e. “//”):

      add_filter('admin_footer', 'add_cuthideshow_buttons');

      If you don’t want one or two of the three buttons from being created, edit the array in the function add_cuthideshow_buttons() to remove the button(s).

  3. Activate the plugin from your WordPress admin ‘Plugins’ page.
Functions:

function c2c_hide_or_cut_text ($text, $allowed_types='cut hide show')

  • $text : The text to be parsed for hiding/cutting appropriately tagged areas (basically the post content)
  • $allowed_types : a space-separated list of tags you want to allow to be parsed from your post content; can be ‘cut’, ‘hide’, and/or ‘show’; the default is ‘cut hide show’; you probably don’t need to change this because you could simply not make use of the tags in your post if you don’t want to

function c2c_cut_link_handler ($linktext, $default_linktext='Read more...')


A helper function called by hide_or_cut_text().

  • $linktext : custom per-cut link text as parsed from original text
  • $default_linktext : the string used for the link for cut text when no per-cut text is defined
Tips & Examples:

See this post for an example of post text (as seen in the admin edit post page).

This post is the rendered example of the previous sample post text.

Release Log:
  • 11 Apr 2005 : v1.2 —
    • Fix so that userlevel= will be acknowledged even when no comment text is provided for a ‘hide’
    • userlevel= argument can now optionally be double-quoted
  • 28 Mar 2005 : v1.1 —
    • Added the function c2c_hide_handler() to support ability to define userlevel= attribute to hide tag; only users at or above the specified userlevel are shown the text
    • Switch from using $single to is_single()
    • Prepended all functions with “c2c_”
    • Removed shortcut specifier in JavaScript calls to create QuickTag buttons
    • Changed license from BSD-New to MIT
    • Plugin is no longer WordPress 1.2 compatible
  • 17 Aug 2004 : v0.91 — Various fixes and new features:
    • New tags: <!–show=single–> (replaces the soon-to-be-phased-out <!–cut=none–>) and <!–show=nonsingle–>
    • Per-cut link text and ‘hide’ comments can be double-quoted: <!–cut = “Read what I cut…” –>
    • Quicktag buttons (the buttons appearing over the text entry field when writing a post) are now automatically created for ‘cut’, ‘hide’, and ‘show’ by this plugin.
    • The newline character has been removed from the output of the cut-link links to allow for inline cutting.
    • The second argument to hide_or_cut_text(), $types, was changed to $allowed_types, which is now a space-separated list of the tags to allow.
  • 25 Jul 2004 : v0.9 — Released to the public
Copyright & Disclaimer:

Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledgements:
I’d like to thank Owen Winkler and Ryan Boren who enlightened me, via code examples, of how this plugin could automatically insert Quicktag buttons.

47 replies on “Plugin: Hide or Cut Post Text”

Is there a way to do the opposite and cut certain portions of the post from the permalink page but viewable in any other page?

oddities with the new 1.5 Strayhorn include the [more] tag not working when you only show a single post.

i thought this plug would be a much better alternative…

seems it suffers from the same issues.

[hide] works as expected

[show] and [cut] don’t function on the index, as only one post is showing.

i’d like to ONLY show the contents between the tag when i am at a permalink, some text to demonstrate that there’s more would be good too.

somehow even this plug is thinking that the index is a permalink.

c’mon 1.5.1!

Just wondering if you’d consider this extra feature:
A tag (perhaps ?) that will allow you to only display part of a post to the general public but the entire post to those that are registered on my site and logged in.

This is what I want to do: create discography pages for a band site with all of the album info available to the general public. Those that are registered on my site and logged in will be able to see that information PLUS a Flash Play button next to each song.

Something like this site:
www.dubtribe.com/index.php?p=53
But with the play button ONLY appearing if the person is logged in.

Is this a possible addition to your plugin, or should I just use the PHP Exec Plugin and wrap the play button in php code that detects whether the person is logged in?

(Code to display the play button.)

(Do not display the play button.

Plugin updated to v1.1

A bit belated in adding this comment, but the plugin was updated on 28 Mar 2005 with the following changes:

* Added the function c2c_hide_handler() to support ability to define userlevel= attribute to hide tag; only users at or above the specified userlevel are shown the text
* Switch from using $single to is_single() (‘single’ now works in WP1.5 without the need for the bugfix coming in WP1.5.1)
* Prepended all functions with “c2c_”
* Removed shortcut specifier in JavaScript calls to create QuickTag buttons
* Changed license from BSD-New to MIT
* Plugin is no longer WordPress 1.2 compatible

fernando: With v1.1 of the plugin, the ‘show’ and ‘cut’ tags should now work as expected.

Mau, hcm: v1.1 also introduces a feature which addresses what you want. You can use the ‘hide’ tag to hide text from users below a given userlevel. Under the “Notes” section above, in the explanation of the ‘hide’ tag, you’ll find out how to use it.

After updating to WP1.5.1, I notice posts within a Category selection shows the text of a cut-link (in my case: “>>> Read more”) appears, but its no longer hot-linked to the post. I could swear this worked in v1.5. Any ideas on how to make it functional within Categories again?

Continues to work fine on blog front.

Cheers!

Does anyone know how to define the userlevel so that anyone who is logged in can see the hidden text?

userlevel=0 doesnt work, and userlevel=1 requires me to upgrade anyone who creates an account…

any ideas?

Tim

[…] I’m also thinking about installing several other WordPress plugins. I’ve been looking for an extended entry plugin, but the only one that I can find that does what I want is one that I CANNOT get to work here. See, what I want is not really an excerpt plugin, which just posts excerpts of every entry, but rather a plugin that “cuts” entries like the LJ-cut feature of LiveJournal. I just want something that I can use to split up longer entries so they don’t take up so much room on my main pages. If anyone knows of anything other than wp-Cut (dead link), please tell me. Hide or Cut Post Text is the plugin I was able to install, but I had no success in getting the thing to work. WP just spat the code back out at me rather than executing it. […]

What would be good in this plugin, is an option to tell those viewing a post that it has been cut or hidden.
So if you have cut a post for unregistered viewers they can see that it is available if they register, or that this post is available to moderators and so on.

[…] » Plugin: Hide or Cut Post Text « « Blog Archive coffee2code.com “Any text falling between and will be hidden from visitors, with no indication any text was hidden. Why? Maybe you want to leave yourself a note that no one else (who doesn’t have the ability to edit your post) can ever see” This is very useful — I often want to put personal notes to myself about something.           0 votes | […]

The dynamic button creation method doesn´t seem to work in my case (WP 2.0.2 – plugin version 1.2 first time installed and working).
How to add them manually to quicktags.js?
Thank you for this great piece of code.

I installed this plug-in with the sole purpose of using the cut feature. On my most recent entry I wanted to to cut the text where my girl survey starts so people who didn’t want to read it didn’t have to. When I went to edit my post, I put the cut tags in but still nothing is working. What am I doing wrong?

I just installed your plugin! It works beautifully with the latest version of wordpress (2.06). My question is, If i use the hide functions without the user level, will my registered users still be able to view the text that i have hidden? or no?? When i used the userlevel function the hidden text was still viewable. So i don’t know if i’m doing it right. With the part “users with higher level should view this” is that where we put the hidden text? or is it where it says “secret stuff”.

The plugin doesn’t work with the latest version of wordpress 2.1; when I go to “write” in the admin area it doesn’t show the quicktags anymore of the “cut”, “hide”, “show” etc. The quicktags only show when i edit the post; and i don’t know why. I hope you will consider updating this plugin for the latest version of wordpress, because i really, really, REALLY enjoy using it on my website. 🙂

Comments are closed.