Skip to content

Instantly share code, notes, and snippets.

View aliboy08's full-sized avatar

Alistair Ponce aliboy08

  • Philippines
View GitHub Profile
@aliboy08
aliboy08 / vite-wp-load-critical-css.php
Created March 15, 2024 05:19
vite wp load critical css
<?php
add_action('wp_head', 'load_critical_css', 0);
function load_critical_css(){
$dir = FF_DIR .'/dist';
$handle = 'src/critical.js';
$manifest = FF\Vite\get_manifest($dir);
if( !$manifest ) return;
@aliboy08
aliboy08 / .gitignore
Last active March 13, 2024 14:30
wp git ignore
/*
!.gitignore
**/.DS_Store
**.log
gitignore/
!wp-content
@aliboy08
aliboy08 / wp-upload-file.php
Last active October 9, 2024 23:44
wp upload file to media library
<?php
class Upload_File {
function upload_file( $file_url ) {
$path_info = pathinfo($file_url);
$file_name = $path_info['filename'];
$attachment_id = $this->get_attachment_id_by_filename($file_name);
if( !$attachment_id ) {
// does not exist yet, upload
@aliboy08
aliboy08 / get-plugin-version.php
Created February 16, 2024 01:03
get plugin version from php file comment
<?php
function get_plugin_version($file){
$file_content = file_get_contents($file);
$tokens = token_get_all( $file_content );
$comment = array(
T_COMMENT,
T_DOC_COMMENT,
);
@aliboy08
aliboy08 / wp-dead-images-cleanup.php
Created February 1, 2024 07:20
Wordpress dead images cleanup
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $id,
) );
$images = [];
foreach( $attachments as $attachment ) {
$images[] = $attachment->guid;
}
@aliboy08
aliboy08 / ff-filters.js
Last active January 18, 2024 03:33
JS Filtering + Search
(function($){$(function(){
function FF_Filters(options){
var _ = this;
this.options = options;
_.filters_init();
_.search_init();
_.sort_init();
}
@aliboy08
aliboy08 / weather.php
Created January 10, 2024 04:34
Weather API
<?php
$weather = get_transient( 'ff_weather' );
$location = 'Port Moresby';
if( !$weather ) {
$api_key = 'ENTER_API_KEY_HERE';
$data = file_get_contents_curl('https://api.weatherapi.com/v1/current.json?key='. $api_key .'&q='. urlencode($location));
if( $data ) {
$weather = json_decode($data);
set_transient('ff_weather', $weather, 3600); // refresh once every hour
}
@aliboy08
aliboy08 / slick-stop-youtube-iframes.js
Created January 8, 2024 06:04
slick slider stop youtube iframes
function load_youtube_api(){
if( typeof YT !== 'undefined' ) return;
var tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
load_youtube_api();
@aliboy08
aliboy08 / limit-words.js
Created December 21, 2023 00:53
limit input words
function limit_words_init(){
var els = document.querySelectorAll('.limit-words');
els.forEach(el=>{
var limit = parseInt(el.attributes.class.value.split('limit-value-')[1].split(' ')[0]);
limit_words(el, limit);
});
function limit_words(el, limit){
@aliboy08
aliboy08 / wc-custom-order-status.php
Created November 14, 2023 05:56
WC add custom order status
<?php
// Custom product status
function register_custom_order_status() {
register_post_status( 'wc-quote', array(
'label' => 'Quote',
'public' => true,
'show_in_admin_status_list' => true,
'show_in_admin_all_list' => true,
'exclude_from_search' => false,
'label_count' => _n_noop( 'Quote <span class="count">(%s)</span>', 'Quote <span class="count">(%s)</span>' )