safecss_filter_attr

説明

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

パラメータ

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

返り値

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


注意

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

プロパティ名6.6.0 6.5.06.4.06.3.06.2.06.1.05.8.05.7.15.3.05.2.05.1.0
プロパティ名6.6.0 6.5.06.4.06.3.06.2.06.1.05.8.05.7.15.3.05.2.05.1.0
background
background-color
background-image
background-position
background-repeat
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
filter
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
grid-column-gap
grid-template-rows
grid-auto-rows
grid-row-start
grid-row-end
grid-row
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
writing-mode
position
top
right
bottom
left
z-index
box-shadow
aspect-ratio
container-type
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

最終更新 : 2024年07月19日 15:14


お勧め

スマートフォン向けの振り分けを自前で行う(2012年1月23日 更新)

PC向けのサイトをスマートフォン対応する場合、WPtouchやktai styleに代表されるスマートフォン対応のテンプレート切り替えプラグインを使用するのが一般的。そういったプラグインはテンプレート切り替え以外の機能も備えており、そういった機能は必ずしも必要ではない。そんなわけで、ここでは超シンプルなスマートフォン向けのテンプレート切り替えを実現する方法を紹介する。

ショートコードを含んだページを表示する前に何か処理する(2014年5月28日 更新)

固定ページまたは投稿ページに独自のフォームを埋め込む。入力→登録の2段階のフォームなら著名なプラグイン「Contact Form 7」を利用すればいいのだが、クライアントの依頼は入力→確認→登録の3段階で組み込む要素が特化していたので、独自の実装方法を考えることになった。

適切なテンプレートファイルを用意してテンプレート内の振り分け処理を無くす(2019年5月24日 更新)

/wp-includes/template-loader.phpではリクエストされたページに応じて現在のテーマにあるテンプレートファイルの中から適切なものを選びに振り分けている。ここでは、さまざまなテンプレートファイルの種類と、テンプレートファイルが省略された場合の内部の動作についてまとめてみる。

管理者ページに文言を表示する(2012年4月19日 更新)

お客様向けに管理者ページをカスタマイズする機会が増えてきている。カスタマイズするページや表示場所、表示内容によっていくつかの手段があるが、今回はページの冒頭部分に任意の文言を表示する方法を紹介する。

5.3の機能強化:ユーザーパスワードの表示と非表示(2019年9月30日 更新)

WordPress 5.3 Beta 1」に記載されていた「Toggle password view」という項目。「Other Changes for Developers」の見出しの中ということもあり、ちょっと調べてみた。