Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
vishalbasnet23 / readme.md
Created April 21, 2016 12:02 — forked from hitautodestruct/readme.md
Generate a custom structure for Wordpress menus.

This gist is for showing an example of a custom wordpress menu.

If you want to get more from the menu item simply have a look at the $item object. i.e:

// Will return a large object with lots of props like title, url, description, id etc.
var_dump( $item );

This code works on Wordpress 4.1.1 as of 31st of March 2015

@vishalbasnet23
vishalbasnet23 / functions.php
Last active December 20, 2017 10:27
Add child, parent and sibling data to page end point of WP-Rest Api fields
<?php
function plugin_prepare_page_json( $data, $post, $request ) {
$_data = $data->data;
if( is_child( $post->post_parent, $post ) ) {
$_data['is_child'] = 'true';
$post_parent = $post->post_parent;
$post_parent_attributes = array();
$thumbnail_id = get_post_thumbnail_id( $post->post_parent );
$thumbnail_full = wp_get_attachment_image_src( $thumbnail_id, 'full' );
$thumbnail_thumb = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail' );
@vishalbasnet23
vishalbasnet23 / functions.php
Last active April 19, 2016 10:08
Add custom endpoint to WP-Rest Api to retrive customizer values of active theme.
<?php
add_action( 'rest_api_init', 'plugin_customizer_fields');
function plugin_customizer_fields() {
register_rest_route( 'beyondthebell/v1', '/customizer-fields/', array(
'methods' => 'GET',
'callback' => 'get_active_theme_customizer_fields',
) );
}
@vishalbasnet23
vishalbasnet23 / date-format.js
Created April 1, 2016 06:20
Safari fix for date NaN issue
function formatDate(createdDate) {
var monthNames = [
"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct",
"Nov", "Dec"
];
var parsedDate = Date.parse(createdDate);
// alert(parsedDate);
var date = new Date(createdDate.replace(/\s/, 'T'));
@vishalbasnet23
vishalbasnet23 / autobck.sh
Last active January 31, 2016 05:56
Auto Backup all the databases every 30 days on server
#!/bin/bash
USER="USER_NAME"
PASSWORD="PASSWORD"
OUTPUT="BACKUP_PATH"
#Deletes all the files before dumping again
rm "$OUTPUT/*gz" > /dev/null 2>&1
databases=`mysql --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
@vishalbasnet23
vishalbasnet23 / clonerepo.sh
Last active April 14, 2017 13:24
Cloning repo and installing WordPress and gitignore file.
#!/bin/bash
if [ "$#" -eq 1 ]; then
if [ -d "$1" ]; then
# Control will enter here if $DIRECTORY exists.
echo "Repository $1 already exists"
exit 0
fi
printf "Are you cloning empty repo \n 1. Yes \n 2. No \n"
@vishalbasnet23
vishalbasnet23 / sendlog.sh
Created November 25, 2015 06:19
Send Email of the git log for the day.
#!/bin/bash
todays_date="$(date +'%Y-%m-%d 09:00')"
current_date_with_time="$(date +'%Y-%m-%d %H:%M')"
printf "today's date is %s\n" "$todays_date"
printf "current date time is %s\n" "$current_date_with_time"
echo -n "Enter Project's name:"
read project_name #enter project name
git_dir="Your Git Directory"
if [ -d "Your Git Directory/$project_name" ]; then
# Control will enter here if $DIRECTORY exists.
@vishalbasnet23
vishalbasnet23 / functions.php
Created November 17, 2015 07:34
Overriding WooCommerce single-product-reviews.php from Plugin.
function override_template( $template ) {
global $woocommerce;
if ( get_post_type() == 'product' && file_exists( untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/woocommerce/single-product-reviews.php' ) ) {
return $this->cpm_woopr_plugin_path() . '/woocommerce/single-product-reviews.php';
}
return $woocommerce->comments_template_loader($template);
}
add_filter( 'comments_template', 'override_template', 100, 1 );
@vishalbasnet23
vishalbasnet23 / functions.php
Last active November 17, 2015 07:35
Overriding WooCommerce template from plugin.
function cpm_woopr_woocommerce_locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
$_template = $template;
if ( ! $template_path ) {
$template_path = $woocommerce->template_url;
}
$plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/woocommerce/';
// Look within passed path within the theme - this is priority.
$template = locate_template(
array(
@vishalbasnet23
vishalbasnet23 / Sublime-stuffs.txt
Created November 4, 2015 08:00
Install PHPCS with WordPress Coding Standard with Sublime Text 3
1. cmd+shift+p
2. Type phpcs and install it
3. Preferences > Package Settings > Php Code Sniffer > User settings