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_query_single.php
Last active May 16, 2016 10:30
Wordpress :: WP_Query for single
<?php
/* by ID */
$args = array(
'p' => 42, // id of a page, post, or custom type
'post_type' => 'any'
);
$the_query = new WP_Query($args);
/* by post slug */
@harisrozak
harisrozak / centering-element.html
Last active August 29, 2015 14:16
CSS :: A Briliant Way To Centering An Element
<!-- Source: https://css-tricks.com/centering-in-the-unknown -->
<html>
<head>
<style>
.block {
text-align: center;
background: #c0c0c0;
border: #a0a0a0 solid 1px;
margin: 20px;
}
@harisrozak
harisrozak / meta-redirect.php
Last active August 29, 2015 14:17
PHP :: Redirect with meta
<?php
// redirect with meta
$location = 'http://harislab.com';
echo "<meta http-equiv='refresh' content='0;url=$location' />";
echo "<h3>Redirecting...</h3>";
exit();
@harisrozak
harisrozak / centering-element.css
Created March 16, 2015 03:44
CSS :: Another way to centering element
.absolute-centering {
width: 200px;
height: 150px;
position: absolute; /* or fixed */
left: 50%;
margin-left: -100px; /* half of width */
top: 50%;
margin-top: -75px; /* half of height */
}
@harisrozak
harisrozak / index.php
Last active August 29, 2015 14:20
PHP :: Static function and variable
<?php
class Hello
{
private static $greeting = 'Hello, direct static call';
function __construct($string = 'Hello, construct call')
{
self::$greeting = $string;
}
@harisrozak
harisrozak / wp_path_to_url.php
Last active August 29, 2015 14:22
WordPress :: absolute path to url
// WordPress absolute path to url
function path_to_url($path)
{
$url = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path);
$http_proto = is_ssl() ? "https://" : "http://";
return $http_proto . $_SERVER['SERVER_NAME'] . $url;
}
@harisrozak
harisrozak / ajax.php
Last active August 29, 2015 14:23
WordPress :: ajax
<?php
add_action('wp_ajax_ajax_coba', 'ajax_coba' );
function ajax_coba()
{
$id = $_POST['id'];
// json return
$return = array(
'success' => true,
@harisrozak
harisrozak / convertEmbedMedia.js
Created August 26, 2015 08:07
Convert youtube and vimeo link to embed iframe
/**
* Convert youtube and vimeo link to embed iframe
*/
function convertEmbedMedia(html)
{
var origin = html;
var pattern1 = /(?:http?s?:\/\/)?(?:www\.)?(?:vimeo\.com)\/(?:.*\/)?(.+)/g;
var pattern2 = /(?:http?s?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g;
var pattern3 = /([-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?(?:jpg|jpeg|gif|png))/gi;
@harisrozak
harisrozak / google_map.html
Last active February 5, 2016 09:30
Google Map
<!--
Google Map Script
https://developers.google.com/maps/documentation/javascript/reference#MapOptions
-->
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap" async defer></script>
<script type="text/javascript">
function initMap() {
var mapDiv = document.getElementById('google-map');
var map = new google.maps.Map(mapDiv, {
center: {lat: 44.540, lng: -78.546},
@harisrozak
harisrozak / .htaccess
Created March 4, 2016 06:34
Prevent the folder and it's items to direct access
deny from all