Skip to content

Instantly share code, notes, and snippets.

View niraj-shah's full-sized avatar
🏠
Working from home

Niraj Shah niraj-shah

🏠
Working from home
View GitHub Profile
@niraj-shah
niraj-shah / cover_image_url.php
Created March 12, 2014 20:10
Script to upload a photo by URL (i.e. remote resource). Use code with https://gist.github.com/niraj-shah/9514525
<?php
// upload a photo to facebook by URL, will return id of uploaded photo
$photo_uploaded = $facebook->api( $page_id . "/photos", "POST", array(
'url' => 'http://healthhub.co/wp-content/uploads/2014/02/Group-Slider.jpg', // remote URL to image
'no_story' => true // suppress automatic image upload story, optional
) );
@niraj-shah
niraj-shah / cover_photo_upload.php
Last active April 8, 2017 09:50
Script to upload a photo and set it as the cover image for a Facebook Page
<?php
// include Facebook PHP SDK
include "facebook/facebook.php";
// init Facebook SDK with app settings
$facebook = new Facebook( array( 'appId' => APP_ID, 'secret' => APP_SECRET ) );
// enable file upload support
$facebook->setFileUploadSupport( true );
@niraj-shah
niraj-shah / wp_toolbar_complete.php
Created February 17, 2014 15:31
Complete version of custom toolbar plugin
<?php
/**
* @package MyToolbar
*/
/*
Plugin Name: MyToolbar
Plugin URI: http://www.webniraj.com
Description: This plugin creates a custom toolbar
Version: 1.0
<?php
// remove WordPress items from toolbar
function preload_my_toolbar() {
global $wp_admin_bar;
// remove WordPress logo
$wp_admin_bar->remove_node('wp-logo');
// remove search button
@niraj-shah
niraj-shah / wp_menu.php
Last active August 29, 2015 13:56
WordPress Plugin to Customise Toolbar
<?php
/**
* @package MyToolbar
*/
/*
Plugin Name: MyToolbar
Plugin URI: http://www.webniraj.com
Description: This plugin creates a custom toolbar
Version: 1.0
@niraj-shah
niraj-shah / ajax_csrf.html
Created January 12, 2014 15:18
Added CSRF token to AJAX calls using Form Serialization
<!-- create form with open_form() -->
<form action="http://testapplication.com/login" method="post" accept-charset="utf-8" id="login-form" class="login">
<div style="display:none">
<input type="hidden" name="csrf_test_name" value="80bfb80b356d6d31f4ce4dad0c6cf69e">
</div>
...
...
</form>
<!-- Update AJAX code to post serialized data -->
@niraj-shah
niraj-shah / ajax_csrf.html
Last active January 3, 2016 00:59
Added CSRF token to AJAX calls using JavaScript Variable
<!-- add to HEAD -->
<script type="text/javascript">
var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
</script>
<!-- Update AJAX code, change csrf_test_name as needed -->
<script type="text/javascript">
$.post( ajax_url, { data: 'value', 'csrf_test_name': csrf_value }, function( response ) {
// response
}, 'json' );
@niraj-shah
niraj-shah / manual_csrf.php
Last active January 3, 2016 00:49
Manual CSRF token in CodeIgniter
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
@niraj-shah
niraj-shah / login_form.php
Created January 12, 2014 14:53
CodeIgnitor Form with CSRF token added
<form action="http://testapplication.com/login" method="post" accept-charset="utf-8" id="login-form" class="login">
<div style="display:none">
<input type="hidden" name="csrf_test_name" value="80bfb80b356d6d31f4ce4dad0c6cf69e">
</div>
...
...
</form>
@niraj-shah
niraj-shah / login_form.php
Created January 12, 2014 14:47
CodeIgniter login for with CSRF
# load helper manually
$this->load->helper('form');
# create form
echo form_open( base_url( 'login' ), array( 'id' => 'login-form', 'class' => 'login' ) );