Skip to content

Instantly share code, notes, and snippets.

View mehrshaddarzi's full-sized avatar

Mehrshad Darzi mehrshaddarzi

View GitHub Profile
@mehrshaddarzi
mehrshaddarzi / LaravelEloquentCheatSheet.md
Last active September 7, 2021 05:02 — forked from MrTomek/EloquentCheatSheet.md
Laravel Eloquent relationships cheat sheet
@mehrshaddarzi
mehrshaddarzi / tickets.php
Created December 29, 2019 07:36 — forked from imath/tickets.php
Using WP Statuses for custom Post Types.
<?php
/**
* Using WP Statuses for custom Post Types.
*
* @link http://github.com/imath/wp-statuses
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
@mehrshaddarzi
mehrshaddarzi / functions.php
Created May 21, 2019 07:43 — forked from EvanHerman/functions.php
Localize the jquery datepicker in WordPress using the WP_Locale object
<?php
add_action( 'admin_enqueue_scripts', 'admin_print_js' );
public function admin_print_js() {
global $wp_locale;
//add the jQuery UI elements shipped with WP
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-datepicker' );
@mehrshaddarzi
mehrshaddarzi / edd_custom_licencing.php
Created March 4, 2019 07:04 — forked from vpratfr/edd_custom_licencing.php
EDD - Custom acitivation limit and expiration dates for variable pricing and bundles
/**
* Function to consolidate purchase data because info is missing from edd_get_payment_meta_cart_details
*/
function mlabs_get_product_price_id_for_purchase( $download_id, $payment_id ) {
$purchase_details = edd_get_payment_meta_cart_details( $payment_id, true );
if ( !is_array( $purchase_details ) ) return false;
foreach( $purchase_details as $item ) {
if( $item['id'] == $download_id ) {
//https://wordpress.stackexchange.com/questions/15376/how-to-set-default-screen-options
add_filter( 'hidden_meta_boxes', 'custom_hidden_meta_boxes' );
function custom_hidden_meta_boxes( $hidden ) {
// Hide meta boxes on the single Post screen
// Left column
$hidden[] = 'postexcerpt'; // Post Excerpts
$hidden[] = 'trackbacksdiv'; // Send Trackbacks
$hidden[] = 'postcustom'; // Custom Fields
$hidden[] = 'commentstatusdiv'; // Discussion
@mehrshaddarzi
mehrshaddarzi / functions.php
Created September 10, 2018 06:50 — forked from florentsorel/functions.php
WooCommerce : overirde loop/orderby.php template by button group with Bootstrap
<?php
/*
File : functions.php (in your theme)
Override "woocommerce_before_shop_loop" hook.
Add a check : (Line 41 - 43)
Avoid error if administrator choosing "rating" in administration and rating are disabled.
IF "woocommerce_enable_review_rating" option equal "no"
AND
"woocommerce_default_catalog_orderby" option equal "rating"
@mehrshaddarzi
mehrshaddarzi / gulpfile.js
Created February 23, 2018 18:49 — forked from Ammly/gulpfile.js
Gulp file to optimize js,css and images
npm install gulp-concat gulp-uglify gulp-strip-debug gulp-autoprefixer gulp-minify-css gulp-changed gulp-imagemin gulp-jshint --save-dev
// include gulp
var gulp = require('gulp');
//jshint
var jshint = require('gulp-jshint');
var changed = require('gulp-changed');
//imgs
var imagemin = require('gulp-imagemin');
var minifyHTML = require('gulp-minify-html');
@mehrshaddarzi
mehrshaddarzi / back-with-fallback.js
Created February 20, 2018 17:21 — forked from schjetne/back-with-fallback.js
Code to navigate to previous page in history if it exists, otherwise go back to a default "back" location.
// Use: ><a href="list.html" class="js-back">Go back</a>
$('.js-back').on('click', function(evt) {
if (document.referrer != "") {
evt.preventDefault();
history.back();
}
});
@mehrshaddarzi
mehrshaddarzi / plugin-filter.php
Created February 1, 2018 14:21 — forked from carlodaniele/plugin-filter.php
A Must-use plugin to filter active plugins in on a per-page basis.
<?php
// returns the path of the request URI without the query string
// see http://php.net/manual/en/function.parse-url.php
// and http://php.net/manual/en/reserved.variables.server.php
// and http://php.net/manual/en/url.constants.php
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
$is_admin = strpos( $request_uri, '/wp-admin/' );
@mehrshaddarzi
mehrshaddarzi / page-faculty-staff.php
Created November 11, 2017 19:42 — forked from freerangetech/page-faculty-staff.php
Switch to Blog and WP_Query Example
<?php
function smcm_pull_faculty_from_directory() {
//Get the slug of the calling site... array element [3]
$site_slug = explode ("/", get_site_url());
// blog id of the directory
$blog_id = 7;