Musings of Wired Pig

The Sum of all the Parts

Creative Commons Post Plugin

Posted by Wired Pig May - 14 - 2008 - Wednesday
Viewed By 4 Unique Visitors No Comments

Post to Twitter
Post to Plurk
Post to Ping.fm
Post to Digg

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.

  1. < ?php
  2. /*
  3. Plugin Name: Creative Commons Post plugin
  4. Version: 0.1
  5. Author: Glenn Howell
  6. Use:
  7.  
  8. When creating a post, create one of the following post meta data keys and set it with a value of one (1) -
  9.  
  10.    cc_by         for a Creative Commons 3.0 Attribution Only (Commercial Use and Derivatives Allowed) license.
  11.    cc_by_nd      for a Creative Commons 3.0 Attribution, No Derivatives (Commercial Use Allowed) license.
  12.    cc_by_sa      for a Creative Commons 3.0 Attribution, Share Alike (Commercial Use Allowed) license.
  13.    cc_by_nc      for a Creative Commons 3.0 Attribution, Non-Commercial license.
  14.    cc_by_nc_sa   for a Creative Commons 3.0 Attribution, Non-Commercial, Share Alike license.
  15.    cc_by_nc_nd   for a Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives license.
  16.    cc_public     for a Creative Commons Public Domain License
  17.    cc_copyright  This inserts a full copyright notice.
  18.  
  19. 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.
  20.  
  21. 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.
  22.  
  23. 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.
  24.  
  25. ***
  26.  
  27. This program is free software; you can redistribute it and/or modify
  28. it under the terms of the GNU General Public License as published by
  29. the Free Software Foundation; either version 2 of the License, or
  30. (at your option) any later version.
  31.  
  32. This program is distributed in the hope that it will be useful,
  33. but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35. GNU General Public License for more details.
  36.  
  37. You should have received a copy of the GNU General Public License
  38. along with this program; if not, write to the Free Software
  39. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  40. ***
  41.  
  42. */
  43.  
  44. function cc_license_wp($content) {
  45.  
  46.     // Hello
  47.     global $post;
  48.  
  49.         // CC BY-NC-SA 3.0 Licenses (Attribution, Non-Commercial, Share Alike) ** DEFAULT **
  50.         $my_cc1 = ‘This <span>work</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License</a>.’;
  51.  
  52.         // CC BY-NC-ND 3.0 Licenses (Attribution, Non-Commercial, No Derivatives)
  53.         $my_cc2 = ‘This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/us/">Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License</a>.’;
  54.  
  55.         // CC BY 3.0 Licenses (Attribution, Commercial Okay, Derivatives Okay)
  56.         $my_cc3 = ‘This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/us/">Creative Commons Attribution 3.0 United States License</a>.’;
  57.  
  58.         // CC BY 3.0 Licenses (Attribution, No Derivatives)
  59.         $my_cc4 = ‘This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nd/3.0/us/">Creative Commons Attribution-No Derivative Works 3.0 United States License</a>.’;
  60.  
  61.         // CC BY 3.0 Licenses (Attribution, Non-Commercial)
  62.         $my_cc5 = ‘This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/us/">Creative Commons Attribution-Noncommercial 3.0 United States License</a>.’;
  63.  
  64.         // CC BY 3.0 Licenses (Attribution, Non-Commercial, No Derivatives)
  65.         $my_cc6 = ‘This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/us/">Creative Commons Attribution-Noncommercial 3.0 United States License</a>.’;
  66.  
  67.         // CC BY 3.0 Licenses (Attribution, Share Alike)
  68.         $my_cc7 = ‘This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/us/">Creative Commons Attribution-Noncommercial 3.0 United States License</a>.’;
  69.  
  70.         // DIV-width in percents or pixels (Example: "90%" or "450px")
  71.         $my_width = ‘100%’;
  72.  
  73.         // Alignment of the buttons ("left", "right" or "center")
  74.         $my_align = ‘center’;
  75.  
  76.         // Location of the folder with the icons of the buttons ** NOT USED **
  77.         $my_images_folder = get_settings(‘home’) . ‘/wp-content/plugins/cc_license_wp/images/’;
  78.  
  79.         // We take the post details in the following variables
  80.         $my_link = get_permalink($post->ID);
  81.         $my_title = get_the_title($post->ID);
  82.  
  83. // Do Not Edit Below This Line
  84.  
  85. // Functions To Call Specific Notices Based On Post Meta Data
  86.  
  87. // Sets the notice for: Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives
  88.  
  89. if ( get_post_meta($post->ID, ‘cc_by_nc_sa’, true) ) {
  90.  
  91.         if ( !is_feed() &amp;&amp; !is_page() ) {
  92.  
  93.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-BY-NC-ND –>’ . "\n"
  94.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  95.                   . ‘
  96. <div style="padding: 16px 0pt;">’ . "\n"
  97.                   . $my_cc2 . "\n"
  98.                   . ‘</div>
  99. ‘ . "\n"
  100.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  101.     }
  102.         return $content;
  103. }
  104.  
  105. elseif ( get_post_meta($post->ID, ‘cc_by’, true) ) {
  106.  
  107. // Sets the notice for: Creative Commons 3.0 Attribution Only (Not for Commercial or Derivation)
  108.  
  109.         if ( !is_feed() &amp;&amp; !is_page() ) {
  110.  
  111.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-BY –>’ . "\n"
  112.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  113.                   . ‘
  114. <div style="padding: 16px 0pt;">’ . "\n"
  115.                   . $my_cc3 . "\n"
  116.                   . ‘</div>
  117. ‘ . "\n"
  118.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  119.     }
  120.         return $content;
  121. }
  122.  
  123. elseif ( get_post_meta($post->ID, ‘cc_by_nd’, true) ) {
  124.  
  125. // Sets the notice for: Creative Commons 3.0 Attribution, No Derivatives (Commercial Use Allowed)
  126.  
  127.         if ( !is_feed() &amp;&amp; !is_page() ) {
  128.  
  129.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-BY-ND –>’ . "\n"
  130.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  131.                   . ‘
  132. <div style="padding: 16px 0pt;">’ . "\n"
  133.                   . $my_cc4 . "\n"
  134.                   . ‘</div>
  135. ‘ . "\n"
  136.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  137.     }
  138.         return $content;
  139. }
  140.  
  141. elseif ( get_post_meta($post->ID, ‘cc_by_nc’, true) ) {
  142.  
  143. // Sets the notice for: Creative Commons 3.0 Attribution, Non-Commercial
  144.  
  145.         if ( !is_feed() &amp;&amp; !is_page() ) {
  146.  
  147.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-BY-NC –>’ . "\n"
  148.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  149.                   . ‘
  150. <div style="padding: 16px 0pt;">’ . "\n"
  151.                   . $my_cc5 . "\n"
  152.                   . ‘</div>
  153. ‘ . "\n"
  154.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  155.     }
  156.         return $content;
  157. }
  158.  
  159. elseif ( get_post_meta($post->ID, ‘cc_by_nc_nd’, true) ) {
  160.  
  161. // Sets the notice for: Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives
  162.  
  163.         if ( !is_feed() &amp;&amp; !is_page() ) {
  164.  
  165.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-BY-NC-ND –>’ . "\n"
  166.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  167.                   . ‘
  168. <div style="padding: 16px 0pt;">’ . "\n"
  169.                   . $my_cc6 . "\n"
  170.                   . ‘</div>
  171. ‘ . "\n"
  172.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  173.     }
  174.         return $content;
  175. }
  176.  
  177. elseif ( get_post_meta($post->ID, ‘cc_by_sa’, true) ) {
  178.  
  179. // Sets the notice for: Creative Commons 3.0 Attribution, Non-Commercial, No Derivatives
  180.  
  181.         if ( !is_feed() &amp;&amp; !is_page() ) {
  182.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-BY-SA –>’ . "\n"
  183.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  184.                   . ‘
  185. <div style="padding: 16px 0pt;">’ . "\n"
  186.                   . $my_cc7 . "\n"
  187.                   . ‘</div>
  188. ‘ . "\n"
  189.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  190.     }
  191.         return $content;
  192. }
  193.  
  194. elseif ( get_post_meta($post->ID, ‘cc_public’, true) ) {
  195.  
  196. // Sets the notice for: Creative Commons Public Domain
  197.  
  198.         if ( !is_feed() &amp;&amp; !is_page() ) {
  199.  
  200.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-PD –>’ . "\n"
  201.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  202.                   . ‘
  203. <div style="padding: 16px 0pt;">’ . "\n"
  204.                   . ‘This work is licensed under the <a href="http://creativecommons.org/licenses/publicdomain/">Creative Commons Public Domain</a>.’ . "\n"
  205.                   . ‘</div>
  206. ‘ . "\n"
  207.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  208.     }
  209.         return $content;
  210. }
  211.  
  212. elseif ( get_post_meta($post->ID, ‘cc_copyright’, true) ) {
  213.  
  214. // Sets the notice for: Full Copyright
  215.  
  216.         if ( !is_feed() &amp;&amp; !is_page() ) {
  217.  
  218.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-CO –>’ . "\n"
  219.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  220.                   . ‘
  221. <div style="padding: 16px 0pt;">’ . "\n"
  222.                   . ‘This work is Copyrighted and may not be used without the express permission of the copyright holder.’ . "\n"
  223.                   . ‘</div>
  224. ‘ . "\n"
  225.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  226.     }
  227.         return $content;
  228. }
  229.  
  230. else {
  231.  
  232. // Sets the default notice for: Creative Commons 3.0 Attribution, Non-Commercial, Share Alike
  233.  
  234.         if ( !is_feed() &amp;&amp; !is_page() ) {
  235.  
  236.                 $content .= "\n\n" . ‘<!– Begin Wired Pigs Creative Commons plugin CC-BY-NC-SA –>’ . "\n"
  237.                   . ‘<!– blog.wiredpig.us/copyright –>’ . "\n"
  238.                   . ‘
  239. <div style="padding: 16px 0pt;">’ . "\n"
  240.                   . $my_cc1 . "\n"
  241.                   . ‘</div>
  242. ‘ . "\n"
  243.                                   . ‘<!– End Wired Pigs Creative Commons plugin –>’ . "\n\n";
  244.     }
  245.         return $content;
  246. }
  247.  
  248. }
  249.  
  250. add_filter(‘the_content’, ‘cc_license_wp’, 1097);
  251.  
  252. ?>
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?

Popularity: unranked [?]


Post to TwitterPost to Plurk
Post to Yahoo BuzzPost to Delicious
Post to DiggPost to Ping.fm
Post to RedditPost to StumbleUpon

Leave a Reply

CommentLuv Enabled
WPs Blog (here) WPs Twitter WPs Flickr Photos WPs Del.icio.us WPs Facebook Profile WPs Blogspot Blog  
   WPs LinkedIn Profile WPs Technorati WPs Utterz WPs YouTube Videos WPs Qik Videos  
Get Adobe Flash playerPlugin by wpburn.com wordpress themes