Skip to content

Instantly share code, notes, and snippets.

View danielcharrua's full-sized avatar

Daniel danielcharrua

View GitHub Profile
@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 / 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 / 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 / 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' );
@danielcharrua
danielcharrua / git-reset.sh
Last active July 11, 2023 06:34 — forked from manparvesh/git-cleanup.sh
Git remove all commits except the current one
#!/usr/bin/env bash
rm -rf .git
git init
git add .
git commit -m "Initial commit"
git remote add origin <git origin url>
git push -u --force origin <branch>
@danielcharrua
danielcharrua / .htaccess
Created May 8, 2023 15:14
Disable access to files inside WordPress upload sub-folder with cookie
# This file must be placed inside the directory eg. wp-content/uploads/documents
# Will prevent direct access for anyone but a logged-in user with a valid wordpress_logged_in cookie
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} ^.*(mp3|m4a|jpeg|jpg|gif|png|bmp|pdf|doc|docx|ppt|pptx|)$
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule . - [R=403,L]
@danielcharrua
danielcharrua / functions.php
Created April 19, 2023 12:12
Execute WordPress function from URL
<?php
// Run by doing https://domain.com/wp-admin/admin-ajax.php?action=osm_id_callback_action
// For users not logged in
add_action('wp_ajax_nopriv_osmid_callback_action', 'osm_id_callback_action');
// For users logged in
add_action('wp_ajax_osmid_callback_action', 'osm_id_callback_action');
@danielcharrua
danielcharrua / functions-cookies.php
Last active April 6, 2023 12:35
Block third party cookies with GDPR Cookie Compliance WordPress plugin
<?php
/* Force page reload on gpdr_cookie accept */
add_action('gdpr_force_reload', '__return_true');
/*
* Disable cookie for Omnisend for Woocommerce
* Here we are disabling a plugin option, the filter does not exists inside the plugin
* We are directly changing an option value using https://developer.wordpress.org/reference/hooks/option_option/
* https://wordpress.org/plugins/omnisend-connect/
@danielcharrua
danielcharrua / Update .gitignore
Created December 13, 2022 16:22 — forked from c33k/Update .gitignore
Updating .gitignore and cleaning the cache
//First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
//This removes any changed files from the index(staging area), then just run:
git add .
//Commit
git commit -m "Atualizando .gitignore para..."
@danielcharrua
danielcharrua / functions.php
Last active September 27, 2022 12:05
Block cookies with gdpr-cookie-compliance (Facebook, Analytics, Omnisend)
<?php
// https://wordpress.org/plugins/gdpr-cookie-compliance/
/* disable fbp cookie on gdpr_cookie plugin */
add_filter('facebook_for_woocommerce_integration_pixel_enabled', 'gdpr_cookie_facebook_wc', 20);
function gdpr_cookie_facebook_wc()
{
$enable_fb_wc = true;
if (function_exists('gdpr_cookie_is_accepted')) :
$enable_fb_wc = gdpr_cookie_is_accepted('thirdparty');