Skip to content

Instantly share code, notes, and snippets.

View KennyGScott's full-sized avatar

Kenny G KennyGScott

  • Vancouver, WA
View GitHub Profile
@KennyGScott
KennyGScott / index.html
Created May 27, 2022 04:44
Vanilla JS Pagination Example
<div id="output"></div>
<a href="javascript:prevPage()" id="btn_prev">Prev</a>
<ul id="pages"></ul>
<a href="javascript:nextPage()" id="btn_next">Next</a>
@KennyGScott
KennyGScott / wp-bulk-posts.php
Last active May 8, 2017 21:39
WP - Bulk Create Pages/Post Types
<?php
$post_type = 'post';
$author_id = 1;
$titles = array(
"Post Title"
"Something Else"
);
/*** No need to edit below here ***/
@KennyGScott
KennyGScott / woocommerce-ship-class-by-cat.php
Created May 4, 2017 20:20
Woocommerce - Change Shipping Class By Category/Categories
<?php
/**
* Couldn't find copy/paste code anywhere so I wrote it myself. The interwebz failed me.
*/
/** The category ID's with the posts you want to change */
$category_ids = array(48, 50, 51, 52, 53); // array of ints or single int
/** The shipping class to set for the products */
$shipping_class_slug = "postcards"; // found in "shipping classes" in woocommerce settings
@KennyGScott
KennyGScott / es6-generate-days.js
Created April 1, 2017 01:42
Generates the correct number of days for a given month and year selection
/*
Assumes you have the months and years already set up in your HTML
*/
function generateDays()
{
const thisYear = new Date().getFullYear();
const thisMonth = new Date().getMonth();
// Where XXX is your 'select' element ID for the Year
// Where YYY is your 'select' element ID for the Month
@KennyGScott
KennyGScott / _isElement.js
Last active February 17, 2017 19:15
Checks if element exists before execution
/* NOTE: you do not need to pass `elem` to callBack, it is optional.
USAGE:
This is the es5/jquery implementation */
_isElement('.some_selector', function(elem) {
console.log(elem + ' exists.');
});
/* Vanilla JS/ES5 */
@KennyGScott
KennyGScott / month-year-dropdown-helpers.php
Created December 19, 2016 19:37
Month & Year Dropdown Render Helper functions
<?php
function render_month_dropdown($select_name, $id, $label, $selected_month)
{
$dropdown = '<label for="' . $select_name . '">' . $label . '</label>';
$dropdown .= '<select id="' . $id . '" name="' . $select_name . '">';
$months = array(
'January',
'February',
'March',
'April',
@KennyGScott
KennyGScott / drupal-debug-entity.php
Last active November 17, 2016 21:54
Helper function for debugging entities - Drupal 7
<?php
/* Helper function for debugging entities - Drupal 7 */
function debug_entity($w) {
$values = array();
foreach ($w->getPropertyInfo() as $key => $val) {
$values[$key] = $w->$key->value();
}
return $values;
}
<?php
$sortMe = array(
"item" => "Title",
"item" => "Another Title",
);
$arr = array();
foreach ($sortMe as $key => $row)
{
$arr[$key] = $row['item'];
}
<?php
// Returns a clean url slug
function wp_slug($string)
{
return rtrim(strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string))), "-");
}
// Items to convert to slug
$items = array(
"Item #1",
"Item #2 ", // Dirty input - Trailing space
@KennyGScott
KennyGScott / date-range-generator.js
Last active December 3, 2015 16:27
Lists a range of specified years
var startDate, endDate;
startDate = 1900;
endDate = 2000;
/** No more editing */
document.write(startDate + "<br>");
while (startDate !== endDate)
{