Skip to content

Instantly share code, notes, and snippets.

@niksudan
niksudan / reorder_date.php
Last active August 29, 2015 14:07
Reorder date string [PHP]
<?php
/**
* Reorder date string
*
* @param string $input
* @param string $currentFormat
* @param string $newFormat
* @return string
*/
function reorder_date( $input, $currentFormat, $newFormat )
@niksudan
niksudan / pre_var_dump.php
Last active August 29, 2015 14:09
Formatted var_dump [PHP]
<?php
/**
* Formatted var_dump()
*
* @param variable $var
* @param string $title
* @return void
*/
function pre_var_dump( $var, $title = NULL )
{
@niksudan
niksudan / custom_posts.php
Last active August 29, 2015 14:10
Get posts loops [WordPress]
<?php
/**
* Using get_posts() function
*/
$custom_posts = get_posts( array(
'post_type' => 'post_type_name',
) );
$tmp_post = $post; foreach ( $custom_posts as $post ) : setup_postdata( $post );
// loop
@niksudan
niksudan / truncate.php
Last active August 29, 2015 14:10
Truncates a string [PHP]
<?php
/**
* Truncates a string
*
* @param string text
* @param int limit
* @return string
*/
function truncate( $text, $limit )
{
@niksudan
niksudan / get_thumbnail_url.php
Last active August 29, 2015 14:10
Get post thumbnail URL [WordPress]
<?php
/**
* Get post thumbnail URL
*
* @param string $size
* @return string
*/
function get_thumbnail_url( $size = 'thumbnail' )
{
global $post;
@niksudan
niksudan / flex.css
Last active August 29, 2015 14:11
Flexbox class [CSS]
/**
* Generic flexbox class
*/
.flex {
display: flex;
align-items: stretch;
justify-content: center;
}
@media (max-width: 750px) { .flex { display: inherit; } }
@niksudan
niksudan / download_file.php
Last active August 29, 2015 14:11
Download a file [PHP]
<?php
/**
* Download a file
*
* @param string $file
* @return void
*/
function download_file( $file )
{
if ( file_exists($file) && $file != $_SERVER['DOCUMENT_ROOT'] ) {
@niksudan
niksudan / register_post_type_labels.php
Last active August 29, 2015 14:11
Assign custom post type labels quickly [WordPress]
<?php
/**
* Assign custom post type labels quickly
*
* @param string $singular
* @param string $plural
* @return array
*/
function register_post_type_labels( $singular, $plural = NULL )
{
@niksudan
niksudan / transition-mixin.scss
Created December 13, 2014 13:39
CSS animation mixin [Sass]
@mixin transition($transition-property, $transition-time: 0.3s, $method: ease-in-out) {
-webkit-transition: $transition-property $transition-time $method;
-moz-transition: $transition-property $transition-time $method;
-ms-transition: $transition-property $transition-time $method;
-o-transition: $transition-property $transition-time $method;
transition: $transition-property $transition-time $method;
}
@niksudan
niksudan / ajax_form_submit.js
Last active August 29, 2015 14:11
Ajax form submission [jQuery]
/**
* jQuery Ajax Form Submission
*/
jQuery( document ).ready(function( $ ) {
$( document ).on( 'click', 'input[type="submit"]', function() {
var form = $( this ).closet( 'form' );
$.post( form.attr( 'action' ), form.serialize(), function( data ) {
// Success