Skip to content

Instantly share code, notes, and snippets.

View amrikarisma's full-sized avatar
💭
I may be slow to respond.

Amri amrikarisma

💭
I may be slow to respond.
View GitHub Profile
@amrikarisma
amrikarisma / Javascript Format NPWP
Created April 4, 2023 04:57 — forked from yudapc/Javascript Format NPWP
Javascript Format NPWP. NPWP is ID tax each people of indonesian. Specificly in frontend need to format NPWP before render to user
//
// Javascript Format NPWP
//
function formatNpwp(value) {
if (typeof value === 'string') {
return value.replace(/(\d{2})(\d{3})(\d{3})(\d{1})(\d{3})(\d{3})/, '$1.$2.$3.$4-$5.$6');
}
}
@amrikarisma
amrikarisma / functions.php
Created January 24, 2023 10:31 — forked from ChrisLTD/functions.php
Fix so you can preview ACF field changes in Wordpress admin
<?php
/*
Debug preview with custom fields
Taken from: http://support.advancedcustomfields.com/forums/topic/preview-solution/
See also: http://support.advancedcustomfields.com/forums/topic/2nd-every-other-post-preview-throws-notice/
*/
add_filter('_wp_post_revision_fields', 'add_field_debug_preview');
function add_field_debug_preview($fields){
$fields["debug_preview"] = "debug_preview";
return $fields;
@amrikarisma
amrikarisma / custom-feed.php
Last active January 3, 2023 03:01
How to create custom feed WordPress without Plugins
<?php
/**
* Create custom function and custom rss template.
* URL : /feed/feedname
* When url 404 not found, please open permalink setting then try again.
*/
add_action('init', 'customRSS');
function customRSS(){
add_feed('feedname', 'customRSSFunc');
@amrikarisma
amrikarisma / auto-regenerate-thumb.php
Last active December 14, 2022 08:29
WordPress generate new size for old posts
<?php
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Put the function in a class to make it more extendable
class KRS_regen_media
{
public function krs_regenerate($imageId)
{
$imagePath = wp_get_original_image_path($imageId);
@amrikarisma
amrikarisma / withPrice.php
Created August 24, 2022 18:04
Example scope with lowest price
<?php
public function scopeWithPrice($smartphone)
{
$queryGetMinPrice = $smartphone->select([
'*',
'price' => ProductPrice::select('price')->where('priceable_type', Smartphone::class)->whereColumn('priceable_id', 'smartphones.id')->orderBy('price', 'ASC')->take(1)
]);
return $queryGetMinPrice;
}
@amrikarisma
amrikarisma / preview_input_file_image.js
Created August 22, 2022 03:59
Preview image on input file before upload
<input type="file" accept="image/*" onchange="loadFile(event)">
<img id="output"/>
<script>
var loadFile = function(event) {
var output = document.getElementById('output');
output.src = URL.createObjectURL(event.target.files[0]);
output.onload = function() {
URL.revokeObjectURL(output.src) // free memory
}
};
@amrikarisma
amrikarisma / docker-compose.yml
Created August 11, 2022 07:30
Run legacy PHP 5.3 and MySQL 5.1 on Docker
# Run legacy PHP 5.3 and MySQL 5.1 on Docker
version: '3.7'
services:
php:
container_name: 'php-5.3.29-apache'
depends_on:
- mysql
image: php:5.3.29-apache
volumes:
- ./www:/var/www
@amrikarisma
amrikarisma / functions.php
Created July 19, 2022 12:13
Remove or hide all about WP Comments from Dashboard Admin
<?php
// Removes from admin menu
add_action( 'admin_menu', 'my_remove_admin_menus' );
function my_remove_admin_menus() {
remove_menu_page( 'edit-comments.php' );
}
// Removes from post and pages
add_action('init', 'remove_comment_support', 100);
function remove_comment_support() {
@amrikarisma
amrikarisma / functions.scss
Last active July 19, 2022 12:14
auto mix color on hover
// Shade a color: mix a color with black
// Example : shade-color($color__btn-primary, 10%)
@function shade-color($color, $weight) {
@return mix(black, $color, $weight);
}
@amrikarisma
amrikarisma / hide-plugin-network.php
Last active July 18, 2022 18:14
Hide WordPress Plugin from table list (WP Multisite)
<?php
function mu_hide_plugins_network( $plugins ) {
// let's hide akismet
if( in_array( 'akismet/akismet.php', array_keys( $plugins ) ) ) {
unset( $plugins['akismet/akismet.php'] );
}
return $plugins;
}
add_filter( 'all_plugins', 'mu_hide_plugins_network' );