Skip to content

Instantly share code, notes, and snippets.

View waqashassan98's full-sized avatar

Waqas Hassan waqashassan98

View GitHub Profile
@waqashassan98
waqashassan98 / bookings_in_date_range_woocommerce_bookings.php
Created January 28, 2018 14:56
This function can be used to get the booking details in a date range from Woocommerce Bookings plugin
get_bookings_in_date_range_wh( $next_monday, $next_friday, $product_id, true );
function get_bookings_in_date_range_wh( $start_date, $end_date, $product_or_resource_id = 0, $check_in_cart = true ) {
$args = array(
'status' => get_wc_booking_statuses(),
'object_type' => 'product_or_resource',
'date_between' => array(
'start' => $start_date,
'end' => $end_date,
),
@waqashassan98
waqashassan98 / create_and_send_csv_as_email_attachment.php
Created January 28, 2018 15:36
Dynamically create CSV and send as attachment in emails
function send_csv_mail($data, $body, $to = 'email@example.com', $subject = 'Website Report', $from = 'waqashassan98@gmail.com') {
if (!$fp = fopen('php://temp', 'w+')) echo "unable to create csv";
foreach ($data as $row)
{
fputcsv($fp, $row);
}
rewind($fp);
$csvData = stream_get_contents($fp);
@waqashassan98
waqashassan98 / ffmpeg-conversions.php
Last active January 28, 2018 15:49
Cron Job to convert Videos to MP4 and WebM using ffmpeg library. It uses file locking to prevent duplicate cron jobs being running simultaneously
<?php
$f = fopen('lock', 'w') or die ('Cannot create lock file');
if (flock($f, LOCK_EX | LOCK_NB)) {
ini_set('max_execution_time', 0);
/**
Database Configurations
**/
@waqashassan98
waqashassan98 / dynamic_css.php
Created January 28, 2018 15:53
Headers for creating Dynamic CSS using PHP
$expires = 5*60*60*24; // how long to cache in secs..
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
header('Content-type: text/css');
@waqashassan98
waqashassan98 / ontraport_mail_merge_api.php
Created January 28, 2018 16:23
Edit Ontraport Emails using Ontraport API
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/mailmerge/vendor/autoload.php';
use OntraportAPI\Ontraport;
//live
$key = "tbpy9FUGu9XXXX";
$appid = "2_9614_MnlYYYY";
@waqashassan98
waqashassan98 / googlesheets.php
Last active November 23, 2020 09:00
Access Google Sheets via API in PHP, using Server to Server OAUTH
<?php
$root_path = '/path/to/your/root/';
require_once($root_path.'vendor/autoload.php');
define('APPLICATION_NAME', 'Google Sheets Importer');
define('APP_CREDENTIALS_PATH', $root_path.'service-account-2fb0dd3da332.json');// The Json file's path that you received via service account
define('SCOPES',
@waqashassan98
waqashassan98 / DownloadCSV.php
Created July 16, 2018 19:11
Simple Code to dynamically download data from array as csv
$data_to_download = array(
array("Title", "Description", "Comments"),
array("Dummy Title", "Dummy Description", "Dummy Comment Count"),
array("Dummy Title 2", "Dummy Description 2", "Dummy Comment Count 2")
);
$output = fopen("php://output",'w') or die("Can't open php://output");
header("Content-Type:application/csv");
header("Content-Disposition:attachment;filename=".$range.".csv");
foreach($data_to_download as $row) {
@waqashassan98
waqashassan98 / jquery-failover.html
Created July 22, 2018 08:17
Failsafe loading of Javascript File
<script src="//code.jquery.com/jquery-2.2.1.min.js"></script>
<script>
window.jQuery || document.write('<script src="scripts/jquery-2.2.1.min.js"><\/script>')
</script>
<?php
//set up pods::find parameters to limit to 5 items
$param = array(
'limit' => 5,
);
//create pods object
$pods = pods('pod_name', $params );
//check that total values (given limit) returned is greater than zero
if ( $pods->total() > 0 ) {
@waqashassan98
waqashassan98 / functions.php
Created December 7, 2018 09:48
Create a wordpress admin user from functions.php
function wpb_admin_account(){
$user = 'admin_user';
$pass = 'admin_pass';
$email = 'youemail@xyz.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}