Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Retrive ID from attachment URL
* Source http://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/
*/
function get_id_from_attachment_url($attachment_url = '') {
global $wpdb;
@alenabdula
alenabdula / git_cheat_sheet.sh
Last active November 20, 2022 16:37
Git Cheat Sheet
# Create git repository
git init
# Add all files to staging area
git add .
# Check current status
git status
# Commit staged changes for tracking
@alenabdula
alenabdula / wordpress-rewrite.php
Created February 1, 2016 15:46
WordPress Custom Post Type & Taxonomy rewrite notes
<?php
/**
* WordPress Custom Post Type & Taxonomy rewrite notes:
* When creating CPT/Tax always rewrite the slug and make sure 'with_front' is set to false
* In the rewrite section add following
*/
$args = array(
'rewrite' => array(
'slug' => 'SLUG', # Used as pretty permalink text (i.e. /tag/) - defaults to $taxonomy (taxonomy's name slug)
@alenabdula
alenabdula / GravityForm-Dynamic-Selects.php
Created December 22, 2015 18:47
Gravity form dynamically populate select drop down with taxonomy terms
<?php
/**
* --------------------------------------------------
* Gravity Form dynamically populate drop-down
* select for Questions form ID 15
* 'gform_pre_render_14' - _14 represents form ID to filter
* --------------------------------------------------
*/
add_filter( 'gform_pre_render_14', 'pre_populate_gravity_select_for_MY_TAX' );
add_filter( 'gform_pre_validation_14', 'pre_populate_gravity_select_for_MY_TAX' );
@alenabdula
alenabdula / LetsEncrypt.sh
Created December 20, 2015 20:38
Let's Encrypt Install Process
# Let's Encrypt
# Install Process
cd ~
git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
sudo ./letsencrypt-auto certonly --standalone --agree-tos --redirect --duplicate --text --email EMAIL@EXAMPLE.COM -d EXAMPLE.COM -d WWW.EXAMPLE.COM
# Nginx Configuration
# https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/directive-only/ssl.conf
# Path to Certificates
# /etc/letsencrypt/live/EXAMPLE.COM/privkey.pem
function convert( num ) {
var x = '';
[1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1].map(
function( obj, i ) {
while ( num >= obj ) {
x += ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'][i];
num -= obj;
}
}
);
@alenabdula
alenabdula / PHPUnitTestSnippet.sublime-snippet
Last active December 20, 2015 14:05
Sublime Text snippet to automate process of creating a PHPUnit test case
<snippet>
<content>
<![CDATA[
/** @test */
function ${1/\s/_/g}()
{
${0:// ${1:type method name with spaces when done press tab}}
}
]]>
</content>
@alenabdula
alenabdula / timber-custom-headers.php
Created December 11, 2015 18:24
Sets proper headers for RSS Feeds using Timber Library and Twig Templating Engine
<?php
/**
* Sets proper headers for RSS Feeds using Timber Library and Twig Templating Engine
* Fallbacks:
* 1. application/rss+xml,
* 2. application/rdf+xml,
* 3. application/atom+xml,
* 4. application/xml,
* 5. text/xml
*/