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 / admin-enqueue-script.php
Last active September 3, 2019 04:21
WordPress :: Datepicker on admin
<?php
public function bid_tabulation_enqueue_script( $hook ) {
global $post;
if( $hook == 'post.php' && isset( $post->post_type ) && $post->post_type == 'bid-tabulation' ) {
// load script & style
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_style( 'jquery-ui-datepicker', $GLOBALS['mu_assets_url'] . 'jquery-ui.min.css' );
@harisrozak
harisrozak / learn-namespace.php
Last active May 27, 2019 00:01
PHP :: Learn Namespace
<?php
// Main namespace
namespace Haris\Learn\OONamespace;
// Constant
const FILE = __FILE__;
// Require files
require_once dirname(FILE) . '/module-one.php';
@harisrozak
harisrozak / wp_query_fields_ids.php
Last active April 26, 2019 06:44
WordPress::Wp_Query with field ids
<?php
$args = array(
'post_type' => 'custom-post',
'posts_per_page' => 10,
'post_status' => 'publish',
'author' => 1,
'fields' => 'ids',
'tax_query' => array(
array(
@harisrozak
harisrozak / init-custom-download-page.php
Last active October 26, 2018 04:23
WordPress::Create custom static page on custom url
<?php
add_action('init', 'create_download_page');
public function create_download_page() {
global $wp;
$home_url = network_home_url();
$download_url = trailingslashit(network_home_url('download'));
// current url path
$current_path = parse_url(add_query_arg(array()), PHP_URL_PATH);
@harisrozak
harisrozak / datepicker-range.js
Last active September 6, 2018 01:42
Apply the right behavior of two datepicker.js fields that act as range of dates
jQuery(document).ready(function($) {
$("#date-start").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd/mm/yy',
altField: 'input[name="date-start"]',
altFormat: 'yymmdd',
minDate: new Date(),
maxDate: '+2y',
onSelect: function(date){
@harisrozak
harisrozak / acf-option-with-wpml.php
Last active February 8, 2018 10:15
WordPress :: Get ACF option field on WPML multi languages
<?php
// display current language
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
echo "<pre>Current language code: ";
print_r(ICL_LANGUAGE_CODE);
echo "</pre>";
}
// get all WPML languages
@harisrozak
harisrozak / loop_wget.sh
Last active March 22, 2018 07:05
Loop command on linux with bash file
#! /bin/bash
while [ "true" ]; do
# Do looping.
echo "-----------------------------"
date -u
echo "doing wget.."
wget --no-check-certificate -q -O - http://example.com >/dev/null 2>&1
echo "done, sleeping for a minute"
sleep 60
@harisrozak
harisrozak / position-absolute-center.css
Created October 24, 2017 06:22
CSS position absolute center
.container {
width: 25%;
height: 50px;
position: relative;
}
.container .popup {
position: absolute;
width: 300px;
margin-left: 50%;
@harisrozak
harisrozak / write_log.php
Created August 23, 2017 02:41
Funstion PHP write log
function write_log($filename, $message, $overwrite = false) {
$myfile = fopen($filename, "w") or die("Unable to open file!");
if($overwrite) {
$txt = '[' . date("Y-m-d H:i:s") . '] Messages: ' . "\n" . $message;
fwrite($myfile, $txt);
fclose($myfile);
}
else {
$old_content = file_get_contents($myfile);
@harisrozak
harisrozak / wp-pass-variable-to-template-part.php
Created July 24, 2017 06:13
WordPress :: Pass variable to template part
<?php
// file archive.php
set_query_var( 'user_id', absint( $user->ID ) );
get_template_part( 'template-parts/user', 'details' );
// file template-parts/user-details.php
var_dump($user_id);