dongma7725 2019-05-29 21:49
浏览 38

从保存的文本区域输入创建数组

I am developing a Wordpress plugin. I am saving data from a multiline textarea input. I need to retrieve the saved data and create an array using the line brakes in the text area as the delimiter.

// register setting
add_settings_field(
  'api_pv_exclude_from_brand',
  'Exclude Words in Brand',
  'api_pv_text_area_callback',
  'api-pv-settings',
  'api_pv_general_options_section',
  [ 'id' => 'api_pv_exclude_from_brand', 'label' => 'Please enter words one per line. With the above option, Require Brand in Title, some times brands will have words in them that are harder to match in a YouTube title, for example, the brand <u>Cooler Master Co. Ltd</u>. We would want to ignore Co. and Ltd and just accept videos with <u>Cooler Master</u> in the title.' ]
);  

// validate setting
if ( isset( $input['api_pv_exclude_from_brand'] ) ) {
    $input['api_pv_exclude_from_brand'] = wp_kses_post( $input['api_pv_exclude_from_brand'] );
}

// callback

function api_pv_text_area_callback( $args ) {
    $options = get_option( 'api_pv_options', api_pv_default_options() );
    $id    = isset( $args['id'] )    ? $args['id']    : '';
    $label = isset( $args['label'] ) ? $args['label'] : '';
    $allowed_tags = wp_kses_allowed_html( 'post' );
    $value = isset( $options[$id] ) ? wp_kses( stripslashes_deep( $options[$id] ), $allowed_tags ) : '';
    echo '<textarea id="api_pv_options_'. $id .'" name="api_pv_options['. $id .']" rows="5" cols="50">'. $value .'</textarea><br />';
    echo '<label for="api_pv_options_'. $id .'">'. $label .'</label>';
}

// get option and create array
$plugin_options = wp_parse_args(get_option('api_pv_options'), api_pv_default_options());
$test = sanitize_text_field($plugin_options['api_pv_exclude_from_brand']);
$lines = explode("
", $test);
foreach( $lines as $line ){
  echo $line;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改