Skip to content

Instantly share code, notes, and snippets.

View mostafasoufi's full-sized avatar
🍬

Mostafa Soufi mostafasoufi

🍬
View GitHub Profile
@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 / 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 / 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 / single.php
Created January 14, 2017 20:26
Show post view
<?php echo wp_statistics_pages($post->ID); ?>
<?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 January 3, 2017 12:33
Get first post link in Wordpress
<?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 January 3, 2017 06:04
Login into wordpress using URL
<?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() );
@mostafasoufi
mostafasoufi / functions.php
Created December 20, 2016 11:44
Get total (parrent & child) comment
<?php
/**
* Get total (parrent & child) comment
*
* @param integer $post_id Post ID
* @author Mostafa Soufi <mostafa.soufi@hotmail.com>
*/
public function get_total_count( $post_id ) {
global $wpdb, $table_prefix;
@mostafasoufi
mostafasoufi / function.php
Created November 13, 2016 09:03
Disable m4a and m4b type in wordpress upload
<?php
/**
* Modify mime types
* @param array $mime_types Mime types
*/
public function modify_mime_type($mime_types){
// Unset m4a type
unset( $mime_types['mp3|m4a|m4b'] );
// Added mp3 type
@mostafasoufi
mostafasoufi / query.sql
Created November 6, 2016 06:04
Get total post type from wordpress with Query
select `post_type`, count(*) from `wp_posts` group by `post_type`