Last active
September 30, 2015 13:33
-
-
Save jdembowski/3d3c64f788902959858e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Are You Licensed? | |
Description: This plugin checks your hostname to see if you are adhering to the <a href="http://wordpressfoundation.org/trademark-policy/">WordPress Foundation Trademark Policy</a>. It does <strong>not</strong> check if you are running an activated installation of WordPress. This not a Microsoft plugin. | |
Author: Jan Dembowski | |
Author URI: https://blog.dembowski.net/ | |
Version: 0.3 | |
*/ | |
add_action( 'loop_end' , 'mh_licensed' ); | |
// add_action( 'loop_start' , 'mh_licensed' ); | |
function mh_licensed( $query ) { | |
// I want to output the license statement after the main loop and no where else. | |
if( $query->is_main_query() ) { | |
// This will explode the home_url() into an array along the '.' character | |
// and slice the last 3 elements into an array. | |
// So if I have a home_url() of "aa.bb.cc.dd.ee.domain.tld/wordpress" then | |
// this will rip out the "ee", "domain" and "tld/wordpress" parts only. | |
// The array will either have 3 or 2 elements in it. | |
$mh_output = array_slice( explode( '.' , home_url() ) , -3 , 3 ); | |
// If the 2nd level domain contains 'wordpress' then echo that we're bad people | |
if ( strpos( strtolower( $mh_output[ count( $mh_output ) - 2 ] ) , 'wordpress' ) ) { | |
$mh_message = 'We use "wordpress" in our second level domain which is a contravention '; | |
$mh_message .= 'of the <a href="http://wordpressfoundation.org/trademark-policy/" target="_blank">WordPress Foundation Tardemark Policy.</a> '; | |
$mh_message .= 'We may not be nice people. You should leave our site and never return.'; | |
echo '<p style="text-align: center; padding: 10px 20px 10px 20px;">' . $mh_message . '</p>'; | |
return; | |
} | |
// If the 3rd level domain contains 'wordpress' then we're compliant and say so. | |
if ( strpos( strtolower( $mh_output[ count( $mh_output ) - 3 ] ) , 'wordpress' ) ) { | |
$mh_message = 'We use "wordpress" in our subdomain in compliance with '; | |
$mh_message .= '<a href="http://wordpressfoundation.org/trademark-policy/" target="_blank">The WordPress Foundation Trademark Policy.</a>'; | |
echo '<p style="text-align: center; padding: 10px 20px 10px 20px;">' . $mh_message . '</p>'; | |
return; | |
} | |
// If the directory contains 'wordpress' then we're compliant and say so. | |
if ( strpos( strtolower( $mh_output[ count( $mh_output ) - 1 ] ) , 'wordpress' ) ) { | |
$mh_message = 'We use "wordpress" in our subdirectory name in compliance with '; | |
$mh_message .= '<a href="http://wordpressfoundation.org/trademark-policy/" target="_blank">The WordPress Foundation Trademark Policy.</a>'; | |
echo '<p style="text-align: center; padding: 10px 20px 10px 20px;">' . $mh_message . '</p>'; | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment