Skip to content

Instantly share code, notes, and snippets.

View damianwajer's full-sized avatar

Damian Wajer damianwajer

View GitHub Profile
@damianwajer
damianwajer / wp-auto-update.php
Last active August 29, 2015 14:08
[WordPress] Automatic Background Updates for WordPress core, plugins and themes.
<?php
/**
* WordPress Automatic Background Updates
*
* @link http://codex.wordpress.org/Configuring_Automatic_Background_Updates
* @link http://www.sitepoint.com/a-guide-to-updating-wordpress/
*/
// disable automatic updates
add_filter( 'automatic_updater_disabled', '__return_true' );
@damianwajer
damianwajer / wp-shortcode-select.php
Last active August 29, 2015 14:08
[WordPress] Add Shortcode Select to WP Editor
<?php
/*
* Add Shortcode Select to WP Editor
*/
function custom_shortcode_select() {
// display shortcode select only on edit screen
$screen = get_current_screen();
if ( $screen != null && ( $screen->base == 'post' || $screen->base == 'edit-tags' ) ) {
@damianwajer
damianwajer / wp-get-posts-array.php
Created November 7, 2014 09:25
[WordPress] Function to get an array with all posts from specific post type
<?php
/**
* Get an array with all posts from specific post type
*
* @param string $post_type retrieves posts by Post Types
*
* @return array with post ID as a key and post title as a value
*/
function get_posts_array( $post_type = 'post' ) {
@damianwajer
damianwajer / taxonomy.php
Last active August 29, 2015 14:08
[WordPress] Taxonomy template
<?php
/**
* Taxonomy template
* @link http://codex.wordpress.org/Class_Reference/WP_Query
*/
// Protect against arbitrary paged values
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$taxonomy = get_query_var( 'taxonomy' );
$term = get_query_var( 'term' );
@damianwajer
damianwajer / archive-post_type.php
Created November 7, 2014 10:16
[WordPress] Template to retrieve the terms in a taxonomy
<?php
/**
* Template to retrieve the terms in a taxonomy
* @link http://codex.wordpress.org/Function_Reference/get_terms
*/
$terms = get_terms( 'section' );
echo '<ul>';
@damianwajer
damianwajer / admin.js
Last active April 17, 2018 10:46
[WordPress] Conditional Meta Box / Custom fields depending on page template in WP Admin
jQuery( document ).ready( function ( $ ) {
var $pageTemplate = $( "#page_template" ),
$metaBoxID = $( "#meta_box_id" );
$pageTemplate.on( "change", function () {
if ( $( this ).val() == "templates/page-custom.php" ) {
$metaBoxID.show();
} else {
$metaBoxID.hide();
}
@damianwajer
damianwajer / fix.css
Last active September 8, 2021 00:26
[CSS] Fix for font smoothing / antialiasing on Mac OS X (too heavy fonts)
.font-fix {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}
@damianwajer
damianwajer / isMobile.js
Last active August 29, 2015 14:10
Detect mobile browser in JavaScript
if (/android|webos|iphone|ipad|iemobile|windows phone|ipod|bb10|blackberry/i.test(navigator.userAgent.toLowerCase())) {
// Code goes here
}
/*
* Code from http://detectmobilebrowsers.com
* License: public domain
*/
window.mobilecheck = function() {
@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
*/
@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';