Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Dipak C. Gajjar dipakcg

🎯
Focusing
View GitHub Profile
@dipakcg
dipakcg / current_date.html
Created Apr 2, 2014
Generate current date using Javascript
View current_date.html
<script type="text/javascript"> //Generate current date
var currentDate = new Date();
var month = currentDate.getMonth() + 1;
var day = currentDate.getDate();
var year = currentDate.getFullYear();
document.write(day + "/" + month + "/" + year);
//-->
</script>
@dipakcg
dipakcg / prevent_sql_injection.php
Created Apr 2, 2014
Sample PHP Code (MySQLi insert query) to prevent SQL injection
View prevent_sql_injection.php
<?php
/* Use mysql parameterized statements rather than simple mysql query to prevent sql injection */
// Connect to MySQLi - Change DB_HOST, DB_USER, DB_PASS, DB_NAME with appropriate values
$mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or DIE ('Could not connect to the database:' . mysqli_connect_error());
mysqli_set_charset($mysqli, 'utf-8');
// Change field1 and so on with database fields.
$stmt = $dbc->prepare("INSERT INTO database_name (field1, field2, field3, field4, field5)
VALUES (?, ?, ?, ?, ?)");
// s = string, i = integer, d = double
@dipakcg
dipakcg / style.css
Created Aug 20, 2014
Change the Default Text Selection Color
View style.css
/* Add the below code in main stylesheet */
/* ORANGE background and WHITE font-color */
::-moz-selection {
background-color: #FF6200;
color: #FFFFFF;
}
::selection {
background-color: #FF6200;
color: #FFFFFF;
@dipakcg
dipakcg / functions.php
Created Aug 24, 2014
WordPress - Display update notification for Admins
View functions.php
/* Adding this PHP code to the functions.php of WordPress theme will only display WordPress update notifications to admin users. */
global $user_login;
get_currentuserinfo();
if (!current_user_can('update_plugins')) {
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}
@dipakcg
dipakcg / .htaccess
Created Aug 26, 2014
WordPress - Protect wp-config.php file from brute force attacks
View .htaccess
# Add the following code in .htaccess to protect wp-config.php file from brute force attacks
<Files wp-config.php>
order allow,deny
deny from all
</Files>
@dipakcg
dipakcg / .htaccess
Created Aug 26, 2014
WordPress - Protect .htaccess file from brute force attacks
View .htaccess
# Add the following code in .htaccess to protect .htaccess file from brute force attacks
<Files .htaccess>
order allow,deny
deny from all
</Files>
@dipakcg
dipakcg / functions.php
Last active Aug 29, 2015
WordPress - Use Gravatar image as WordPress favicon
View functions.php
<?php
// Add the following code in theme's functions.php file to use Gravatar image as favicon (16x16 favicon.ico)
function dcg_gravatar_favicon() {
// Replace email here
$GetEmailHash = md5(strtolower(trim('me@dipakgajjar.com')));
?>
<link rel="shortcut icon" href="<?php echo 'http://www.gravatar.com/avatar/' . $GetEmailHash . '?s=16;'; ?>" type="image/x-icon" />
<?php
}
add_action('wp_head', 'dcg_gravatar_favicon');
@dipakcg
dipakcg / functions.php
Created Sep 5, 2014
WordPress - Pass URL (with ? and &) to shortcode_atts in shortcode function
View functions.php
// Add following code into functions.php of WordPress theme
function willhill_text($atts) {
extract( shortcode_atts( array(
"xmlurl"=>'http://'),
$atts
)
);
$str_format = str_replace(array("&#038;","&amp;"), "&", $xmlurl);
@dipakcg
dipakcg / functions.php
Last active Aug 29, 2015
WordPress - Modify default role names “Administrator, Editor, Author, Contributor, Subscriber” to fit your needs
View functions.php
/*
Change the default role names (Administrator, Editor, Author, Contributor, Subscriber) to any custom names.
Add the following code in theme's functions.php file (edit lines 5 and 6 for custom name).
*/
function wp_change_role_name() {
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();
$wp_roles->roles['contributor']['name'] = 'Owner';
@dipakcg
dipakcg / functions.php
Created Oct 31, 2014
WordPress - Replace ‘Enter Title Here’ Text
View functions.php
/*
Replace ‘Enter Title Here’ Text in WordPress ( http://i.imgur.com/ZAzGY6g.png )
Add the following code in theme's functions.php file.
Read more at : http://gajjar.me/1q6ADaI
*/
function wpb_change_title_text( $title ){
$screen = get_current_screen();
if ( 'movie' == $screen->post_type ) {