Skip to content

Instantly share code, notes, and snippets.

View khoipro's full-sized avatar
💭
#devops #wordpress #vuejs #docker

Nguyễn Minh Khôi khoipro

💭
#devops #wordpress #vuejs #docker
View GitHub Profile
@khoipro
khoipro / functions.php
Created April 23, 2024 07:52
WP Sample function convert Youtube URL (ACF) to post content (for using existing Embeds feature in WordPress)
<?php
// For example, logged in to your WordPress and hit http://sample.com/?action=update_videos once
add_action('wp', function() {
if ( !is_user_logged_in() ) return;
if ( empty( $_GET['action'] ) ) return;
if ($_GET['action'] !== 'update_videos') return;
@khoipro
khoipro / .htaccess
Created April 17, 2024 09:13
Maintenance Web (index.html)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.html
RewriteRule ^ /index.html [R=302]
</IfModule>
@khoipro
khoipro / mixins.css
Last active March 10, 2024 04:40
postCSS Mixins to help you save your CSS time
@define-mixin bottom-line-left $color, $height: 4px, $width: 60px, $padding: 0.25em, $margin: 1em {
position: relative;
margin-bottom: $margin;
padding-bottom: $padding;
&::after {
content: '';
position: absolute;
left: 0;
bottom: 0;
@khoipro
khoipro / .htaccess
Last active January 27, 2024 00:48
Run a WP maintenance task
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
@khoipro
khoipro / class-rewrites.php
Created January 15, 2024 11:42
The sample class Rewrites to remove a post type slug/
<?php
/**
* Rewrites Class
*
* @package CodetotTheme
* @author codetot
* @since 0.0.1
*/
namespace CODETOT\Theme;
@khoipro
khoipro / debug.log
Last active January 6, 2024 19:21
Sample function delete related attachments (created by ACF) when deleting a post
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 189
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 190
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 191
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 192
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 193
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 194
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 195
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 196
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete gallery attachment id 197
[06-Jan-2024 16:29:06 UTC] INFO: Delete product 188: delete video attachment id 235
@khoipro
khoipro / functions.php
Created January 4, 2024 14:48
Sample way to delete post tags by ids (export from Google Sheets with rows)
<?php
// Step 1: Copy all Google Sheets' row and process to only number with commas
// It looks like
// 197
// 112
// 256
// https://www.browserling.com/tools/text-rows-to-columns
// Step 2: Open with any IDE such like Visual Studio Code to remove all whitespace, eg: "192 ,91" => "192,91"
// Step 3: Place a term ids list replace $$raw_term_ids to remove it.
@khoipro
khoipro / Runcloud.md
Last active March 25, 2024 19:32
Hardening Runcloud VPS

Hardening VPS in Runcloud

Change SSH port

Step 1: Visit Dashboard > Choose Server > Security

Add New Rule
Globally Open Port, port 2040 (or your port)
Protocal: TCP
@khoipro
khoipro / sample-lazyload-sections.php
Last active January 8, 2024 22:02
Sample section lazyload using <noscript> - DRAFTING
<?php
/** Drafting **/
add_filter('the_content', 'codetot_lazyload_home_sections', 1000);
function codetot_lazyload_home_sections( $content ) {
$front_page_id = get_option('page_on_front');
if ( ! is_page( $front_page_id ) ) {
return $content;
}
@khoipro
khoipro / yoast-seo.php
Last active November 1, 2023 12:34
Get Yoast SEO meta by calling a DB
<?php
function get_yoast_seo_category_meta_title( $object_id) {
global $wpdb;
$table_name = $wpdb->prefix . 'yoast_indexable';
$result = $wpdb->get_row( $wpdb->prepare("SELECT title FROM $table_name WHERE `object_id` = '%s' AND `object_sub_type` = 'category';", $object_id), ARRAY_A );
return $result['title'] ?? 'None';