我想将” Hi”与提交的值[$ x]连接起来, 并使用简码在页面或帖子中显示它。我试图将值[$ x]发送到另一个函数[display_output($ x)], 然后在add_shortcode()中使用该函数[display_output]名称, 但它只显示” Hi”, 而不显示提交的值[$ x ]。如果我的方法是错误的, 那么还有其他方法可以通过使用简码在页面或帖子中使用提交的值。我是wordpress插件开发的新手。提前致谢。
<?php
/*
Plugin Name: Iron Man
Plugin URI: https://rajbiswas.com
Description: My Plugin Dev.
Version: 0.1
Author: RB
*/
/*Adding option page in dashboard*/
function my_plugin_settings()
{
add_menu_page( 'My Plugin', 'myCust Form', 'administrator', 'insert-my-plugin_bro', 'my_plugin_settings_page', 'dashicons-translation', '60'
);
}
add_action('admin_menu', 'my_plugin_settings');
/*registering input group and field*/
function my_plugin_options()
{
register_setting('my-form-group', 'user_input_name');
}
add_action('admin_init', 'my_plugin_options');
function my_plugin_settings_page()
{
?>
<h1>hello fellas</h1>
<form action="options.php" method="post">
<?php settings_fields('my-form-group'); ?>
<input type="text" name="user_input_name" value="<?php echo esc_attr(get_option('user_input_name')) ?>" >
<?php //submit_button(); ?>
<input type="submit" value="submit" name="submit" >
<form>
<?php
$x = get_option('user_input_name');
display_output($x); //Sending $x to another function and trying to use it using shortcode.
}
function display_output($x)
{
echo "HI"." ".$x; //I want to concatenate "Hi" with $x and print it in page/post wherever I use shortcode([test-shortcode]). But it is not working.
}
add_shortcode('test-shortcode', 'display_output');
?>
#1
如果将输入保存到选项, 请尝试在简码函数中检索此选项。你可以全局使用get_option。
function display_output($x)
{
$x = get_option('user_input_name');
echo "HI"." ".$x; //I want to concatenate "Hi" with $x and print it in page/post wherever I use shortcode([test-shortcode]). But it is not working.
}
add_shortcode('test-shortcode', 'display_output');
评论前必须登录!
注册