Plugin Directory

Changeset 3213045


Ignore:
Timestamp:
12/25/2024 04:38:17 PM (15 months ago)
Author:
tkc49
Message:

Update to version 1.14.0 from GitHub

Location:
import-kintone
Files:
4 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • import-kintone/tags/1.14.0/admin/class-admin.php

    r3007573 r3213045  
    11<?php
     2/**
     3 * Admin class
     4 *
     5 * @package import-kintone
     6 */
     7
    28namespace publish_kintone_data;
    39
    4 class Admin{
    5 
    6     private $nonce   = 'kintone_to_wp_';
    7 
    8     public function __construct(){
     10/**
     11 * Admin class
     12 *
     13 * @package import-kintone
     14 */
     15class Admin {
     16
     17    /**
     18     * Nonce
     19     *
     20     * @var string
     21     */
     22    private $nonce = 'kintone_to_wp_';
     23
     24    /**
     25     * Constructor
     26     *
     27     * @return void
     28     */
     29    public function __construct() {
    930        // Create Admin Menu.
    1031        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    1132        add_action( 'save_post', array( $this, 'update_post_kintone_data' ), 10, 3 );
    1233    }
     34    /**
     35     * Admin menu
     36     *
     37     * @return void
     38     */
    1339    public function admin_menu() {
    14         add_submenu_page( 'options-general.php', 'Publish kintone data', 'Publish kintone data', 'manage_options', 'publish-kintone-data-setting', array(
    15             $this,
    16             'kintone_to_wp_setting'
    17         ) );
    18     }
     40        add_submenu_page(
     41            'options-general.php',
     42            'Publish kintone data',
     43            'Publish kintone data',
     44            'manage_options',
     45            'publish-kintone-data-setting',
     46            array(
     47                $this,
     48                'kintone_to_wp_setting',
     49            )
     50        );
     51    }
     52    /**
     53     * Kintone to WP setting
     54     *
     55     * @return void
     56     */
    1957    public function kintone_to_wp_setting() {
    2058
     
    2563                $kintone_basci_information = array();
    2664
    27                 $kintone_basci_information['domain']    = sanitize_text_field( trim( $_POST['kintone_to_wp_kintone_url'] ) );
    28                 $kintone_basci_information['app_id']    = sanitize_text_field( trim( $_POST['kintone_to_wp_target_appid'] ) );
     65                $kintone_basci_information['domain']    = isset( $_POST['kintone_to_wp_kintone_url'] ) ? sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_url'] ) ) : '';
     66                $kintone_basci_information['app_id']    = isset( $_POST['kintone_to_wp_target_appid'] ) ? sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_target_appid'] ) ) : '';
    2967                $kintone_basci_information['url']       = 'https://' . $kintone_basci_information['domain'] . '/k/v1/form.json?app=' . $kintone_basci_information['app_id'];
    30                 $kintone_basci_information['token']     = sanitize_text_field( trim( $_POST['kintone_to_wp_kintone_api_token'] ) );
    31                 $kintone_basci_information['post_type'] = sanitize_text_field( trim( $_POST['kintone_to_wp_reflect_post_type'] ) );
     68                $kintone_basci_information['token']     = isset( $_POST['kintone_to_wp_kintone_api_token'] ) ? sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_api_token'] ) ) : '';
     69                $kintone_basci_information['post_type'] = isset( $_POST['kintone_to_wp_reflect_post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_reflect_post_type'] ) ) : '';
    3270
    3371                $error_flg = false;
     
    3573                    echo '<div class="error notice is-dismissible"><p><strong>Domain is required</strong></p></div>';
    3674                    $error_flg = true;
    37                 } else if ( ! $kintone_basci_information['post_type'] ) {
     75                } elseif ( ! $kintone_basci_information['post_type'] ) {
    3876                    echo '<div class="error notice is-dismissible"><p><strong>Post type is required</strong></p></div>';
    3977                    $error_flg = true;
     
    5290                $kintone_app_fields_code_for_wp = array();
    5391                if ( isset( $_POST['kintone_to_wp_kintone_field_code_for_post_title'] ) ) {
    54                     $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_post_title'] = sanitize_text_field( $_POST['kintone_to_wp_kintone_field_code_for_post_title'] );
     92                    $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_post_title'] = sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_field_code_for_post_title'] ) );
    5593                }
    5694                if ( isset( $_POST['kintone_to_wp_kintone_field_code_for_post_contents'] ) ) {
    57                     $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_post_contents'] = sanitize_text_field( $_POST['kintone_to_wp_kintone_field_code_for_post_contents'] );
     95                    $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_post_contents'] = sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_field_code_for_post_contents'] ) );
    5896                }
    5997                if ( isset( $_POST['kintone_to_wp_kintone_field_code_for_terms'] ) && is_array( $_POST['kintone_to_wp_kintone_field_code_for_terms'] ) ) {
    60                     $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_terms'] = $_POST['kintone_to_wp_kintone_field_code_for_terms'];
     98                    $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_terms'] = array_map(
     99                        'sanitize_text_field',
     100                        array_map( 'wp_unslash', $_POST['kintone_to_wp_kintone_field_code_for_terms'] )
     101                    );
    61102                }
    62103                if ( isset( $_POST['kintone_to_wp_kintone_field_code_for_featured_image'] ) ) {
    63                     $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_featured_image'] = sanitize_text_field( $_POST['kintone_to_wp_kintone_field_code_for_featured_image'] );
     104                    $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_featured_image'] = sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_field_code_for_featured_image'] ) );
    64105                }
    65106
    66107                if ( isset( $_POST['kintone_to_wp_setting_custom_fields'] ) && is_array( $_POST['kintone_to_wp_setting_custom_fields'] ) ) {
    67                     $kintone_app_fields_code_for_wp['kintone_to_wp_setting_custom_fields'] = $_POST['kintone_to_wp_setting_custom_fields'];
    68                 }
    69 
     108                    $kintone_app_fields_code_for_wp['kintone_to_wp_setting_custom_fields'] = array_map(
     109                        'sanitize_text_field',
     110                        array_map( 'wp_unslash', $_POST['kintone_to_wp_setting_custom_fields'] )
     111                    );
     112                }
    70113
    71114                $this->update_kintone_app_fields_code_for_wp( $kintone_app_fields_code_for_wp );
     
    76119
    77120            }
    78 
    79121        }
    80122
    81123        $wp_n = wp_nonce_field( $this->nonce );
    82 
    83124
    84125        $kintone_url           = get_option( 'kintone_to_wp_kintone_url' );
     
    92133        echo '<h2>Setting Publish kintone data</h2>';
    93134        echo '<form method="post" action="">';
     135        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    94136        echo $wp_n;
    95137
     
    97139        echo '  <tr valign="top">';
    98140        echo '      <th scope="row"><label for="add_text">kintone domain</label></th>';
    99         echo '      <td><input name="kintone_to_wp_kintone_url" type="text" id="kintone_to_wp_kintone_url" value="' . ( $kintone_url == "" ? "" : esc_textarea( $kintone_url ) ) . '" class="regular-text" /></td>';
     141        echo '      <td><input name="kintone_to_wp_kintone_url" type="text" id="kintone_to_wp_kintone_url" value="' . ( '' === $kintone_url ? '' : esc_textarea( $kintone_url ) ) . '" class="regular-text" /></td>';
    100142        echo '  </tr>';
    101143        echo '  <tr valign="top">';
    102144        echo '      <th scope="row"><label for="add_text">API Token</label><br><span style="font-size:10px;">Permission: show record</span></th>';
    103         echo '      <td><input name="kintone_to_wp_kintone_api_token" type="text" id="kintone_to_wp_kintone_api_token" value="' . ( $api_token == "" ? "" : esc_textarea( $api_token ) ) . '" class="regular-text" /></td>';
     145        echo '      <td><input name="kintone_to_wp_kintone_api_token" type="text" id="kintone_to_wp_kintone_api_token" value="' . ( '' === $api_token ? '' : esc_textarea( $api_token ) ) . '" class="regular-text" /></td>';
    104146        echo '  </tr>';
    105147        echo '  <tr valign="top">';
    106148        echo '      <th scope="row"><label for="add_text">Reflect kintone to post_type</label></th>';
    107149        echo '      <td>';
    108         echo '          kintone APP ID:<input name="kintone_to_wp_target_appid" type="text" id="kintone_to_wp_target_appid" value="' . ( $target_appid == "" ? "" : esc_textarea( $target_appid ) ) . '" class="small-text" /> ->';
     150        echo '          kintone APP ID:<input name="kintone_to_wp_target_appid" type="text" id="kintone_to_wp_target_appid" value="' . ( '' === $target_appid ? '' : esc_textarea( $target_appid ) ) . '" class="small-text" /> ->';
    109151        echo '          WordPress Post Type:<select name="kintone_to_wp_reflect_post_type">';
    110152        echo '              <option value=""></option>';
    111         echo '              <option ' . selected( $reflect_post_type, "post", false ) . ' value="post">post</option>';
    112         echo '              <option ' . selected( $reflect_post_type, "page", false ) . ' value="page">page</option>';
    113         echo $this->get_html_post_type_form_slect_option( $reflect_post_type );
     153        echo '              <option ' . selected( $reflect_post_type, 'post', false ) . ' value="post">post</option>';
     154        echo '              <option ' . selected( $reflect_post_type, 'page', false ) . ' value="page">page</option>';
     155        echo $this->get_html_post_type_form_slect_option( $reflect_post_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    114156        echo '          </select>';
    115157        echo '      </td>';
     
    126168
    127169            if ( is_wp_error( $kintone_form_data ) ) {
    128                 // Error
     170                // Error.
    129171                if ( ! empty( $old_kintone_data ) ) {
    130172                    $disp_data = $old_kintone_data;
    131173                }
    132174            } else {
    133                 // Success
     175                // Success.
    134176                $disp_data = $kintone_form_data;
    135177            }
    136         } else {
    137             // Nothing
    138             if ( ! empty( $old_kintone_data ) ) {
    139                 $disp_data = $old_kintone_data;
    140             }
     178        } elseif ( ! empty( $old_kintone_data ) ) {
     179            // Nothing.
     180            $disp_data = $old_kintone_data;
    141181        }
    142182
    143183        if ( ! empty( $disp_data ) ) {
    144184
    145 
    146185            echo '<form method="post" action="">';
    147186
     187            // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    148188            echo $wp_n;
    149189
    150             echo 'Please set this URL to kintone\'s WEBHOOK-><strong>' . site_url( '/wp-admin/admin-ajax.php?action=kintone_to_wp_start' ) . '</strong><br><span style="font-size:10px;">Permission: post record, update record, delete record</span>';
     190            echo 'Please set this URL to kintone\'s WEBHOOK-><strong>' . esc_url( site_url( '/wp-admin/admin-ajax.php?action=kintone_to_wp_start' ) ) . '</strong><br><span style="font-size:10px;">Permission: post record, update record, delete record</span>';
    151191            echo '<br/>';
    152192            echo '<br/>';
     
    156196            echo '      <td>';
    157197            echo '          <select name="kintone_to_wp_kintone_field_code_for_post_title">';
    158             echo $this->get_html_post_title_form_select_option( $disp_data );
     198            echo $this->get_html_post_title_form_select_option( $disp_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    159199            echo '          </select>';
    160200            echo '      </td>';
     
    164204            echo '      <td>';
    165205            echo '          <select name="kintone_to_wp_kintone_field_code_for_post_contents">';
    166             echo $this->get_html_post_contents_form_select_option( $disp_data );
     206            echo $this->get_html_post_contents_form_select_option( $disp_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    167207            echo '          </select>';
    168208            echo '      </td>';
     
    171211            echo '      <th scope="row"><label for="add_text">Select Term</label></th>';
    172212            echo '      <td>';
    173             echo $this->get_html_taxonomy_form_select( $disp_data, $reflect_post_type );
     213            echo $this->get_html_taxonomy_form_select( $disp_data, $reflect_post_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    174214            echo '      </td>';
    175215            echo '  </tr>';
     
    178218            echo '      <td>';
    179219            echo '          <select name="kintone_to_wp_kintone_field_code_for_featured_image">';
    180             echo $this->get_html_featured_image_form_select_option( $disp_data );
     220            echo $this->get_html_featured_image_form_select_option( $disp_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    181221            echo '          </select>';
    182222            echo '      </td>';
     
    185225            echo '      <th scope="row"><label for="add_text">Setting Custom Field</label></th>';
    186226            echo '      <td>';
    187             echo $this->get_html_custom_field_form_input( $disp_data );
     227            echo $this->get_html_custom_field_form_input( $disp_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    188228            echo '      </td>';
    189229            echo '  </tr>';
     
    197237
    198238        echo '</div>';
    199 
    200239    }
    201240    /**
     
    246285        $retun_data                         = Kintone_Utility::kintone_api( $url, get_option( 'kintone_to_wp_kintone_api_token' ) );
    247286        $retun_data['kintone_to_wp_status'] = 'normal';
    248         $publish_kintone_data = new Publish_Kintone_Data();
     287        $publish_kintone_data               = new Publish_Kintone_Data();
    249288        $publish_kintone_data->sync( $retun_data );
    250 
    251     }
    252     private function bulk_update() {
    253 
    254         // 一旦全記事を下書きにする
     289    }
     290    /**
     291     * Bulk update.
     292     *
     293     * @return void
     294     */
     295    public function bulk_update() {
     296
     297        // 一旦全記事を下書きにする.
    255298        $post_type = apply_filters( 'publish_kintone_data_reflect_post_type', get_option( 'kintone_to_wp_reflect_post_type' ), 'bulk_update' );
    256299        $args      = array(
     
    259302            'post_status'    => 'publish',
    260303        );
    261         // The Query
     304
    262305        $the_query = new \WP_Query( $args );
    263306        if ( $the_query->have_posts() ) {
    264307            while ( $the_query->have_posts() ) {
    265308                $the_query->the_post();
    266                 // 下書きに更新する
     309                // 下書きに更新する.
    267310                wp_update_post(
    268311                    array(
     
    277320
    278321        $kintone_data['records'] = array();
    279         $last_id = 0;
    280         $reacquisition_flag = true;
     322        $last_id                 = 0;
     323        $reacquisition_flag      = true;
    281324
    282325        while ( $reacquisition_flag ) {
    283326
    284             $query = apply_filters( 'import_kintone_change_bulk_update_query', '$id > ' . $last_id . ' order by $id asc limit 500');
     327            $query = apply_filters( 'import_kintone_change_bulk_update_query', '$id > ' . $last_id . ' order by $id asc limit 500' );
    285328
    286329            $url        = 'https://' . get_option( 'kintone_to_wp_kintone_url' ) . '/k/v1/records.json?app=' . get_option( 'kintone_to_wp_target_appid' ) . '&query=' . $query;
     
    292335                $reacquisition_flag = false;
    293336            } else {
    294                 $last_id = end($retun_data['records'])['$id']['value'];
     337                $last_id = end( $retun_data['records'] )['$id']['value'];
    295338            }
    296339        }
     
    302345            $data['record']               = $value;
    303346            $data['kintone_to_wp_status'] = 'normal';
    304             $data['type'] = 'UPDATE_RECORD';
    305             $data['app'] = array(
    306                 'id' => get_option( 'kintone_to_wp_target_appid' )
     347            $data['type']                 = 'UPDATE_RECORD';
     348            $data['app']                  = array(
     349                'id' => get_option( 'kintone_to_wp_target_appid' ),
    307350            );
    308351            $data                         = apply_filters( 'kintone_to_wp_kintone_data', $data );
    309             $publish_kintone_data = new Publish_Kintone_Data();
     352            $publish_kintone_data         = new Publish_Kintone_Data();
    310353            $publish_kintone_data->sync( $data );
    311354        }
    312355
    313356        echo '<div class="updated fade"><p><strong>Updated</strong></p></div>';
    314 
    315     }
     357    }
     358    /**
     359     * Update kintone app fields code for wp
     360     *
     361     * @param array $kintone_app_fields_code_for_wp .
     362     *
     363     * @return void
     364     */
    316365    private function update_kintone_app_fields_code_for_wp( $kintone_app_fields_code_for_wp ) {
    317366
     
    345394            update_option( 'kintone_to_wp_kintone_field_code_for_featured_image', $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_featured_image'] );
    346395        }
    347 
    348     }
    349 
    350 
     396    }
     397
     398    /**
     399     * Update kintone basci information
     400     *
     401     * @param array $kintone_basci_information .
     402     * @param array $kintone_form_data .
     403     *
     404     * @return void
     405     */
    351406    private function update_kintone_basci_information( $kintone_basci_information, $kintone_form_data ) {
    352 
    353407
    354408        if ( empty( $kintone_basci_information['url'] ) ) {
     
    375429            update_option( 'kintone_to_wp_reflect_post_type', $kintone_basci_information['post_type'] );
    376430        }
    377 
    378431
    379432        if ( ! is_wp_error( $kintone_form_data ) ) {
     
    387440            echo '<div class="updated notice is-dismissible"><p><strong>Success</strong></p></div>';
    388441        }
    389 
    390     }
    391 
     442    }
     443
     444    /**
     445     * Get html custom field form input
     446     *
     447     * @param array $kintone_app_form_data .
     448     *
     449     * @return string
     450     */
    392451    private function get_html_custom_field_form_input( $kintone_app_form_data ) {
    393452
    394         $html_setting_custom_fields = "";
     453        $html_setting_custom_fields  = '';
    395454        $html_setting_custom_fields .= '<table>';
    396         $setting_custom_fields      = get_option( 'kintone_to_wp_setting_custom_fields' );
     455        $setting_custom_fields       = get_option( 'kintone_to_wp_setting_custom_fields' );
    397456
    398457        foreach ( $kintone_app_form_data['properties'] as $kintone_form_value ) {
     
    411470            if ( array_key_exists( 'code', $kintone_form_value ) ) {
    412471                $html_setting_custom_fields .= '<tr>';
    413                 if ( $kintone_form_value['type'] == 'RECORD_NUMBER' ) {
    414 
    415                     $html_setting_custom_fields .= '<th>' . esc_html( $kintone_form_value['label'] ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</th><td><input readonly="readonly" type="text" name="kintone_to_wp_setting_custom_fields[' . esc_attr( $kintone_form_value['code'] ) . ']" value="kintone_record_id" class="regular-text" /></td>';
     472                if ( 'RECORD_NUMBER' === $kintone_form_value['type'] ) {
     473
     474                    $html_setting_custom_fields .= '<th>' . esc_html( $kintone_form_value['label'] ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</th><td><input readonly="readonly" type="text" name="kintone_to_wp_setting_custom_fields[' . esc_attr( $kintone_form_value['code'] ) . ']" value="kintone_record_id" class="regular-text" /></td>';
    416475
    417476                } else {
     
    422481                    }
    423482
    424                     $html_setting_custom_fields .= '<th>' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</th><td><input type="text" name="kintone_to_wp_setting_custom_fields[' . esc_attr( $kintone_form_value['code'] ) . ']" value="' . esc_attr( $input_val ) . '" class="regular-text" /></td>';
     483                    $html_setting_custom_fields .= '<th>' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</th><td><input type="text" name="kintone_to_wp_setting_custom_fields[' . esc_attr( $kintone_form_value['code'] ) . ']" value="' . esc_attr( $input_val ) . '" class="regular-text" /></td>';
    425484
    426485                }
    427486                $html_setting_custom_fields .= '</tr>';
    428487            }
    429 
    430488        }
    431489        $html_setting_custom_fields .= '</table>';
    432490
    433491        return $html_setting_custom_fields;
    434 
    435     }
    436 
     492    }
     493
     494    /**
     495     * Get html post type form slect option
     496     *
     497     * @param string $reflect_post_type .
     498     *
     499     * @return string
     500     */
    437501    private function get_html_post_type_form_slect_option( $reflect_post_type ) {
    438502
    439503        $args       = array(
    440504            'public'   => true,
    441             '_builtin' => false
     505            '_builtin' => false,
    442506        );
    443507        $post_types = get_post_types( $args, 'names' );
     
    449513
    450514        return $html_option;
    451 
    452     }
    453 
     515    }
     516
     517    /**
     518     * Get html featured image form select option
     519     *
     520     * @param array $kintone_app_form_data .
     521     *
     522     * @return string
     523     */
    454524    private function get_html_featured_image_form_select_option( $kintone_app_form_data ) {
    455525
     
    468538                }
    469539
    470                 $html_select_featured_image .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_featured_image, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</option>';
    471             }
    472 
     540                $html_select_featured_image .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_featured_image, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</option>';
     541            }
    473542        }
    474543
     
    476545    }
    477546
     547    /**
     548     * Get html post title form select option
     549     *
     550     * @param array $kintone_app_form_data .
     551     *
     552     * @return string
     553     */
    478554    private function get_html_post_title_form_select_option( $kintone_app_form_data ) {
    479555
     
    492568                }
    493569
    494                 $html_select_post_title .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_post_title, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</option>';
    495             }
    496 
     570                $html_select_post_title .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_post_title, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</option>';
     571            }
    497572        }
    498573
    499574        return $html_select_post_title;
    500 
    501     }
    502 
     575    }
     576
     577    /**
     578     * Get html post contents form select option
     579     *
     580     * @param array $kintone_app_form_data .
     581     *
     582     * @return string
     583     */
    503584    private function get_html_post_contents_form_select_option( $kintone_app_form_data ) {
    504585        $html_select_post_contents            = '';
     
    516597                }
    517598
    518                 $html_select_post_contents .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_post_contents, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</option>';
    519             }
    520 
     599                $html_select_post_contents .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_post_contents, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</option>';
     600            }
    521601        }
    522602
     
    525605
    526606
     607    /**
     608     * Get html taxonomy form select
     609     *
     610     * @param array  $kintone_app_form_data .
     611     * @param string $reflect_post_type .
     612     *
     613     * @return string
     614     */
    527615    private function get_html_taxonomy_form_select( $kintone_app_form_data, $reflect_post_type ) {
    528616
    529         // Category
     617        // Category.
    530618        $terms = get_taxonomies(
    531619            array(),
     
    539627            if ( in_array( $reflect_post_type, $term->object_type ) ) {
    540628
    541                 $html_select_term             .= $term->label . '-><select name="kintone_to_wp_kintone_field_code_for_terms[' . $term->name . ']">';
     629                $html_select_term            .= $term->label . '-><select name="kintone_to_wp_kintone_field_code_for_terms[' . $term->name . ']">';
    542630                $kintone_field_code_for_terms = get_option( 'kintone_to_wp_kintone_field_code_for_terms' );
    543631
     
    557645
    558646                    if ( array_key_exists( 'code', $kintone_form_value ) ) {
    559                         $html_select_term .= '<option ' . selected( $kintone_form_value['code'], $input_val, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $kintone_form_value['label'] ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</option>';
     647                        $html_select_term .= '<option ' . selected( $kintone_form_value['code'], $input_val, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $kintone_form_value['label'] ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</option>';
    560648                    }
    561649                }
     
    566654
    567655        return $html_select_term;
    568 
    569     }
     656    }
     657
     658    /**
     659     * Get kintone id without appcode
     660     *
     661     * @param string $id .
     662     *
     663     * @return string
     664     */
    570665    private function get_kintone_id_without_appcode( $id ) {
    571666
     
    582677
    583678        return $id;
    584 
    585679    }
    586680}
  • import-kintone/tags/1.14.0/publish-kintone-data.php

    r3007573 r3213045  
    44 * Plugin URI:
    55 * Description: The data of kintone can be reflected on WordPress.
    6  * Version:     1.13.1
     6 * Version:     1.14.0
    77 * Author:      Takashi Hosoya
    88 * Author URI:  http://ht79.info/
     
    1010 * Text Domain: kintone-to-wp
    1111 * Domain Path: /languages
     12 *
     13 * @package import-kintone
    1214 */
    1315
     
    3335
    3436define( 'KINTONE_TO_WP_URL', plugins_url( '', __FILE__ ) );
    35 define( 'KINTONE_TO_WP_PATH', dirname( __FILE__ ) );
     37define( 'KINTONE_TO_WP_PATH', __DIR__ );
    3638
    37 $data          = get_file_data(
     39$data = get_file_data(
    3840    __FILE__,
    39     array( 'ver' => 'Version', 'langs' => 'Domain Path' )
     41    array(
     42        'ver'   => 'Version',
     43        'langs' => 'Domain Path',
     44    )
    4045);
    4146
     
    4853);
    4954
    50 
    51 function init(){
     55/**
     56 * Initialize the plugin.
     57 *
     58 * @return void
     59 */
     60function init() {
    5261    require_once KINTONE_TO_WP_PATH . '/inc/class-kintone-utility.php';
    5362
  • import-kintone/tags/1.14.0/readme.txt

    r3007573 r3213045  
    44Requires at least: 4.9
    55Tested up to: 6.4.2
    6 Stable tag: 1.13.1
     6Stable tag: 1.14.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6060
    6161== Changelog ==
     62
     63= 1.14.0 (2024-12-26) =
     64* [Added] Support executing bulk update from PHP command line
     65* Code forma
    6266
    6367= 1.13.1 (2023-12-09) =
  • import-kintone/trunk/admin/class-admin.php

    r3007573 r3213045  
    11<?php
     2/**
     3 * Admin class
     4 *
     5 * @package import-kintone
     6 */
     7
    28namespace publish_kintone_data;
    39
    4 class Admin{
    5 
    6     private $nonce   = 'kintone_to_wp_';
    7 
    8     public function __construct(){
     10/**
     11 * Admin class
     12 *
     13 * @package import-kintone
     14 */
     15class Admin {
     16
     17    /**
     18     * Nonce
     19     *
     20     * @var string
     21     */
     22    private $nonce = 'kintone_to_wp_';
     23
     24    /**
     25     * Constructor
     26     *
     27     * @return void
     28     */
     29    public function __construct() {
    930        // Create Admin Menu.
    1031        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    1132        add_action( 'save_post', array( $this, 'update_post_kintone_data' ), 10, 3 );
    1233    }
     34    /**
     35     * Admin menu
     36     *
     37     * @return void
     38     */
    1339    public function admin_menu() {
    14         add_submenu_page( 'options-general.php', 'Publish kintone data', 'Publish kintone data', 'manage_options', 'publish-kintone-data-setting', array(
    15             $this,
    16             'kintone_to_wp_setting'
    17         ) );
    18     }
     40        add_submenu_page(
     41            'options-general.php',
     42            'Publish kintone data',
     43            'Publish kintone data',
     44            'manage_options',
     45            'publish-kintone-data-setting',
     46            array(
     47                $this,
     48                'kintone_to_wp_setting',
     49            )
     50        );
     51    }
     52    /**
     53     * Kintone to WP setting
     54     *
     55     * @return void
     56     */
    1957    public function kintone_to_wp_setting() {
    2058
     
    2563                $kintone_basci_information = array();
    2664
    27                 $kintone_basci_information['domain']    = sanitize_text_field( trim( $_POST['kintone_to_wp_kintone_url'] ) );
    28                 $kintone_basci_information['app_id']    = sanitize_text_field( trim( $_POST['kintone_to_wp_target_appid'] ) );
     65                $kintone_basci_information['domain']    = isset( $_POST['kintone_to_wp_kintone_url'] ) ? sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_url'] ) ) : '';
     66                $kintone_basci_information['app_id']    = isset( $_POST['kintone_to_wp_target_appid'] ) ? sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_target_appid'] ) ) : '';
    2967                $kintone_basci_information['url']       = 'https://' . $kintone_basci_information['domain'] . '/k/v1/form.json?app=' . $kintone_basci_information['app_id'];
    30                 $kintone_basci_information['token']     = sanitize_text_field( trim( $_POST['kintone_to_wp_kintone_api_token'] ) );
    31                 $kintone_basci_information['post_type'] = sanitize_text_field( trim( $_POST['kintone_to_wp_reflect_post_type'] ) );
     68                $kintone_basci_information['token']     = isset( $_POST['kintone_to_wp_kintone_api_token'] ) ? sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_api_token'] ) ) : '';
     69                $kintone_basci_information['post_type'] = isset( $_POST['kintone_to_wp_reflect_post_type'] ) ? sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_reflect_post_type'] ) ) : '';
    3270
    3371                $error_flg = false;
     
    3573                    echo '<div class="error notice is-dismissible"><p><strong>Domain is required</strong></p></div>';
    3674                    $error_flg = true;
    37                 } else if ( ! $kintone_basci_information['post_type'] ) {
     75                } elseif ( ! $kintone_basci_information['post_type'] ) {
    3876                    echo '<div class="error notice is-dismissible"><p><strong>Post type is required</strong></p></div>';
    3977                    $error_flg = true;
     
    5290                $kintone_app_fields_code_for_wp = array();
    5391                if ( isset( $_POST['kintone_to_wp_kintone_field_code_for_post_title'] ) ) {
    54                     $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_post_title'] = sanitize_text_field( $_POST['kintone_to_wp_kintone_field_code_for_post_title'] );
     92                    $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_post_title'] = sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_field_code_for_post_title'] ) );
    5593                }
    5694                if ( isset( $_POST['kintone_to_wp_kintone_field_code_for_post_contents'] ) ) {
    57                     $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_post_contents'] = sanitize_text_field( $_POST['kintone_to_wp_kintone_field_code_for_post_contents'] );
     95                    $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_post_contents'] = sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_field_code_for_post_contents'] ) );
    5896                }
    5997                if ( isset( $_POST['kintone_to_wp_kintone_field_code_for_terms'] ) && is_array( $_POST['kintone_to_wp_kintone_field_code_for_terms'] ) ) {
    60                     $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_terms'] = $_POST['kintone_to_wp_kintone_field_code_for_terms'];
     98                    $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_terms'] = array_map(
     99                        'sanitize_text_field',
     100                        array_map( 'wp_unslash', $_POST['kintone_to_wp_kintone_field_code_for_terms'] )
     101                    );
    61102                }
    62103                if ( isset( $_POST['kintone_to_wp_kintone_field_code_for_featured_image'] ) ) {
    63                     $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_featured_image'] = sanitize_text_field( $_POST['kintone_to_wp_kintone_field_code_for_featured_image'] );
     104                    $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_featured_image'] = sanitize_text_field( wp_unslash( $_POST['kintone_to_wp_kintone_field_code_for_featured_image'] ) );
    64105                }
    65106
    66107                if ( isset( $_POST['kintone_to_wp_setting_custom_fields'] ) && is_array( $_POST['kintone_to_wp_setting_custom_fields'] ) ) {
    67                     $kintone_app_fields_code_for_wp['kintone_to_wp_setting_custom_fields'] = $_POST['kintone_to_wp_setting_custom_fields'];
    68                 }
    69 
     108                    $kintone_app_fields_code_for_wp['kintone_to_wp_setting_custom_fields'] = array_map(
     109                        'sanitize_text_field',
     110                        array_map( 'wp_unslash', $_POST['kintone_to_wp_setting_custom_fields'] )
     111                    );
     112                }
    70113
    71114                $this->update_kintone_app_fields_code_for_wp( $kintone_app_fields_code_for_wp );
     
    76119
    77120            }
    78 
    79121        }
    80122
    81123        $wp_n = wp_nonce_field( $this->nonce );
    82 
    83124
    84125        $kintone_url           = get_option( 'kintone_to_wp_kintone_url' );
     
    92133        echo '<h2>Setting Publish kintone data</h2>';
    93134        echo '<form method="post" action="">';
     135        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    94136        echo $wp_n;
    95137
     
    97139        echo '  <tr valign="top">';
    98140        echo '      <th scope="row"><label for="add_text">kintone domain</label></th>';
    99         echo '      <td><input name="kintone_to_wp_kintone_url" type="text" id="kintone_to_wp_kintone_url" value="' . ( $kintone_url == "" ? "" : esc_textarea( $kintone_url ) ) . '" class="regular-text" /></td>';
     141        echo '      <td><input name="kintone_to_wp_kintone_url" type="text" id="kintone_to_wp_kintone_url" value="' . ( '' === $kintone_url ? '' : esc_textarea( $kintone_url ) ) . '" class="regular-text" /></td>';
    100142        echo '  </tr>';
    101143        echo '  <tr valign="top">';
    102144        echo '      <th scope="row"><label for="add_text">API Token</label><br><span style="font-size:10px;">Permission: show record</span></th>';
    103         echo '      <td><input name="kintone_to_wp_kintone_api_token" type="text" id="kintone_to_wp_kintone_api_token" value="' . ( $api_token == "" ? "" : esc_textarea( $api_token ) ) . '" class="regular-text" /></td>';
     145        echo '      <td><input name="kintone_to_wp_kintone_api_token" type="text" id="kintone_to_wp_kintone_api_token" value="' . ( '' === $api_token ? '' : esc_textarea( $api_token ) ) . '" class="regular-text" /></td>';
    104146        echo '  </tr>';
    105147        echo '  <tr valign="top">';
    106148        echo '      <th scope="row"><label for="add_text">Reflect kintone to post_type</label></th>';
    107149        echo '      <td>';
    108         echo '          kintone APP ID:<input name="kintone_to_wp_target_appid" type="text" id="kintone_to_wp_target_appid" value="' . ( $target_appid == "" ? "" : esc_textarea( $target_appid ) ) . '" class="small-text" /> ->';
     150        echo '          kintone APP ID:<input name="kintone_to_wp_target_appid" type="text" id="kintone_to_wp_target_appid" value="' . ( '' === $target_appid ? '' : esc_textarea( $target_appid ) ) . '" class="small-text" /> ->';
    109151        echo '          WordPress Post Type:<select name="kintone_to_wp_reflect_post_type">';
    110152        echo '              <option value=""></option>';
    111         echo '              <option ' . selected( $reflect_post_type, "post", false ) . ' value="post">post</option>';
    112         echo '              <option ' . selected( $reflect_post_type, "page", false ) . ' value="page">page</option>';
    113         echo $this->get_html_post_type_form_slect_option( $reflect_post_type );
     153        echo '              <option ' . selected( $reflect_post_type, 'post', false ) . ' value="post">post</option>';
     154        echo '              <option ' . selected( $reflect_post_type, 'page', false ) . ' value="page">page</option>';
     155        echo $this->get_html_post_type_form_slect_option( $reflect_post_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    114156        echo '          </select>';
    115157        echo '      </td>';
     
    126168
    127169            if ( is_wp_error( $kintone_form_data ) ) {
    128                 // Error
     170                // Error.
    129171                if ( ! empty( $old_kintone_data ) ) {
    130172                    $disp_data = $old_kintone_data;
    131173                }
    132174            } else {
    133                 // Success
     175                // Success.
    134176                $disp_data = $kintone_form_data;
    135177            }
    136         } else {
    137             // Nothing
    138             if ( ! empty( $old_kintone_data ) ) {
    139                 $disp_data = $old_kintone_data;
    140             }
     178        } elseif ( ! empty( $old_kintone_data ) ) {
     179            // Nothing.
     180            $disp_data = $old_kintone_data;
    141181        }
    142182
    143183        if ( ! empty( $disp_data ) ) {
    144184
    145 
    146185            echo '<form method="post" action="">';
    147186
     187            // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    148188            echo $wp_n;
    149189
    150             echo 'Please set this URL to kintone\'s WEBHOOK-><strong>' . site_url( '/wp-admin/admin-ajax.php?action=kintone_to_wp_start' ) . '</strong><br><span style="font-size:10px;">Permission: post record, update record, delete record</span>';
     190            echo 'Please set this URL to kintone\'s WEBHOOK-><strong>' . esc_url( site_url( '/wp-admin/admin-ajax.php?action=kintone_to_wp_start' ) ) . '</strong><br><span style="font-size:10px;">Permission: post record, update record, delete record</span>';
    151191            echo '<br/>';
    152192            echo '<br/>';
     
    156196            echo '      <td>';
    157197            echo '          <select name="kintone_to_wp_kintone_field_code_for_post_title">';
    158             echo $this->get_html_post_title_form_select_option( $disp_data );
     198            echo $this->get_html_post_title_form_select_option( $disp_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    159199            echo '          </select>';
    160200            echo '      </td>';
     
    164204            echo '      <td>';
    165205            echo '          <select name="kintone_to_wp_kintone_field_code_for_post_contents">';
    166             echo $this->get_html_post_contents_form_select_option( $disp_data );
     206            echo $this->get_html_post_contents_form_select_option( $disp_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    167207            echo '          </select>';
    168208            echo '      </td>';
     
    171211            echo '      <th scope="row"><label for="add_text">Select Term</label></th>';
    172212            echo '      <td>';
    173             echo $this->get_html_taxonomy_form_select( $disp_data, $reflect_post_type );
     213            echo $this->get_html_taxonomy_form_select( $disp_data, $reflect_post_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    174214            echo '      </td>';
    175215            echo '  </tr>';
     
    178218            echo '      <td>';
    179219            echo '          <select name="kintone_to_wp_kintone_field_code_for_featured_image">';
    180             echo $this->get_html_featured_image_form_select_option( $disp_data );
     220            echo $this->get_html_featured_image_form_select_option( $disp_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    181221            echo '          </select>';
    182222            echo '      </td>';
     
    185225            echo '      <th scope="row"><label for="add_text">Setting Custom Field</label></th>';
    186226            echo '      <td>';
    187             echo $this->get_html_custom_field_form_input( $disp_data );
     227            echo $this->get_html_custom_field_form_input( $disp_data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    188228            echo '      </td>';
    189229            echo '  </tr>';
     
    197237
    198238        echo '</div>';
    199 
    200239    }
    201240    /**
     
    246285        $retun_data                         = Kintone_Utility::kintone_api( $url, get_option( 'kintone_to_wp_kintone_api_token' ) );
    247286        $retun_data['kintone_to_wp_status'] = 'normal';
    248         $publish_kintone_data = new Publish_Kintone_Data();
     287        $publish_kintone_data               = new Publish_Kintone_Data();
    249288        $publish_kintone_data->sync( $retun_data );
    250 
    251     }
    252     private function bulk_update() {
    253 
    254         // 一旦全記事を下書きにする
     289    }
     290    /**
     291     * Bulk update.
     292     *
     293     * @return void
     294     */
     295    public function bulk_update() {
     296
     297        // 一旦全記事を下書きにする.
    255298        $post_type = apply_filters( 'publish_kintone_data_reflect_post_type', get_option( 'kintone_to_wp_reflect_post_type' ), 'bulk_update' );
    256299        $args      = array(
     
    259302            'post_status'    => 'publish',
    260303        );
    261         // The Query
     304
    262305        $the_query = new \WP_Query( $args );
    263306        if ( $the_query->have_posts() ) {
    264307            while ( $the_query->have_posts() ) {
    265308                $the_query->the_post();
    266                 // 下書きに更新する
     309                // 下書きに更新する.
    267310                wp_update_post(
    268311                    array(
     
    277320
    278321        $kintone_data['records'] = array();
    279         $last_id = 0;
    280         $reacquisition_flag = true;
     322        $last_id                 = 0;
     323        $reacquisition_flag      = true;
    281324
    282325        while ( $reacquisition_flag ) {
    283326
    284             $query = apply_filters( 'import_kintone_change_bulk_update_query', '$id > ' . $last_id . ' order by $id asc limit 500');
     327            $query = apply_filters( 'import_kintone_change_bulk_update_query', '$id > ' . $last_id . ' order by $id asc limit 500' );
    285328
    286329            $url        = 'https://' . get_option( 'kintone_to_wp_kintone_url' ) . '/k/v1/records.json?app=' . get_option( 'kintone_to_wp_target_appid' ) . '&query=' . $query;
     
    292335                $reacquisition_flag = false;
    293336            } else {
    294                 $last_id = end($retun_data['records'])['$id']['value'];
     337                $last_id = end( $retun_data['records'] )['$id']['value'];
    295338            }
    296339        }
     
    302345            $data['record']               = $value;
    303346            $data['kintone_to_wp_status'] = 'normal';
    304             $data['type'] = 'UPDATE_RECORD';
    305             $data['app'] = array(
    306                 'id' => get_option( 'kintone_to_wp_target_appid' )
     347            $data['type']                 = 'UPDATE_RECORD';
     348            $data['app']                  = array(
     349                'id' => get_option( 'kintone_to_wp_target_appid' ),
    307350            );
    308351            $data                         = apply_filters( 'kintone_to_wp_kintone_data', $data );
    309             $publish_kintone_data = new Publish_Kintone_Data();
     352            $publish_kintone_data         = new Publish_Kintone_Data();
    310353            $publish_kintone_data->sync( $data );
    311354        }
    312355
    313356        echo '<div class="updated fade"><p><strong>Updated</strong></p></div>';
    314 
    315     }
     357    }
     358    /**
     359     * Update kintone app fields code for wp
     360     *
     361     * @param array $kintone_app_fields_code_for_wp .
     362     *
     363     * @return void
     364     */
    316365    private function update_kintone_app_fields_code_for_wp( $kintone_app_fields_code_for_wp ) {
    317366
     
    345394            update_option( 'kintone_to_wp_kintone_field_code_for_featured_image', $kintone_app_fields_code_for_wp['kintone_to_wp_kintone_field_code_for_featured_image'] );
    346395        }
    347 
    348     }
    349 
    350 
     396    }
     397
     398    /**
     399     * Update kintone basci information
     400     *
     401     * @param array $kintone_basci_information .
     402     * @param array $kintone_form_data .
     403     *
     404     * @return void
     405     */
    351406    private function update_kintone_basci_information( $kintone_basci_information, $kintone_form_data ) {
    352 
    353407
    354408        if ( empty( $kintone_basci_information['url'] ) ) {
     
    375429            update_option( 'kintone_to_wp_reflect_post_type', $kintone_basci_information['post_type'] );
    376430        }
    377 
    378431
    379432        if ( ! is_wp_error( $kintone_form_data ) ) {
     
    387440            echo '<div class="updated notice is-dismissible"><p><strong>Success</strong></p></div>';
    388441        }
    389 
    390     }
    391 
     442    }
     443
     444    /**
     445     * Get html custom field form input
     446     *
     447     * @param array $kintone_app_form_data .
     448     *
     449     * @return string
     450     */
    392451    private function get_html_custom_field_form_input( $kintone_app_form_data ) {
    393452
    394         $html_setting_custom_fields = "";
     453        $html_setting_custom_fields  = '';
    395454        $html_setting_custom_fields .= '<table>';
    396         $setting_custom_fields      = get_option( 'kintone_to_wp_setting_custom_fields' );
     455        $setting_custom_fields       = get_option( 'kintone_to_wp_setting_custom_fields' );
    397456
    398457        foreach ( $kintone_app_form_data['properties'] as $kintone_form_value ) {
     
    411470            if ( array_key_exists( 'code', $kintone_form_value ) ) {
    412471                $html_setting_custom_fields .= '<tr>';
    413                 if ( $kintone_form_value['type'] == 'RECORD_NUMBER' ) {
    414 
    415                     $html_setting_custom_fields .= '<th>' . esc_html( $kintone_form_value['label'] ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</th><td><input readonly="readonly" type="text" name="kintone_to_wp_setting_custom_fields[' . esc_attr( $kintone_form_value['code'] ) . ']" value="kintone_record_id" class="regular-text" /></td>';
     472                if ( 'RECORD_NUMBER' === $kintone_form_value['type'] ) {
     473
     474                    $html_setting_custom_fields .= '<th>' . esc_html( $kintone_form_value['label'] ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</th><td><input readonly="readonly" type="text" name="kintone_to_wp_setting_custom_fields[' . esc_attr( $kintone_form_value['code'] ) . ']" value="kintone_record_id" class="regular-text" /></td>';
    416475
    417476                } else {
     
    422481                    }
    423482
    424                     $html_setting_custom_fields .= '<th>' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</th><td><input type="text" name="kintone_to_wp_setting_custom_fields[' . esc_attr( $kintone_form_value['code'] ) . ']" value="' . esc_attr( $input_val ) . '" class="regular-text" /></td>';
     483                    $html_setting_custom_fields .= '<th>' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</th><td><input type="text" name="kintone_to_wp_setting_custom_fields[' . esc_attr( $kintone_form_value['code'] ) . ']" value="' . esc_attr( $input_val ) . '" class="regular-text" /></td>';
    425484
    426485                }
    427486                $html_setting_custom_fields .= '</tr>';
    428487            }
    429 
    430488        }
    431489        $html_setting_custom_fields .= '</table>';
    432490
    433491        return $html_setting_custom_fields;
    434 
    435     }
    436 
     492    }
     493
     494    /**
     495     * Get html post type form slect option
     496     *
     497     * @param string $reflect_post_type .
     498     *
     499     * @return string
     500     */
    437501    private function get_html_post_type_form_slect_option( $reflect_post_type ) {
    438502
    439503        $args       = array(
    440504            'public'   => true,
    441             '_builtin' => false
     505            '_builtin' => false,
    442506        );
    443507        $post_types = get_post_types( $args, 'names' );
     
    449513
    450514        return $html_option;
    451 
    452     }
    453 
     515    }
     516
     517    /**
     518     * Get html featured image form select option
     519     *
     520     * @param array $kintone_app_form_data .
     521     *
     522     * @return string
     523     */
    454524    private function get_html_featured_image_form_select_option( $kintone_app_form_data ) {
    455525
     
    468538                }
    469539
    470                 $html_select_featured_image .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_featured_image, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</option>';
    471             }
    472 
     540                $html_select_featured_image .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_featured_image, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</option>';
     541            }
    473542        }
    474543
     
    476545    }
    477546
     547    /**
     548     * Get html post title form select option
     549     *
     550     * @param array $kintone_app_form_data .
     551     *
     552     * @return string
     553     */
    478554    private function get_html_post_title_form_select_option( $kintone_app_form_data ) {
    479555
     
    492568                }
    493569
    494                 $html_select_post_title .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_post_title, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</option>';
    495             }
    496 
     570                $html_select_post_title .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_post_title, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</option>';
     571            }
    497572        }
    498573
    499574        return $html_select_post_title;
    500 
    501     }
    502 
     575    }
     576
     577    /**
     578     * Get html post contents form select option
     579     *
     580     * @param array $kintone_app_form_data .
     581     *
     582     * @return string
     583     */
    503584    private function get_html_post_contents_form_select_option( $kintone_app_form_data ) {
    504585        $html_select_post_contents            = '';
     
    516597                }
    517598
    518                 $html_select_post_contents .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_post_contents, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</option>';
    519             }
    520 
     599                $html_select_post_contents .= '<option ' . selected( $kintone_form_value['code'], $kintone_field_code_for_post_contents, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $label ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</option>';
     600            }
    521601        }
    522602
     
    525605
    526606
     607    /**
     608     * Get html taxonomy form select
     609     *
     610     * @param array  $kintone_app_form_data .
     611     * @param string $reflect_post_type .
     612     *
     613     * @return string
     614     */
    527615    private function get_html_taxonomy_form_select( $kintone_app_form_data, $reflect_post_type ) {
    528616
    529         // Category
     617        // Category.
    530618        $terms = get_taxonomies(
    531619            array(),
     
    539627            if ( in_array( $reflect_post_type, $term->object_type ) ) {
    540628
    541                 $html_select_term             .= $term->label . '-><select name="kintone_to_wp_kintone_field_code_for_terms[' . $term->name . ']">';
     629                $html_select_term            .= $term->label . '-><select name="kintone_to_wp_kintone_field_code_for_terms[' . $term->name . ']">';
    542630                $kintone_field_code_for_terms = get_option( 'kintone_to_wp_kintone_field_code_for_terms' );
    543631
     
    557645
    558646                    if ( array_key_exists( 'code', $kintone_form_value ) ) {
    559                         $html_select_term .= '<option ' . selected( $kintone_form_value['code'], $input_val, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $kintone_form_value['label'] ) . '(' . esc_html( $kintone_form_value['code'] ) . ')' . '</option>';
     647                        $html_select_term .= '<option ' . selected( $kintone_form_value['code'], $input_val, false ) . ' value="' . esc_attr( $kintone_form_value['code'] ) . '">' . esc_html( $kintone_form_value['label'] ) . '(' . esc_html( $kintone_form_value['code'] ) . ')</option>';
    560648                    }
    561649                }
     
    566654
    567655        return $html_select_term;
    568 
    569     }
     656    }
     657
     658    /**
     659     * Get kintone id without appcode
     660     *
     661     * @param string $id .
     662     *
     663     * @return string
     664     */
    570665    private function get_kintone_id_without_appcode( $id ) {
    571666
     
    582677
    583678        return $id;
    584 
    585679    }
    586680}
  • import-kintone/trunk/publish-kintone-data.php

    r3007573 r3213045  
    44 * Plugin URI:
    55 * Description: The data of kintone can be reflected on WordPress.
    6  * Version:     1.13.1
     6 * Version:     1.14.0
    77 * Author:      Takashi Hosoya
    88 * Author URI:  http://ht79.info/
     
    1010 * Text Domain: kintone-to-wp
    1111 * Domain Path: /languages
     12 *
     13 * @package import-kintone
    1214 */
    1315
     
    3335
    3436define( 'KINTONE_TO_WP_URL', plugins_url( '', __FILE__ ) );
    35 define( 'KINTONE_TO_WP_PATH', dirname( __FILE__ ) );
     37define( 'KINTONE_TO_WP_PATH', __DIR__ );
    3638
    37 $data          = get_file_data(
     39$data = get_file_data(
    3840    __FILE__,
    39     array( 'ver' => 'Version', 'langs' => 'Domain Path' )
     41    array(
     42        'ver'   => 'Version',
     43        'langs' => 'Domain Path',
     44    )
    4045);
    4146
     
    4853);
    4954
    50 
    51 function init(){
     55/**
     56 * Initialize the plugin.
     57 *
     58 * @return void
     59 */
     60function init() {
    5261    require_once KINTONE_TO_WP_PATH . '/inc/class-kintone-utility.php';
    5362
  • import-kintone/trunk/readme.txt

    r3007573 r3213045  
    44Requires at least: 4.9
    55Tested up to: 6.4.2
    6 Stable tag: 1.13.1
     6Stable tag: 1.14.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6060
    6161== Changelog ==
     62
     63= 1.14.0 (2024-12-26) =
     64* [Added] Support executing bulk update from PHP command line
     65* Code forma
    6266
    6367= 1.13.1 (2023-12-09) =
Note: See TracChangeset for help on using the changeset viewer.