Skip to content

Instantly share code, notes, and snippets.

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

Hieu Huynh hieuhuynh93

💭
I may be slow to respond.
View GitHub Profile
@hieuhuynh93
hieuhuynh93 / enable_comment.php
Last active June 13, 2022 07:18
Enable comment
function enableCommentByCat() {
global $wpdb;
$getPosts = new WP_Query( array( 'category_name' => 'ten_category') );
if ( $getPosts->have_posts() ) {
while ( $getPosts->have_posts() ) {
$getPosts->the_post();
$postId = get_the_ID();
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_status = 'open' WHERE ID=$postId"));
}
} else {
@hieuhuynh93
hieuhuynh93 / related.php
Created June 13, 2022 06:47
Related post by title
@hieuhuynh93
hieuhuynh93 / toURLFriendly.php
Created March 13, 2021 14:37 — forked from xbill82/toURLFriendly.php
PHP: String to URL friendly
<?
/**
* @param String $str The input string
* @return String The string without accents
*/
function removeAccents( $str )
{
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð',
'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã',
'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ',
@hieuhuynh93
hieuhuynh93 / retrieveUrl.php
Last active January 29, 2021 16:42
parse url in php
<?php
// ======= PATHINFO ====== //
$x = pathinfo($url);
$x['dirname'] 🡺 https://example.com/subFolder
$x['basename'] 🡺 myfile.php?var=blabla#555 // Unsecure!
$x['extension'] 🡺 php?var=blabla#555 // Unsecure!
$x['filename'] 🡺 myfile
// ======= PARSE_URL ====== //
$x = parse_url($url);
@hieuhuynh93
hieuhuynh93 / timezone.json
Created December 30, 2020 10:26
timezone.json
[
{
"name": "(UTC -11:00) Pacific/Midway",
"code": "Pacific/Midway"
},
{
"name": "(UTC -11:00) Pacific/Niue",
"code": "Pacific/Niue"
},
{
@hieuhuynh93
hieuhuynh93 / Install Composer using MAMP's PHP.md
Created September 14, 2020 06:31 — forked from irazasyed/Install Composer using MAMP's PHP.md
Instructions on how to change preinstalled Mac OS X PHP to MAMP's PHP Installation and then install Composer Package Management

Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management


Instructions to Change PHP Installation


First, Lets find out what version of PHP we're running (To find out if it's the default version).

To do that, Within the terminal, Fire this command:

which php

@hieuhuynh93
hieuhuynh93 / next-post-wp.php
Last active September 7, 2020 17:03
Lấy bài viết next/previous wordpress - cakedeli
<?php
function install_next_post_sc(){
$class = 'next_post_';
global $post;
$categories = get_the_category($post->ID);
if(!empty($categories)){
$category = $categories[0]->term_id;
} else {
$category = '';
}
@hieuhuynh93
hieuhuynh93 / infinite-previous-next-looping.php
Created September 7, 2020 06:39 — forked from banago/infinite-previous-next-looping.php
Infinite next and previous post looping in WordPress
<?php
/**
* Infinite next and previous post looping in WordPress
*/
if( get_adjacent_post(false, '', true) ) {
previous_post_link('%link', '&larr; Previous Post');
} else {
$first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post();
echo '<a href="' . get_permalink() . '">&larr; Previous Post</a>';
wp_reset_query();
@hieuhuynh93
hieuhuynh93 / toc.php
Last active August 29, 2020 07:25
create toc for wordpress without plugin
<?php
add_filter('the_content', function ($content) {
$toc_output = '';
$matches = null;
$smatches = null;
$had_headers = array();
preg_match_all('/<h[2-3].*?>.*?<\/h[2-3]>/i', $content, $matches);
if (!empty($matches[0]) && count($matches[0]) > 0)
foreach ($matches[0] as $headertag) {
preg_match('/>(.*?)<\/(h[2-3])>/i', $headertag, $smatches);
@hieuhuynh93
hieuhuynh93 / facebook_warning.html
Created August 25, 2020 17:17 — forked from tosbourn/facebook_warning.html
How to recreate Facebook's console warning
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
const warningTitleCSS = 'color:red; font-size:60px; font-weight: bold; -webkit-text-stroke: 1px black;';
const warningDescCSS = 'font-size: 18px;';