Plugin Directory

Changeset 3437610


Ignore:
Timestamp:
01/12/2026 10:57:18 AM (3 months ago)
Author:
jidaikobo
Message:

Update to version 3.3.1

Location:
dashi
Files:
1 deleted
13 edited
28 copied

Legend:

Unmodified
Added
Removed
  • dashi/tags/3.3.1/classes/Posttype/Base.php

    r3265039 r3437610  
    358358    {
    359359        $custom_fields = static::get('custom_fields');
    360 
    361         $opts = false;
    362         if (isset($custom_fields[$key]))
    363         {
    364             $opts = isset($custom_fields[$key]['options']) ? $custom_fields[$key]['options'] : false;
    365         }
     360        $opts = null;
     361
     362        if (isset($custom_fields[$key]['options'])) {
     363            $opts = Util::resolveOptions($custom_fields[$key]['options']);
     364        }
     365
     366        // $opts = false;
     367        // if (isset($custom_fields[$key]))
     368        // {
     369        //  $opts = isset($custom_fields[$key]['options']) ? $custom_fields[$key]['options'] : false;
     370        // }
    366371
    367372        // optsが見つかってないので、fieldsを疑う
     
    370375            foreach ($custom_fields as $field => $v)
    371376            {
    372                 if ( ! isset($v['fields'][$key])) continue;
    373 
    374                 $opts = isset($custom_fields['fields'][$key]['options']) ?
    375                     $custom_fields['fields'][$key]['options'] :
    376                     false;
     377                if (!isset($v['fields'][$key]['options'])) continue;
     378                $opts = Util::resolveOptions($v['fields'][$key]['options']);
     379                break;
     380
     381                // if ( ! isset($v['fields'][$key])) continue;
     382
     383                // $opts = isset($custom_fields['fields'][$key]['options']) ?
     384                //  $custom_fields['fields'][$key]['options'] :
     385                //  false;
    377386            }
    378387        }
    379388
    380389        // ここまで見つかっていないということは、妥当でない値を尋ねているか、設定値が妥当でないので、例外をスローする
    381         if ( ! $opts)
     390        if (!is_array($opts))
    382391        {
    383392            throw new \Exception (sprintf(__('%s is incorrect argument or setting of custom_fields of %s is wrong.', 'dashi'), $key, get_called_class()));
  • dashi/tags/3.3.1/classes/Posttype/Csv.php

    r3265039 r3437610  
    114114            {
    115115                $value = $post->$k ?: '' ;
     116
     117                // ★ options の解決(Closure / array / null)
     118                $options = \Dashi\Core\Util::resolveOptions($v['options'] ?? null);
     119
    116120                if (
    117121                    in_array($v['type'], array('select', 'radio', 'checkbox')) &&
    118                     isset($v['options'][$value])
     122                    isset($options[$value])
    119123                )
    120124                {
    121                     $value = $v['options'][$value];
     125                    $value = $options[$value];
    122126                }
    123127                if ($excel_compati)
  • dashi/tags/3.3.1/classes/Posttype/CustomFields.php

    r3268587 r3437610  
    364364        if (isset($value['args']['type']))
    365365        {
     366            // ★ options の正規化
     367            $options = $value['args']['options'] ?? null;
     368            $options = Util::resolveOptions($options);
     369
    366370            $html = '';
    367371            switch ($value['args']['type'])
     
    452456                        $key,
    453457                        $val,
    454                         $value['args']['options'],
     458                        $options,
    455459                        $description,
    456460                        $attrs,
     
    463467                        $key,
    464468                        $val,
    465                         $value['args']['options'],
     469                        $options,
    466470                        $description,
    467471                        $attrs,
     
    475479                        $key,
    476480                        $val,
    477                         $value['args']['options'],
     481                        $options,
    478482                        $description,
    479483                        $attrs,
  • dashi/tags/3.3.1/classes/Posttype/CustomFieldsCategories.php

    r3265039 r3437610  
    2828            $description = isset($custom_field['description']) ? $custom_field['description'] : '';
    2929            $attrs = isset($custom_field['attrs']) ? $custom_field['attrs'] : array();
    30             $options = isset($custom_field['options']) ? $custom_field['options'] : array();
     30            // $options = isset($custom_field['options']) ? $custom_field['options'] : array();
     31            $options = [];
     32            if (isset($custom_field['options'])) {
     33                $options = \Dashi\Core\Util::resolveOptions($custom_field['options']);
     34            }
    3135            $label = isset($custom_field['label']) ? $custom_field['label'] : $key;
    3236            $id = 'upload_field_'.$key;
     
    121125            foreach ($custom_fields as $key => $val) {
    122126                $new_value = Input::post($key);
    123                 $new_value = Input::post($key);
    124127                if (is_array($new_value)) {
    125128                    $new_value = array_map('sanitize_text_field', $new_value);
     
    127130                    $new_value = sanitize_text_field($new_value);
    128131                }
    129                 $new_value = maybe_serialize($new_value);
    130                 $old_value = isset($old_values[$key]) ? $old_values[$key] : '';
    131                 if (trim($new_value) === '') {
     132
     133                // $new_value = maybe_serialize($new_value);
     134                if ($new_value === '' || $new_value === []) {
    132135                    $new_values[$key] = '';
    133136                } else {
    134                     $new_values[$key] = $new_value;
     137                    $new_values[$key] = maybe_serialize($new_value);
    135138                }
     139
     140                // $old_value = isset($old_values[$key]) ? $old_values[$key] : '';
     141                // if (trim($new_value) === '') {
     142                //     $new_values[$key] = '';
     143                // } else {
     144                //     $new_values[$key] = $new_value;
     145                // }
    136146            }
    137147        }
  • dashi/tags/3.3.1/classes/Posttype/Index.php

    r3343992 r3437610  
    5757            if ($column_name != $key) continue;
    5858
    59             if (
    60                 $field['type'] == 'taxonomy'
    61             )
     59            if (isset($field['type']) && $field['type'] === 'taxonomy')
    6260            {
    6361                $terms = wp_get_post_terms( $post_id, $key, array("fields" => "names") );
     
    6664            // checkbox or multiple
    6765            else if (
    68                 $field['type'] == 'checkbox' ||
    69                 ($field['type'] == 'select' && isset($field['multiple']))
     66                isset($field['type']) &&
     67                (
     68                    $field['type'] == 'checkbox' ||
     69                    ($field['type'] == 'select' && isset($field['multiple']))
     70                )
    7071            )
    7172            {
     
    9293    private static function displayValue($v, $field)
    9394    {
     95        $options = $field['options'] ?? null;
     96        $options = Util::resolveOptions($options);
     97
    9498        // 値がない
    9599        // 文字列の0が来る場合があるのでstrlen()もかける
     
    102106        }
    103107        // そのまま表示
    104         elseif ( ! isset($field['options']) && $v)
     108        elseif ( ! isset($options) && $v)
    105109        {
    106110            echo esc_html($v);
    107111        }
    108112        // 配列&複数
    109         elseif (isset($field['options']) && is_array($v))
     113        elseif (isset($options) && is_array($v))
    110114        {
    111115            $arr = array();
    112116            foreach ($v as $vv)
    113117            {
    114                 $arr[] = $field['options'][$vv];
     118                $arr[] = $options[$vv];
    115119            }
    116120            echo esc_html(join(',', $arr));
    117121        }
    118122        // 選択式
    119         elseif (isset($field['options']) && ! is_array($v))
    120         {
    121             echo esc_html($field['options'][$v]);
     123        elseif (isset($options) && ! is_array($v))
     124        {
     125            echo esc_html($options[$v]);
    122126        }
    123127    }
  • dashi/tags/3.3.1/classes/Posttype/PublicForm.php

    r3262717 r3437610  
    720720        {
    721721            if (isset($v['private_form_only']) && $v['private_form_only'] == true) continue;
     722
     723            if (isset($v['options'])) {
     724                $v['options'] = \Dashi\Core\Util::resolveOptions($v['options']);
     725            }
    722726
    723727            $html.= '<dt>'.esc_html($v['label']).'</dt>';
     
    10591063            if ($is_admin && isset($fields[$k]['public_form_allow_send_by_mail']) && $fields[$k]['public_form_allow_send_by_mail'] === false) continue;
    10601064
     1065            $field = $fields[$k];
     1066            if (isset($field['options'])) {
     1067                $field['options'] = \Dashi\Core\Util::resolveOptions($field['options']);
     1068            }
     1069
    10611070            // taxonomies
    10621071            $terms = array();
     
    11011110                    foreach ($v as $vv)
    11021111                    {
    1103                         if (isset($fields[$k]['options']) && isset($fields[$k]['options'][$vv]))
     1112                        if (isset($field['options']) && isset($field['options'][$vv]))
    11041113                        {
    1105                             $tmps[] = esc_html($fields[$k]['options'][$vv]).'('.esc_html($vv).')';
     1114                            $tmps[] = esc_html($field['options'][$vv]).'('.esc_html($vv).')';
    11061115                        }
    11071116                        elseif (isset($terms[$vv]))
     
    11231132            else
    11241133            {
    1125                 if (isset($fields[$k]['options']) && isset($fields[$k]['options'][$v]))
    1126                 {
    1127                     $body.= esc_html($fields[$k]['options'][$v]).'('.esc_html($v).")\n\n";
     1134                if (isset($field['options']) && isset($field['options'][$v]))
     1135                {
     1136                    $body.= esc_html($field['options'][$v]).'('.esc_html($v).")\n\n";
    11281137                }
    11291138                elseif (isset($terms[$v]))
  • dashi/tags/3.3.1/classes/Posttype/Revisions.php

    r2269647 r3437610  
    150150        }
    151151
     152        if (isset($current_custom_field['options'])) {
     153            $current_custom_field['options']
     154                = \Dashi\Core\Util::resolveOptions($current_custom_field['options']);
     155        }
     156
    152157        // array
    153158        $type = isset($current_custom_field['type']) ? $current_custom_field['type'] : '';
  • dashi/tags/3.3.1/classes/Posttype/Save.php

    r3304628 r3437610  
    525525        $genStr = function ($post_id, $field_name, $fields, $strs)
    526526        {
     527            // ★ options を解決
     528            if (isset($fields['options'])) {
     529                $fields['options'] = \Dashi\Core\Util::resolveOptions($fields['options']);
     530            }
     531
    527532            // stored value
    528533            $val = get_post_meta($post_id, $field_name);
  • dashi/tags/3.3.1/classes/Util.php

    r2008902 r3437610  
    319319        die(Util::s($message));
    320320    }
     321
     322    /**
     323     * resolveOptions
     324     *
     325     * @param  array|callable | function $options
     326     * @return array
     327     */
     328    public static function resolveOptions($options)
     329    {
     330        return is_callable($options) ? call_user_func($options) : $options;
     331    }
    321332}
  • dashi/tags/3.3.1/dashi.php

    r3358366 r3437610  
    77Text Domain: dashi
    88Domain Path: /languages/
    9 Version: 3.3.0
     9Version: 3.3.1
    1010Author URI: http://www.jidaikobo.com/
    1111thx: https://github.com/trentrichardson/jQuery-Timepicker-Addon/tree/master/src
    1212License: GPL2
    1313
    14 Copyright 2025 jidaikobo (email: support@jidaikobo.com)
     14Copyright 2026 jidaikobo (email: support@jidaikobo.com)
    1515
    1616This program is free software; you can redistribute it and/or modify
  • dashi/tags/3.3.1/readme.txt

    r3358366 r3437610  
    33Donate link: http://www.jidaikobo.com/donate.html
    44Tags: custom field, custom post type
    5 Tested up to: 6.8.2
    6 Stable tag: 3.3.0
     5Tested up to: 6.9.0
     6Stable tag: 3.3.1
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
    9 Requires PHP: 5.4
     9Requires PHP: 7.0
    1010
    1111Useful classes for creating a custom post type. Creates Page Parts custom post type. Designed for theme developers.
     
    4343== Changelog ==
    4444
     45= 3.3.1 =
     46fix: resolve custom field options lazily to avoid undefined array key warnings
     47fix: stabilize handling of options in select / radio / checkbox fields
     48note: minimum required PHP version is now 7.0
     49
    4550= 3.3.0 =
    4651add tiny class to seach template
  • dashi/trunk/classes/Posttype/Base.php

    r3265039 r3437610  
    358358    {
    359359        $custom_fields = static::get('custom_fields');
    360 
    361         $opts = false;
    362         if (isset($custom_fields[$key]))
    363         {
    364             $opts = isset($custom_fields[$key]['options']) ? $custom_fields[$key]['options'] : false;
    365         }
     360        $opts = null;
     361
     362        if (isset($custom_fields[$key]['options'])) {
     363            $opts = Util::resolveOptions($custom_fields[$key]['options']);
     364        }
     365
     366        // $opts = false;
     367        // if (isset($custom_fields[$key]))
     368        // {
     369        //  $opts = isset($custom_fields[$key]['options']) ? $custom_fields[$key]['options'] : false;
     370        // }
    366371
    367372        // optsが見つかってないので、fieldsを疑う
     
    370375            foreach ($custom_fields as $field => $v)
    371376            {
    372                 if ( ! isset($v['fields'][$key])) continue;
    373 
    374                 $opts = isset($custom_fields['fields'][$key]['options']) ?
    375                     $custom_fields['fields'][$key]['options'] :
    376                     false;
     377                if (!isset($v['fields'][$key]['options'])) continue;
     378                $opts = Util::resolveOptions($v['fields'][$key]['options']);
     379                break;
     380
     381                // if ( ! isset($v['fields'][$key])) continue;
     382
     383                // $opts = isset($custom_fields['fields'][$key]['options']) ?
     384                //  $custom_fields['fields'][$key]['options'] :
     385                //  false;
    377386            }
    378387        }
    379388
    380389        // ここまで見つかっていないということは、妥当でない値を尋ねているか、設定値が妥当でないので、例外をスローする
    381         if ( ! $opts)
     390        if (!is_array($opts))
    382391        {
    383392            throw new \Exception (sprintf(__('%s is incorrect argument or setting of custom_fields of %s is wrong.', 'dashi'), $key, get_called_class()));
  • dashi/trunk/classes/Posttype/Csv.php

    r3265039 r3437610  
    114114            {
    115115                $value = $post->$k ?: '' ;
     116
     117                // ★ options の解決(Closure / array / null)
     118                $options = \Dashi\Core\Util::resolveOptions($v['options'] ?? null);
     119
    116120                if (
    117121                    in_array($v['type'], array('select', 'radio', 'checkbox')) &&
    118                     isset($v['options'][$value])
     122                    isset($options[$value])
    119123                )
    120124                {
    121                     $value = $v['options'][$value];
     125                    $value = $options[$value];
    122126                }
    123127                if ($excel_compati)
  • dashi/trunk/classes/Posttype/CustomFields.php

    r3268587 r3437610  
    364364        if (isset($value['args']['type']))
    365365        {
     366            // ★ options の正規化
     367            $options = $value['args']['options'] ?? null;
     368            $options = Util::resolveOptions($options);
     369
    366370            $html = '';
    367371            switch ($value['args']['type'])
     
    452456                        $key,
    453457                        $val,
    454                         $value['args']['options'],
     458                        $options,
    455459                        $description,
    456460                        $attrs,
     
    463467                        $key,
    464468                        $val,
    465                         $value['args']['options'],
     469                        $options,
    466470                        $description,
    467471                        $attrs,
     
    475479                        $key,
    476480                        $val,
    477                         $value['args']['options'],
     481                        $options,
    478482                        $description,
    479483                        $attrs,
  • dashi/trunk/classes/Posttype/CustomFieldsCategories.php

    r3265039 r3437610  
    2828            $description = isset($custom_field['description']) ? $custom_field['description'] : '';
    2929            $attrs = isset($custom_field['attrs']) ? $custom_field['attrs'] : array();
    30             $options = isset($custom_field['options']) ? $custom_field['options'] : array();
     30            // $options = isset($custom_field['options']) ? $custom_field['options'] : array();
     31            $options = [];
     32            if (isset($custom_field['options'])) {
     33                $options = \Dashi\Core\Util::resolveOptions($custom_field['options']);
     34            }
    3135            $label = isset($custom_field['label']) ? $custom_field['label'] : $key;
    3236            $id = 'upload_field_'.$key;
     
    121125            foreach ($custom_fields as $key => $val) {
    122126                $new_value = Input::post($key);
    123                 $new_value = Input::post($key);
    124127                if (is_array($new_value)) {
    125128                    $new_value = array_map('sanitize_text_field', $new_value);
     
    127130                    $new_value = sanitize_text_field($new_value);
    128131                }
    129                 $new_value = maybe_serialize($new_value);
    130                 $old_value = isset($old_values[$key]) ? $old_values[$key] : '';
    131                 if (trim($new_value) === '') {
     132
     133                // $new_value = maybe_serialize($new_value);
     134                if ($new_value === '' || $new_value === []) {
    132135                    $new_values[$key] = '';
    133136                } else {
    134                     $new_values[$key] = $new_value;
     137                    $new_values[$key] = maybe_serialize($new_value);
    135138                }
     139
     140                // $old_value = isset($old_values[$key]) ? $old_values[$key] : '';
     141                // if (trim($new_value) === '') {
     142                //     $new_values[$key] = '';
     143                // } else {
     144                //     $new_values[$key] = $new_value;
     145                // }
    136146            }
    137147        }
  • dashi/trunk/classes/Posttype/Index.php

    r3343992 r3437610  
    5757            if ($column_name != $key) continue;
    5858
    59             if (
    60                 $field['type'] == 'taxonomy'
    61             )
     59            if (isset($field['type']) && $field['type'] === 'taxonomy')
    6260            {
    6361                $terms = wp_get_post_terms( $post_id, $key, array("fields" => "names") );
     
    6664            // checkbox or multiple
    6765            else if (
    68                 $field['type'] == 'checkbox' ||
    69                 ($field['type'] == 'select' && isset($field['multiple']))
     66                isset($field['type']) &&
     67                (
     68                    $field['type'] == 'checkbox' ||
     69                    ($field['type'] == 'select' && isset($field['multiple']))
     70                )
    7071            )
    7172            {
     
    9293    private static function displayValue($v, $field)
    9394    {
     95        $options = $field['options'] ?? null;
     96        $options = Util::resolveOptions($options);
     97
    9498        // 値がない
    9599        // 文字列の0が来る場合があるのでstrlen()もかける
     
    102106        }
    103107        // そのまま表示
    104         elseif ( ! isset($field['options']) && $v)
     108        elseif ( ! isset($options) && $v)
    105109        {
    106110            echo esc_html($v);
    107111        }
    108112        // 配列&複数
    109         elseif (isset($field['options']) && is_array($v))
     113        elseif (isset($options) && is_array($v))
    110114        {
    111115            $arr = array();
    112116            foreach ($v as $vv)
    113117            {
    114                 $arr[] = $field['options'][$vv];
     118                $arr[] = $options[$vv];
    115119            }
    116120            echo esc_html(join(',', $arr));
    117121        }
    118122        // 選択式
    119         elseif (isset($field['options']) && ! is_array($v))
    120         {
    121             echo esc_html($field['options'][$v]);
     123        elseif (isset($options) && ! is_array($v))
     124        {
     125            echo esc_html($options[$v]);
    122126        }
    123127    }
  • dashi/trunk/classes/Posttype/PublicForm.php

    r3262717 r3437610  
    720720        {
    721721            if (isset($v['private_form_only']) && $v['private_form_only'] == true) continue;
     722
     723            if (isset($v['options'])) {
     724                $v['options'] = \Dashi\Core\Util::resolveOptions($v['options']);
     725            }
    722726
    723727            $html.= '<dt>'.esc_html($v['label']).'</dt>';
     
    10591063            if ($is_admin && isset($fields[$k]['public_form_allow_send_by_mail']) && $fields[$k]['public_form_allow_send_by_mail'] === false) continue;
    10601064
     1065            $field = $fields[$k];
     1066            if (isset($field['options'])) {
     1067                $field['options'] = \Dashi\Core\Util::resolveOptions($field['options']);
     1068            }
     1069
    10611070            // taxonomies
    10621071            $terms = array();
     
    11011110                    foreach ($v as $vv)
    11021111                    {
    1103                         if (isset($fields[$k]['options']) && isset($fields[$k]['options'][$vv]))
     1112                        if (isset($field['options']) && isset($field['options'][$vv]))
    11041113                        {
    1105                             $tmps[] = esc_html($fields[$k]['options'][$vv]).'('.esc_html($vv).')';
     1114                            $tmps[] = esc_html($field['options'][$vv]).'('.esc_html($vv).')';
    11061115                        }
    11071116                        elseif (isset($terms[$vv]))
     
    11231132            else
    11241133            {
    1125                 if (isset($fields[$k]['options']) && isset($fields[$k]['options'][$v]))
    1126                 {
    1127                     $body.= esc_html($fields[$k]['options'][$v]).'('.esc_html($v).")\n\n";
     1134                if (isset($field['options']) && isset($field['options'][$v]))
     1135                {
     1136                    $body.= esc_html($field['options'][$v]).'('.esc_html($v).")\n\n";
    11281137                }
    11291138                elseif (isset($terms[$v]))
  • dashi/trunk/classes/Posttype/Revisions.php

    r2269647 r3437610  
    150150        }
    151151
     152        if (isset($current_custom_field['options'])) {
     153            $current_custom_field['options']
     154                = \Dashi\Core\Util::resolveOptions($current_custom_field['options']);
     155        }
     156
    152157        // array
    153158        $type = isset($current_custom_field['type']) ? $current_custom_field['type'] : '';
  • dashi/trunk/classes/Posttype/Save.php

    r3304628 r3437610  
    525525        $genStr = function ($post_id, $field_name, $fields, $strs)
    526526        {
     527            // ★ options を解決
     528            if (isset($fields['options'])) {
     529                $fields['options'] = \Dashi\Core\Util::resolveOptions($fields['options']);
     530            }
     531
    527532            // stored value
    528533            $val = get_post_meta($post_id, $field_name);
  • dashi/trunk/classes/Util.php

    r2008902 r3437610  
    319319        die(Util::s($message));
    320320    }
     321
     322    /**
     323     * resolveOptions
     324     *
     325     * @param  array|callable | function $options
     326     * @return array
     327     */
     328    public static function resolveOptions($options)
     329    {
     330        return is_callable($options) ? call_user_func($options) : $options;
     331    }
    321332}
  • dashi/trunk/dashi.php

    r3358366 r3437610  
    77Text Domain: dashi
    88Domain Path: /languages/
    9 Version: 3.3.0
     9Version: 3.3.1
    1010Author URI: http://www.jidaikobo.com/
    1111thx: https://github.com/trentrichardson/jQuery-Timepicker-Addon/tree/master/src
    1212License: GPL2
    1313
    14 Copyright 2025 jidaikobo (email: support@jidaikobo.com)
     14Copyright 2026 jidaikobo (email: support@jidaikobo.com)
    1515
    1616This program is free software; you can redistribute it and/or modify
  • dashi/trunk/readme.txt

    r3358366 r3437610  
    33Donate link: http://www.jidaikobo.com/donate.html
    44Tags: custom field, custom post type
    5 Tested up to: 6.8.2
    6 Stable tag: 3.3.0
     5Tested up to: 6.9.0
     6Stable tag: 3.3.1
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
    9 Requires PHP: 5.4
     9Requires PHP: 7.0
    1010
    1111Useful classes for creating a custom post type. Creates Page Parts custom post type. Designed for theme developers.
     
    4343== Changelog ==
    4444
     45= 3.3.1 =
     46fix: resolve custom field options lazily to avoid undefined array key warnings
     47fix: stabilize handling of options in select / radio / checkbox fields
     48note: minimum required PHP version is now 7.0
     49
    4550= 3.3.0 =
    4651add tiny class to seach template
Note: See TracChangeset for help on using the changeset viewer.