Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
danielcharrua / remove_emoji.php
Created April 2, 2020 11:23
Remove emoji from PHP string.
/**
* This function removes emoji from string
* Used to filter Twilio SMS/MMS for emoji characters and send messages using GSM instead of UCS-2
*
* Usage remove_emoji('Lorem ipsum 🥊dolor 🤒sit amet, consectetur adipiscing 🍂 elit. 🌰🍁🌿🌾🌼🌻');
*/
function remove_emoji($text){
return preg_replace('/[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0077}\x{E006C}\x{E0073}\x{E007F})|[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0073}\x{E0063}\x{E0074}\x{E007F})|[\x{1F3F4}](?:\x{E0067}\x{E0062}\x{E0065}\x{E006E}\x{E0067}\x{E007F})|[\x{1F3F4}](?:\x{200D}\x{2620}\x{FE0F})|[\x{1F3F3}](?:\x{FE0F}\x{200D}\x{1F308})|[\x{0023}\x{002A}\x{0030}\x{0031}\x{0032}\x{0033}\x{0034}\x{0035}\x{0036}\x{0037}\x{0038}\x{0039}](?:\x{FE0F}\x{20E3})|[\x{1F441}](?:\x{FE0F}\x{200D}\x{1F5E8}\x{FE0F})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467}\x{200D}\x{1F467})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F467})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F466}\x{200D}\x{1F466})|[\x{1F468}\x{1F469}](?:\x{200D}\x{1F466})|[\
@danielcharrua
danielcharrua / functions.php
Created July 14, 2023 10:09
Replace social icon from social icon block on WordPress
<?php
/*
* Replace social icon from social icon block on WordPress.
* In this case we are replacing the wordpress icon for a custom svg one.
*/
add_filter(
'render_block',
function( $block_content, $block ) {
if ( 'core/social-link' === $block['blockName'] && 'wordpress' === $block['attrs']['service'] ) {
@danielcharrua
danielcharrua / laravelworker
Last active July 4, 2024 18:56 — forked from ibrunotome/supervisord.service
Install and configure supervisord on centos 7.
[program:app1-laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=<your-php-path> <your-artisan-path> queue:work --tries=3
autostart=true
autorestart=true
numprocs=2
redirect_stderr=true
stdout_logfile=<your-logfile-path>
[program:app2-laravel-worker]
@danielcharrua
danielcharrua / functions.php
Created May 27, 2024 13:14
send woocommerce additional email when local pickup
<?php
add_action('woocommerce_order_status_processing', 'send_custom_email_for_local_pickup', 10, 1);
function send_custom_email_for_local_pickup($order_id) {
if (!$order_id) return;
// Obtener el pedido
$order = wc_get_order($order_id);
@danielcharrua
danielcharrua / functions.php
Created January 31, 2024 16:04
Create WordPress user with access only to WooCommerce Analytics
<?php
/*
* Add new role for Marketing Analytics in WooCommerce
*
* @author Daniel P. - charrua.es
*/
$analytics_role = add_role(
'manage_store_analytics',
@danielcharrua
danielcharrua / functions.php
Last active December 9, 2023 23:29
Add thumbnail to Next Post/ Previous post on Astra Theme
<?php
/**
* Add thumbnail to Next Post/ Previous post.
*
* @param array $args Arguments for next post / previous post links.
* @return array
*/
function astra_change_next_prev_text( $args ) {
$next_post = get_next_post();
@danielcharrua
danielcharrua / astra_blog_gutenberg_content.php
Last active December 9, 2023 23:28
Add Gutenberg content to blog page on Astra
//Please add this to your functions.php
/**
* This snippet adds Blog page Gutenberg content before the posts grid on Astra theme if you are using a static homepage.
*
* First create a page for displaying posts, for example "Blog", add any Gutenberg block.
* Then on settings assign a static frontpage and the created "Blog" page to blog posts.
*
* You can now add any block content to the "Blog" page and it will be shown before the posts loop.
*/
@danielcharrua
danielcharrua / find.php
Last active October 25, 2023 08:53
cPanel get last modified files under public_html
<?php
// Create file "find.php" inside public_html, replace the path, open in browser.
// The script will find files modified in the last 2 days.
$files_modifiied = shell_exec('find /home1/cpanel_username/public_html/ -type f -mtime -2');
echo "<pre>$files_modifiied</pre>";
?>
@danielcharrua
danielcharrua / gravity_forms_date_conditional.js
Created January 6, 2021 18:06
Add conditional fields depending on a date field
<script>
gform.addAction( 'gform_input_change', function( elem, formId, fieldId ) {
if ( fieldId == 13 ) {
valorCampoDate = elem.value;
var parts = valorCampoDate.split( '/' );
// Presta atención al mes ( parts[1] ); JavaScript cuenta los meses desde 0:
// Enero - 0, Febrero - 1, etc.
var myDate = new Date( parts[2], parts[1] - 1, parts[0] );
// Cambiar el valor del campo oculto.
@danielcharrua
danielcharrua / functions.php
Created July 11, 2023 08:24
WordPress - Add an admin menu link for Reusable Blocks
<?php
/**
* Add an admin menu link for Reusable Blocks
*/
function my_reusable_blocks_admin_menu() {
add_menu_page( 'Reusable Blocks', 'Reusable Blocks', 'edit_posts', 'edit.php?post_type=wp_block', '', 'dashicons-editor-table', 22 );
}
add_action( 'admin_menu', 'my_reusable_blocks_admin_menu' );