Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Nikhil Nikschavan

View GitHub Profile
@Nikschavan
Nikschavan / auto-update-plugin.php
Last active Sep 8, 2016
Automatically update WordPress plugins whenever updates are available
View auto-update-plugin.php
<?php
function auto_update_specific_plugins ( $update, $item ) {
// Array of plugin slugs to always auto-update
$plugins = array (
'bb-ultimate-addon',
);
if ( in_array( $item->slug, $plugins ) ) {
return true; // Always update plugins in this array
} else {
@Nikschavan
Nikschavan / user.php
Last active Sep 19, 2016
Add this file in `wp-content/mu-plugins/user.php` and just reload the site, a new user will be created with username and password used in the script below.
View user.php
<?php
add_action( 'init', 'add_new_user' );
function add_new_user() {
$website = "http://example.com";
$userdata = array(
'user_login' => 'user_name',
'user_url' => $website,
'user_pass' => 'user_password',
@Nikschavan
Nikschavan / mysql-monitor.sh
Created Dec 20, 2016
Shell script to restart MySQL automatically when it shuts down
View mysql-monitor.sh
#!/bin/bash
UP=$(pgrep mysql | wc -l);
if [ "$UP" -ne 1 ];
then
echo "MySQL is down.";
sudo service mysql start
fi
View change-header-per-page.php
<?php
/**
* Change the dynamic header for a particular page.
*
* @param String $header_id Page/Template ID of the header set from the options panel.
* @return String Page/Template ID of the header after manipulation.
*/
function bbhf_header_override( $header_id ) {
View phpcs.xml.dist
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">
<description>Generally-applicable sniffs for WordPress plugins</description>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.3-"/>
<rule ref="WordPress-Core" />
<rule ref="WordPress-Docs" />
@Nikschavan
Nikschavan / ssl.conf.template
Created Jan 29, 2018
Nginx SSL Configuration for Let's Encrypt.
View ssl.conf.template
listen 443 http2 ssl;
ssl on;
ssl_certificate /etc/letsencrypt/live/<your-domain>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<your-domain>/privkey.pem;
@Nikschavan
Nikschavan / astra-woocommerce-sensei-wrappers.php
Last active Feb 1, 2018
Astra Theme wrappers for the WooCommerce sensei
View astra-woocommerce-sensei-wrappers.php
<?php // don't copy this line to your file.
// disable the default wrappers for the WooCommerce Sensei templates.
global $woothemes_sensei;
remove_action( 'sensei_before_main_content', array( $woothemes_sensei->frontend, 'sensei_output_content_wrapper' ), 10 );
remove_action( 'sensei_after_main_content', array( $woothemes_sensei->frontend, 'sensei_output_content_wrapper_end' ), 10 );
/**
* Load the correct wrappers for the WooCommerce Sensei layouts.
*/
@Nikschavan
Nikschavan / allow-html-tags-in-post-excerpt.php
Created Feb 27, 2018
Allow iframe in the WordPress post excerpt.
View allow-html-tags-in-post-excerpt.php
<?php // don't copy this line in your code.
function your_prefix_custom_excerpt($text) {
$raw_excerpt = $text;
if ( '' == $text ) {
//Retrieve the post content.
$text = get_the_content('');
//Delete all shortcode tags from the content.
@Nikschavan
Nikschavan / woocommerce-remove-uncategorized-from-breadcrumb.php
Last active Feb 28, 2018
Remove Untitled category from the breadcrumb.
View woocommerce-remove-uncategorized-from-breadcrumb.php
<?php // don't copy this line in your code.
/**
* Remove uncategorized from the WooCommerce breadcrumb.
*
* @param Array $crumbs Breadcrumb crumbs for WooCommerce breadcrumb.
* @return Array WooCommerce Breadcrumb crumbs with default category removed.
*/
function your_prefix_wc_remove_uncategorized_from_breadcrumb( $crumbs ) {
$category = get_option( 'default_product_cat' );
$caregory_link = get_category_link( $category );
@Nikschavan
Nikschavan / astra-single-post-navigation-same-category.php
Created Mar 13, 2018
Make single post navigation to get links for posts in same category - Astra theme - https://wpastra.com/
View astra-single-post-navigation-same-category.php
<?php
function your_prefix_single_post_navigation_same_category( $args ) {
$args[ 'in_same_term' ] = true;
return $args;
}
add_filter( 'astra_single_post_navigation', 'your_prefix_single_post_navigation_same_category' );
You can’t perform that action at this time.