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 / functions.php
Created September 4, 2014 05:16
[Wordpress] [Multisite] Get latest post from wordpress multisite blog
/* Get Latest post from all blogs */
function recent_mu_posts( $howMany = 10 ) {
global $wpdb;
global $table_prefix;
// get an array of the table names that our posts will be in
// we do this by first getting all of our blog ids and then forming the name of the
// table and putting it into an array
$rows = $wpdb->get_results( "SELECT blog_id from $wpdb->blogs WHERE
public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0';" );
@qutek
qutek / functions.php
Last active October 31, 2023 07:03
[Wordpress] [Multisite] Get featured image by blog id on wordpress multisite
/* Get featured image */
if( !function_exists( 'get_the_post_thumbnail_by_blog' ) ) {
function get_the_post_thumbnail_by_blog($blog_id=NULL,$post_id=NULL,$size='post-thumbnail',$attrs=NULL) {
global $current_blog;
$sameblog = false;
if( empty( $blog_id ) || $blog_id == $current_blog->ID ) {
$blog_id = $current_blog->ID;
$sameblog = true;
}
@qutek
qutek / rh_get_widget_data_for.php
Last active August 29, 2015 14:07 — forked from kingkool68/rh-get-widget-data-for-all-sidebars.php
[Wordpress] Display raw widget data
function rh_get_widget_data_for($sidebar_name) {
global $wp_registered_sidebars, $wp_registered_widgets;
// Holds the final data to return
$output = array();
// Loop over all of the registered sidebars looking for the one with the same name as $sidebar_name
$sibebar_id = false;
foreach( $wp_registered_sidebars as $sidebar ) {
if( $sidebar['name'] == $sidebar_name ) {
@qutek
qutek / parse_path.php
Last active February 2, 2020 12:09
[PHP][htaccess] Parse path from Clean URL (Prety Permalink)
<?php
/**
* parse path to get from clean URL
* @return [array] [array of requested uri]
*/
function parse_path() {
$path = array();
if (isset($_SERVER['REQUEST_URI'])) {
$request_path = explode('?', $_SERVER['REQUEST_URI']);
@qutek
qutek / functions.php
Created October 6, 2014 09:25
[Wordpress] Replace https
function filter_content_match_protocols( $content ) {
$search = $replace = get_bloginfo( 'home' );
if ( ! preg_match( '|/$|', $search ) )
$search = $replace = "$search/";
if ( is_ssl() ) {
$search = str_replace( 'https://', 'http://', $search );
$replace = str_replace( 'http://', 'https://', $replace );
}
@qutek
qutek / file.php
Last active July 11, 2022 18:02
[Wordpress] Display data with native wordpress table
<?php
/*
Plugin Name: Custom table example
Description: example plugin to demonstrate wordpress capatabilities
Plugin URI: http://mac-blog.org.ua/
Author URI: http://mac-blog.org.ua/
Author: Marchenko Alexandr
License: Public Domain
Version: 1.1
*/
@qutek
qutek / functions.php
Created October 27, 2014 07:46
[Wordpress] [Buddypress] Batch add user to buddypress group
<?php
/**
* Batch Add user to buddypress group
*/
add_action('load-users.php',function() {
if(isset($_POST['action']) && ($_POST['action'] == 'groupadd') && isset($_POST['bp_gid']) && isset($_POST['allusers'])) {
// print_r($_POST); exit();
$group_id = $_POST['bp_gid'];
@qutek
qutek / class.page-template.php
Last active August 29, 2015 14:08
[Wordpress] Create page template from plugin
<?php
/**
* Plugin Name: MHT Domain Search
* Description: Page template domain registration for mega high tech.
* Author: Lafif Astahdziq
* Author URI: http://astahdziq.in/
* Version: 1.0
*
* 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
@qutek
qutek / funtions.php
Created November 3, 2014 06:21
[Wordpress] Add metabox and custom column
<?php
/**
* Custom metabox to change priority displaying courses
* ====================================================
*/
add_action( 'add_meta_boxes', 'tj_amb_priority_courses' );
function tj_amb_priority_courses() {
add_meta_box( 'tj_mb_priority_courses', 'Display Priority', 'tj_mb_priority_courses_cb', 'sfwd-courses', 'side', 'high' );
}
@qutek
qutek / db-error.php
Created November 4, 2014 09:27
[Wordpress] Custom error database connection page
<?php
/**
* Custom wordpress error database connection page
* @put this file on your wp-content/ folder.
* @name file : db-error.php
*
*/
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');