ID, '_avc_ais_meta', true ); $meta = is_array( $meta ) ? $meta : array(); $page_type = isset( $meta['page_type'] ) ? esc_attr( $meta['page_type'] ) : 'auto'; $faq_question_class = isset( $meta['faq_question_class'] ) ? esc_attr( $meta['faq_question_class'] ) : ''; $faq_answer_class = isset( $meta['faq_answer_class'] ) ? esc_attr( $meta['faq_answer_class'] ) : ''; // メタボックスのフォーム. ?>
post_type, $allowed_post_types, true ) ) { return; } $style_path = AVC_AIS_DIR . 'assets/dist/css/admin.min.css'; $style_version = file_exists( $style_path ) ? filemtime( $style_path ) : AVC_AIS_VERSION; wp_enqueue_style( 'ais-admin', AVC_AIS_URL . 'assets/dist/css/admin.min.css', array(), $style_version ); } /** * メタボックスのデータを保存する * * @param int $post_id 投稿ID */ public function save_meta_box( $post_id ) { // Autosave やリビジョンでは処理しない。 if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) { return; } // 対象外の投稿タイプでは処理しない。 $allowed_post_types = apply_filters( 'avc_ais_meta_allowed_post_types', array( 'post', 'page' ) ); if ( ! is_array( $allowed_post_types ) ) { $allowed_post_types = array( 'post', 'page' ); } if ( ! in_array( get_post_type( $post_id ), $allowed_post_types, true ) ) { return; } // nonce チェック if ( ! isset( $_POST['avc_ais_meta_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['avc_ais_meta_nonce'] ) ), 'avc_ais_meta_nonce' ) ) { return; } // 権限チェック if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } // データを保存 $raw_meta = array(); if ( isset( $_POST['avc_ais_meta'] ) ) { $raw_meta = (array) wp_unslash( $_POST['avc_ais_meta'] ); $raw_meta = array_map( 'sanitize_text_field', $raw_meta ); } $allowed_page_types = array( 'auto', 'Article', 'FAQPage', 'QAPage', 'WebPage' ); $meta = array(); if ( isset( $raw_meta['page_type'] ) ) { $page_type = sanitize_text_field( $raw_meta['page_type'] ); // 想定外の値は保存せず、デフォルトにフォールバック。 $meta['page_type'] = in_array( $page_type, $allowed_page_types, true ) ? $page_type : 'auto'; } if ( isset( $raw_meta['faq_question_class'] ) ) { $faq_question_class = sanitize_text_field( $raw_meta['faq_question_class'] ); if ( '' === $faq_question_class || preg_match( '/^[A-Za-z0-9\-_]+$/', $faq_question_class ) ) { $meta['faq_question_class'] = $faq_question_class; } } if ( isset( $raw_meta['faq_answer_class'] ) ) { $faq_answer_class = sanitize_text_field( $raw_meta['faq_answer_class'] ); if ( '' === $faq_answer_class || preg_match( '/^[A-Za-z0-9\-_]+$/', $faq_answer_class ) ) { $meta['faq_answer_class'] = $faq_answer_class; } } update_post_meta( $post_id, '_avc_ais_meta', $meta ); } } /* phpcs:enable WordPress.Files.LineLength.TooLong */