Skip to content

Instantly share code, notes, and snippets.

View hasinhayder's full-sized avatar
🚀
Back on track, yayyyy!

Hasin Hayder hasinhayder

🚀
Back on track, yayyyy!
View GitHub Profile
@hasinhayder
hasinhayder / gist:5886783
Last active December 19, 2015 02:59
Change number of posts displayed in WordPress blog page by weekdays
function number_of_posts_per_day($query){
if (date("l")=="Sunday") {
$query->set('posts_per_page', 20);
}
elseif (date("l")=="Monday") {
$query->set('posts_per_page', 10);
}
elseif (date("l")=="Tuesday") {
$query->set('posts_per_page', 5);
}
@hasinhayder
hasinhayder / fetch.php
Last active August 29, 2015 13:57
A new twig function which can fetch external URL via GET or POST and pass arbitrary parameters while fetching
<?php
//file: fetch.php
use Twig_Extension;
use Twig_Function_Method;
class Fetch extends Twig_Extension
{
public function fetch ($url, $params=array())
{
if($url){
$ch = curl_init($url);
@hasinhayder
hasinhayder / singleton.php
Last active May 15, 2019 07:12
singleton
<?php
class Car{
private $numberPlate;
function __construct(){
$this->numberPlate = "G ".mt_rand(1,1000);
}
function honk(){
echo "Pip Pip. The Numberplate is {$this->numberPlate} \n";
}

Keybase proof

I hereby claim:

  • I am hasinhayder on github.
  • I am hasin (https://keybase.io/hasin) on keybase.
  • I have a public key whose fingerprint is 8319 D4D0 29CE 3C50 F788 D033 95EB 88C0 DF4D 79A3

To claim this, I am signing this object:

@hasinhayder
hasinhayder / cdn.php
Created July 1, 2014 13:47
Replace uploaded image urls by CDN
<?php
function change_to_cdn_url() {
return 'http://your.cdn.url/wp-content/uploads';
}
add_filter( 'pre_option_upload_url_path', 'change_to_cdn_url' );
@hasinhayder
hasinhayder / fetch attachment
Last active August 29, 2015 14:06
fetch media attachments via javascript in wp
for(i=0;i<selected_ids.length;i++){
if(selected_ids[i]>0){
var attachment = new wp.media.model.Attachment.get(selected_ids[i]);
attachment.fetch({success:function(att){
container.append("<li><img src='" + att.attributes.sizes.thumbnail.url + "'</li>");
}});
}
}
@hasinhayder
hasinhayder / fetch-attachment.js
Last active January 23, 2018 06:00
Fetch WordPress Media Files (Attachments) Via Backbone Model
var attachment_id = 1234;
var attachment = new wp.media.model.Attachment.get(attachment_id);
attachment.fetch({success:function(att){
if (_.contains(['png','jpg','gif','jpeg'],att.get('subtype'))) {
console.log(att.attributes);
$("<img/>").attr("src",att.attributes.sizes.thumbnail.url).appendTo($("body"));
}
}});
@hasinhayder
hasinhayder / wp_adjacent_posts_links.php
Created October 10, 2014 18:43
Getting link for next and previous post in WordPress
@hasinhayder
hasinhayder / functions.php
Created October 29, 2014 19:12
Redirect WordPress posts to the editor if someone types /edit at the end of the permalink
<?php
function init_url_rewrite_rule(){
add_rewrite_endpoint( 'edit',EP_PERMALINK | EP_PAGES | EP_ATTACHMENT );
if(get_option("EDIT_REWRITE_RULE")!=1){
flush_rewrite_rules();
update_option("EDIT_REWRITE_RULE",1);
}
}
function redirect_edit_url(){
@hasinhayder
hasinhayder / envato-screenshots-downloader.php
Last active November 14, 2017 18:37
Download large preview images from the envato item's screenshots page
#!/usr/bin/env php
<?php
//usage: php envato-screenshots-downloader.php /path/to/save/screenshots http://url/to/screenshots/page
set_time_limit(0);
$dir = $argv[1];
$source = $argv[2];
print_r($argv);
mkdir ($dir);
$src = file_get_contents($source);
$pattern = '/src="(https:\/\/0.s3[a-zA-Z0-9_\-\.\/%]+)"/i';