Skip to content

Instantly share code, notes, and snippets.

View damianwajer's full-sized avatar

Damian Wajer damianwajer

View GitHub Profile
@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&TB_iframe=true');
window.send_to_editor = function (html) {
var imgUrl = $("img", html).attr("src");
$area.find(".image-url").val(imgUrl);
@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 / 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 / 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 / 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 / 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 / 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 / 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 / wp-manage-comments.sql
Last active August 29, 2015 14:11
[WordPress] Remove comments support
/* thanks to: http://www.catswhocode.com/blog/manage-wordpress-comments-using-sql */
/* Delete all spam comments */
DELETE from wp_comments WHERE comment_approved = 'spam';
/* Delete all comments between two dates */
DELETE FROM wp_comments
WHERE comment_date > '2013-11-15 01:10:04'
AND comment_date <= '2013-11-20 00:10:04';
@damianwajer
damianwajer / limit-text-length.php
Last active February 28, 2022 11:35
[PHP] Limit text length by characters
<?php
/**
* limit_text_length
* Function to limit text length by characters.
*
* @param string $string
* @param int $length
*
* @return string
*/