Skip to content

Instantly share code, notes, and snippets.

View laxmariappan's full-sized avatar

Lax Mariappan laxmariappan

View GitHub Profile
@jtsternberg
jtsternberg / cmb2-number-field.php
Last active February 13, 2025 09:43
CMB2 Number Field
<?php
$cmb->add_field( array(
'name' => __( 'Postive numbers', 'theme-domain' ),
'desc' => __( 'Numbers only', 'msft-newscenter' ),
'id' => $prefix . 'number',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
@bhongy
bhongy / Wordpress: Do if the_content is not empty
Last active September 15, 2023 03:36
Wordpress: Check if the_content is empty / do something only when the_content is empty
<?php if ( get_the_content() ) { ?>
// do or output something
<?php } ?> // break php tag for HTML block
@AlexPashley
AlexPashley / replace.php
Last active January 25, 2023 23:40
PHP: function that will replace textual URLs with HTML links, this also works for email addresses.
<?php
function replace_links( $text )
{
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
$ret = ' ' . $text;
// Replace Links with http://
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\" rel=\"nofollow\">\\2</a>", $ret);
@tobedoit
tobedoit / gist:4146888
Created November 26, 2012 06:43
Wordpress: Set display name with 'first name'
/* Sets the user's display name (always) to first name last name, when it's available **************************************
** http://stackoverflow.com/questions/9326315/wordpress-change-default-display-name-publicy-as-for-all-existing-users *** */
/* !아이디 대신 이름으로 나타내기 ********************************************************************************************* */
/* Sets the user's display name (always) to first name last name, when it's avail. */
add_action ('admin_head','make_display_name_f_name_last_name');
function make_display_name_f_name_last_name(){
$users = get_users(array('fields'=>'all'));
foreach($users as $user){
$user = get_userdata($user->ID);
$display_name = $user->first_name;
@bzerangue
bzerangue / transform.php
Created March 22, 2012 21:42
PHP: XSLT Transformation
<?php
// You instantiating the XSLTProcessor - libXSLT
$xmlProc = new XsltProcessor();
// Your XSLT Stylesheet for transforming XML
$xslt = new DomDocument();
$xslt -> load("example.xsl");
// This prepares the XSLT for transform
$xmlProc -> importStylesheet($xslt);