Skip to content

Instantly share code, notes, and snippets.

View JayWood's full-sized avatar
:octocat:
Levelling up, one commit at a time.

JayWood

:octocat:
Levelling up, one commit at a time.
View GitHub Profile
@JayWood
JayWood / product-class.php
Created August 31, 2016 19:33
Woocommerce Product Class
<?php
function fb_1398591523488596( $classes, $class, $post_id ) {
if ( 'product' == get_post_type( $post_id ) ) {
$classes[] = "my-amazing-product-class";
}
return $classes;
}
@JayWood
JayWood / wordpress-ftp-example.php
Last active August 9, 2016 19:54
Full sourcecode for a blog article at WebDevStudios.com
<?php
class WDS_FTPext_How_To {
/**
* Instance of WDS_FTPext_How_To
* @var WDS_FTPext_How_To
*/
public static $instance = null;
<?php
funciton get_an_id() {
$posts_arr = get_posts( array( 'fields' => 'ids', 'posts_per_page' => 1, 'no_found_rows' => true ) );
$post_id = false;
if ( ! empty( $posts_arr ) ) {
$post_id = $posts_arr[0];
}
return $post_id;
Time: 12/05/16 23:31
Description: Loading NBT data
java.io.UTFDataFormatException: malformed input around byte 5
at java.io.DataInputStream.readUTF(DataInputStream.java:656)
at java.io.DataInputStream.readUTF(DataInputStream.java:564)
at net.minecraft.nbt.NBTTagCompound.func_152448_b(NBTTagCompound.java:383)
at net.minecraft.nbt.NBTTagCompound.func_152446_a(NBTTagCompound.java:50)
at net.minecraft.nbt.NBTTagList.func_152446_a(NBTTagList.java:54)
at net.minecraft.nbt.NBTTagCompound.func_152449_a(NBTTagCompound.java:393)
<?php
function update_post_replys() {
$reply_ids = get_posts( array(
'post_type' => 'reply',
'posts_per_page' => -1 // Pulls ALL posts.
'post_status' => 'any' // Defaults to publish, so set any to get all
'fields' => 'ids' // Save on php memory, only grab post ID's
) );
@JayWood
JayWood / wpcli-posts-generator.php
Created May 6, 2016 14:14
A robust random posts generator with support for multisite, taxonomies, term counts, post counts, post types, featured images, featured image types, and more.
<?php
if ( defined( 'WP_CLI' ) && WP_CLI ) {
class JW_Random_Posts extends WP_CLI_Command {
private $args, $assoc_args;
/**
* Generates a Random set of posts
*
@JayWood
JayWood / co-authors-query.php
Last active February 10, 2023 22:46
Query by co-authors for Co-Authors Plus
<?php
function query_by_co_authors() {
$current_user = wp_get_current_user();
// Your standard query
$post_args = array(
'post_type' => 'post',
'posts_per_page' => 10,
@JayWood
JayWood / ajax-test.js
Created April 11, 2016 19:59
adding in nonce to post data
/**
* SerializeOnDemand
*
* In theory you could do this inline, but sometimes its easier to just
* do it within a method and re-use it where you need to.
*
* @return {object} Serialized Object
*/
var searializeOnDemand = function() {
// Go ahead and serialize the form data.
@JayWood
JayWood / ajax-example.js
Created April 11, 2016 19:53
ajax example
jQuery.post( ajaxurl, jQuery( '#theForm' ).seraizlize(), function( response ) {
/**
* At this point, response should equal a json encoded response
* SO if you're doing something like this:
*
* wp_send_json_success( array( 'some_key' => 'some value' ) )
* you can access it like so:
*/
if ( response.success ) {
@JayWood
JayWood / example_class.js
Last active March 24, 2016 13:38
Sending shortcode attributes to JS
// Basic linear javascript for example_class ajax
/**
* Ajax Success Handler
* @param {obj} data Response Object
* @return {null}
*/
var ajaxSuccess = function( data ) {
if ( window.console ) {
window.console.log( data );