Skip to content

Instantly share code, notes, and snippets.

Avatar
🍜
Ramen and Code

Guido Scialfa widoz

🍜
Ramen and Code
View GitHub Profile
View wp-block-locking-toggling-filter.php
<?php
\add_filter('block_editor_settings_all', static function (array $settings): array {
$currentUserRoles = \wp_get_current_user()->roles;
$allowedUserRoles = ['editor', 'administrator'];
$isUserAllowed = (bool)\array_intersect($currentUserRoles, $allowedUserRoles);
if (!$isUserAllowed) {
$settings['canLockBlocks'] = false;
}
@widoz
widoz / admin-notify.php
Last active Apr 24, 2022
Helper function to show a WordPress admin notice
View admin-notify.php
<?php
function notify(string $message, string $noticeType, array $allowedMarkup = []): void
{
$callback = function () use ($message, $noticeType, $allowedMarkup) {
?>
<div class="notice notice-<?= \sanitize_html_class($noticeType) ?>">
<p><?= \wp_kses($message, $allowedMarkup) ?></p>
</div>
<?php
};
@widoz
widoz / insertArrayPos.php
Last active Oct 22, 2018
Array Functions
View insertArrayPos.php
<?php
function arrayInsertInPos(
$needle,
array &$haystack,
$pos,
$preserve = false,
$recursive = false
): array {
$keys = array_filter(
@widoz
widoz / reorder.php
Last active Jun 1, 2017
Form Functions
View reorder.php
<?php
/**
* Re Order Files
*
* @since ${SINCE}
* @access private
*
* @param array $list An array $_FILES like to re-order
*
* @return array The re-order array list
@widoz
widoz / wpPostByName.php
Last active Feb 29, 2020
Wp Post by Name
View wpPostByName.php
<?php
/**
* Get post by name
*
* @since 2.0.0
*
* @param string $name The name ( slug ) of the post to retrieve.
* @param string $post_type The post type. Optional. Default to 'post'.
*
* @return WP_Post The post object
@widoz
widoz / wp-screen-reader-text.scss
Last active Feb 29, 2020
Wp Screen Reader Text Less Mixin
View wp-screen-reader-text.scss
@mixin screen-reader-text {
& {
clip : rect(1px, 1px, 1px, 1px);
position : absolute !important;
height : 1px;
width : 1px;
overflow : hidden;
&:focus {
View switch-upload-dir-path-url.php
<?php
/**
* Switch Upload Dir & Url
*
* @since 1.0.0
*
* @param string $file The file path.
* @param string $switch The reference to the string to replace. Allowed 'dir>url', 'url>dir'.
*
* @return string The file url
View extraImageNameChoose.php
<?php
/**
* Add Extra Image sizes
*
* Add extra image size to chosen select
*
* @param array $list The list of the default wordpress image sizes
* @return array $list The filtered image sizes
*/
add_filter( 'image_size_names_choose', function( $list ) {