Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Nikhil Nikschavan

🎯
Focusing
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 / 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 / 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' );
@Nikschavan
Nikschavan / astra-sidebar-before-content.css
Created Apr 2, 2018
Astra Theme - Move the sidebar before the content on mobile
View astra-sidebar-before-content.css
@media (max-width: 768px) {
#primary {
order: 2;
}
#secondary {
order: 1;
}
.ast-container {
@Nikschavan
Nikschavan / astra-sidebar-before-content.css
Created Apr 2, 2018
Astra Theme - Move the sidebar before the content on mobile
View astra-sidebar-before-content.css
@media (max-width: 768px) {
#primary {
order: 2;
}
#secondary {
order: 1;
}
.ast-container {
You can’t perform that action at this time.