Skip to content

Instantly share code, notes, and snippets.

View ahmu83's full-sized avatar
🎯
Focusing

Ahmad Karim ahmu83

🎯
Focusing
View GitHub Profile
<?php
/**
* Break a string into
* n number of equal
* parts to an array
*/
$string = 'This-is-a-long-string-that-has-some-random-text-with-hyphens!';
$string_length = strlen($string);
<?php
// This will break if the ENUM values have comma (,) in them
function get_enum_values($wpdb, $table, $field) {
$values = array();
$table = "{$wpdb->prefix}{$table}";
$query = "SHOW COLUMNS FROM {$table} WHERE Field = '{$field}'";
$results = $wpdb->get_results($query, ARRAY_A);
<?php
/**
* There is not a hard and fast rule to check if the
* current page is the blog page (the page you set in
* the settings to display blog posts). This is what the
* documentation says: "There is no conditional tag for the blog page."
*
* Read the full section here: https://codex.wordpress.org/Conditional_Tags
*
* Not sure if there is another way to achieve this!
<!DOCTYPE html>
<html>
<head>
<title>Simple CSS Loading Icon</title>
</head>
<style type="text/css" media="screen">
body {
margin-top: 150px;
<?php
/**
* Function to check for more than one
* array keys of a long/nested associative array.
*
* i.e, instead of doing this $var['key1']['key2'] (which will result in undefined
* notice if the key/index does not exist) you can do this isset_key($var, 'key1', 'key2')
*
* @param array $var Array variable
<!-- Transparent GIF Image Favicon -->
<link rel="icon" href="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" type="image/gif">
<!-- Black GIF Image Favicon -->
<link rel="icon" href="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" type="image/gif">
<!-- Transparent PNG Image Favicon -->
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" type="image/png">
@ahmu83
ahmu83 / copy-to-clipboard-bookmarklet.md
Created January 4, 2022 21:52 — forked from stefanmaric/copy-to-clipboard-bookmarklet.md
Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard

Copy-to-clipboard Bookmarklet

Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard.

This is the base javascript:

(function (text) {
  var node = document.createElement('textarea')
  var selection = document.getSelection()
@ahmu83
ahmu83 / Javascript Cookie Helper.js
Last active June 15, 2023 10:45
Javascript Cookie Helper for easy cookie manipulation
<?php
/**
* This function retrieves post meta using a custom $wpdb query. There are two reasons for this approach.
* 1. When doing get_post_meta to query all the meta keys it returns an array or array
* 2. This function also queries for LIKE fields. i.e, get_post_meta2(1, 'first_name, last_name, hobby_%')
*
* TODO: distinct meta_key, meta_value
*
*/
@ahmu83
ahmu83 / wp-debug.php
Last active April 23, 2023 01:54
WP_DEBUG Toggler. Toggle WP_DEBUG using a URL parameter.
<?php
/**
* WP_DEBUG toggle for conveniently turning on and off from the a URL param "debug"
* Its good when working on a staging site where you need debug functionality on/off
*
* usage:
*
* Include this file in wp-config.php (include 'wp-debug.php';)
* Make sure to comment out all these constants in wp-config.php
*