Skip to content

Instantly share code, notes, and snippets.

View Abd-Ur-Rehman's full-sized avatar
🎯
👨‍💻Living and breathing in code...

Abd Ur Rehman Abd-Ur-Rehman

🎯
👨‍💻Living and breathing in code...
View GitHub Profile
@Abd-Ur-Rehman
Abd-Ur-Rehman / functions.php
Created December 24, 2016 22:05
Create a child theme in WordPress
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
/*
Theme Name: Twenty Fifteen Child
Theme URI: http://www.abdurrehman.net/blog Description:
Twenty Fifteen Child
Theme Author: Abd Ur Rehman
Author URI: http://www.abdurrehman.net
Template: twentyseventeen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Database Name: wordpress
User Name (database): root
Password (database): root
Database Host/server: localhost
Table Prefix: wp_
// Disabling admin bar for non admin users (this would work on a non-Woo site...)
function abdurrehman_net_hide_admin_bar_if( $show ) {
if ( /* CONDITION */ ) $show = false;
return $show;
}
add_filter( 'show_admin_bar', 'abdurrehman_net_hide_admin_bar_if' );
/**
* Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from seeing the admin bar.
*
*/
function wc_disable_admin_bar( $show_admin_bar ) {
if ( apply_filters( 'woocommerce_disable_admin_bar', get_option( 'woocommerce_lock_down_admin', 'yes' ) === 'yes' ) && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_woocommerce' ) ) ) {
$show_admin_bar = false;
}
function bbloomer_hide_admin_bar_if_non_admin( $show ) {
if ( ! current_user_can( 'administrator' ) ) $show = false;
return $show;
}
add_filter( 'show_admin_bar', 'bbloomer_hide_admin_bar_if_non_admin', 20, 1 );
// please note the priority = '20' to make sure we run the filter after Woo's one
add_action ( 'woocommerce_after_shop_loop_item', 'user_logged_in_product_already_bought', 30);
function user_logged_in_product_already_bought() {
if ( is_user_logged_in() ) {
global $product;
$current_user = wp_get_current_user();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->id ) ) echo '<div class="user-bought">&hearts; Hey ' . $current_user->first_name . ', you\'ve purchased this in the past. Buy again?</div>';
}
{
"token": "s3924fdb1d93304f73fd1r13101e59f05b240d7f",
"include_users": ["ernilambar"]
}
@Abd-Ur-Rehman
Abd-Ur-Rehman / block access to readme.html
Created February 23, 2017 22:56
Block access to readme.html e.g. In the .htaccess file:
<files readme.html>
order allow,deny
deny from all
</files>
function lynt_remove_ver( $src ) {
$src = remove_query_arg('ver', $src);
return $src;
}
add_filter( 'script_loader_src', 'lynt_remove_ver' );
add_filter( 'style_loader_src', 'lynt_remove_ver' );