This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('wp_ajax_ajax_coba', 'ajax_coba' ); | |
function ajax_coba() | |
{ | |
$id = $_POST['id']; | |
// json return | |
$return = array( | |
'success' => true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Hello | |
{ | |
private static $greeting = 'Hello, direct static call'; | |
function __construct($string = 'Hello, construct call') | |
{ | |
self::$greeting = $string; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 */ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// redirect with meta | |
$location = 'http://harislab.com'; | |
echo "<meta http-equiv='refresh' content='0;url=$location' />"; | |
echo "<h3>Redirecting...</h3>"; | |
exit(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Source: https://css-tricks.com/centering-in-the-unknown --> | |
<html> | |
<head> | |
<style> | |
.block { | |
text-align: center; | |
background: #c0c0c0; | |
border: #a0a0a0 solid 1px; | |
margin: 20px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |