Creative Commons Post Plugin

I wanted a way to ad a Creative Commons notice at the bottom of each post and I wanted the plugin to be able to pick what license was used based on the post authors preference. That lead me, over the last few days, to create the Creative Commons Post plugin.

You can see an example of it at the bottom of this post (above the comments).

Basic Use -

When creating a post, create one of the following post meta data keys and set it with a value of one (1)(1) -

Post Meta Data Key Resulting License Displayed
cc_by Creative Commons 3.0 Attribution Only (Commercial Use and Derivatives Allowed) license.
cc_by_nd Creative Commons 3.0 Attribution, No Derivatives (Commercial Use Allowed) license.
cc_by_sa Creative Commons 3.0 Attribution, Share Alike (Commercial Use Allowed) license.
cc_by_nc Creative Commons 3.0 Attribution, Non-Commercial license.
cc_by_nc_sa Creative Commons 3.0 Attribution, Non-Commercial, Share Alike license.
cc_by_nc_nd Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives license.
cc_public Creative Commons Public Domain License.
cc_copyright Inserts a full copyright notice.

Not setting any of the above values will insert a default license for Creative Commons 3.0 Attribution, Non-Commercial, Share Alike (BY-NC-SA) license in the post. This can easily be changed to not display any license unless a value it set.

Notice: When setting one of the values above, SET ONLY ONE. Do not set multiple values for one post as it will screw up the system.

I had very specific needs when I created this plugin. As a result, there are no graphic elements present when the CC License is displayed on a post page.

This plugin works with WordPress 2.5.1 and should work with 2.3+.

To Do:

  • Add an options page for the plugin.
  • Tidy up / Streamline the code.
  • Other minor tweaks.

I want to thank Alexander Dichev for his Add Me Dichev plugin that I used as the framework for this plugin.

< ?php
/*
Plugin Name: Creative Commons Post plugin
Version: 0.1
Plugin URI: blog.wiredpig.us/2008/05/14/creative-commons-post-plugincreative-commons-post-plugin/
Description: Wired Pigs Creative Commons plugin ads a user defined Creative Commons notice at the bottom of each post. The plugin was adapted from Add Me Dichev by Alexander Dichev. See plugin code for documentation.
Author: Glenn Howell
Author URI: blog.wiredpig.us/

Use:

When creating a post, create one of the following post meta data keys and set it with a value of one (1) -

   cc_by         for a Creative Commons 3.0 Attribution Only (Commercial Use and Derivatives Allowed) license.
   cc_by_nd      for a Creative Commons 3.0 Attribution, No Derivatives (Commercial Use Allowed) license.
   cc_by_sa      for a Creative Commons 3.0 Attribution, Share Alike (Commercial Use Allowed) license.
   cc_by_nc      for a Creative Commons 3.0 Attribution, Non-Commercial license.
   cc_by_nc_sa   for a Creative Commons 3.0 Attribution, Non-Commercial, Share Alike license.
   cc_by_nc_nd   for a Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives license.
   cc_public     for a Creative Commons Public Domain License
   cc_copyright  This inserts a full copyright notice.

Not setting any of the above values will insert a default license for Creative Commons 3.0 Attribution, Non-Commercial, Share Alike (BY-NC-SA) license in the post.

Notice: When setting one of the values above, SET ONLY ONE. Do not set multiple values for one post as it will screw up the system.

I had very specific needs when I created this plugin. As a result, there are no graphic elements present when the CC License is displayed on a post page.

***
Copyright 2008  Wired Pig  (email : wiredpig@gmail.com)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
***

*/

function cc_license_wp($content) {

    // Hello
    global $post;

        // CC BY-NC-SA 3.0 Licenses (Attribution, Non-Commercial, Share Alike) ** DEFAULT **
        $my_cc1 = 'This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.';

        // CC BY-NC-ND 3.0 Licenses (Attribution, Non-Commercial, No Derivatives)
        $my_cc2 = 'This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.';

        // CC BY 3.0 Licenses (Attribution, Commercial Okay, Derivatives Okay)
        $my_cc3 = 'This work is licensed under a Creative Commons Attribution 3.0 United States License.';

        // CC BY 3.0 Licenses (Attribution, No Derivatives)
        $my_cc4 = 'This work is licensed under a Creative Commons Attribution-No Derivative Works 3.0 United States License.';

        // CC BY 3.0 Licenses (Attribution, Non-Commercial)
        $my_cc5 = 'This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.';

        // CC BY 3.0 Licenses (Attribution, Non-Commercial, No Derivatives)
        $my_cc6 = 'This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.';

        // CC BY 3.0 Licenses (Attribution, Share Alike)
        $my_cc7 = 'This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.';

	// DIV-width in percents or pixels (Example: "90%" or "450px")
	$my_width = '100%';

	// Alignment of the buttons ("left", "right" or "center")
	$my_align = 'center';

	// Location of the folder with the icons of the buttons ** NOT USED **
	$my_images_folder = get_settings('home') . '/wp-content/plugins/cc_license_wp/images/';

	// We take the post details in the following variables
	$my_link = get_permalink($post->ID);
        $my_title = get_the_title($post->ID);

// Do Not Edit Below This Line

// Functions To Call Specific Notices Based On Post Meta Data

// Sets the notice for: Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives

if ( get_post_meta($post->ID, 'cc_by_nc_sa', true) ) {

	if ( !is_feed() && !is_page() ) {

		$content .= "\n\n" . '' . "\n"
                  . '' . "\n"
                  . '
' . "\n" . $my_cc2 . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } elseif ( get_post_meta($post->ID, 'cc_by', true) ) { // Sets the notice for: Creative Commons 3.0 Attribution Only (Not for Commercial or Derivation) if ( !is_feed() && !is_page() ) { $content .= "\n\n" . '' . "\n" . '' . "\n" . '
' . "\n" . $my_cc3 . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } elseif ( get_post_meta($post->ID, 'cc_by_nd', true) ) { // Sets the notice for: Creative Commons 3.0 Attribution, No Derivatives (Commercial Use Allowed) if ( !is_feed() && !is_page() ) { $content .= "\n\n" . '' . "\n" . '' . "\n" . '
' . "\n" . $my_cc4 . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } elseif ( get_post_meta($post->ID, 'cc_by_nc', true) ) { // Sets the notice for: Creative Commons 3.0 Attribution, Non-Commercial if ( !is_feed() && !is_page() ) { $content .= "\n\n" . '' . "\n" . '' . "\n" . '
' . "\n" . $my_cc5 . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } elseif ( get_post_meta($post->ID, 'cc_by_nc_nd', true) ) { // Sets the notice for: Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives if ( !is_feed() && !is_page() ) { $content .= "\n\n" . '' . "\n" . '' . "\n" . '
' . "\n" . $my_cc6 . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } elseif ( get_post_meta($post->ID, 'cc_by_sa', true) ) { // Sets the notice for: Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives if ( !is_feed() && !is_page() ) { $content .= "\n\n" . '' . "\n" . '' . "\n" . '
' . "\n" . $my_cc7 . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } elseif ( get_post_meta($post->ID, 'cc_public', true) ) { // Sets the notice for: Creative Commons Public Domain if ( !is_feed() && !is_page() ) { $content .= "\n\n" . '' . "\n" . '' . "\n" . '
' . "\n" . 'This work is licensed under the Creative Commons Public Domain.' . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } elseif ( get_post_meta($post->ID, 'cc_copyright', true) ) { // Sets the notice for: Full Copyright if ( !is_feed() && !is_page() ) { $content .= "\n\n" . '' . "\n" . '' . "\n" . '
' . "\n" . 'This work is Copyrighted and may not be used without the express permission of the copyright holder.' . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } else { // Sets the default notice for: Creative Commons 3.0 Attribution, Non-Commercial, Share Alike if ( !is_feed() && !is_page() ) { $content .= "\n\n" . '' . "\n" . '' . "\n" . '
' . "\n" . $my_cc1 . "\n" . '
' . "\n" . '' . "\n\n"; } return $content; } } add_filter('the_content', 'cc_license_wp', 1097); ?>

Popularity: unranked

Footnotes:

Footnotes are for reference only and may have little, if anything to do with the text from the post.



  1. Or any value. What the meta data key is set to is not important. Just that the key is present. []


Exciting, huh?
This entry was posted in Asides and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv Enabled
Please leave these two fields as-is: