Skip to content

Instantly share code, notes, and snippets.

View mehrshaddarzi's full-sized avatar

Mehrshad Darzi mehrshaddarzi

View GitHub Profile
@mehrshaddarzi
mehrshaddarzi / gist:a7472ebd0f2983f5ef4d523851b82ac4
Created September 17, 2017 09:28 — forked from boonebgorges/gist:2185537
Recursively sort the output of get_categories() in order of parent-child hierarchy
<?php
$categories = get_the_category();
// Assemble a tree of category relationships
// Also re-key the category array for easier
// reference
$category_tree = array();
$keyed_categories = array();
@mehrshaddarzi
mehrshaddarzi / orm.php
Last active August 27, 2019 18:59
orm collection
<?php
//relation for deletting in migration
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
//if exist
Notification::where('tel', '=', $tel)->where('read', '=', '1')->exists();
//create
irantime();
function array_insert( $array, $index, $insert ) {
return array_slice( $array, 0, $index, true ) + $insert +
array_slice( $array, $index, count( $array ) - $index, true);
}
add_filter( 'manage_resource_posts_columns' , function ( $columns ) {
return array_insert( $columns, 2, [
'image' => 'Featured Image'
] );
});
/**
* A widget that does amazing things!
*/
class Amazing_Widget extends WP_Widget {
/**
* Registers the widget with the WordPress Widget API.
*
* @return void.
*/
public static function register() {
@mehrshaddarzi
mehrshaddarzi / meta_valu_order.php
Created September 24, 2017 19:41
Wp_query Order By Meta Valur number
$args = array(
'posts_per_page' => -1,
'product_cat' => $cat,
'post_type' => 'product',
'orderby' => 'meta_value_num',
'meta_key' => '_price',
'order' => 'asc'
);
<!DOCTYPE html>
<html>
<body>
<style>
#holder.hover { border: 10px dashed #0c0 !important; }
</style>
<form method="post" action="http://httpbin.org/post" enctype="multipart/form-data">
<input id="name"><br/>
<input id="type"><br/>
<input id="size"><br/>
@mehrshaddarzi
mehrshaddarzi / List Of Error function in jQuery Ajax
Last active September 21, 2019 07:31
complete Ajax Form in wordpress + file Upload
console.log(jqXHR.status); //https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
console.log(jqXHR.readyState); //https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
console.log(jqXHR.responseJSON);
console.log(jqXHR.responseText);
$.ajax({
url: wp_extensions_js_var.wp_rest_url + '/' + token + '/v1/test-connection?domain=' + domain,
type: 'get',
dataType: "json",
cache: false,
@mehrshaddarzi
mehrshaddarzi / load_excel.php
Created October 9, 2017 15:27
Load Excel file in php with phpexcel
require_once str_replace("\\","/",get_template_directory()) . '/includes/phpexcel/PHPExcel.php';
// Create new PHPExcel object
//$objPHPExcel = new PHPExcel();
// Create new PHPExcel object
$upload_dir = str_replace("\\","/",wp_upload_dir()['basedir']);
try {
@mehrshaddarzi
mehrshaddarzi / not_allow_delete.php
Created October 9, 2017 20:15
Not allow Delete User in Wordpress with condition
add_filter(
'user_row_actions',
function($actions, $user_object) {
$result = new WP_Query(
array(
'author'=> $user_object->ID,
'post_type'=>'portfolio',
'posts_per_page'=>1,
)
);
@mehrshaddarzi
mehrshaddarzi / bootstrap-pagination.php
Last active October 11, 2017 06:22 — forked from ediamin/bootstrap-pagination.php
Bootstrap Pagination for WordPress
// https://www.kevinleary.net/wordpress-pagination-paginate_links/
/*
* custom pagination with bootstrap .pagination class
* source: http://www.ordinarycoder.com/paginate_links-class-ul-li-bootstrap/
*/
function bootstrap_pagination( $echo = true ) {
global $wp_query;