Skip to content

Instantly share code, notes, and snippets.

@smajda
Created September 4, 2009 21:12
Show Gist options
  • Save smajda/181137 to your computer and use it in GitHub Desktop.
Save smajda/181137 to your computer and use it in GitHub Desktop.
<?php
// Adds Creative Commons license to WordPress RSS feeds
// Modify this for your site & license
$feed_license = array(
"moduleNamespace" => 'xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"',
"ccNamespace" => 'xmlns:cc="http://creativecommons.org/ns#"',
"link" => "http://creativecommons.org/licenses/by-nc-sa/3.0/",
"ccName" => "Creative Commons BY-NC-SA",
"years" => '2003-'.date("Y")
);
// RSS 2.0
function rss2_ns_additions() { // namespace additions
global $feed_license;
echo $feed_license['moduleNamespace']."\n";
}
add_action('rss2_ns','rss2_ns_additions');
function rss2_head_additions() { // head additions
global $feed_license;
echo '<copyright>Copyright '.$feed_license["years"].' ';
echo bloginfo_rss('name');
echo '</copyright>'."\n";
echo "\t<creativeCommons:license>".$feed_license['link']."</creativeCommons:license>\n";
}
add_action('rss2_head','rss2_head_additions');
function rss2_item_additions() { // item additions
global $feed_license;
echo "\t<creativeCommons:license>".$feed_license['link']."</creativeCommons:license>\n";
}
add_action('rss2_item','rss2_item_additions');
// RSS 1.0 (RDF)
function rdf_ns_additions() { // namespace additions
global $feed_license;
echo $feed_license['ccNamespace']."\n";
}
add_action('rdf_ns','rdf_ns_additions');
function rdf_head_additions() { // head additions
global $feed_license;
echo '<copyright>Copyright '.$feed_license["years"].' ';
echo bloginfo_rss('name');
echo '</copyright>'."\n";
echo "\t<cc:license rdf:resource=\"".$feed_license['link']."\" />\n";
}
add_action('rdf_header','rdf_head_additions');
function rdf_item_additions() { // item additions
global $feed_license;
echo "<cc:license rdf:resource=\"".$feed_license['link']."\" />\n";
}
add_action('rdf_item','rdf_item_additions');
// Atom
function atom_head_additions() { // head additions
global $feed_license;
echo "<link rel=\"license\" type =\"application/rdf+xml\" href=\"".$feed_license['link']."rdf\" />\n";
}
add_action('atom_head','atom_head_additions');
function atom_item_additions() { // item additions
global $feed_license;
echo "\t\t<link rel=\"license\" type =\"text/html\" href=\"".$feed_license['link']."\" />\n";
}
add_action('atom_entry','atom_item_additions');
// RSS 0.92
function rss_head_additions() { // head additions
global $feed_license;
echo '<copyright>Copyright '.$feed_license["years"].' ';
echo bloginfo_rss('name');
echo ', '.$feed_license['ccName'];
echo '</copyright>'."\n";
}
add_action('rss_head','rss_head_additions');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment