Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Created August 21, 2014 12:46
Show Gist options
  • Save WillBrubaker/01cbaffc63a5df7d92bf to your computer and use it in GitHub Desktop.
Save WillBrubaker/01cbaffc63a5df7d92bf to your computer and use it in GitHub Desktop.
Code snippet to load custom messages for jQuery validation plugin within the Awesome Surveys WordPress plugin
<?php
/*
Plugin Name: Code With WP Custom Snippets
Plugin URI: http://codewithwp.com/
Description: This plugin holds custom code snippets that interact with both themes and plugins related to this website.
Author: Thomas Griffin
Author URI: http://thomasgriffinmedia.com/
Version: 1.0.0
License: GNU General Public License v2.0 or later
License URI: http://www.opensource.org/licenses/gpl-license.php
*/
/*
Copyright 2012 Thomas Griffin (email : thomas@thomasgriffinmedia.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
*/
// ======================================================================= //
// PLACE ALL OF YOUR CUSTOM CODE BELOW THIS COMMENT BLOCK //
// ======================================================================= //
add_filter( 'the_content', 'wwm_catch_as_shortcode', 5, 1 );
add_action( 'wp_enqueue_scripts', 'wwm_register_validation_messages', 20, 0 );
function wwm_catch_as_shortcode( $content ) {
if ( strpos( $content, '[wwm_survey id=' ) ) {
wp_enqueue_script( 'validation-messages-nl' );
}
return $content;
}
function wwm_register_validation_messages() {
wp_register_script( 'validation-messages-nl', plugins_url( 'messages_nl.js', __FILE__ ), array( 'jquery', 'jquery-validation-plugin' ), '1.13.1', true );
}
// ======================================================================= //
// PLACE ALL OF YOUR CUSTOM CODE ABOVE THIS COMMENT BLOCK //
// ======================================================================= //
add_filter( 'http_request_args', 'cwwp_hide_plugin_updates', 5, 2 );
/**
* Removes the plugin from repo update checks to avoid errant updates.
*
* @since 1.0.0
* @link http://markjaquith.wordpress.com/2009/12/14/excluding-your-plugin-or-theme-from-update-checks/
*
* @param array $r The request data
* @param string $url The URL which is being pinged for updates
* @return array $r The amended request data
*/
function cwwp_hide_plugin_updates( $r, $url ) {
/** If the URL is not from the WordPress API, return the request */
if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) )
return $r;
/** Unset our plugin if it exists */
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[plugin_basename( __FILE__ )] );
unset( $plugins->active[array_search( plugin_basename( __FILE__ ), $plugins->active )] );
$r['body']['plugins'] = serialize( $plugins );
/** Return the request */
return $r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment