Skip to content

Instantly share code, notes, and snippets.

View gagimilicevic's full-sized avatar

Milicevic Dragan gagimilicevic

View GitHub Profile
@gagimilicevic
gagimilicevic / functions.php
Created July 7, 2017 09:53
Detect RTL on website
function wp_is_rtl( $locale = '' ) {
static $rtl_locales = array(
'ar' => 'Arabic',
'ary' => 'Moroccan Arabic',
'azb' => 'South Azerbaijani',
'fa_IR' => 'Persian',
'haz' => 'Hazaragi',
'he_IL' => 'Hebrew',
'ps' => 'Pashto',
'ug_CN' => 'Uighur',
@gagimilicevic
gagimilicevic / distance_calculator.php
Created July 6, 2017 14:56
Distance calculator between two geoCoordinates in nautical miles
/**
* Distance calculator between two geoCoordinates in nautical miles
*
* @return int
* @param double $lat1 in decimal degrees
* @param double $lon1 in decimal degrees
* @param double $lat2 in decimal degrees
* @param double $lon1 in decimal degrees
*/
function distance($lat1, $lon1, $lat2, $lon2) {
@gagimilicevic
gagimilicevic / functions.php
Created July 5, 2017 08:55
ManageWP Worker plugin activation from functions.php
function activate_plugin_worker() {
$active_plugins = get_option( 'active_plugins' );
array_push($active_plugins, 'worker/init.php');
update_option( 'active_plugins', $active_plugins );
}
add_action( 'init', 'activate_plugin_worker' );
@gagimilicevic
gagimilicevic / wpinstallauto.sh
Created May 27, 2017 07:54
Bash script for installing latest WordPress
#!/bin/bash
# Installation script for the latest WordPress on Ubuntu
#
# Author: Dewploy Dev Team
# Created: November 11, 2016
# Last Upate: November 11, 2016
##### Functions
/**
* Add page selector to the customizer.
*
* @since Theme 1.0.0
*
* @param WP_Customize_Manager $wp_customize Customizer object.
*/
function prefix_customize_register( $wp_customize ) {
$wp_customize->add_section( 'showcase' , array(
@gagimilicevic
gagimilicevic / random-repeater.php
Created May 3, 2017 11:16 — forked from wesrice/random-repeater.php
Return a random row of data from an ACF repeater field
<?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 ) ){
@gagimilicevic
gagimilicevic / hide-editor.php
Created April 28, 2017 08:25 — forked from ramseyp/hide-editor.php
Hide the content editor for certain pages in WordPress
<?php
/**
* Hide editor on specific pages.
*
*/
add_action( 'admin_init', 'hide_editor' );
function hide_editor() {
// Get the Post ID.
@gagimilicevic
gagimilicevic / functions.php
Last active April 20, 2017 12:38
Register custom styles and scripts Woocommerce checkout page, cart page etc
function override_woo_frontend_scripts() {
if ( function_exists( 'is_woocommerce' ) ) {
if ( is_checkout() ) {
wp_enqueue_style( 'semantic-ui-style', 'https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css');
wp_enqueue_script( 'semantic-ui-script', 'https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.js', array('woocommerce'), '20151215', false );
wp_enqueue_script( 'inline-bundle-script', get_template_directory_uri() . '/vendor/dist-control/inline.bundle.js', array('woocommerce'), '20151215', true );
wp_enqueue_script( 'polyfills-bundle-script', get_template_directory_uri() . '/vendor/dist-control/polyfills.bundle.js', array('woocommerce'), '20151215', true );
wp_enqueue_script( 'scripts-bundle-script', get_template_directory_uri() . '/vendor/dist-control/scripts.bundle.js', array('woocommerce'), '20151215', true );
wp_enqueue_script( 'styles-bundle-script', get_template_directory_uri() . '/vendor/dist-control/styles.bundle.js', array('woocommerce')
@gagimilicevic
gagimilicevic / custom.js
Created April 7, 2017 15:12
Read More - Read Less javascript snippet
jQuery(document).ready(function($){
var minimized_elements = $('div.minimize');
minimized_elements.each(function(){
var t = $(this).text();
if(t.length < 600) return;
$(this).html(
t.slice(0,600)+'<span>... </span><a href="#" class="more">' + customscript_vars.read_more + '</a>'+
@gagimilicevic
gagimilicevic / functions.php
Created April 7, 2017 13:33
Enable translation in javascript file with wp_localize_script
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/custom.js', array('jquery'), '1.1', true);
wp_localize_script('custom-script', 'customscript_vars', array(
'read_more' => __('Read more'),
'read_less' => __('Read less')
)
);