Skip to content

Instantly share code, notes, and snippets.

View aliboy08's full-sized avatar

Alistair Ponce aliboy08

  • Philippines
View GitHub Profile
@aliboy08
aliboy08 / upload_dist.bat
Last active July 2, 2024 08:32
WPEngine dist folder upload script
@echo off
setlocal
set install_name=bigdaddylocal
set theme_folder=fivebyfive
REM Set variables
set remote_base_dir=/sites/%install_name%/wp-content/themes/%theme_folder%/
set ssh_host=%install_name%@%install_name%.ssh.wpengine.net
@aliboy08
aliboy08 / wp-ajax-fetch-boilerplate.php
Last active May 1, 2024 12:11
wp ajax boilerplate with fetch
<?php
add_action('wp_ajax_ACTION_HERE', function(){
$response = [
'post' => $_POST,
];
wp_send_json($response);
});
?>
<script>
@aliboy08
aliboy08 / script_ready_check.js
Created March 28, 2024 04:12
Script ready checker
function script_ready_check(script, cb, interval, limit){
var time = 0;
var check = setInterval(function(){
if( typeof script !== 'undefined' ) {
clearInterval(check);
cb();
}
time += interval;
if( time >= limit ) {
clearInterval(check);
@aliboy08
aliboy08 / group-items.js
Created March 28, 2024 02:54
group array of items into multiple sub arrays
function group_items(items, items_per_group){
var groups = [
[],
];
var current_group = 0;
var group_items_count = 0;
for( var i = 0; i < items.length; i++ ) {
@aliboy08
aliboy08 / wp-vite.php
Last active March 15, 2024 13:36
WP + Vite
<?php
namespace FF\Vite;
function get_manifest(){
$manifest_file = __DIR__ . '/dist/.vite/manifest.json';
$manifest = wp_json_file_decode( $manifest_file );
return $manifest;
}
function get_mode(){
@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
Created March 7, 2024 04:17
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;
}