Skip to content

Instantly share code, notes, and snippets.

View mennwebs's full-sized avatar

Menn mennwebs

View GitHub Profile
@mennwebs
mennwebs / slack-files-downloader.sh
Last active May 2, 2024 03:47 — forked from greird/slack-files-downloader.sh
Download all files from a Slack workspace export folder.
#!/bin/bash
#
# This script will browse a Slack export folder and download all files in a new /export folder
#
# HOW TO:
# 1. As a Workspace admin, download an export of your Slack history (https://www.slack.com/services/export)
# 2. Make sure you have jq installed (https://stedolan.github.io/jq/)
# 3. Place this file at the root of your Slack export folder, next to channels.json
# 4. Run `bash slack-files-downloader.sh` in your terminal
#
@mennwebs
mennwebs / functions.php
Last active February 13, 2024 02:35
WordPress - Random Slug
add_filter('wp_unique_post_slug', 'seed_unique_slug', 10, 4);
function seed_unique_slug($slug, $post_id, $post_status, $post_type)
{
if (in_array($post_type, ['post', 'product'])) {
$post = get_post($post_id);
if (empty($post->post_name) || $slug != $post->post_name) {
$slug = randomSlug();
}
}
return $slug;
@mennwebs
mennwebs / deploy-sftp.yml
Created January 10, 2024 01:53
GitHub Action: Push to Deploy sFTP
on: [push]
jobs:
deploy_job:
runs-on: ubuntu-latest
name: deploy
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Dependencies
@mennwebs
mennwebs / th-address.json
Created November 20, 2023 02:16
Thai Address from Postal Code - JSON
This file has been truncated, but you can view the full file.
[
{
"zipCode": "10100",
"subDistrictList": [
{
"subDistrictId": "100801",
"districtId": "1008",
"provinceId": "10",
"subDistrictName": "ป้อมปราบ"
@mennwebs
mennwebs / functions.php
Created October 18, 2023 12:00
WP - Running No. Slug
<?php
// Running No. Slug
add_action('wp_insert_post', 'change_slug');
function change_slug($post_id, $force = false)
{
$post_types = ['news', 'faq'];
$post_type = $_POST['post_type'];
if (!in_array($post_type, $post_types) || get_field('no', $post_id)) {
return;
@mennwebs
mennwebs / style.css
Created February 26, 2023 08:51
Class _th and _en (show only Thai, English language)
._th:not(:lang(th)),
._en:not(:lang(en-US)) {
display: none !important;
}
@mennwebs
mennwebs / functions.php
Last active February 15, 2023 23:50
GenerateBlocks - Output CSS with Content (for Frontend, to get WordPress content via API)
// GENERATEBLOCKS CSS
if (function_exists('generateblocks_get_frontend_block_css')) {
add_filter('the_content', 'p_css');
}
function p_css($content) {
global $post;
$css = wp_strip_all_tags(generateblocks_get_frontend_block_css());
return '<style id="gb-css">' . $css . '</style>' . $content;
@mennwebs
mennwebs / functions.php
Created April 8, 2022 09:47
WP Shortcode to show Custom Field.
<?php
// Custom Field: demo_field
// Shortcode: [show_field]
function show_custom_field() {
$meta = get_post_meta( get_the_ID(), 'demo_field', true );
return '<em>' . $meta . '</em>';
}
add_shortcode('show_field', 'show_custom_field');
@mennwebs
mennwebs / functions.php
Created September 21, 2021 14:14
Seed Stat Pro - Change Post Views for specific Post ID.
<?php
add_filter('sstp_views', 'sstp_change_views',10, 2 );
function sstp_change_views($num, $postID) {
if ($postID == 123) {
return $num + 500;
}
return $num;
}
@mennwebs
mennwebs / front-page.php
Created July 18, 2021 10:07
Seed Stat - Most Popular (Last 30 Days)
<div class="most-popular">
<?php
$args = array(
'posts_per_page' => 5,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_key' => 's_stat',
'date_query' => array(
'after' => '30 days ago'
)