Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
obiPlabon / array-mapx.php
Created January 15, 2017 17:33
PHP custom array mapping function which supports key/index
<?php
/**
* PHP default array map function doesn't provide access to array item key
* So there is no way to map array based on some condition which depends on
* array item key. And that's why array_mapx is here to help you in that case.
* @param array $arr Array that is going to be mapped
* @param callable $callback Callback function to map array $a
* @param boolean $preserve_keys To maintain the old keys
* @return array Mapped array
*/
@obiPlabon
obiPlabon / vc-parent-child-communication.js
Last active December 12, 2019 11:07
Parent to child and child to parent (bidirectional) communication in Visual Composer shortcode
/**
NOTES:
========================
0. Extend container view from "VcColumnView" so that you get a clean UI.
1. Render method called after element is added (cloned), and on first initalization.
2. Use model.getParam(param_name) to get specific param from params.
3. Use model.get("params") to get complete params object.
4. If params is changed then shortcode will be rendered automatically.
5. You do not need to override method that you are not going change, in our file "render".
**/
@obiPlabon
obiPlabon / custom_view.js
Created January 2, 2017 13:42 — forked from pavelthq/custom_view.js
Visual Composer: Custom markup element example
window.VcCustomElementView = vc.shortcode_view.extend( {
elementTemplate: false,
$wrapper: false,
changeShortcodeParams: function ( model ) {
var params;
window.VcCustomElementView.__super__.changeShortcodeParams.call( this, model );
params = _.extend( {}, model.get( 'params' ) );
if ( ! this.elementTemplate ) {
this.elementTemplate = this.$el.find( '.vc_custom-element-container' ).html();
/* =========================================================
* composer-view.js v0.2.1
* =========================================================
* Copyright 2013 Wpbakery
*
* Visual composer backbone/underscore version
* ========================================================= */
(function ( $ ) {
var i18n = window.i18nLocale,
store = vc.storage,
@obiPlabon
obiPlabon / vc-js-events.js
Last active October 5, 2019 12:46
List of some Visual Composer JS events
// Fixed named events
var _events = [
"vc:access:initialize",
"vc:access:backend:ready",
"shortcodes:vc_row:add:param:name:parallax",
"shortcodes:vc_row:update:param:name:parallax",
"shortcodes:vc_single_image:sync",
"shortcodes:vc_single_image:add",
"shortcodes:add:param:type:el_id",
"click:media_editor:add_image",
@obiPlabon
obiPlabon / উত্তরাধিকার.js
Last active January 26, 2017 12:07
Code snippet from http://উত্তরাধিকার.বাংলা/
/**
* Code snippet from http://উত্তরাধিকার.বাংলা/
*
* Really inspiring if you wanna know code smell
* and how to write bad code
*/
function determine_ashaba(sel_rel_arr,ashabas_from_qh,exclude_from_qh,qhs)
{
var ashabas = [];
<!-- START header.php -->
<!DOCTYPE html>
<html>
<head>
<!-- Other head stuff lives here -->
<?php wp_head(); ?>
</head>
<body>
<?php
if ( is_page_template( 'special-page-template-name.php' ) ) :
@obiPlabon
obiPlabon / pmg-rewrite.php
Created December 3, 2016 09:41 — forked from chrisguitarguy/pmg-rewrite.php
WordPress rewrite tutorial
<?php
/*
Plugin Name: Rewrite Rule Tutorials
*/
add_action( 'init', 'pmg_rewrite_add_rewrites' );
function pmg_rewrite_add_rewrites()
{
add_rewrite_endpoint( 'json', EP_PERMALINK );
add_rewrite_rule(
@obiPlabon
obiPlabon / dom-utility.js
Last active September 4, 2016 07:27
Helpful DOM utility functions in venilla JS
// Code written by Me and
// doc written by Zafree [http://github.com/zafree] vai :D
// Get Siblings
// It is a simple function to get all child from parent
// Feel free to use it like a Pro
@obiPlabon
obiPlabon / mb-register.php
Last active August 9, 2016 09:02
Snippet to register WordPress metabox
<?php
function wp_class_register_mb() {
add_meta_box(
'wpclass-mb', // unique id
esc_html__( 'WP Class Metabox', 'text-domain' ), // metabox title
'wp_class_mb_cb', // metabox callback
array('post','page'), // screen name [string|array]
'side', // context
'high' // priority
);