Skip to content

Instantly share code, notes, and snippets.

View qutek's full-sized avatar
💻
Working from home

Lafif Astahdziq qutek

💻
Working from home
View GitHub Profile
@qutek
qutek / Wordpress virtual page
Created November 8, 2014 16:49
[Wordpress] Virtual Page
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@qutek
qutek / functions.php
Last active November 19, 2021 11:21
[Wordpress] Disable wordpress comment
<?php
// Disable support for comments and trackbacks in post types
function df_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
@qutek
qutek / post-receive
Last active August 29, 2015 14:09
[Git] Automatic Deployment with git hooks
/**
* Create directory and init as --bare repo
*/
mkdir repo && cd repo
mkdir site.git && cd site.git
git init --bare
/**
@qutek
qutek / site_options.php
Last active August 29, 2015 14:10
[Wordpress] Sample options page
<?php
/**
* _s Theme Options
*
* @package _s
* @since _s 1.0
*/
/**
* Register the form setting for our _s_options array.
@qutek
qutek / strtr_replace.php
Created November 24, 2014 05:52
[PHP] Replace string to variable with pattern
<?php
/**
* Replace string with pattern
* (example use: for mail templating)
*
* @codes array();
* @pattern string;
*/
$message = 'coba username {username} atau {user_email}';
@qutek
qutek / functions.php
Last active March 15, 2016 00:01
[Wordpress][Buddypress] Add new menu item buddypress profile
<?php
function custom_bp_nav() {
global $bp;
bp_core_new_nav_item(
array(
'name' => __( 'Site Settings', 'buddypress' ),
'slug' => 'site-settings',
'position' => 80,
'screen_function' => 'site_settings_screen',
@qutek
qutek / backup.sh
Created January 28, 2015 10:01
[shell] Script to backup mysql databases with split
#!/bin/bash
### change the values below where needed.....
### taken from http://moinne.com/blog/ronald/mysql/backup-large-databases-with-mysqldump
DBNAMES="MyDb1 MyDb2 MyDb3"
HOST="--host=localhost"
USER="--user=root"
PASSWORD="--password=MyPassword"
BACKUP_DIR="/MyBackupDirectory"
#### you can change these values but they are optional....
@qutek
qutek / .htaccess
Created February 4, 2015 11:48
[server] Rewrite old domain to new domain
#rewrite all subdomain on old domain to subdomain on new domain
RewriteCond %{HTTP_HOST} ^(.*)\.olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://%1.newdomain.com/$1 [R=301,L]
# rewrite all links to new domain
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
@qutek
qutek / terminal.sh
Created February 20, 2015 11:13
[Server][Git] Fixing git-receive-pack: command not found
## Run on server
alias git-receive-pack="/usr/local/cpanel/3rdparty/bin/git-receive-pack"
## I still need to add it to my ~/.bashrc
export PATH=$PATH:"/usr/local/cpanel/3rdparty/bin"
## Also, on a side note the whole stdin: is not a TTY error can be fixed by removing the /home/git/.bashrc file.
@qutek
qutek / functions.php
Created March 2, 2015 08:46
[Wordpress] Function to get all post from category slug with wpdb
function _getPostByCategory($post_type, $category_slug){
global $wpdb;
$query = "SELECT p.*, terms.term_taxonomy_id, terms.term_id, terms.slug, terms.name from $wpdb->posts p INNER JOIN
( SELECT rel.object_id , rel.term_taxonomy_id, term.term_id, term.name, term.slug FROM $wpdb->term_relationships rel
INNER JOIN (SELECT ttax.term_taxonomy_id, ttax.term_id, t.name, t.slug FROM $wpdb->term_taxonomy ttax
INNER JOIN $wpdb->terms t ON t.term_id = ttax.term_id
) term
ON rel.term_taxonomy_id = term.term_taxonomy_id ) terms
ON p.ID = terms.object_id