Skip to content

Instantly share code, notes, and snippets.

💭
Hard working

Mostafa Soufi mostafasoufi

View GitHub Profile
@mostafasoufi
mostafasoufi / functions.php
Last active Mar 15, 2019
Sending SMS in WordPress (Required WP-SMS plugin)
View functions.php
<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 / update.sh
Created Sep 1, 2018
Run some commands in bulk project with bash script
View update.sh
#!/bin/bash
RED='\033[0;31m'
NC='\033[0m'
array=(
"project-name1"
"project-name2"
)
for i in ${array[*]}
@mostafasoufi
mostafasoufi / query.sql
Last active Jan 3, 2018
Change wordpress URLs with Mysql query
View query.sql
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
@mostafasoufi
mostafasoufi / functinos.php
Created Sep 17, 2017
How get pages stat list with page slug
View functinos.php
<?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 / functinos.php
Last active Sep 6, 2017
Get next & previous post in WordPress
View functinos.php
<?php
/**
* Get Next & Previous post
*
* @param $post_id
* @param $category_id
* @param string $taxonomy
*
* @return array
*/
@mostafasoufi
mostafasoufi / checker.php
Last active Sep 5, 2017
PHP & MySQL checker
View checker.php
<?php
/**
* Class Service_Checker
* @author Mostafa Soufi
*/
class Service_Checker {
/**
* @var array
*/
@mostafasoufi
mostafasoufi / function.php
Last active May 7, 2017
Disable REST API endpoints in the WordPress
View function.php
<?php
// Removed wordpress rest endpoints
remove_action( 'rest_api_init', 'create_initial_rest_routes', 99 );
@mostafasoufi
mostafasoufi / date_diff.php
Last active Mar 10, 2017
Get Number of days between two dates
View date_diff.php
<?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)
View single.php
<?php echo wp_statistics_pages($post->ID); ?>
@mostafasoufi
mostafasoufi / functions.php
Created Jan 4, 2017
Upload custom post type files in another folder.
View functions.php
<?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;
}
You can’t perform that action at this time.