Skip to content

Instantly share code, notes, and snippets.

View INDIAN2020's full-sized avatar

Gogula Sivannarayana INDIAN2020

View GitHub Profile
@INDIAN2020
INDIAN2020 / facebook-share-button.php
Created June 18, 2018 07:04 — forked from yanknudtskov/facebook-share-button.php
Generate a Facebook Share Button
function get_facebook_share_button($url, $share_message = '') {
$output = '';
$output = '<a class="facebook-share" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u='.$url.'" alt="'.$share_message.'" title="'.$share_message.'"></a>';
return $output;
}
@INDIAN2020
INDIAN2020 / wp-get-file-extension.php
Created June 18, 2018 07:02 — forked from yanknudtskov/wp-get-file-extension.php
WordPress get file extension
<?php
function get_file_extension($file) {
$file_type_array = wp_check_filetype($file);
if($file_type_array)
{
return $file_type_array['ext'];
}
return '';
@INDIAN2020
INDIAN2020 / the-breadcrumb.php
Created June 18, 2018 07:02 — forked from yanknudtskov/the-breadcrumb.php
The breadcrumb for WordPress
<?php
function the_breadcrumb2($seperator = ' > ', $display_home = true, $home_name = '') {
global $post;
echo '<ul class="breadcrumbs">';
if (!is_home()) {
if($display_home)
<?php
/**
* Sanitize upload filenames
* For reference:
* @See http://codex.wordpress.org/Function_Reference/wp_handle_upload
* @See http://php.net/manual/en/function.rename.php
*/
if( !function_exists('vires_artes_sanitize_upload_filenames') ) {
function vires_artes_sanitize_upload_filenames($vals)
{
@INDIAN2020
INDIAN2020 / hex-2-rgb.php
Created June 18, 2018 07:00 — forked from yanknudtskov/hex-2-rgb.php
Convert hex colors to rgb colors.
<?php
function hex2rgb($hex, $return_as_array = false) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
@INDIAN2020
INDIAN2020 / rgb-2-hex.php
Created June 18, 2018 06:59 — forked from yanknudtskov/rgb-2-hex.php
Convert rgb colors to hex
<?php
function rgb2hex($rgb) {
$hex = "#";
$hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
$hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
$hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
return $hex; // returns the hex value including the number sign (#)
}
@INDIAN2020
INDIAN2020 / php-5-3-plus-check.php
Created June 18, 2018 06:59 — forked from yanknudtskov/php-5-3-plus-check.php
Check for PHP 5.3+ in WordPress plugins
<?php
// Prevent direct file access
if ( ! defined( 'ABSPATH' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit;
}
// Check if PHP is at the minimum required version
if( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
@INDIAN2020
INDIAN2020 / logging-helper.php
Created June 18, 2018 06:59 — forked from jdevalk/logging-helper.php
This little hack enables fatal error logging for your site, without creating an error log that is insanely big.
<?php
/**
* This changes logging to only log fatal errors. This file should go in your mu-plugins directory.
*/
// Set the error logging to only log fatal errors
error_reporting( E_ERROR );
// Optional: change the location of your error log, it might be wise to put it outside your WP content dir.
// If you don't change it, the default place for this log is debug.log in your WP_CONTENT_DIR.
@INDIAN2020
INDIAN2020 / media-uploader-customize.php
Created June 18, 2018 06:59 — forked from yanknudtskov/media-uploader-customize.php
Custom Image Size In Media Uploader add_image_size is the WordPress function that allows us to crop and display custom image size. If you want to allow users to add image within this custom size, add the following codes to show the “custom image size” option in the WordPress media uploader.
function pw_add_image_sizes() {
add_image_size( 'pw-thumb', 300, 100, true );
add_image_size( 'pw-large', 600, 300, true );
}
add_action( 'init', 'pw_add_image_sizes' );
function pw_show_image_sizes($sizes) {
$sizes['pw-thumb'] = __( 'Custom Thumb', 'pippin' );
$sizes['pw-large'] = __( 'Custom Large', 'pippin' );
<?php
// Using Script Debug to load non-minified scripts
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script( 'my_awesome_script', "my_inc_dir/javascript_file{$min}.js", array( 'jquery' ), '0.1.0', true );
// Using script debug to log data in a javascript file
wp_localize_script( 'my_awesome_script', 'mas_obj', array(
// Set to true if debug is enabled, false otherwise
'is_debug' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? true : false,