Skip to content

Instantly share code, notes, and snippets.

@gaupoit
gaupoit / api_gateway_mapping_template.json
Created March 3, 2018 09:37
API Gateway Mapping Template to pass querystring to AWS Lambda
{
"body" : $input.json('$'),
"headers": {
#foreach($header in $input.params().header.keySet())
"$header": "$util.escapeJavaScript($input.params().header.get($header))" #if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"params": {
@gaupoit
gaupoit / getWCGroups.js
Created June 8, 2018 17:10
Get World Cup Groups
const DOC = require('dynamodb-doc');
const dynamo = DOC.DynamoDB();
exports.handler = (event, context, callback) => {
// TODO implement
const params = {
TableName: "groups"
};
dynamo.scan(params, (err, data) => {
@gaupoit
gaupoit / custom_menu_page.php
Created July 8, 2018 08:45
Add the custom menu page in WordPerss
<?php
function define_admin_hooks() {
add_action( 'admin_menu', 'your_callback_handle_menu' );
}
function your_callback_handle_menu() {
add_menu_page('Your Page Title', 'Your Menu Title', 'administrator', 'your-menu-slug', 'function_to_render_setting_ui', 'dashicons-smiley');
}
function function_to_render_setting_ui() {
@gaupoit
gaupoit / showPopup.js
Created July 10, 2018 01:36
How to show media library popup in WordPress?
//We need to call wp_enqueue_media function in backend to load all media javascript API
(function() {
function showMediaFilePopup() {
//Add a custom media uploader object
var uploader = wp.media.frames.file_frame = wp.media({
title: 'Choose Media',
frame: 'select',
button: {
text: 'Choose Media'
},
@gaupoit
gaupoit / custom_page_post_column.php
Created July 12, 2018 08:26
Add custom column in pages or posts WordPress table
<?php
add_filter( 'manage_posts_columns', 'add_new_column_handler' );
function add_new_column_handler( $columns ) {
$columns['your_custom_column_name'] = 'Column Title';
return $columns;
}
@gaupoit
gaupoit / custom_page_column.php
Created July 12, 2018 08:32
Add a custom page column
<?php
add_filter( 'manage_pages_columns', 'add_new_column_handler' );
function add_new_column_handler( $columns ) {
$columns['your_custom_column_name'] = 'Column Title';
return $columns;
}
@gaupoit
gaupoit / custom_page_post_column_content.php
Last active July 12, 2018 08:53
Add custom page and post content
<?php
add_filter( 'manage_posts_columns', 'add_new_column_handler' );
function add_new_column_handler( $columns ) {
$columns['your_custom_column_name'] = 'Column Title';
return $columns;
}
add_action( 'manage_posts_custom_column', 'add_custom_column_content' );
<?php
add_filter( 'manage_pages_columns', 'add_new_column_handler' );
function add_new_column_handler( $columns ) {
$columns['your_custom_column_name'] = 'Column Title';
return $columns;
}
add_action( 'manage_pages_custom_column', 'add_custom_column_content' );
/* Display custom column's content */
function add_custom_column_content( $column, $post_id ) {
//We will check whether the column is our defined column above by name
@gaupoit
gaupoit / My_DB_construct.php
Created August 1, 2018 14:19
My_DB class __contruct function
<?php
class My_Table {
protected $table_version;
protected $table_name;
public function __contruct() {
global $wpdb;
$this->db_version = get_option('my_table_version') === false ? '1.0' : get_option('my_table_version');
$this->table_name = $wpdb->prefix . 'my_table';
}
<?php
class My_Table {
....
private function init() {
global $wpdb;
if ($wpdb->get_var("SHOW TABLES LIKE '$this->table_name'") != $this->table_name) {
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $this->table_name (