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 / oop_sample.php
Last active August 29, 2015 14:05
PHP :: Sample OOP Style
<?php
/**
* PHP OOP sample
* Tutorial here: http://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762
*/
class MyClass
{
public $variable;
public static $static_variable;
@harisrozak
harisrozak / sample_prototype.js
Last active August 29, 2015 14:05
JS :: Sample Javascript Prototype
var Hello = function()
{
this.a = 1;
}
Hello.prototype.dolly = function()
{
this.b = 2;
this.c = this.a + this.b;
@harisrozak
harisrozak / index.html
Last active August 29, 2015 14:05
HTML + JS :: Sample jQuery plugin, boilerplate OOP jQuery plugin
<html>
<head>
<title>Sample jQuery Plugin</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="plugin.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
@harisrozak
harisrozak / simple-excerpt.php
Last active May 28, 2023 20:12
PHP :: Simple PHP Excerpt
<?php
/**
* $pos = get cut position based on fixed position ($fixed),
* but without break last word
*/
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
$excerpt = '';
$fixed = 25;
@harisrozak
harisrozak / wp_editor_save_options.php
Last active August 29, 2015 14:06
WordPress :: enable another admin level to save the custom options
<?php
// editor level
$editor = get_role('editor');
$editor->add_cap('edit_theme_options');
register_setting('opt-group', 'opt_1');
register_setting('opt-group', 'opt_2');
add_filter('option_page_capability_opt-group', 'opt_group_editor_save_options');
function opt_group_editor_save_options($cap) {
@harisrozak
harisrozak / wp_custom_post_type_on_archive.php
Last active August 29, 2015 14:06
WordPress :: Make Archives.php Include Custom Post Types
<?php
add_filter('pre_get_posts', 'namespace_add_custom_types');
function namespace_add_custom_types( $query ) {
if( !is_admin() && is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'your-custom-post-type-here'
));
return $query;
@harisrozak
harisrozak / expandable_search_form.html
Last active August 29, 2015 14:07
HTML + CSS + JS :: Expandable Search Form
<link href="style.css" rel="stylesheet">
<h1>Expandable Search Form</h1>
<h3>Demo 1</h3>
<form>
<input type="search" placeholder="Search">
</form>
<h3>Demo 2</h3>
<form id="demo-2">
@harisrozak
harisrozak / wp_query.php
Last active October 9, 2017 09:30
WordPress :: Sample WP Query
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => -1, // -1 mean show all data
'post_status' => 'publish',
// with multiple taxonomy, if not just get rid the relation and put only one taxonomy array
'tax_query' => array(
'relation' => 'AND',
array(
@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);
@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">