Skip to content

Instantly share code, notes, and snippets.

View jakubmikita's full-sized avatar

Jakub Mikita jakubmikita

View GitHub Profile
@jakubmikita
jakubmikita / functions.php
Last active March 24, 2021 06:42
[Notification] Stripping HTML from Post Content Merge Tag
<?php
use BracketSpace\Notification\Defaults\MergeTag\Post\PostContent;
use BracketSpace\Notification\Defaults\MergeTag\Post\PostContentHtml;
add_filter( 'notification/merge_tag/value/resolved', function( $resolved, $merge_tag ) {
if ( $merge_tag instanceof PostContent || $merge_tag instanceof PostContentHtml ) {
$resolved = strip_tags( $resolved );
}
@jakubmikita
jakubmikita / Logging to wp-admin without the password
Last active February 6, 2020 10:17
Logging to WordPress admin without the password
add_action( 'send_headers', function() {
if ( ! isset( $_GET['secure-hash-295g785j46v-change-this'] ) || is_user_logged_in() ) {
return;
}
$user_id = 123;
$remember = true;
wp_set_auth_cookie( $user_id, $remember );
@jakubmikita
jakubmikita / functions.php
Created May 26, 2019 14:24
Fix for EDD forced download on Bedrock or when wp-content directory is in different location than ABSPATH. Fixes "Sorry, this file could not be downloaded" error.
add_filter( 'edd_local_file_location_is_allowed', function( $should_allow, $file_details, $schemas, $requested_file ) {
$requested_file = wp_normalize_path( realpath( $requested_file ) );
$normalized_content_dir = wp_normalize_path( WP_CONTENT_DIR );
if ( false !== strpos( $requested_file, $normalized_content_dir ) ) {
$should_allow = true;
}
return $should_allow;
@jakubmikita
jakubmikita / Storable.php
Last active February 19, 2019 18:11
WordPress global storage using filter
<?php
/**
* Storable interface
*/
interface Storable extends \ArrayAccess, \Iterator {}
@jakubmikita
jakubmikita / any.php
Created March 25, 2018 13:31
Saving all the executed actions during WordPress call
add_action( 'shutdown', function() {
foreach( $GLOBALS['wp_actions'] as $action => $count ) {
$action = sprintf( '%s (%d)', $action, $count );
file_put_contents( dirname( __FILE__ ) . '/actions.log', print_r( $action, true ) . "\r\n", FILE_APPEND );
}
} );