Skip to content

Instantly share code, notes, and snippets.

View zzap's full-sized avatar

Milana Cap zzap

View GitHub Profile
@zzap
zzap / pluralize-string.php
Created September 30, 2016 19:03
Properly pluralize string.
<?php
/**
* Define irregular plurals
*
* @return array Array of irregular plurals
*/
function zzap_irregular_plurals() {
$irregulars = array(
'man' => 'men',
@zzap
zzap / wp-custom-meta.php
Created September 30, 2016 18:44
Check if custom field is populated and echo it or return its value, if any.
<?php
/**
* Custom meta
*
* Check if the field is populated and echo it
* or return its value, if any.
*
* @link https://developer.wordpress.org/reference/functions/get_post_meta/
*
* @param string $custom_field Unique id for custom field
@zzap
zzap / wp-strip-inactive-shortcodes.php
Created September 30, 2016 18:21
Strip shortcode tags for inactive shortcodes and leave content as is.
<?php
/**
* Hook
*/
add_filter( 'the_content', 'remove_inactive_shortcodes' );
/**
* Remove inactive shortcodes
*
* Make sure inactive shortcodes don't leave their junk in the content.
* We are striping their tags, leaving content as is. This function is attached to
@zzap
zzap / wp-cpt-post-classes.php
Created September 30, 2016 18:14
Custom post classes for custom post types based on taxonomies Default 'posts' in WordPress have, among other, classes based on their categories and tags. This function adds post classes to custom post types based on taxonomies.
<?php
/**
* Hook
*/
add_filter( 'post_class' , 'zzap_cpt_post_class' );
/**
* Custom post classes for custom post types based on taxonomies
*
* Default 'posts' in WordPress have, among other, classes
* based on their categories and tags. This function adds
@zzap
zzap / wp-global-var.php
Created September 30, 2016 18:06
The most used WordPress core functions in one global var for easier sitewide usage.
<?php
/**
* Global variables
*
* The most used WordPress core functions
* in one global var for easier sitewide usage.
*
* @return array Returns array
*/
function zzap_global_site() {
@zzap
zzap / wp_get_mime_types
Created September 28, 2016 08:02 — forked from davidmottershead/wp_get_mime_types
WordPress MIME types July 2014
function wp_get_mime_types() {
/**
* Filter the list of mime types and file extensions.
*
* This filter should be used to add, not remove, mime types. To remove
* mime types, use the 'upload_mimes' filter.
*
* @since 3.5.0
*
* @param array $wp_get_mime_types Mime types keyed by the file extension regex
@zzap
zzap / _decimal.scss
Created February 8, 2016 12:18 — forked from terkel/_decimal.scss
Rounding decimals in Sass
// _decimal.scss | MIT License | gist.github.com/terkel/4373420
// Round a number to specified digits.
//
// @param {Number} $number A number to round
// @param {Number} [$digits:0] Digits to output
// @param {String} [$mode:round] (round|ceil|floor) How to round a number
// @return {Number} A rounded number
// @example
// decimal-round(0.333) => 0
@zzap
zzap / WordPress maximum upload file size with .htaccess
Last active May 25, 2016 12:11
WordPress - change maximum upload file size with .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
.....
</IfModule>
# END WordPress
# this is not working any more
# 500 internal error is being returned
php_value upload_max_filesize 64M
<?php
$last_modified = human_time_diff( the_modified_date('U','','', false), current_time('timestamp') );
$number_of_x = preg_replace('/[^0-9]*/', '', $last_modified);
if ( strpos( $last_modified, 'min' ) || strpos( $last_modified, 'hour' ) || strpos($last_modified, 'sec' ) ) {
$wiki_date = $last_modified;
} elseif ( $number_of_x > 365 ) {
$wiki_date = __( 'a long time' );
} elseif ( $number_of_x >= 180 ) {
$wiki_date = __( 'less than a year' );
} elseif ( $number_of_x >= 60 ) {
<?php
// Get the repeater field
$repeater = get_field( 'repeater_field_name' );
// Get a random rows. Change the second parameter in array_rand() to how many rows you want.
$random_rows = array_rand( $repeater, 2 );
// Loop through the random rows if more than one is returned
if( is_array( $random_rows ) ){