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 / 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 / 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 / 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 / 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 / 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 / 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.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 / 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 / wp_add_user_profile.php
Last active August 29, 2015 14:10
WordPress :: Add User Profile Information
<?php
/* Field */
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) {
?>
<h3>Extra profile information</h3>
<table class="form-table">
@harisrozak
harisrozak / wp_add_image_meta.php
Last active August 29, 2015 14:09
WordPress :: Add image meta size
<?php
add_action('init', 'generate_new_thumbnail' );
function generate_new_thumbnail()
{
add_theme_support('post-thumbnails');
// the last argument is to crop or no
add_image_size('post-thumb', 620, 207, true);
add_image_size('home-thumb', 220, 180, true);