Skip to content

Instantly share code, notes, and snippets.

View kodie's full-sized avatar
💻
#doworkson

Kodie Grantham kodie

💻
#doworkson
View GitHub Profile
<?php
function sideroad_login_logo() {
$ratio = (get_custom_header()->height / get_custom_header()->width);
$width = 320;
$height = ($width * $ratio);
?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url('<?php header_image(); ?>');
width: <?php echo $width; ?>px;
@kodie
kodie / meteorSettings.js
Created February 8, 2017 17:47
Meteor template helper to access public settings
Template.registerHelper('meteorSettings', function(settings) {
var setting = Meteor.settings.public;
if (settings) {
var eachSetting = settings.split('.');
for (i = 0; i < eachSetting.length; i++) {
setting = setting[eachSetting[i]];
}
}
return setting;
});
@kodie
kodie / Modify_HTML.php
Last active November 16, 2018 13:55
Use PHP to modify an HTML fragment with the proper encoding
<?php
$html = '<article class="grid-item"><p>Hello World</p></article><article class="grid-item"><p>Goodbye World</p></article>';
$head = '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>';
libxml_use_internal_errors(true);
$dom = new DOMDocument('1.0', 'utf-8');
$dom->loadHTML($head . $html);
$xpath = new DOMXPath($dom);
// Loop through all article.grid-item elements and add the "invisible" class to them
@kodie
kodie / wp_acf_tax_migrate.php
Created December 5, 2018 20:24
Migrate ACF field data to a taxonomy
<?php
$query = new WP_Query(array(
'post_type' => 'employee',
'posts_per_page' => -1
));
while($query->have_posts()) {
$query->the_post();
$taxonomy = 'department';
@kodie
kodie / wp_range_post_count.php
Last active July 23, 2019 19:35
WordPress pagination indicator "Showing 20 – 29 of 138 posts"
<?php
$paged = max(1, (int) $wp_query->query_vars['paged']);
$first_post_index = $paged === 1 ? 1 : ((($paged - 1) * (int) $wp_query->query_vars['posts_per_page']) + 1);
$last_post_index = (($first_post_index + (int) $wp_query->post_count) - 1);
echo "Showing {$first_post_index} – {$last_post_index} of {$wp_query->found_posts} posts";
?>
eyJ2ZXJzaW9uIjoxLjMsImZlYXR1cmVzIjp7ImxvY2F0aW9uIjp7InJvb20iOnRydWUsIm91dHNpZGUiOnRydWV9fSwic3RvcmVzIjp7Indvb2QiOjI0MiwiZnVyIjoxMzUuNSwidGVldGgiOjU2LCJiYWl0Ijo0NywibWVhdCI6MTYuNSwic2NhbGVzIjoxNCwiY2hhcm0iOjMsImN1cmVkIG1lYXQiOjgzLCJjbG90aCI6NSwibGVhdGhlciI6MjZ9LCJjaGFyYWN0ZXIiOnt9LCJpbmNvbWUiOnsiZ2F0aGVyZXIiOnsiZGVsYXkiOjEwLCJzdG9yZXMiOnsid29vZCI6Mn0sInRpbWVMZWZ0Ijo0fSwiYnVpbGRlciI6eyJkZWxheSI6MTAsInN0b3JlcyI6eyJ3b29kIjoyfSwidGltZUxlZnQiOjEwfSwiaHVudGVyIjp7ImRlbGF5IjoxMCwic3RvcmVzIjp7ImZ1ciI6NiwibWVhdCI6Nn0sInRpbWVMZWZ0Ijo1fSwidHJhcHBlciI6eyJkZWxheSI6MTAsInN0b3JlcyI6eyJtZWF0IjotMSwiYmFpdCI6MX0sInRpbWVMZWZ0Ijo1fSwiY2hhcmN1dGllciI6eyJkZWxheSI6MTAsInN0b3JlcyI6eyJtZWF0IjotNSwid29vZCI6LTUsImN1cmVkIG1lYXQiOjF9LCJ0aW1lTGVmdCI6MX0sInRhbm5lciI6eyJkZWxheSI6MTAsInN0b3JlcyI6eyJmdXIiOjAsImxlYXRoZXIiOjB9LCJ0aW1lTGVmdCI6MX19LCJ0aW1lcnMiOnt9LCJnYW1lIjp7ImJ1aWxkZXIiOnsibGV2ZWwiOjR9LCJ0ZW1wZXJhdHVyZSI6eyJ2YWx1ZSI6NCwidGV4dCI6ImhvdCJ9LCJmaXJlIjp7InZhbHVlIjo0LCJ0ZXh0Ijoicm9hcmluZyJ9LCJidWlsZGluZ3MiOnsiY2FydCI6MSwidHJhcCI6NywiaHV0
@kodie
kodie / add_quotes_to_serialized_string.php
Created September 28, 2019 16:04
Adds double quotes back to a serialized string after they have been removed and then unserializes it to return an array
<?php
$str = unserialize(str_replace('s:0:;', 's:0:"";', preg_replace('/(.*?)(s:\d+:)([^{};]*?)([;}]+)/', '$1$2"$3"$4', $str)));
?>
@kodie
kodie / client-index.html
Created October 29, 2019 17:35
Meteor - Display inline SVG content
<template name="Home">
{{> Svg svg='my-svg'}}
</template>
@kodie
kodie / wp_hm_clear_transients.php
Created December 20, 2019 20:00
A function that allows you to clear all transients either by running the function, calling it via AJAX, or by calling it via CURL
<?php
// Clears all transients, can be ran via the function, via AJAX or by manually running:
// curl -d "action=hm_clear_transients" https://website.com/wordpress/wp-admin/admin-ajax.php
add_action('wp_ajax_hm_clear_transients', 'hm_clear_transients');
add_action('wp_ajax_nopriv_hm_clear_transients', 'hm_clear_transients');
function hm_clear_transients() {
global $wpdb;
$rows = $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '%_transient_%'");
if (wp_doing_ajax()) wp_send_json_success($rows);
return $rows;
@kodie
kodie / wp_add_admin_menu_separators.php
Created March 12, 2020 15:32
Adds additional separators to WordPress's admin dashboard menu
<?php
// Adds additional separators to WordPress's admin dashboard menu
add_action('admin_menu', 'add_admin_menu_separators');
function add_admin_menu_separators() {
function add_separator($position) {
global $menu;
$index = 0;
foreach($menu as $offset => $section) {