safecss_filter_attr

説明

string safecss_filter_attr( string $css [ , string $deprecated = '' ] )
インラインスタイルをサニタイズする。

パラメータ

  • $css
    style属性値を指定。
  • $deprecated
    使用不可(省略時は'')。

返り値

ルールに適合しない内容を取り除いたstyle属性値を返す。


注意

有効なスタイルのプロパティ名はバージョンによって異なる(適宜追加されてきている)。

プロパティ名6.2.06.1.05.8.05.7.15.3.05.2.05.1.0
プロパティ名6.2.06.1.05.8.05.7.15.3.05.2.05.1.0
background
background-color
background-image
background-position
background-size
background-attachment
background-blend-mode
border
border-radius
border-width
border-color
border-style
border-right
border-right-color
border-right-style
border-right-width
border-bottom
border-bottom-color
border-bottom-style
border-bottom-width
border-left
border-left-color
border-left-style
border-left-width
border-top
border-top-color
border-top-style
border-top-width
border-spacing
border-collapse
caption-side
columns
column-count
column-fill
column-gap
column-rule
column-span
column-width
color
font
font-family
font-size
font-style
font-variant
font-weight
letter-spacing
line-height
text-align
text-decoration
text-indent
text-transform
height
min-height
max-height
width
min-width
max-width
margin
margin-right
margin-bottom
margin-left
margin-top
margin-block-start
margin-block-end
margin-inline-start
margin-inline-end
padding
padding-right
padding-bottom
padding-left
padding-top
padding-block-start
padding-block-end
padding-inline-start
padding-inline-end
flex
flex-basis
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
gap
column-gap
row-gap
grid-template-columns
grid-auto-columns
grid-column-start
grid-column-end
grid-column-gap
grid-template-rows
grid-auto-rows
grid-row-start
grid-row-end
grid-row-gap
grid-gap
justify-content
justify-items
justify-self
align-content
align-items
align-self
clear
cursor
direction
float
list-style-type
object-fit
object-position
overflow
vertical-align
position
top
right
bottom
left
z-index
aspect-ratio
calc()
var()
min()
max()
minmax()
clamp()

'safe_style_css'フィルターにて得られる内容が空の場合、パラメータ$cssはそのまま返り値となる。


使用例

  • インラインスタイルをサニタイズする。
    <?php $inline_style = safecss_filter_attr( $inline_style ); ?>

フィルター

[2.8.1]'safe_style_css'フィルターを呼び出す。パラメータ$attrには有効なスタイルのプロパティ名を列挙した配列が格納されている。
$allowed_attr = apply_filters( 'safe_style_css', $attr );

アクション

直接実行するアクションはありません。

ソースファイル

/wp-includes/kses.php

最終更新 : 2023年03月31日 13:27


お勧め

ブロックエディターの色設定を変えてみる(2019年12月11日 更新)

バージョン5.3で機能強化されたブロックエディター。対応を考えて新テーマ「Twenty Twenty」のソースコードを眺めていく。

「姓」の後に「名」を(2013年11月6日 更新)

WordPressのユーザー情報設定ページでは、「名(First name)」の後に「姓(Last name)」を入力するようになっている。日本向けのユーザー登録できるサイトの場合、この並び順はちょっと違和感があるので、「姓」「名」の順に入力できるようにした。

ホームディレクトリから過去のファイルを削除する(2013年1月27日 更新)

WordPressで構築したサイトのホームディレクトリには、現在使われていないファイルが残っている時がある。3.5.1もリリースされたことだし、これを機にホームディレクトリを整理整頓した。

Login rebuilder 2.6.5の新機能紹介(2021年3月8日 更新)

今回追加したものは、管理者のダッシュボードに表示されるログウィジェットの日時について任意の書式を設定する機能である。これまで日時の書式はサイト設定を利用していたが、ログの日時については揃えた方が見やすいと思ったので、今回の機能で対応することにしました。

投稿情報を連想配列で参照する(2018年5月27日 更新)

投稿情報は、タイトルや本文、投稿日時といったいくつかのデータが含んでおり、多くの場合オブジェクトになっている。これを連想配列で扱いたい場合はキャストして型変換することが多かった。基本的にはキャストで問題ないのだが、ふと目に留まったto_arrayメソッドが興味深かったのでメモとして残しておく。