Skip to content

Instantly share code, notes, and snippets.

View gagimilicevic's full-sized avatar

Milicevic Dragan gagimilicevic

View GitHub Profile
@gagimilicevic
gagimilicevic / upload-a-file.MD
Created September 27, 2022 10:47 — forked from ahmadawais/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@gagimilicevic
gagimilicevic / npm.upgrade
Created May 3, 2022 14:46
Upgrading Node.js to latest version
npm cache clean -f
npm install -g n
n stable
@gagimilicevic
gagimilicevic / gist:05af90509f238bb8dcc0c0d393bc8c91
Created June 22, 2021 13:37 — forked from Marian0/gist:4d689c33164bc9daf0e1
Disable wordpress Frontend by htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/wp-admin
RewriteCond %{REQUEST_URI} !/wp-includes
RewriteCond %{REQUEST_URI} !/wp-login\.php$
RewriteCond %{REQUEST_URI} !/wp-content
RewriteCond %{REQUEST_URI} !/feed
@gagimilicevic
gagimilicevic / gist:e65bf1db6611d2042bf34cbc1586fd2f
Created April 15, 2021 09:29 — forked from Braunson/gist:8aa2e0084098c84f0d8f
jQuery $.browser is deprecated, here's a drop in working fix to resolve $.browser errors so you can continue using $.browser.
(function( $ ){
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || [];
return {
@gagimilicevic
gagimilicevic / basic-dropdown-usage.php
Created February 18, 2021 15:33 — forked from joshuadavidnelson/basic-dropdown-usage.php
Filter wp_dropdown_categories by post type.
<?php
/**
* Using wp_dropdown_categories with the post type filter applied.
*
* @link https://joshuadnelson.com/category-taxonomy-dropdown-filtered-by-post-type/
*/
// Taxonomy dropdown arguments
$args = array(
'taxonomy' => 'department',
// Stop all ajax request by http://tjrus.com/blog/stop-all-active-ajax-requests
$.xhrPool = []; // array of uncompleted requests
$.xhrPool.abortAll = function() { // our abort function
$(this).each(function(idx, jqXHR) {
jqXHR.abort();
});
$.xhrPool.length = 0
};
$.ajaxSetup({
@gagimilicevic
gagimilicevic / aux-functions.php
Created December 10, 2020 15:16 — forked from eduwass/duplicate-post.php
Programmatically duplicating a WordPress post
<?php
/**
* Duplicates a post & its meta and it returns the new duplicated Post ID
* @param [int] $post_id The Post you want to clone
* @return [int] The duplicated Post ID
*/
function duplicate($post_id) {
$title = get_the_title($post_id);
$oldpost = get_post($post_id);
@gagimilicevic
gagimilicevic / git.txt
Created December 8, 2020 14:34
`git` discard all local changes/commits and pull from upstream
git discard all local changes/commits and pull from upstream
git reset --hard origin/master
git pull origin master
<?php
//create and modifying dates month
//creating new current date
$date_from = date('Y-m-01'); //first day of the current month
$date_to = date('Y-m-t'); //last day of the current month using t, use d for
//creating previous month date
$date_from_prev = date('Y-m-01', strtotime("first day of last month"));
$date_to_prev = date('Y-m-t', strtotime("last day of last month"));
@gagimilicevic
gagimilicevic / gist:f657f7756e06afbf4ed7da120dc313e3
Created June 19, 2020 11:12 — forked from thiamteck/gist:877276
JQuery Datepicker with Month and Year only
$(document).ready(function(){
$(".monthPicker").datepicker({
dateFormat: 'mm-yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();