Skip to content

Instantly share code, notes, and snippets.

View vpadhariya's full-sized avatar

Vijay Padhariya vpadhariya

View GitHub Profile
@vpadhariya
vpadhariya / GenerateBaseModelsController.php
Last active August 10, 2017 08:16
Yii2 Generate Base models (put this file into your yii2 project under console/controller/GenerateBaseModelsController.php) and run php yii generate-base-models
<?php
namespace console\controllers;
use Yii;
/**
* Controller to Generate base models
* NOTE : make sure you are using Development Environment.
* @author digitize
@vpadhariya
vpadhariya / widgetFactory.php
Created August 6, 2015 14:20
Yii 1.1.16 Widget Factory Setting -- (put them under protected/config/widgetFactory.php) and in main.php file include using "CMap::mergeArray()" method
<?php
/**
* Common Settings for widgets across whole project
* @reference : http://www.yiiframework.com/doc/api/1.1/CWidgetFactory
* Based on Bootstrap CSS class
*/
return array(
'components' => array(
'widgetFactory' => array( // Default properties for some widgets
@vpadhariya
vpadhariya / WordPress-Auto-Login-Script.php
Last active August 31, 2023 19:15
WordPress Auto Login Script
<?php
// Set a veriable for redirection (Optional)
$redirect_to = '';
/**
* WordPress Auto login script
*/
if(!is_user_logged_in())
{
@vpadhariya
vpadhariya / WordPress-Add-Taxonomy-to-RSS-Feeds.php
Last active August 10, 2017 08:23
WordPress Add Taxonomy (Category or Tag) before post title in RSS Feeds
<?php
/**
* Prepend taxonomy name before feed title for Articles
* This will work for any custom post type or custom taxonomy
*/
function add_feed_item_title($content)
{
global $wp_query;
@vpadhariya
vpadhariya / WordPress-remove-query-string-from-static-resource.php
Last active August 10, 2017 08:22
WordPress remove query string from static resource
<?php
/**
* Remove query string from static resource
* @param type $src
* @return type
*/
function _remove_script_version($src)
{
$return = $src;
@vpadhariya
vpadhariya / WordPress-trash-post-if-category-deleted.php
Last active August 10, 2017 08:21
In wordpress there were some certain requirement if the category was deleted then we need to Trash the posts attached to theme, here is the code how to achieve this easily.
<?php
/**
* If any category is deleted move all attached posts into trash
*/
function trash_category_posts($object_id, $tt_ids)
{
/**
* 1. Check the post_type
* 2. Check the action is delete or delete-tag
* 3. Check the taxonomy type is "category"
@vpadhariya
vpadhariya / PHP-Trim-output.php
Last active August 10, 2017 08:21
PHP Trim html output of a html page
<?php
/**
* Trim output of html
*/
function trim_output($buffer)
{
// Replace key with their values.
$replace = array(
"#<!--.*?-->#s" => "", // strip comments
@vpadhariya
vpadhariya / wordpres-get-posts-base-on-category-ratio.php
Created October 11, 2017 08:34
WordPress - Get posts base on ratio percentage per category
<?php
/**
* Category Ratio: Get Posts base on Custom % per category it means that each category.
*
* Get Category ratio from Settings like below.
* $category_ratio = array(category_id for selected category => inserted category ratio);
*
* NOTE: Most important the total of category ratio for all the selected categories must be 100%
* (this you need to set using JavaScript logic on back admin) otherwise it will create problem.
@vpadhariya
vpadhariya / clone site using wget.txt
Created January 23, 2018 07:57
Clone site and remove query string values from the files in linux.
# Clone entire site.
wget --content-disposition --execute robots=off --recursive --no-parent --continue --no-clobber http://example.com
# Remove query string from a static resource.
for i in `find $1 -type f -name "*\?*"`; do mv $i `echo $i | cut -d? -f1`; done
@vpadhariya
vpadhariya / create_directory.php
Last active July 24, 2018 10:23
In any of core php project this function will help you create directory structure like follow PROJECT_ROOT/uploads/1_100 PROJECT_ROOT/uploads/101_200 PROJECT_ROOT/uploads/201_300 here is how to use it below will create PROJECT_ROOT/uploads/1_100 and return its path. createDir(1, "PROJECT_ROOT/uploads/"); Where PROJECT_ROOT is the hard path of th…
<?php
/**
* Creates a directory according to given id and parent dir path
* @params integer $id this id will decide which directory to return or create and then return
* @params string $parent this will decide what is the path of the directory.
*/
function createDir($id, $parent)
{
$nd_dirlimit = 100;
$mod = ceil($id / $nd_dirlimit) - 1;