Skip to content

Instantly share code, notes, and snippets.

View INDIAN2020's full-sized avatar

Gogula Sivannarayana INDIAN2020

View GitHub Profile
<?php
class My_Class {
public function my_func() {
// We can error log our data here.
error_log( __LINE__ ); // outputs 6
// Or we can also log which method we're in
error_log( __METHOD__ ); // outputs My_Class::my_func
}
@INDIAN2020
INDIAN2020 / list-user-role-name.php
Created June 18, 2018 06:57 — forked from yanknudtskov/list-user-role-name.php
List custom rolenames in the WordPress Admin User List area
<?php
/**
* Display Custom Roles in WordPress Admin
*/
add_action('manage_users_custom_column', 'yanco_show_user_roles_column_content', 10, 3);
function yanco_show_user_roles_column_content($value, $column_name, $user_id) {
global $wp_roles;
$user = get_userdata( $user_id );
// Post thumbnails support
add_theme_support('post-thumbnails');
// Menu support
add_theme_support('menus');
<?php
// Post editor styling
add_theme_support('editor-style');
// Post formats support
@INDIAN2020
INDIAN2020 / plugin.php
Created June 18, 2018 06:37 — forked from yanknudtskov/plugin.php
Dependent Plugin Activation/Deactivation and Alert
<?php
/*
* Dependent Plugin Activation/Deactivation
*
* Sources:
* 1. https://pippinsplugins.com/checking-dependent-plugin-active/
* 2. http://10up.com/blog/2012/wordpress-plug-in-self-deactivation/
*
*/
@INDIAN2020
INDIAN2020 / wc-categories-fallaback-image.php
Created June 18, 2018 06:37 — forked from yanknudtskov/wc-categories-fallaback-image.php
Remember to upload fallback-image.png to /wp-content/THEME_NAME/images where THEME_NAME is name of the directory of the active theme #woocommerce
<?php
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="" />';
@INDIAN2020
INDIAN2020 / oop-functions.php
Created June 18, 2018 06:37 — forked from yanknudtskov/oop-functions.php
OOP Functions for WordPress functions.php
<?php
class Functions {
private $theme_name;
private $theme_version;
public function __construct( $theme_name, $theme_version ) {
$this->theme_name = $theme_name;
@INDIAN2020
INDIAN2020 / allow-widget-title-html.php
Created June 18, 2018 06:34 — forked from yanknudtskov/allow-widget-title-html.php
Allow HTML tags in Widget Titles Insert tags with [ ] instead of < >
/**
* Allow HTML in Widget Titles
*/
function html_widget_title( $title ) {
//HTML tag opening/closing brackets
$title = str_replace( '[', '<', $title );
$title = str_replace( '[/', '</', $title );
// bold -- changed from 's' to 'strong' because of strikethrough code
$title = str_replace( 'strong]', 'strong>', $title );
$title = str_replace( 'b]', 'b>', $title );
@INDIAN2020
INDIAN2020 / add-to-cart.php
Created June 18, 2018 06:33 — forked from yanknudtskov/add-to-cart.php
Display Product Variations in the Shop Loop
<?php
/**
* Loop Add to Cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/loop/add-to-cart.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@INDIAN2020
INDIAN2020 / gravityforms-auto-trigger-next-previous.js
Created June 18, 2018 06:33 — forked from yanknudtskov/gravityforms-auto-trigger-next-previous.js
jQuery example to trigger next/previous buttons on GravityForms #gravity-forms
// This is the initial GravityForms binding, it will be lost upon a page change with next/previous
// Thus we make a bind on gform_page_loaded event also
if( jQuery('.custom-form').length > 0 ) {
jQuery('.gfield_radio input[type=radio]').bind("click", function() {
//console.log('Clicked: ' + jQuery( this ).closest('.gform_page').find('.gform_page_footer .gform_next_button.button') );
jQuery(this).closest('.gform_page').find('.gform_page_footer .gform_next_button.button').click();
});
}
jQuery(document).bind('gform_page_loaded', function(event, form_id, current_page){
@INDIAN2020
INDIAN2020 / upload-file-programatically.php
Created June 18, 2018 06:33 — forked from yanknudtskov/upload-file-programatically.php
Upload a file to the WordPress Media Library programatically using the URL of the file
<?php
//$file = '/path/to/file.png';
$file = rtrim(ABSPATH, '/').parse_url( 'http://url-to-file/file.png' , PHP_URL_PATH);
$filename = basename($file);
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],