Skip to content

Instantly share code, notes, and snippets.

View aliboy08's full-sized avatar

Alistair Ponce aliboy08

  • Philippines
View GitHub Profile
<?php
function ff_aweber_mass_update_fields(
$file = '',
$list_id = 2534516, // thedigitalinsurer
$consumerKey = 'AkFCmZ046GCL17wKVR0L2xsV',
$consumerSecret = 'Sa5Ugpm40NHMcIWKC6TGeDEl204JThMy0nBHFXc4',
$accessKey = 'AgzYa7KUgu0UBivqDk22tJdS',
$accessSecret = 'XmLHVT4mW1oKI5VwWIEBSGhWvfavaxja2zQZn8TN'
)
{
@aliboy08
aliboy08 / get months between 2 dates
Created February 23, 2018 02:22
PHP get months between 2 dates
$start = new DateTime('2013-08-01');
$start->modify('first day of this month');
$end = new DateTime(date('Y-m-d')); // current date
$end->modify('first day of next month');
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $dt) {
echo $dt->format("F Y");
}
@aliboy08
aliboy08 / simple-load-more-js
Last active October 2, 2018 23:15
Simple Load More JS
<html>
<head>
<style>
.ff-load-more > .item {
display: none;
}
.ff-load-more > .item.active {
display: block;
}
<?php
$url = 'https://fivebyfive.com.au/wp-json/wp/v2/posts';
// Using file_get_contents
// Some hostings might disable this for security purposes
$result = file_get_contents($url);
$result = json_decode($result);
foreach( $result as $post ) {
echo '<pre>'. print_r($post->title->rendered, true) . '</pre>';
}
// Using url
<?php
// Send data to hubspot
$hubspot_portal_id = '4421750';
$hubspot_form_guid = '35d60c88-89f4-46a6-b2e8-996f60cd5445';
$url = 'https://forms.hubspot.com/uploads/form/v2/'. $hubspot_portal_id .'/'. $hubspot_form_guid;
$data = array();
if( isset($_POST['ff_quiz_first_name']) ) $data['firstname'] = $_POST['ff_quiz_first_name'];
if( isset($_POST['ff_quiz_last_name']) ) $data['lastname'] = $_POST['ff_quiz_last_name'];
@aliboy08
aliboy08 / woocommerce-modify-shipping-cost.php
Created October 5, 2018 02:35
Woocommerce - modify shipping cost depending on quantity
// Free retail shipping
add_filter('woocommerce_package_rates','ff_override_flat_rate_price',100,2);
function ff_override_flat_rate_price($rates,$package) {
// Modify shipping cost for Books depending on quantity
if( ff_get_cart_total_quantity() >= 2 && ff_get_cart_total_quantity() <= 3 ) {
// 2 or 3 = 15.95
foreach ($rates as $rate) {
//Set the price
$rate->cost = 15.95;
//Set the TAX
@aliboy08
aliboy08 / wordpress-pagination-js-fix.php
Last active October 8, 2018 01:29
Wordpress js pagination hack fix if rewrite is not working
// Pagination fix
if( $('.wp-pagenavi').length ) {
var url, match, find_page_var, page_var, split_page_var, new_page_parameter, new_url;
$('.wp-pagenavi a').each(function(){
url = $(this).attr('href');
// get the page parameter from the url
match = /\/page\/[0-9]+\//g.exec(url);
if( match ) {
page_var = match[0];
split_page_var = page_var.split('/');
@aliboy08
aliboy08 / php-create-posts-from-xml-feed-using-curl.php
Created October 11, 2018 00:33
PHP create posts from xml feed
<?php
$feed_url = 'https://batchaws.adcourier.com/panel/?q=U2FsdGVkX19JpL80ZgsoSN4F3N3Ut1LGKwgX7VVH7q4RgdsLDocx-3L9VEoNT8WW';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $feed_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
$xml = curl_exec($ch);
$jobs_feed = simplexml_load_string($xml);
@aliboy08
aliboy08 / ff-get-image-id-by-url.php
Last active October 18, 2018 00:54
Check if image exists in the WP database, return id if found
function ff_get_image_id_by_url($image_url, $type = 'full') {
global $wpdb;
if( $type === 'full' ) {
// Search url
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
} else {
// Search name using LIKE
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid LIKE '%s';", '%' . $wpdb->esc_like($image_url) . '%' ));
}
if( $attachment )
@aliboy08
aliboy08 / ff-set-post-term-with-fallback.php
Last active January 19, 2023 09:34
Set term to post id, create term if it does not exist
// Set post term to post id, create term if it does not exist
function ff_set_post_term_with_fallback($post_id, $value, $taxonomy, $create_new = true ){
if( $value == '' ) return;
// Search term
$term = term_exists( $value, $taxonomy);
if( $term ) {
// Term exists
wp_set_post_terms( $post_id, $term['term_id'], $taxonomy, true );
} else {
// Term does not exist, create new