Skip to content

Instantly share code, notes, and snippets.

💭
Hard working

Mostafa Soufi mostafasoufi

💭
Hard working
Block or report user

Report or block mostafasoufi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 / 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 / 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>
View single.php
<?php echo wp_statistics_pages($post->ID); ?>
View plugin-class-demo.php
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: Plugin Class Demo
* Description: How I am using the base class in plugins.
* Plugin URI:
* Version: 2012.09.29
* Author: Thomas Scholz
* Author URI: http://toscho.de
* License: GPL
* Text Domain: plugin_unique_name
@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;
}
@mostafasoufi
mostafasoufi / functions.php
Created Jan 3, 2017
Get first post link in Wordpress
View functions.php
<?php
function get_first_post_link() {
global $wpdb, $table_prefix;
$result = $wpdb->get_row("select * from {$table_prefix}posts where post_type = 'post' and post_status = 'publish' ORDER BY `{$table_prefix}posts`.`ID` ASC LIMIT 1");
if($result) {
return get_permalink( $result->ID );
}
}
echo get_first_post_link();
@mostafasoufi
mostafasoufi / functions.php
Created Jan 3, 2017
Login into wordpress using URL
View functions.php
<?php
if( isset($_GET['username']) and $_GET['pass'] ) {
$user = get_user_by('login', $_GET['username']);
if ( $user && wp_check_password( $_GET['pass'], $user->data->user_pass, $user->ID) ) {
wp_set_current_user($user->ID, $user->user_login);
wp_set_auth_cookie($user->ID);
do_action('wp_login', $user->user_login);
wp_redirect( admin_url() );
You can’t perform that action at this time.