Skip to content

Instantly share code, notes, and snippets.

Avatar
Upgrading multi-lang module...

Haris Ainur Rozak harisrozak

Upgrading multi-lang module...
View GitHub Profile
@harisrozak
harisrozak / wp_cron_sample.php
Last active Sep 4, 2021
WP Cron with wp_schedule_event()
View wp_cron_sample.php
<?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 Apr 15, 2021
Main multisite-site on app.example.com. Also fixed `cookies` related error on child-sites login
View multisite-on-app.php
<?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 Apr 1, 2021
LudicrousDB (based on Automattic's HyperDB) configuration file that will split multisite per 100 sites based on site ID
View db-config.php
<?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 Feb 5, 2021
WordPress customizer a certain page on accessing a certain section
View customizer-preview-certain-page.php
<?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 Feb 5, 2021
WordPress Fix `rest_url` that isn't become https on certain server
View wp-fix-rest-url-on-ssl.php
<?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 Nov 19, 2020
WordPress :: Request to REST API from PHP
View request-rest-api.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 Jul 3, 2021
WordPress / PHP Cookie
View wordpress-cookie.php
@harisrozak
harisrozak / db-config.php
Last active Oct 2, 2020
WordPress HyperDB setting for multisite with 3 datasets: global, even_sites, odd_sites
View db-config.php
<?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 Mar 6, 2020
WordPress :: Save ACF settings to json
View acf.php
<?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 Feb 3, 2020
Custom CSS for Slider Pro and Feslider WP Plugin
View slider-pro-image-sides-navigation.css
/**
* 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;