Skip to content

Instantly share code, notes, and snippets.

@OsamaShabrez
Created January 3, 2015 18:35
Show Gist options
  • Save OsamaShabrez/6b47f3c38073c6aed542 to your computer and use it in GitHub Desktop.
Save OsamaShabrez/6b47f3c38073c6aed542 to your computer and use it in GitHub Desktop.
A temporary Plugin I created to keep small php snippets independent of theme functions.php file
<?php
/**
* Plugin Name: MyTemporaryPlugin
* Plugin URI: http://OsamaShabrez.com
* Description: This is small temporary plugin created to keep small php codes idependent of theme or other plugin files
* Version: 1.0.1
* Author: Muhammad Osama Shabrez
* Author URI: http://OsamaShabrez.com
* Network: false
* License: GPL2
*/
/* Copyright 2015 Muhammad Osama Shabrez (email : Contact@OsamaShabrez.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
*/
defined('ABSPATH') or die("No script bitches please!");
//Block Referal URL exploit for Comments
function verify_comment_referer_tempplugin() {
if (!wp_get_referer()) {
wp_die( __('You cannot post comment at this time, may be you need to enable referrers in your browser.') );
}
}
add_action('check_comment_flood', 'verify_comment_referer_tempplugin');
// Create Nonce
function add_nonce_field_to_comment_form() {
wp_nonce_field('comment_form_nonce_field');
}
// Include Nonce To Comment Form
add_action('comment_form', 'add_nonce_field_to_comment_form');
// Check Nonce Field Validity
function check_nonce_field_on_comment_form() {
if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'comment_form_nonce_field')) {
die('Nonce Check Failed - Killing Request');
}
}
// Add Nonce Check To Comment Form Post
add_action('pre_comment_on_post', 'check_nonce_field_on_comment_form');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment