Skip to content

Instantly share code, notes, and snippets.

View johnbocook's full-sized avatar
💯
I come here for the dark theme.

John Bocook johnbocook

💯
I come here for the dark theme.
View GitHub Profile
<?php
function add_embed_tweet_meta_box() {
add_meta_box(
'paulund_embed_tweet_meta_box', // $id
'Post Embed Tweets Meta Box', // $title
'show_embed_tweet_meta_box', // $callback
'post', // $page
'normal', // $context
'high'); // $priority
}
@johnbocook
johnbocook / author_slug_to_profile.php
Created September 28, 2013 05:16
Changes WordPress author slug from author to profile.
add_action('init', 'cng_author_base');
function cng_author_base() {
global $wp_rewrite;
$author_slug = 'profile'; // change slug name
$wp_rewrite->author_base = $author_slug;
}
@johnbocook
johnbocook / wp-config-define.php
Created September 28, 2013 05:20
Define wordpress home and site url.
define('WP_HOME','http://domain.com/wordpress');
define('WP_SITEURL','http://domain.com/wordpress');
@johnbocook
johnbocook / remove_generator.php
Created September 28, 2013 05:25
Removes wordpress generators meta.
<?php
/* Remove WordPress generator meta tag */
remove_action('wp_head', 'wp_generator');
@johnbocook
johnbocook / find_repace_custom_field_data.php
Created September 28, 2013 05:28
Find and replace custom field data in wordpress.
<?php
find_replace_custom_field_data( $post_ID = NULL, $custom_field_name = NULL, $search_for = NULL, $replace_with = NULL ) {
if ( isset( $post_ID ) && isset( $custom_field_name ) )
$get_ custom_field = get_post_meta( $post_ID, $custom_field_name, TRUE );
$custom_field_new = str_replace( $search_for, $replace_with, custom_field );
set_post_meta( $post_ID, $custom_field_new );`
}
@johnbocook
johnbocook / custom-eventtype.php
Created September 29, 2013 22:06
Registers a wordpress Custom Post Type for Events and create's a metabox for event time.
<?php
/*
Plugin Name: City Events
Plugin URI: http://JohnBocook.com
Description: Registers a Custom Post Type for Events and create's a metabox for event time.
Version: 1.0
Author: John Bocook
Author URI: http://johnbocook.com
License: Public Domain
*/
@johnbocook
johnbocook / jsonapi.php
Last active December 28, 2015 02:09
Mysql query in PHP converted to json feed and displayed on page.
<?php
//change these settings
$dbhost = "";
$dbusername = "":
$dbpassword = "":
$dbname = "";
$dbtable = "";
//connect to database and grab the data
@johnbocook
johnbocook / PHP Query.php
Last active December 28, 2015 23:49
The PHP code below, will return the columns firstname, lastname from the Friends table.
<?php
//
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
@johnbocook
johnbocook / Facebook follower count.php
Created December 27, 2013 06:27
Get Facebook follower count
<?php $json = file_get_contents('http://api.facebook.com/method/fql.query?format=json&query=select+fan_count+from+page+where+page_id%3D475488679182886');
$decode = json_decode($json);
echo $decode[0]; // Fan Count
?>
@johnbocook
johnbocook / ExpirePHPsession.php
Last active January 1, 2016 12:19
Expire a PHP Session After X Minutes
<?php
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
// last request was more than 30 minutes ago
session_unset(); // unset $_SESSION variable for the run-time
session_destroy(); // destroy session data in storage
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
/*
You can also use an additional time stamp to regenerate the session ID periodically to avoid attacks on sessions like session fixation: