Skip to content

Instantly share code, notes, and snippets.

View mustafauysal's full-sized avatar
💭
addressing some issues... 🧑🏻‍💻

Mustafa Uysal mustafauysal

💭
addressing some issues... 🧑🏻‍💻
View GitHub Profile
@mustafauysal
mustafauysal / clean-woo-product-term-archives.php
Last active February 15, 2024 21:28
Quick fix to purge product archives when product updated.
<?php
add_filter( 'powered_cache_advanced_cache_purge_urls', function ( $urls, $post_id ) {
if ( 'product' === get_post_type( $post_id ) ) {
$urls[] = get_permalink( $post_id );
$urls[] = get_permalink( wc_get_page_id( 'shop' ) );
$terms = wp_get_post_terms( $post_id, [ 'product_tag', 'product_cat' ] );
foreach ( $terms as $term ) {
$urls[] = get_term_link( $term );
@mustafauysal
mustafauysal / change-magic-login-shortcode-msg.php
Created January 5, 2024 16:49
example snippet to change magic login default message dynamically with JS
<?php
add_action( 'wp_footer', function () {
?>
<script>
document.addEventListener('DOMContentLoaded', function () {
var messageElement = document.querySelector('.magic-login-form-header .message');
if (messageElement) {
messageElement.innerText = 'Your new message here';
}
<?php
add_action( 'plugins_loaded', function () {
$request_url = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '';
if ( false !== strpos( $request_url, '/checkout' ) || false !== strpos( $request_url, '/finalizar-compra' ) ) {
add_filter( 'powered_cache_fo_disable', '__return_true' );
add_filter( 'powered_cache_fo_disable_css_combine', '__return_true' );
add_filter( 'powered_cache_fo_disable_css_minify', '__return_true' );
add_filter( 'powered_cache_fo_disable_js_combine', '__return_true' );
<?php
add_action( 'wp_footer', 'magic_login_auto_fill_email_from_url' );
add_action( 'login_footer', 'magic_login_auto_fill_email_from_url' );
function magic_login_auto_fill_email_from_url() {
?>
<script>
// Function to get URL parameters
function getURLParameter(name) {
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
# Pass .well-known/security.txt to WordPress
RewriteRule ^\.well-known/security\.txt$ index.php [L]
@mustafauysal
mustafauysal / phast-purge-with-powered-cache.php
Last active May 23, 2023 14:39
Remove phastpress cache when purging cache on Powered Cache
<?php
add_action( 'plugins_loaded', function () {
add_action( 'powered_cache_flushed', 'flush_phast_cache' );
add_action( 'powered_cache_purge_all_cache', 'flush_phast_cache' );
add_action( 'powered_cache_clean_site_cache_dir', 'flush_phast_cache' );
} );
function flush_phast_cache() {
$cache_dir = WP_CONTENT_DIR . '/cache/';
@mustafauysal
mustafauysal / update.sql
Created May 19, 2023 14:18
Convert latin1_* to utf8_
ALTER TABLE wp_posts CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
UPDATE wp_posts SET post_content = CONVERT(CAST(CONVERT(post_content USING latin1) AS BINARY) USING utf8);
UPDATE wp_posts SET post_title = CONVERT(CAST(CONVERT(post_title USING latin1) AS BINARY) USING utf8);
UPDATE wp_posts SET post_excerpt = CONVERT(CAST(CONVERT(post_excerpt USING latin1) AS BINARY) USING utf8);
UPDATE wp_posts SET post_status = CONVERT(CAST(CONVERT(post_status USING latin1) AS BINARY) USING utf8);
UPDATE wp_posts SET comment_status = CONVERT(CAST(CONVERT(comment_status USING latin1) AS BINARY) USING utf8);
UPDATE wp_posts SET ping_status = CONVERT(CAST(CONVERT(ping_status USING latin1) AS BINARY) USING utf8);
UPDATE wp_posts SET post_password = CONVERT(CAST(CONVERT(post_password USING latin1) AS BINARY) USING utf8);
UPDATE wp_posts SET post_name = CONVERT(CAST(CONVERT(post_name USING latin1) AS BINARY) USING utf8);
UPDATE wp_posts SET to_ping = CONVERT(CAST(CONVERT(to_ping USING latin1) AS BINARY) USING
@mustafauysal
mustafauysal / drop-tables-ms.php
Created January 10, 2023 19:27
Drop all tables belonging to the site during the deletion of the site on multisite.
<?php
/**
* Drop all tables belongs to site.
*
* @param array $tables The tables to drop.
* @param int $blog_id The site ID.
*
* @return array
*/
@mustafauysal
mustafauysal / drop-hustle-and-forminator-tables-on-ms.php
Created January 9, 2023 15:51
Removes hustle and forminator tables when deleting a blog on multisite installation
<?php[
add_filter( 'wpmu_drop_tables', function ( $tables, $blog_id ) {
global $wpdb;
$hustle = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->get_blog_prefix( $blog_id ) . 'hustle' ) . '%' ), ARRAY_A );
if ( ! empty( $hustle ) ) {
foreach ( $hustle as $hustle_table ) {
$hustle_table = array_values( $hustle_table );
@mustafauysal
mustafauysal / change-magic-login-strings.php
Created November 29, 2022 20:14
Change magic login strings
<?php
add_filter( 'gettext', 'change_magic_login_strings', 10, 3 );
function change_magic_login_strings( $translated_text, $untranslated_text, $domain ) {
if ( 'magic-login' !== $domain ) {
return $translated_text;
}
if ( 'Username or Email Address' === $untranslated_text ) {