Skip to content

Instantly share code, notes, and snippets.

View ashokmhrj's full-sized avatar

Ashok Maharjan ashokmhrj

  • Web Equation
  • Nepal
View GitHub Profile
@ashokmhrj
ashokmhrj / zip-archive-recursive-fn.php
Last active June 10, 2016 06:18
Archive folder php
<?php
/**
* PHP script to zip folder using RecursiveDirectoryIterator PHP function
*/
// Get real path for folder
$folder_to_zip = realpath("path-to-folder");
//saving zip
$zipname = "zip-file-name.zip";
<?php
/**
* PHP script for zip directory recursive function
*/
//source: http://ramui.com/articles/php-zip-files-and-directory.html
function recurse_zip($src,&$zip,$path_length) {
$dir = opendir($src);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
@ashokmhrj
ashokmhrj / importing-db.php
Last active June 10, 2016 06:42
Importing tables structures and data using php
<?php
/**
* Importing tables structures and data using php
*/
function backup_database( $tables = '*' ){
try{
$conn = mysqli_connect($host_name, $username, $password, $dbname);
//get all of the tables
if($tables == '*') {
$tables = array();
@ashokmhrj
ashokmhrj / wordpress-excerpt-html-format.php
Created December 29, 2015 10:42
Wordpress excerpt html tags with formatting
<?php
/**
* this wordpress script is for accepting the excerpt function with html format along with css design.
*/
// child custom excerpt length
function custom_excerpt_length( $length ) {
return 199;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
@ashokmhrj
ashokmhrj / importing-db-cli.php
Last active January 7, 2016 07:08
PHP Importing database via CLI mode
<?php
/**
* import db via Command Line Interface (CLI) PHP
*/
define('DBUSER','DBUSER');
define('DBPASSWD','DBPASSWRD');
define('DATABASE','DBNAME');
define('HOST','host');
$filename = "backup-" . date("d-m-Y") . ".sql.gz";
@ashokmhrj
ashokmhrj / custom-template-plugin.php
Last active October 21, 2023 13:36
Get Template Part From plugin directory
<?php
/**
* The below function will help to load template file from plugin directory of wordpress
* Extracted from : http://wordpress.stackexchange.com/questions/94343/get-template-part-from-plugin
*/
define('PLUGIN_DIR_PATH','Your-plugin-directory-path');
function ccm_get_template_part($slug, $name = null) {
do_action("ccm_get_template_part_{$slug}", $slug, $name);
@ashokmhrj
ashokmhrj / lat-long.php
Created January 13, 2016 10:01
Fetch Latitude and lonigitude
<?php
/**
* Fetch Latitude and Longitude
* Need google api key with geo code enabled
*/
function get_lat_long($address){
$address = str_replace(", ", ",+", $address);
$address = str_replace("+", "+", $address);
$address = str_replace(" ", "+", $address);
@ashokmhrj
ashokmhrj / remove_harmful-code.php
Last active June 10, 2016 07:40
remove malicious code wordpress
<?php
/**
* remove malicious code
* Removing a string in a PHP file with Start and End
*/
set_time_limit(0);
define('ABSPATH', dirname( __FILE__ ) );
@ashokmhrj
ashokmhrj / MY_Router.php
Last active April 29, 2021 19:21
HMVC Router for handling moduler routing in Codeigniter 3.x
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
/**
* Router Class
*
* Parses URIs and determines routing
*
* @package CodeIgniter
* @subpackage Libraries
* @author ashokmhrj
@ashokmhrj
ashokmhrj / wp-pagination.php
Last active April 17, 2018 11:37 — forked from mishalrai/WP-bootstrap-pagination.php
Wordpress pagination with bootstrap pagination design
<?php
/**
* Wordpress pagination
* paginate_links
* https://codex.wordpress.org/Function_Reference/paginate_links
*/
function wp_pagination($echo = true) {
global $wp_query;
$big = 999999999; // need an unlikely integer