Skip to content

Instantly share code, notes, and snippets.

View widoz's full-sized avatar
🍜
Ramen and Code

Guido Scialfa widoz

🍜
Ramen and Code
View GitHub Profile
<?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 April 24, 2022 06:33
Helper function to show a WordPress admin notice
<?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 October 22, 2018 14:29
Array Functions
<?php
function arrayInsertInPos(
$needle,
array &$haystack,
$pos,
$preserve = false,
$recursive = false
): array {
$keys = array_filter(
@widoz
widoz / reorder.php
Last active June 1, 2017 08:21
Form Functions
<?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 February 29, 2020 12:47
Wp Post by Name
<?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 February 29, 2020 12:47
Wp Screen Reader Text Less Mixin
@mixin screen-reader-text {
& {
clip : rect(1px, 1px, 1px, 1px);
position : absolute !important;
height : 1px;
width : 1px;
overflow : hidden;
&:focus {
<?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
@widoz
widoz / extraImageNameChoose.php
Last active July 18, 2017 22:03
Media Functions
<?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 ) {