Skip to content

Instantly share code, notes, and snippets.

@brashrebel
Created May 28, 2015 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brashrebel/6d6399548bea4a703baa to your computer and use it in GitHub Desktop.
Save brashrebel/6d6399548bea4a703baa to your computer and use it in GitHub Desktop.
My example of using a Google sheet
<?php
/*
Plugin Name: RBM Schedule
Plugin URI: http://realbigplugins.com
Description: Creates a way for our schedule to be quickly and easily referenced.
Version: 0.1
Author: Kyle Maurer
Author URI: http://realbigmarketing.com
License: GPL2
*/
function rbm_get_data() {
$url = 'https://spreadsheets.google.com/feeds/list/14Bmvn9V1d91ecbITe4V2V2M-nTSfvvDDGJF7PgEapzM/od6/public/values?alt=json';
$request = wp_remote_get( $url );
$request = json_decode( wp_remote_retrieve_body( $request ) );
$output = '';
foreach ( $request->feed->entry as $project ) {
$title = get_object_vars( $project->title );
$duedate = get_object_vars( $project );
$duedate = get_object_vars( $duedate['gsx$duedate'] );
$output .= $title['$t'] . ' - ' . $duedate['$t'] . '@@';
}
return $output;
}
function rbm_post_to_slack() {
if ( 'go' == $_REQUEST['slack'] ) {
$text = json_encode( array(
'text' => rbm_get_data(),
'username' => 'Schedule Bot',
''
)
);
$text = str_replace( '@@', '\n', $text );
$url = 'https://hooks.slack.com/services/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';
wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $text,
'cookies' => array()
)
);
}
}
add_action( 'init', 'rbm_post_to_slack' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment