Skip to content

Instantly share code, notes, and snippets.

View mzalewski's full-sized avatar

Matthew Zalewski mzalewski

View GitHub Profile
@mzalewski
mzalewski / 0_reuse_code.js
Last active August 29, 2015 14:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
'use strict';
var oobManualAuthorization = require('./user-authorization-manual');
var OAuth = require( 'oauth' );
var oauth = new OAuth.OAuth(
// reqURL
'http://wpapi.loc/oauth1/request',
// accessURL
'http://wpapi.loc/oauth1/access',
@mzalewski
mzalewski / node-wpapi-oauth-option1.js
Created October 24, 2016 23:10
Node WPAPI OAuth examples
var WPAPI = require( 'wpapi' );
var wp = new WPAPI({
endpoint: endpointUrl,
oauth: {
clientId: clientId,
clientSecret: clientSecret,
callback: callbackUrl // optional: (defaults to oob)
}
});
@mzalewski
mzalewski / Returner.php
Created December 12, 2016 05:13
Returner helper class
class Returner {
private static $returned = array();
private $value;
public function __construct( $value ) {
$this->value = $value;
}
public function result( $arg ) {
return $this->value;
}
public static function v( $value ) {
<?php
class jpen_Example_Widget extends WP_Widget {
// Set up the widget name and description.
public function __construct() {
$widget_options = array( 'classname' => 'example_widget', 'description' => 'This is an Example Widget' );
parent::__construct( 'example_widget', 'Example Widget', $widget_options );
}
// Create the widget output.
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance[ 'title' ] );
@mzalewski
mzalewski / enqueue.php
Last active January 28, 2017 20:39
Adding scripts/styles to a WordPress plugin
<?php
function myplugin_enqueue_scripts() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_enqueue_style( 'cssname', $plugin_url . 'assets/css.css', array(), '1.0' );
wp_enqueue_script( 'jsname', $plugin_url . 'assets/js.js', array( 'jquery' ), '1.0' );
}
@mzalewski
mzalewski / posttype.php
Last active January 28, 2017 20:38
WordPress Custom Post Type
<?php
function myplugin_add_post_type() {
register_post_type( 'reviews',
array(
'labels' => array(
'name' => __( 'Reviews' ),
'singular_name' => __( 'Review' )
),
'public' => true,
@mzalewski
mzalewski / menu.php
Created January 28, 2017 20:45
Adding a menu page
<?php
function myplugin_options_page()
{
// add top level menu page
add_menu_page(
'Options Page',
'Options Page Title',
'manage_options',
'myplugin-options',
'myplugin_render_options_page'
@mzalewski
mzalewski / listtable.php
Created January 28, 2017 20:53
Create a custom WP List Table
<?php
if( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class MyPlugin_List_Table extends WP_List_Table
{
public function prepare_items()
{
$columns = $this->get_columns();
@mzalewski
mzalewski / shortcode.php
Created January 28, 2017 20:56
Creating a shortcode
<?php
function myplugin_my_shortcode( $atts = array(), $content = '' ) {
echo "This is some shortcode output";
}
add_shortcode('my-shortcode','myplugin_my_shortcode');