Skip to content

Instantly share code, notes, and snippets.

View mostafasoufi's full-sized avatar
🍬

Mostafa Soufi mostafasoufi

🍬
View GitHub Profile
@mostafasoufi
mostafasoufi / date_diff.php
Last active March 10, 2017 20:02
Get Number of days between two dates
<?php
if (!function_exists('get_days_number')) {
/**
* Get Number of days between tho dates
*
* @param string $first_date First date
* @param string $second_date Second date
* @return float
*/
function get_days_number($first_date, $second_date)
@mostafasoufi
mostafasoufi / function.php
Last active May 7, 2017 09:51
Disable REST API endpoints in the WordPress
<?php
// Removed wordpress rest endpoints
remove_action( 'rest_api_init', 'create_initial_rest_routes', 99 );
@mostafasoufi
mostafasoufi / checker.php
Last active September 5, 2017 07:06
PHP & MySQL checker
<?php
/**
* Class Service_Checker
* @author Mostafa Soufi
*/
class Service_Checker {
/**
* @var array
*/
@mostafasoufi
mostafasoufi / functinos.php
Last active September 6, 2017 10:25
Get next & previous post in WordPress
<?php
/**
* Get Next & Previous post
*
* @param $post_id
* @param $category_id
* @param string $taxonomy
*
* @return array
*/
@mostafasoufi
mostafasoufi / functinos.php
Created September 17, 2017 13:11
How get pages stat list with page slug
<?php
global $wpdb, $table_prefix;
$page_slug = '%about%';
$pages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$table_prefix}statistics_pages` WHERE `uri` LIKE %s", $page_slug ) );
echo '<table border="1"><tr><td>ID</td><td>Count</td><td>Slug</td></tr>';
foreach ( $pages as $page ) {
echo "<tr><td>{$page->id}</td><td>{$page->count}</td><td>{$page->uri}</td></tr>";
}
echo '</table>';
@mostafasoufi
mostafasoufi / update.sh
Created September 1, 2018 08:12
Run some commands in bulk project with bash script
#!/bin/bash
RED='\033[0;31m'
NC='\033[0m'
array=(
"project-name1"
"project-name2"
)
for i in ${array[*]}
@mostafasoufi
mostafasoufi / functions.php
Last active March 15, 2019 20:30
Sending SMS in WordPress (Required WP-SMS plugin)
<form method="post" action="">
<label>
Destination number:
<input type="text" value="" name="number" required>
</label>
<label>
Text:
<textarea name="message" required></textarea>
</label>
@mostafasoufi
mostafasoufi / functions.php
Created January 4, 2017 11:08
Upload custom post type files in another folder.
<?php
/**
* Upload custom post type files in another folder
* @author Mostafa soufi <mostafa.soufi@hotmail.com>
*/
add_filter( 'upload_dir', function($args) {
if( !isset($_REQUEST['post_id']) ) {
return $args;
}
@mostafasoufi
mostafasoufi / print.php
Last active December 13, 2019 14:52
Print my name with foreach in PHP
<?php
// TASK 1 - print out your name with one of php loops
foreach (str_split('Mostafa') as $char) {
echo $char;
}
@mostafasoufi
mostafasoufi / dump.sql
Created December 15, 2019 16:22
Employees MySQL Database
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;