Skip to content

Instantly share code, notes, and snippets.

View mattmcgiv's full-sized avatar
😎

Matt McGivney mattmcgiv

😎
View GitHub Profile
@mattmcgiv
mattmcgiv / add-role-to-users.php
Last active January 11, 2017 16:04
Add a role to all users
<?php
//Uncomment the following line for converting one role to another
//add_action( 'the_post', 'convert_subscribers_to_executives' );
function convert_subscribers_to_executives() {
//Note: this only works by navigating to the page with ID 5883 on the site
//to kick off the loop that updates all of the users.
if (get_the_ID() === 5883) {
//get all subscribers from this WP site
$blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' );
@mattmcgiv
mattmcgiv / get_total_num_WC_orders.php
Created April 12, 2016 14:09
Get the total number of WooCommerce orders from WordPress
//gets the total number of WooCommerce orders from the WP database
function get_number_of_orders() {
global $wpdb;
//get number of orders from database as array
$number_of_orders_array_n = $wpdb->get_results(
"SELECT COUNT(*) FROM wp_posts WHERE post_type = 'shop_order'", ARRAY_N);
//convert number of orders array into a number
font-family: -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
@mattmcgiv
mattmcgiv / dashicons.php
Created March 27, 2016 17:47
Add WP Dashicons to front-end
<?php
add_action( 'wp_enqueue_scripts', 'mytheme_scripts' );
/**
* Enqueue Dashicons style for frontend use when enqueuing your theme's style sheet
*/
function mytheme_scripts() {
wp_enqueue_style( 'mytheme-style', get_stylesheet_uri(), 'dashicons' );
}
array(
'name' => __( 'My Number Field', 'theme-domain' ),
'desc' => __( 'Numbers only', 'msft-newscenter' ),
'id' => $prefix . 'number',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
),
@mattmcgiv
mattmcgiv / gulpfile.js
Created January 4, 2016 19:20
Sample gulpfile to get started
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
@mattmcgiv
mattmcgiv / CursorReader.java
Created January 3, 2016 01:39
Read a Cursor in Android
//Cursor named "result"
//if statement makes sure we actually got back some data from the db
if (result.moveToFirst() != false) {
//for each row (representing a row of db)
while (result.moveToNext() != false) {
//for each column, representing a value from the row
for (int i = 0; i < result.getColumnCount(); i++) {
Log.d("Name of db column: ", result.getColumnName(i));
String val = result.getString(i);
Log.d("Value for column: ", val);
@mattmcgiv
mattmcgiv / gulpfile.js
Created November 4, 2015 19:37
Gulpfile.js with jshint, sass, concat, uglify, and rename setup for WordPress theme development
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
@mattmcgiv
mattmcgiv / security_io.php
Created October 29, 2015 17:46
Some useful functions for sanitization, validation, and escaping output
<?php
function mm_sanitize($unsanitized_input) {
//calls a WordPress core function
//verifies UTF-8 encoding, strips tags
//removes whitespace/newlines & octets
//reference:
//https://codex.wordpress.org/Function_Reference/sanitize_text_field
return sanitize_text_field($unsanitized_input);
}
@mattmcgiv
mattmcgiv / gist:a060bf2a0909372aab5b
Created October 6, 2015 19:51
WordPress does post exist (by id)?
<?php
/**
* Determines if a post, identified by the specified ID, exist
* within the WordPress database.
*
* Note that this function uses the 'acme_' prefix to serve as an
* example for how to use the function within a theme. If this were
* to be within a class, then the prefix would not be necessary.
*
* @param int $id The ID of the post to check