Skip to content

Instantly share code, notes, and snippets.

View laxmariappan's full-sized avatar

Lax Mariappan laxmariappan

View GitHub Profile
@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);
@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;
@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);
@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
@jtsternberg
jtsternberg / cmb2-number-field.php
Last active February 28, 2022 03:30
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*',
INITIALISATION
==============
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
@krisatkinson
krisatkinson / gist:7814a29112a16b9649da
Last active March 12, 2024 19:45 — forked from lucasstark/gist:6594983
Example to add meta data to woocommerce cart items
<?php
/*
* Plugin Name: Example Modify Price
*/
class Example_Modify_Price {
private static $instance;
public static function register() {
if (self::$instance == null) {
@eduwass
eduwass / aux-functions.php
Last active August 11, 2022 05:21
Programmatically adding a Page item to a Wordpress nav menu
<?php
/**
* Adds Page to a WordPress navmenu
* @param [int] $page_id The ID of the page you want to add
* @param [str] $page_title Title of menu item
* @param [int] $menu_id NavMenu ID
* @param [int] $parent (Optional) Menu item Parent ID
*/
function add_page_to_menu($page_id, $page_title, $menu_id, $parent = 0){
@EvanHerman
EvanHerman / redirect-user-back-to-product.php
Created November 13, 2015 16:30
WooCommerce - After login, redirect the user back to the last viewed product
<?php
/*
* Add a hidden field to our WooCommerce login form - passing in the refering page URL
* Note: the input (hidden) field doesn't actually get created unless the user was directed
* to this page from a single product page
*/
function redirect_user_back_to_product() {
// check for a referer
$referer = wp_get_referer();
// if there was a referer..
@ashokmhrj
ashokmhrj / custom-template-plugin.php
Last active October 21, 2023 13:36
Get Template Part From plugin directory
<?php
/**
* The below function will help to load template file from plugin directory of wordpress
* Extracted from : http://wordpress.stackexchange.com/questions/94343/get-template-part-from-plugin
*/
define('PLUGIN_DIR_PATH','Your-plugin-directory-path');
function ccm_get_template_part($slug, $name = null) {
do_action("ccm_get_template_part_{$slug}", $slug, $name);