Skip to content

Instantly share code, notes, and snippets.

@dannyconnolly
dannyconnolly / translate_woocommerce.php
Created December 18, 2015 13:22
Change SKU text label in woocommerce to Product Code
function translate_woocommerce($translation, $text, $domain) {
if ($domain == 'woocommerce') {
switch ($text) {
case 'SKU':
$translation = 'Product Code';
break;
case 'SKU:':
$translation = 'Product Code:';
break;
@dannyconnolly
dannyconnolly / modal.js
Last active February 4, 2021 19:19
Vanilla JS Modal
(function() {
// Define constructor
this.Modal = function() {
// Create global element references
this.closeButton = null;
this.modal = null;
this.overlay = null;
// Determine proper prefix
/**
* Get information about available image sizes
*/
function get_image_sizes($size = '')
{
global $_wp_additional_image_sizes;
$sizes = array();
$get_intermediate_image_sizes = get_intermediate_image_sizes();
@dannyconnolly
dannyconnolly / Remove query strings from static resources in wordpress
Created March 19, 2014 10:52
Remove query strings from static resources in wordpress
function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
@dannyconnolly
dannyconnolly / parse.php
Created September 19, 2016 23:06
parse wp feed
<?php
$article_string = file_get_contents( $url );
$article_string = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/', 'filter_xml', $article_string);
$article_xml = simplexml_load_string($article_string);
$namespaces = $article_xml->getNamespaces(true); // get namespaces
function filter_xml($matches) {
return trim(htmlspecialchars($matches[1]));
}
//
// foreach ($article_xml->channel->item as $item) {
@dannyconnolly
dannyconnolly / Hide plugin menu items
Created January 23, 2014 09:04
Hide plugin menu items from menu
function my_remove_menu_pages() {
remove_menu_page('plugin_slug');
remove_menu_page('plugin_slug');
}
add_action( 'admin_menu', 'my_remove_menu_pages' );
@dannyconnolly
dannyconnolly / Hide plugins from admin menu
Created January 23, 2014 09:03
Hide plugins from admin menu even for administrators
/*
* Hide plugins
*/
function hide_essential_plugins() {
global $wp_list_table;
$hidearr = array('plugin_name', 'plugin_name');
$myplugins = $wp_list_table->items;
foreach ($myplugins as $key => $val) {
if (in_array($key,$hidearr)){
unset($wp_list_table->items[$key]);
@dannyconnolly
dannyconnolly / Custom validation on Contact form 7 plugin
Last active January 2, 2016 02:49
Custom validation on Contact form 7 plugin
add_filter( 'wpcf7_validate_text', 'your_validation_filter_func', 10, 2 );
add_filter( 'wpcf7_validate_text*', 'your_validation_filter_func', 10, 2 );
function your_validation_filter_func( $result, $tag ) {
$type = $tag['type'];
$name = $tag['name'];
if ( 'your-id-number-field' == $name ) {
$the_value = $_POST[$name];
@dannyconnolly
dannyconnolly / Hide update notifixcations for wordpress and plugins
Last active January 1, 2016 23:29
Hide update notifixcations for wordpress and plugins
/**
* Hide update notifications
*/
add_action('admin_menu','wphidenag');
function wphidenag() {
remove_action( 'admin_notices', 'update_nag', 3 );
}
/**
* Hide plugin update notifications
@dannyconnolly
dannyconnolly / REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN
Created December 21, 2013 17:23
REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN
// REMOVE THE WORDPRESS UPDATE NOTIFICATION FOR ALL USERS EXCEPT SYSADMIN
global $user_login;
get_currentuserinfo();
if (!current_user_can('update_plugins')) { // checks to see if current user can update plugins
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}