Skip to content

Instantly share code, notes, and snippets.

View mostafasoufi's full-sized avatar
🍬

Mostafa Soufi mostafasoufi

🍬
View GitHub Profile
@mostafasoufi
mostafasoufi / functions.php
Created March 3, 2024 14:39
Show FeedbackBird widget in the WordPress admin area
add_action('admin_enqueue_scripts', function () {
wp_enqueue_script('feedbackbird-app-script', 'https://cdn.jsdelivr.net/gh/feedbackbird/assets@master/wp/app.js?uid=YOUR_UID');
wp_add_inline_script('feedbackbird-app-script', sprintf('var feedbackBirdObject = %s;', json_encode([
'user_email' => function_exists('wp_get_current_user') ? wp_get_current_user()->user_email : '',
'platform' => 'wordpress-admin',
'meta' => [
'php_version' => PHP_VERSION,
'active_plugins' => array_map(function ($plugin, $pluginPath) {
return [
'name' => $plugin['Name'],
@mostafasoufi
mostafasoufi / OrderCommand.php
Last active March 2, 2023 19:07
Regenerate bulk order downloads by WP CLI in WooCommerce
<?php
/**
* Order Command
*/
class OrderCommand
{
/**
* Regenerate order downloads.
*
@mostafasoufi
mostafasoufi / query.sql
Last active January 11, 2023 14:17
Change wordpress URLs with Mysql query
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 / 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 */;
@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 / 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 / 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 / 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 / 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 / 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
*/