Skip to content

Instantly share code, notes, and snippets.

View damianwajer's full-sized avatar

Damian Wajer damianwajer

View GitHub Profile
@damianwajer
damianwajer / clearForm.js
Last active August 29, 2015 14:16
[JavaScript] [jQuery] Clear form elements
function clearFormElements( element ) {
// clear form elements
$( element ).find( ":input" ).each( function () {
switch ( this.type ) {
case "text":
case "email":
case "number":
case "password":
case "tel":
case "date":
@damianwajer
damianwajer / wpsc-clear-cache.php
Created August 25, 2015 12:27
[WordPress] [WP Super Cache] Manually clear the cache from the code
<?php
/**
* Clear the cache on specific page
*/
if ( function_exists( 'wp_cache_post_change' ) ) {
$GLOBALS["super_cache_enabled"] = 1;
wp_cache_post_change( $post_id );
}
/**
@damianwajer
damianwajer / wp-flickr-album-shortcode.php
Created August 28, 2015 14:09
[WordPress] Display gallery from Flickr album with simple shortcode
<?php
/**
* Flickr Gallery shortcode
*
* @author Damian Wajer
* @param $atts
* @return string
*/
function prefix_flickr_gallery_shortcode( $atts ) {
$a = shortcode_atts( array(
@damianwajer
damianwajer / wp-extra-buttons.php
Last active April 6, 2017 09:57
[WordPress] Add extra buttons to WordPress editor (TinyMCE)
<?php
/**
* Additional buttons in TinyMCE editor
*
* @param $buttons
*
* @return array
*/
function wp_extra_buttons( $buttons ) {
$buttons[] = 'hr';
@damianwajer
damianwajer / checkbox.scss
Last active December 15, 2020 13:01
[HTML][CSS][SASS] Custom select, checkbox, radio example with pure CSS | Live demo: https://www.damianwajer.com/blog/custom-styled-form-controls/
// Checkbox
.checkbox-custom {
position: absolute;
opacity: 0;
&__icon-state {
display: inline-block;
margin-right: 5px;
padding: 0;
width: 20px;
@damianwajer
damianwajer / initSelectToggle.js
Last active October 15, 2015 13:25
[JavaScript][jQuery] Example of how to toggle Bootstrap plugin with <select> <option>
/**
* Add support for <select> <option> to Bootstrap plugins
*
* @link http://getbootstrap.com/javascript/
*/
$(".js-select-toggle").on("change", function () {
var $select = $(this);
$select.find("option").each(function () {
var $option = $(this),
@damianwajer
damianwajer / wp-allowed-html.php
Created November 5, 2015 15:27
[WordPress] Allow more HTML tags and attributes in post context.
<?php
/**
* Filter allowed HTML elements.
*
* @param $allowedposttags
* @param $context
*
* @return array
*/
function prefix_filter_allowed_html( $allowedposttags, $context ) {
@damianwajer
damianwajer / admin.js
Last active November 18, 2015 12:09
[WordPress] How to add multiple media uploader buttons on custom option page (an example).
$(".image-upload-button").on("click", function (e) {
var $area = $(this).closest(".image-upload-area"),
send_to_editor_backup = window.send_to_editor;
tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
window.send_to_editor = function (html) {
var imgUrl = $("img", html).attr("src");
$area.find(".image-url").val(imgUrl);
@damianwajer
damianwajer / .maintenance
Last active December 12, 2020 14:58
WordPress Maintenance mode with .maintenance file in root directory (temporary solution). Better option is to use something like: https://wordpress.stackexchange.com/questions/169600/redirect-visitors-to-a-temporary-maintenance-page/169610#169610
<?php $upgrading = time();
@damianwajer
damianwajer / wp-media-categories.php
Created March 19, 2016 14:06
[WordPress] How to add media categories
<?php
/**
* Taxonomy for media files.
*/
function init_media_categories() {
register_taxonomy( 'media_cat', 'attachment', array(
'label' => __( 'Categories' ),
'hierarchical' => true,
'public' => false,
'show_ui' => true,