Skip to content

Instantly share code, notes, and snippets.

@sardbaba
sardbaba / WP-Widget_Language_Chooser
Created May 2, 2014
Wordpress - A textual language chooser widget compatible with qTranslate and qTranslate-slug
View WP-Widget_Language_Chooser
/**
* A textual language chooser widget compatible with qTranslate and qTranslate-slug
* Author: Mauro Mascia
* License: WTFPL (www.wtfpl.net)
*/
class Widget_Language_Chooser extends WP_Widget {
function __construct() {
parent::__construct(
'widget_language_chooser',
View gist:11078290
Drupal.settings.isTouchDevice = function() {
return "ontouchstart" in window;
}
if ( Drupal.settings.isTouchDevice() ) {
Drupal.behaviors.jQueryMobileSlideShowTouchAdvance = {
attach: function(context, settings) {
self = Drupal.behaviors.jQueryMobileSlideShowTouchAdvance;
jQuery.each(jQuery(".views_slideshow_cycle_main.viewsSlideshowCycle-processed"), function(idx, value) {
value.addEventListener("touchstart", self.handleTouchStart);
@sardbaba
sardbaba / functions.js
Created Jun 13, 2013
Fallback to PNG if SVG is not supported. Note: of course, you must create the PNG version of the SVG image. Reference: http://toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script/
View functions.js
( function( $ ) {
$( window ).load( function() {
function supportsSVG() {
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect;
}
if (!supportsSVG()) {
var imgs = document.getElementsByTagName('img');
var dotSVG = /.*\.svg$/;
@sardbaba
sardbaba / wordpress-functions.php
Created May 14, 2013
Add a checkbox for the terms agreement and hooks into wp_authenticate to allow authentication or to display an error message.
View wordpress-functions.php
/**
* Add the terms agreement field
*/
function sardbaba_add_login_field() {
?>
<p class="forgetmenot">
<label for="terms-agreement">
<input name="terms-agreement" type="checkbox" id="terms-agreement" value="agree"> <?php _e( 'I Agree to the terms and conditions' ) ?>
</label>
</p>
@sardbaba
sardbaba / wordpress-function.php
Last active Dec 17, 2015
Hide Standard Shipping option when free shipping is available
View wordpress-function.php
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function sardbaba_hide_standard_shipping_when_free_is_available($available_methods) {
if (isset($available_methods['free_shipping']) AND isset($available_methods['flat_rate'])) {
// remove standard shipping option
unset($available_methods['flat_rate']);
}
@sardbaba
sardbaba / wordpress-function.php
Last active Dec 14, 2015
qtrans_generate_language_list() is a better version of the qtrans_generateLanguageSelectCode() function from qTranslate's Wordpress plugin, originally used to print the languages as an HTML select. This function receive an optional string for the separator that will be echoed and it is able to show your languages as spans followed by separators:…
View wordpress-function.php
/**
* Language list Code for non-Widget users
*
* @global array $q_config
* @param string $sep
*/
function qtrans_generate_language_list($sep = " | ") {
global $q_config;
$languages = qtrans_getSortedLanguages();
$num_langs = count($languages);
@sardbaba
sardbaba / wordpress-function.php
Last active Apr 23, 2018 — forked from GaryJones/gist:1258784
An improved version of the original Jared/Gary version which checks for, in order, the presence of: 1) subcategory template ID 2) subcategory template slug 3) parent category ID 4) parent category slug 5) general category (category.php) You can use it in the function.php file of your theme.
View wordpress-function.php
/**
* Apply a template to all subcategories of a certain parent category.
*
* Initial work by Jared Atchison.
* http://www.jaredatchison.com/2011/10/02/taking-advantage-of-the-template_include-filter/
*
* Revisited by GaryJones https://gist.github.com/GaryJones/1258784
* https://gist.github.com/GaryJones/1258784
*
* An improved version of the original Jared/Gary version which checks for, in order, the presence of the templates:
@sardbaba
sardbaba / drupal-template.php
Last active Oct 13, 2015
Drupal | Omega | Transform the main menu into a select to be used into small screen sizes.
View drupal-template.php
// see also https://gist.github.com/3201854
function mytheme_menu_tree__main_menu($variables) {
return '<select class="mobile-main-menu" onchange="location = this.options[this.selectedIndex].value;">'
. $variables['tree'] . '</select>';
}
function mytheme_menu_link__main_menu($variables) {
global $base_url;
$e = $variables['element'];
@sardbaba
sardbaba / backup_all_dbs.sh
Created Nov 18, 2012
Backup All DB's and transfer to S3 with s3cmd + Rolling on the days of the weeks and on the weeks of the months + a montly backup (for paranoiac guys)
View backup_all_dbs.sh
#!/bin/bash
BACKUP_DIR="~/db_backups"
DBUSER=""
DBPASSWORD=""
BUCKET="your-unique-bucket-name"
FROM='"Backups" <backups@localhost>'
TO='"Admin" <admin@localhost>'
SUBJECT='Backup Log'
You can’t perform that action at this time.