Skip to content

Instantly share code, notes, and snippets.

View raazon's full-sized avatar
❤️
Eat - Sleep - Code

Razon Komar Pal raazon

❤️
Eat - Sleep - Code
View GitHub Profile
$str = 'Phone Number: 1 (100) 123-4567';
preg_match_all('!\d+!', $str, $matches);
$get_numbers = implode(" ",$matches[0]);
$get_value = preg_replace('/\s+/', '', $get_numbers); // remove all whitespace between numbers
echo $get_value;
function wpMediaEditor() {
wp.media.editor.open();
wp.media.editor.send.attachment = function(props, attachment) {
jQuery('input.itclanbd-attachment-id').val(attachment.id);
jQuery('div.itclanbd-attachment-image img').remove();
jQuery('div.itclanbd-attachment-image').append(
jQuery('<img>').attr({
'src': attachment.sizes.thumbnail.url,
'class': 'itclanbd-attachment-thumb',
'alt': attachment.title
@raazon
raazon / script.js
Created October 22, 2018 10:08
Add a user avatar using wordpress Media Library.
function wpMediaEditor() {
wp.media.editor.open();
wp.media.editor.send.attachment = function(props, attachment) {
jQuery('input.itclanbd-attachment-id').val(attachment.id);
jQuery('div.itclanbd-attachment-image img').remove();
jQuery('div.itclanbd-attachment-image').append(
jQuery('<img>').attr({
'src': attachment.sizes.thumbnail.url,
'class': 'itclanbd-attachment-thumb',
'alt': attachment.title
@raazon
raazon / simple-user-avatar.php
Created October 22, 2018 10:10
Add a user avatar using wordpress Media Library.
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access pages directly.
/*
* Load style & scripts
*/
function itclanbd_admin_head_scripts( $hook ) {
$allowed = ['profile.php', 'user-new.php', 'user-edit.php'];
if ( ! in_array( $hook, $allowed ) ) {
return;
}
@raazon
raazon / select-option-user-meta.php
Created October 22, 2018 10:31
Extra profile field as select box
<?php
add_action( 'show_user_profile', 'show_extra_profile_fields' );
add_action( 'edit_user_profile', 'show_extra_profile_fields' );
function show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="gender">Gender</label></th>
<td>
@raazon
raazon / widget-wrap.php
Last active March 22, 2019 23:30
Adding a div to wrap widget content after the widget title ( wrap widget content )
/**
* If no title given then add widget-content wrapper to before_widget
* If title given then add content wrapper to before_widget
*/
add_filter('dynamic_sidebar_params', 'check_widget_template');
function check_widget_template($params){
global $wp_registered_widgets;
$settings_obj = $wp_registered_widgets[$params[0]['widget_id']]['callback'][0];
@raazon
raazon / popular-post-data-setup.php
Created March 25, 2019 17:05
Display Popular Posts by Views in WordPress without a Plugin
<?php
/**
* POPULAR POSTS DATA SETUP
* It will set 'post_views_count' meta data to count popular posts
*/
function ic_set_post_views($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
@raazon
raazon / add-featured-image-from-url.php
Last active December 1, 2023 18:00
How to add a featured image from a URL in WordPress
@raazon
raazon / kingcomposer.php
Created April 2, 2019 05:31
King Composer - Best page builder plugin for wordpress
<?php
// Reference: https://docs.kingcomposer.com/custom-map-elements/
/**
* Add specific class or id into CONTAINER and COLUMN KINGCOMPOSER
* @since 1.0
* @filter shortcode_kc_column
*/
add_filter( 'shortcode_kc_column', 'ic_helper_kc_column_filter' );
@raazon
raazon / readmore-readless-toggle.js
Created April 10, 2019 10:56
jQuery Read More/Less Toggle
// document onload
$(document).ready(function() {
// Configure/customize these variables.
var showChar = 100; // How many characters are shown by default
var ellipsestext = "...";
var moretext = "Show more >";
var lesstext = "Show less";
$('.ic_read_more').each(function() {