0

これは国のプラグインのコードですが、このコードを短い形式で記述する方法がわかりません。

  function save_details( $post_id ) {
            global $post;

            $post_vars = shortcode_atts( array(
                'country_code'     => '',
                'country_list'     => '',
                'flags'            => '',
                'country_details'  => '',
                'country_currency' => '',
                'currency_symbol'  => '',
                'currency_html'    => '',
                'currency_code'    => '',
                'city_list'        => ''
            ), $_POST );

すべての国の名前を 1 ページに表示するには、どの短いコードを記述すればよいか教えてもらえますか?

4

1 に答える 1

0

関数を次のように書き直すことができます

add_shortcode('save_details', function( $atts ) {
        global $post;

        $post_vars = array(
            'country_code'     => '',
            'country_list'     => '',
            'flags'            => '',
            'country_details'  => '',
            'country_currency' => '',
            'currency_symbol'  => '',
            'currency_html'    => '',
            'currency_code'    => '',
            'city_list'        => ''
        );
        extract( shortcode_atts( $post_vars, $atts ) );
        // country_code is now available like so $country_code
        // return data after your done

 });

そして、そのようにアクセスします

//all of your attributes can be used inside the sq brackets
[save_details] and [save_details country_code = "" country_list = ""] 
于 2013-03-07T16:07:08.450 に答える