Skip to content

Instantly share code, notes, and snippets.

View tharlab's full-sized avatar
💭
I may be slow to respond.

Hary AK tharlab

💭
I may be slow to respond.
  • TharLab
  • east java
View GitHub Profile
@agarzon
agarzon / random_color.php
Last active September 11, 2023 17:04
PHP Random Color Generator Hex
<?php $color = dechex(rand(0x000000, 0xFFFFFF)); ?>
<body style="background-color: <?php echo $color; ?>;">
<h1><?php echo $color ?></h1>
</body>
@goldenapples
goldenapples / gravityforms-richeditors.php
Created May 26, 2012 20:19
Rich text editors for Gravity Forms
<?php
/*
Plugin Name: Rich Text editors for Gravity Forms
Description: Converts the textarea fields in Gravity Forms to WordPress rich text editors
Author: Nathaniel Taintor
Author URI: http://goldenapplesdesign.com
Version: 1.0
License: GPLv2
*/
@JeffreyWay
JeffreyWay / set-value.md
Created July 28, 2012 19:09
PHP: Set value if not exist

You know how, in JavaScript, we can set a value to a variable if one doesn't, like this:

name = name || 'joe';

This is quite common and very helpful. Another option is to do:

name || (name = 'joe');
@philbirnie
philbirnie / Instructions
Last active January 17, 2023 20:40
Steps to Combine Wordpress and Codeigniter when CI is in a subdirectory of Wordpress
Instructions
1. Add MY_url_helper.php to CI_directory/application/helpers
2. If the CI app is already built, convert any references to *site_url* in your CI application (aside from the system directory) to the new namespaced function, ci_site_url.
This step prevents Wordpress' site_url function from overwriting CIs. Because both functions are global and CI checks to make sure that site_url has not been set. Once we load the WP bootstrap file, it will have been defined, so CI's function wll never load.
3. Add Wordpress' bootstrap file into CI_directory/index.php right above CI's bootstrap file.
4. Update wp-includes/load.php *(this is necessary if you are using CI's sessions - Wordpress mangles CI's cookies using with magic quotes. (There may be an upgrade-proof way to do this.)
add_action( 'wp_enqueue_scripts', 'remove_comments_sitewide' );
/**
* @author Brad Dalton - WP Sites
* @learn more http://wp.me/p1lTu0-9Xn
*/
function remove_comments_sitewide() {
remove_action( 'genesis_after_post', 'genesis_get_comments_template' );
}
@markjaquith
markjaquith / gist:6225805
Last active February 21, 2024 23:56
WordPress multi-tenant directory structure sharing core files for opcode awesomeness, fast deployments, and low disk usage. With inspiration from @weskoop. "=>" indicates a symlink.
sites
|__ ms.dev
| |__ content
| |__ index.php
| |__ wp => ../../wordpress/stable
| |__ wp-config.php
|__ one.dev
| |__ content
| |__ index.php
| |__ wp => ../../wordpress/stable
@aahan
aahan / WordPress Custom Global Variables.md
Last active March 28, 2024 19:26
Creating and using custom global variables in wordpress.

First create global variables (in functions.php or as a mu-plugin):

<?php

/*
 * CUSTOM GLOBAL VARIABLES
 */
function wtnerd_global_vars() {
@DevinWalker
DevinWalker / woocommerce-optimize-scripts.php
Last active July 10, 2024 09:14
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@mannieschumpert
mannieschumpert / gist:8334811
Last active August 20, 2023 14:58
Filter the submit button in Gravity Forms to change the <input type="submit> element to a <button> element. There's an example in the Gravity Forms documentation, but it lacks the proper code to show your custom button text, AND removes important attributes like the onclick that prevents multiple clicks. I was trying to solve that.
<?php
// filter the Gravity Forms button type
add_filter("gform_submit_button", "form_submit_button", 10, 2);
function form_submit_button($button, $form){
// The following line is from the Gravity Forms documentation - it doesn't include your custom button text
// return "<button class='button' id='gform_submit_button_{$form["id"]}'>'Submit'</button>";
// This includes your custom button text:
return "<button class='button' id='gform_submit_button_{$form["id"]}'>{$form['button']['text']}</button>";
}
// Oops this strips important stuff
@brianoz
brianoz / class-virtualthemedpage-bc.php
Created February 20, 2014 01:10
WordPress Virtual page with theme
<?php
/*
* Virtual Themed Page class
*
* This class implements virtual pages for a plugin.
*
* It is designed to be included then called for each part of the plugin
* that wants virtual pages.
*
* It supports multiple virtual pages and content generation functions.