Skip to content

Instantly share code, notes, and snippets.

View harisrozak's full-sized avatar
Upgrading multi-lang module...

Haris Ainur Rozak harisrozak

Upgrading multi-lang module...
View GitHub Profile
@harisrozak
harisrozak / wp_cron_sample.php
Last active September 4, 2021 07:01
WP Cron with wp_schedule_event()
<?php
/**
* Register the cron on plugin loaded.
* Valid values for the recurrence are ‘hourly’, ‘daily’, and ‘twicedaily’.
* @return void
*/
function harisrozak_register_wp_cron() {
if ( ! wp_next_scheduled( 'harisrozak_wp_cron' ) ) {
wp_schedule_event( time(), 'twicedaily', 'harisrozak_wp_cron' );
@harisrozak
harisrozak / multisite-on-app.php
Last active April 15, 2021 04:37
Main multisite-site on app.example.com. Also fixed `cookies` related error on child-sites login
<?php
/**
* Modify multisite childs subdomain path
* The main multisite path is on app.example.com
* And then it's children should be on foo.example.com, bar.example.com, etc.
* This code should be located on mu-plugins folder
*/
if ( ! function_exists( 'harisrozak_change_site_subdomain' ) ) {
function commercioo_change_site_subdomain( $data ) {
@harisrozak
harisrozak / db-config.php
Last active April 1, 2021 02:56
LudicrousDB (based on Automattic's HyperDB) configuration file that will split multisite per 100 sites based on site ID
<?php
/**
* LudicrousDB configuration file
*
* This file should be copied to ABSPATH/db-config.php and modified to suit your
* database environment. This file comes with a basic configuration by default.
*
* See README.md for documentation.
*
@harisrozak
harisrozak / customizer-preview-certain-page.php
Last active February 5, 2021 03:14
WordPress customizer a certain page on accessing a certain section
<?php
add_action( 'customize_controls_print_scripts', 'custom_customize_controls_print_scripts', 30 );
function custom_customize_controls_print_scripts() {
?>
<script type='text/javascript'>
jQuery( function( $ ) {
wp.customize.panel( 'customize_checkout_settings', function( section ) {
section.expanded.bind( function( isExpanded ) {
if ( isExpanded ) {
@harisrozak
harisrozak / wp-fix-rest-url-on-ssl.php
Last active February 5, 2021 03:15
WordPress Fix `rest_url` that isn't become https on certain server
<?php
add_filter( 'rest_url', function( $url ) {
if ( is_ssl() ) {
$url = set_url_scheme( $url, 'https' );
return $url;
}
return $url;
});
@harisrozak
harisrozak / request-rest-api.php
Created November 19, 2020 03:43
WordPress :: Request to REST API from PHP
<?php
// send data trough REST API
$request = new WP_REST_Request( 'POST', '/wp/v2/custom_post_type' );
$request->set_header( 'content-type', 'application/json' );
$request->set_body( wp_json_encode( $order_data ) );
// get response
$response = rest_do_request( $request );
$response_data = $response->get_data();
@harisrozak
harisrozak / wordpress-cookie.php
Last active July 3, 2021 05:48
WordPress / PHP Cookie
@harisrozak
harisrozak / db-config.php
Last active October 2, 2020 04:21
WordPress HyperDB setting for multisite with 3 datasets: global, even_sites, odd_sites
<?php
/**
* HyperDB configuration file
*
* This file should be installed at ABSPATH/db-config.php
*
* $wpdb is an instance of the hyperdb class which extends the wpdb class.
*
* See readme.txt for documentation.
@harisrozak
harisrozak / acf.php
Created March 6, 2020 06:07
WordPress :: Save ACF settings to json
<?php
/**
* Save ACF settings to json
*/
add_filter( 'acf/settings/load_json', 'astahub_acf_json_load' );
add_filter( 'acf/settings/save_json', 'astahub_acf_json_save' );
function astahub_get_acf_path() {
return get_template_directory() . '/acf-json';
@harisrozak
harisrozak / slider-pro-image-sides-navigation.css
Last active February 3, 2020 02:17
Custom CSS for Slider Pro and Feslider WP Plugin
/**
* Custom CSS for Slider Pro and Feslider WP Plugin
* Make the slide navigation to become image-sides-clicking instead of arrows-clicking
* Tested on Slider Pro v1.3 and Feslider 1.2
*/
.slider-pro > .sp-slides-container > .sp-arrows.sp-arrows {
height: 100%;
top: 0;
margin: 0;