Skip to content

Instantly share code, notes, and snippets.

dtbaker dtbaker

View GitHub Profile
@dtbaker
dtbaker / term-meta.php
Last active Aug 8, 2018 — forked from chrisdc/term-meta.php
Add a custom meta box to the new/edit category pages. The meta data is saved using update_term_meta.
View term-meta.php
<?php
/**
*Add meta box to the term category page.
*/
function dtbaker_taxonomy_edit_meta_field( $term ) {
// Retrieve the existing value(s) for this meta field.
$term_meta = $term && !empty($term->term_id) ? get_term_meta( $term->term_id, 'custom_page_id', true ) : false;
?>
<tr class="form-field">
@dtbaker
dtbaker / remote-ip.php
Last active Mar 17, 2018
Self hosted Dynamic DNS / No-IP script in PHP
View remote-ip.php
<?php
/**
* Simple Dynamic DNS / No-IP script for Route53
*
* Setup:
* 1) Setup a new Route53 zone to hold your dynamic DNS records (e.g. dynamic.mywebsite.net)
* 2) Make sure this instance has permission to modify this Route53 zone (e.g. instance IAM profile, .aws credentials or ENV variables)
* 3) Upload this PHP script to your instance (make sure vendor files are availalbe by running: composer require aws/aws-sdk-php)
* 4) Put the allowed hostnames in the list below
@dtbaker
dtbaker / map.html
Last active Apr 13, 2017
Hide street numbers from Google Maps
View map.html
<style type="text/css">
#map {
width: 750px;
height: 500px;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">
View keybase.md

Keybase proof

I hereby claim:

  • I am dtbaker on github.
  • I am dtbaker (https://keybase.io/dtbaker) on keybase.
  • I have a public key ASC97lhPufWpAR3JpYNuOXAUFR0ETsK3xbBuJtdxUsbiIAo

To claim this, I am signing this object:

@dtbaker
dtbaker / foo.php
Created Feb 26, 2017
Hacky way to import pictures after a WordPress site migration that didn't go well.
View foo.php
// This will search through all blog content and find/replace <a href> and <img src> links
// It will find images on the old multi-site host, e.g. http://dtbaker.net/wp-content/uploads/sites/* and import those images into the new blog, then update the links/src in the post content.
add_action('init', function(){
if(isset($_REQUEST['do_import'])){
ini_set('display_errors',true);
ini_set('error_reporting',E_ALL);
require_once ('wp-admin/includes/admin.php');
@dtbaker
dtbaker / create-quote.php
Last active Jun 2, 2018
Create a quote in UCM from a remote url
View create-quote.php
<?php
chdir('/path/to/ucm/folder/on/webhost/');
include('init.php'); // the UCM init code.
// login as admin
module_security::user_id_temp_set(1);
$customer_data = array(
'customer_name' => 'Name Here',
@dtbaker
dtbaker / code.php
Last active Apr 11, 2019
Add a custom control to an existing Elementor widget
View code.php
// This example will add a custom "select" drop down to the "Image Box"
// This will change the class="" on the rendered image box so we can style the Image Box differently
// based on the selected option from the editor.
// The class will be "my-image-box-style-blue" or "my-image-box-style-green" based on the selected option.
add_action('elementor/element/before_section_end', function( $section, $section_id, $args ) {
if( $section->get_name() == 'image-box' && $section_id == 'section_image' ){
// we are at the end of the "section_image" area of the "image-box"
$section->add_control(
@dtbaker
dtbaker / db.php
Created Jul 19, 2016
Upgrade from mysql_connect() to mysqli_connect() - handle port number and socket.
View db.php
// These are examples of MySQL host names that will work fine in mysql_connect() but fail in mysqli_connect()
// If you are upgrading an old script to mysqli the client may have configured these as values for their database server.
// The below script parses out port number or socket and translates that into a correct mysqli_connect() call.
define('_DB_SERVER', '1.2.3.4:3306');
define('_DB_SERVER', '1.2.3.4:/tmp/socket4');
if(function_exists('mysqli_connect')){
$server = _DB_SERVER;
$port_number = null;
$socket = null;
@dtbaker
dtbaker / run_bot.php
Created May 28, 2016
Run this PHP script and it will start a "bot" user on Slack that does Google Searches for you
View run_bot.php
<?php
require 'vendor/autoload.php';
use PhpSlackBot\Bot;
// Custom command
class MyCommand extends \PhpSlackBot\Command\BaseCommand {
protected function configure() {
$this->setName('bot');
@dtbaker
dtbaker / help.cpp
Created Apr 16, 2016
C++ help? Using
View help.cpp
###### ImAcq.cpp:
ImAcq *imAcqAlloc()
{
ImAcq *imAcq = (ImAcq *)malloc(sizeof(ImAcq));
imAcq->method = IMACQ_PI;
imAcq->RaspiCam_Cv_Camera = ???? // dave added this
imAcq->currentFrame = 1;
You can’t perform that action at this time.