admin管理员组文章数量:1430563
I have two cases for is_rtl
, one doesn't work the other does, but don't know why.
Case1: doesn't work
i define a variable to hold a value depending on is_rtl
, then var_dump
it within the admin_footer
hook, then the result becomes LTR
<?php
/*
Plugin Name: Test
*/
class A{
public function __construct(){
$option_name = is_rtl() ? 'RTL ': 'LTR ';
add_action('admin_footer', function() use($option_name){
echo '<pre dir=ltr>';
var_dump($option_name);
echo '</pre><br>';
});
}
}
$a = new A();
Case2: works
I define the variable inside the callable hooked to admin_footer
, so the result becomes RTL
<?php
/*
Plugin Name: Test
*/
class A{
public function __construct(){
add_action('admin_footer', function(){
$option_name = is_rtl() ? 'RTL ': 'LTR ';
echo '<pre dir=ltr>';
var_dump($option_name);
echo '</pre><br>';
});
}
}
$a = new A();
So why this happens because i need to load options depending on the page direction, but can't get it to work.
I have two cases for is_rtl
, one doesn't work the other does, but don't know why.
Case1: doesn't work
i define a variable to hold a value depending on is_rtl
, then var_dump
it within the admin_footer
hook, then the result becomes LTR
<?php
/*
Plugin Name: Test
*/
class A{
public function __construct(){
$option_name = is_rtl() ? 'RTL ': 'LTR ';
add_action('admin_footer', function() use($option_name){
echo '<pre dir=ltr>';
var_dump($option_name);
echo '</pre><br>';
});
}
}
$a = new A();
Case2: works
I define the variable inside the callable hooked to admin_footer
, so the result becomes RTL
<?php
/*
Plugin Name: Test
*/
class A{
public function __construct(){
add_action('admin_footer', function(){
$option_name = is_rtl() ? 'RTL ': 'LTR ';
echo '<pre dir=ltr>';
var_dump($option_name);
echo '</pre><br>';
});
}
}
$a = new A();
So why this happens because i need to load options depending on the page direction, but can't get it to work.
Share Improve this question asked Jun 4, 2019 at 2:26 MakiomarMakiomar 1517 bronze badges1 Answer
Reset to default 1Case 1 - is_rtl()
is not working because it has been called directly. To use such contditional tags in WordPress, query should already be run. So such function should be used inside the function hooked to appropriate hook. Since it is called directly, its value will be always false.
See https://developer.wordpress/themes/basics/conditional-tags/#where-to-use-conditional-tags
Case 2 - It is working because you can using this tag inside the function hooked to admin_footer
. So, is_rtl()
will give you appropriate value.
So, if admin_footer
is not working for you then, you need to check which hook is appropriate for you and use is_rtl()
inside the function hooked properly.
本文标签: pluginsisrtl returns false while it should return true
版权声明:本文标题:plugins - is_rtl returns false while it should return true 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745440108a2658407.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论