权限没有,则隐藏 function forum_list_access_filter($forumlist, $gid, $allow = 'allowread') { global $grouplist; if (empty($forumlist)) return array(); if (1 == $gid) return $forumlist; $forumlist_filter = $forumlist; $group = $grouplist[$gid]; foreach ($forumlist_filter as $fid => $forum) { if (empty($forum['accesson']) && empty($group[$allow]) || !empty($forum['accesson']) && empty($forum['accesslist'][$gid][$allow])) { unset($forumlist_filter[$fid]); } unset($forumlist_filter[$fid]['accesslist']); } return $forumlist_filter; } function forum_filter_moduid($moduids) { $moduids = trim($moduids); if (empty($moduids)) return ''; $arr = explode(',', $moduids); $r = array(); foreach ($arr as $_uid) { $_uid = intval($_uid); $_user = user_read($_uid); if (empty($_user)) continue; if ($_user['gid'] > 4) continue; $r[] = $_uid; } return implode(',', $r); } function forum_safe_info($forum) { //unset($forum['moduids']); return $forum; } function forum_filter($forumlist) { foreach ($forumlist as &$val) { unset($val['brief'], $val['announcement'], $val['seo_title'], $val['seo_keywords'], $val['create_date_fmt'], $val['icon_url'], $val['modlist']); } return $forumlist; } function forum_format_url($forum) { global $conf; if (0 == $forum['category']) { // 列表URL $url = url('list-' . $forum['fid'], '', FALSE); } elseif (1 == $forum['category']) { // 频道 $url = url('category-' . $forum['fid'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = url('read-' . trim($forum['brief']), '', FALSE); } if ($conf['url_rewrite_on'] > 1 && $forum['well_alias']) { if (0 == $forum['category'] || 1 == $forum['category']) { $url = url($forum['well_alias'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = ($forum['threads'] && $forum['brief']) ? url($forum['well_alias'] . '-' . trim($forum['brief']), '', FALSE) : url($forum['well_alias'], '', FALSE); } } return $url; } function well_forum_alias() { $forumlist = forum_list_cache(); if (empty($forumlist)) return ''; $key = 'forum-alias'; static $cache = array(); if (isset($cache[$key])) return $cache[$key]; $cache[$key] = array(); foreach ($forumlist as $val) { if ($val['well_alias']) $cache[$key][$val['fid']] = $val['well_alias']; } return array_flip($cache[$key]); } function well_forum_alias_cache() { global $conf; $key = 'forum-alias-cache'; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,跨进程需要再加一层缓存:redis/memcached/xcache/apc if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $arr = well_forum_alias(); } else { $arr = cache_get($key); if (NULL === $arr) { $arr = well_forum_alias(); !empty($arr) AND cache_set($key, $arr); } } $cache[$key] = empty($arr) ? '' : $arr; return $cache[$key]; } ?>hardcrop images in gutenberg "latest posts" block
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

hardcrop images in gutenberg "latest posts" block

programmeradmin12浏览0评论

I like the gutenberg "latest posts" block. The problem I have with it is that it doesn't hardcrop images that users upload to the posts. Is there a way to choose a hard-cropped or custom size that I have created through the add_image_size() function?

I don't really have any code, but I think this question is on topic because it's purely about wordpress core. I'm sorry if it isn't!

What I have used to create my custom image size is this though:

add_action( 'after_setup_theme', 'aeroleds_image_sizes' );
function aeroleds_image_sizes() {
    add_image_size( 'banner-image', 400, 300, true ); // (cropped)
}

I like the gutenberg "latest posts" block. The problem I have with it is that it doesn't hardcrop images that users upload to the posts. Is there a way to choose a hard-cropped or custom size that I have created through the add_image_size() function?

I don't really have any code, but I think this question is on topic because it's purely about wordpress core. I'm sorry if it isn't!

What I have used to create my custom image size is this though:

add_action( 'after_setup_theme', 'aeroleds_image_sizes' );
function aeroleds_image_sizes() {
    add_image_size( 'banner-image', 400, 300, true ); // (cropped)
}
Share Improve this question asked Sep 29, 2020 at 5:44 presswordpressword 3801 gold badge4 silver badges13 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 4

The Latest Posts block uses (wp.data.select( 'core/block-editor' ).getSettings() to get) the image sizes in the editor settings which can be filtered via the block_editor_settings hook in PHP:

apply_filters( 'block_editor_settings', array $editor_settings, WP_Post $post )

Filters the settings to pass to the block editor.

And the setting name used for the image sizes is imageSizes.

So for example, to make the custom banner-image size be available in the featured image size dropdown (in the Latest Posts block's settings):

add_filter( 'block_editor_settings', 'wpse_375600' );
function wpse_375600( $editor_settings ) {
    $editor_settings['imageSizes'][] = [
        'slug' => 'banner-image',
        'name' => 'Banner Image',
    ];

    return $editor_settings;
}

And in addition to that the filter being specific to the block editor, your callback can also get access to the post being edited, which is the second parameter ($post) in the filter hook as you can see above. So you could for example filter the settings only for certain posts.

Resources:

  • The Latest Posts block on GitHub

  • The Block Editor's Data » getSettings()

  • Editor Filters » Editor Settings

it looks like you have to also pass your custom image thumbnail sizes to the filter image_size_names_choose. I tried it and this works for displaying custom images sizes as choices in the latest posts dropdown:

add_filter('image_size_names_choose', function( $sizes ){
    return array_merge( $sizes, [ 'banner-image' => 'banner image' ] );
});

This blog explains a similar issue, so I tried his suggestion. https://talhasariyuerek/en/show-all-image-sizes-in-gutenberg-mediaupload-wordpress/

And by the way, the Gutenberg component that controls that dropdown is https://github/WordPress/gutenberg/tree/master/packages/block-editor/src/components/image-size-control

发布评论

评论列表(0)

  1. 暂无评论