Skip to content

Instantly share code, notes, and snippets.

View gdarko's full-sized avatar
Crunching code, one line at a time.

Darko Gjorgjijoski gdarko

Crunching code, one line at a time.
  • Self-employed
  • The Internet
  • 19:25 (UTC +02:00)
View GitHub Profile
@gdarko
gdarko / change-privacy.php
Created March 23, 2020 23:05
Change the view privacy for the new Vimeo uploads from WP Vimeo Videos PRO plugin
<?php
/**
* Change the default view privacy in WP Vimeo Videos PRO
* This only applies if you have Vimeo Plus, Vimeo PRO, Vimeo Business (or higher level) account.
* @url https://developer.vimeo.com/api/guides/videos/interact#set-vimeo-privacy
*/
function dgv_default_privacy_1821210($privacy) {
$privacy = 'unlisted';
return $privacy;
@gdarko
gdarko / str_contains.php
Last active May 2, 2024 02:43
str_contains() was introduced in PHP8. This is a polyfill for PHP7 or lower.
<?php
if (!function_exists('str_contains')) {
/**
* Check if substring is contained in string
*
* @param $haystack
* @param $needle
*
* @return bool
*/
@gdarko
gdarko / class-email-post-authors.php
Last active July 15, 2019 20:46
Email Blog Authors Example
<?php
if ( class_exists( 'WP_Batch' ) ) {
/**
* Class Email_Blog_Authors
*/
class Email_Post_Authors extends WP_Batch {
/**
* Unique identifier of each batch
@gdarko
gdarko / gravityforms_username.php
Last active April 26, 2019 16:39
GravityForms + User Registrations plugin: Use first name and last name in the form to generate username out of both. Append number if the username exists.
<?php
/**
* Check if there is still pending registration for specific username
* @param $username
*
* @return bool
*/
function dg_check_pending_registration($username) {
global $wpdb;
$table = $wpdb->prefix . 'signups';
@gdarko
gdarko / class-dg-image-import.php
Created December 26, 2018 09:43
Import images to media library from specific directory.
<?php
/**
* Class DG_Image_Import
* @author Darko Gjorgjijoski <dg@darkog.com>
* @license GPLv2
* @copyright 2019
*
* Handles import of images from a specific subfolder of your root site dir (eg public_html/your_data_dir) to WordPress media library.
* Has basic lock/unlock functionality to avoid colisions.
@gdarko
gdarko / form.php
Last active June 10, 2019 12:11
Upload image using WordPress media uploader
<form method="POST">
<div class="form-row">
<label>Name</label>
<input type="text" placeholder="Enter name">
<div>
<div class="form-row">
<?php
$key = 'profile_picture';
$placeholder = 'https://placehold.it/150x150?text=IMG';
$current_value = get_user_meta(get_current_user_id(), $key, true);
@gdarko
gdarko / gb.sh
Created May 29, 2018 15:25
Quick Geekbench 3 Benchmark for Linux
#!/bin/bash
sudo apt-get install libc6:i386 libstdc++6:i386
wget http://cdn.primatelabs.com/Geekbench-3.4.2-Linux.tar.gz
tar -zxvf Geekbench-3.4.2-Linux.tar.gz
cd dist/Geekbench-3.4.2-Linux/
./geekbench
@gdarko
gdarko / general.php
Last active May 31, 2019 23:35
Useful Vanilla PHP and WordPress helper functions.
<?php
// This file contains general useful PHP functions that can be included everywhere.
/**
* Wrapper for writing the interactions to /wp-content/uploads/ file
*
* @param $message
* @param string $filename
*/
function dg_log_write( $message, $filename = "log.txt" ) {
@gdarko
gdarko / cloudflare-update-record.sh
Last active March 2, 2018 00:20 — forked from benkulbertis/cloudflare-update-record.sh
Cloudflare API v4 Dynamic DNS Update in Bash
#!/bin/bash
# CHANGE THESE
auth_email="user@example.com"
auth_key="c2547eb745079dac9320b638f5e225cf483cc5cfdda41" # found in cloudflare account settings
zone_name="$1"
record_name="$2"
# MAYBE CHANGE THESE
ip=$(curl -s http://ipv4.icanhazip.com)
@gdarko
gdarko / methods.php
Last active May 2, 2018 14:23
WordPress REST Route Example
<?php
function dg_get_data() {
return array(
'name' => 'Darko Gjorgjijoski',
'age' => 23
);
}