Skip to content

Instantly share code, notes, and snippets.

💭
Hard working

Mostafa Soufi mostafasoufi

View GitHub Profile
@mostafasoufi
mostafasoufi / functions.php
Created Aug 22, 2016
Modify mime type in wordpress
View functions.php
<?php
/**
* Modify wordpress mime types
* @param array $existing_mimes current mimes
*/
function modify_mime_type($existing_mimes){
return array_merge($existing_mimes, array(
'7z' => 'application/x-7z-compressed',
'rar' => 'package/rar',
'tar' => 'package/x-tar',
@mostafasoufi
mostafasoufi / functions.php
Last active Aug 22, 2016
Wordpress post field validation (Change post status to draft if post is not complete)
View functions.php
<?php
/**
* Change post status to draft if post is not complete
* @param integer $post_id Post ID
* @param object $post Post Object
* @author Mostafa Soufi <mostafa.soufi@hotmail.com>
*/
function validate_post_field($post_id, $post) {
// Check post status
if( $post->post_status != 'publish' )
@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 / functions.php
Last active Sep 25, 2016
Comment fields position order handler
View functions.php
<?php
/**
* Comment fields position order handler
* @param array $form Form fields
* @author Mostafa Soufi <mostafa.soufi@hotmail.com>
* @link (http://mostafa-soufi.ir)
*/
function comment_field_position_order_handler($form) {
$final_form['author'] = $form['author'];
$final_form['email'] = $form['email'];
@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)
@mostafasoufi
mostafasoufi / query.sql
Created Nov 6, 2016
Get total post type from wordpress with Query
View query.sql
select `post_type`, count(*) from `wp_posts` group by `post_type`
@mostafasoufi
mostafasoufi / function.php
Created Nov 13, 2016
Disable m4a and m4b type in wordpress upload
View function.php
<?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 / 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 / functions.php
Created Dec 20, 2016
Get total (parrent & child) comment
View functions.php
<?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 / 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.