Skip to content

Instantly share code, notes, and snippets.

View neverything's full-sized avatar

Silvan Hagen neverything

View GitHub Profile
@neverything
neverything / functions.php
Last active October 27, 2023 13:53
WordPress: Strip image metadata on upload to the media library using Imagick. Learn more https://silvanhagen.com/strip-image-meta-data-wordpress/
<?php
add_filter( 'wp_handle_upload', 'yourprefix_strip_metadata_from_images_on_upload' );
function yourprefix_strip_metadata_from_images_on_upload( array $upload ): array {
if ( ! in_array( $upload['type'], array( 'image/jpeg', 'image/png', 'image/gif' ), true ) ) {
return $upload;
}
try {
yourprefix_strip_metadata_from_image( $upload['file'] );
<?php
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Rule;
<?php
// On top of the User model add:
use App\Notifications\MagicLoginLink;
use Grosv\LaravelPasswordlessLogin\PasswordlessLogin;
// In the model class, add the following methods:
public function sendMagicLoginLinkNotification(): void
{
$this->notify(new MagicLoginLink($this->getMagicLoginLink()));
<?php
namespace App\Listeners;
use App\Events\RequestMagicLoginLink;
use App\Models\User;
class SendMagicLoginLinkNotification
{
/**
@neverything
neverything / install_plugins.sh
Created September 22, 2023 14:14
Get the 108 most popular WordPress plugins and install them using the WP CLI
#!/bin/bash
# Download the JSON file
curl -sSL https://plugintable.com/plugins.json -o plugins.json
# Extract the plugin slugs using jq
plugin_slugs=$(jq -r '.[].slug' plugins.json)
# Loop through each plugin slug and install it using wp-cli
for slug in $plugin_slugs; do
@neverything
neverything / functions.php
Last active August 25, 2023 14:59
WordPress: Disable blocks for all users on certain post types. See details https://silvanhagen.com/writing/disable-wordpress-blocks-for-all-users/
<?php
add_filter( 'allowed_block_types_all', function( $allowed_blocks, $editor_context ) {
if ( in_array( $editor_context->post?->post_type, ['post', 'page'] ) ) {
$blocks = array_diff(
array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ),
[
'core/image',
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!-- Define the Alpine.js component using x-data -->
<div x-data="{ show: false }">
<!-- Bind the type attribute to the value of show using the :type notation -->
<input :type="show ? 'text' : 'password'" name="password" type="password" value="LookMaaGreatPassw0rd!" />
<!-- Toggle the value of show on click using @click and bind the class
attribute to it using the :class notation -->
<svg @click="show = !show" :class="{'block': !show, 'hidden':show }">...</svg>