@@ -195,7 +195,7 @@ function add_ids_to_blocks_recursive( $blocks ) {
195195 if ( isset ( $ block ['blockName ' ] ) && in_array ( $ block ['blockName ' ], $ supported_blocks , true ) && isset ( $ block ['innerHTML ' ] ) && isset ( $ block ['innerContent ' ] ) && isset ( $ block ['innerContent ' ][0 ] ) ) {
196196 $ block ['innerHTML ' ] = add_anchor_attribute ( $ block ['innerHTML ' ], $ inner_html_id_instance );
197197 $ block ['innerContent ' ][0 ] = add_anchor_attribute ( $ block ['innerContent ' ][0 ], $ inner_content_id_instance );
198- } elseif ( isset ( $ block ['attrs ' ]['ref ' ] ) ) {
198+ } elseif ( isset ( $ block ['attrs ' ]['ref ' ] ) ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedElseif
199199 // search in reusable blocks (this is not finished because I ran out of ideas.)
200200 // $reusable_block_id = $block['attrs']['ref'];
201201 // $reusable_block_content = parse_blocks(get_post($reusable_block_id)->post_content);.
@@ -218,7 +218,7 @@ function render_callback_simpletoc( $attributes ) {
218218 $ is_backend = defined ( 'REST_REQUEST ' ) && REST_REQUEST && 'edit ' === filter_input ( INPUT_GET , 'context ' );
219219 $ title_text = $ attributes ['title_text ' ] ? esc_html ( trim ( $ attributes ['title_text ' ] ) ) : __ ( 'Table of Contents ' , 'simpletoc ' );
220220 $ alignclass = ! empty ( $ attributes ['align ' ] ) ? 'align ' . $ attributes ['align ' ] : '' ;
221- $ class_name = ! empty ( $ attributes ['className ' ] ) ? strip_tags ( $ attributes ['className ' ] ) : '' ;
221+ $ class_name = ! empty ( $ attributes ['className ' ] ) ? wp_strip_all_tags ( $ attributes ['className ' ] ) : '' ;
222222 $ title_level = $ attributes ['title_level ' ];
223223
224224 $ wrapper_enabled = apply_filters ( 'simpletoc_wrapper_enabled ' , false ) || true === (bool ) get_option ( 'simpletoc_wrapper_enabled ' , false ) || true === (bool ) get_option ( 'simpletoc_accordion_enabled ' , false );
@@ -394,7 +394,7 @@ function simpletoc_sanitize_string( $string_to_sanitize ) {
394394 // Sanitizes a title, replacing whitespace and a few other characters with dashes.
395395 $ sanitized_string = sanitize_title_with_dashes ( $ string_without_accents );
396396 // Encode for use in an url.
397- $ urlencoded = urlencode ( $ sanitized_string );
397+ $ urlencoded = rawurlencode ( $ sanitized_string );
398398 return $ urlencoded ;
399399}
400400
@@ -452,7 +452,7 @@ function add_anchor_attribute( $html, $headline_class_instance = null ) {
452452 continue ;
453453 }
454454 // Set id attribute.
455- $ heading_text = trim ( strip_tags ( $ html ) );
455+ $ heading_text = trim ( wp_strip_all_tags ( $ html ) );
456456 $ anchor = $ headline_class_instance ->get_headline_anchor ( $ heading_text );
457457 $ tag ->setAttribute ( 'id ' , $ anchor );
458458 }
@@ -489,7 +489,7 @@ function generate_toc( $headings, $attributes ) {
489489 $ this_depth = (int ) $ headings [ $ line ][2 ];
490490 $ next_depth = isset ( $ headings [ $ line + 1 ][2 ] ) ? (int ) $ headings [ $ line + 1 ][2 ] : '' ;
491491 $ exclude_headline = should_exclude_headline ( $ headline , $ attributes , $ this_depth );
492- $ title = trim ( strip_tags ( $ headline ) );
492+ $ title = trim ( wp_strip_all_tags ( $ headline ) );
493493 $ custom_id = extract_id ( $ headline );
494494 $ link = $ custom_id ? $ custom_id : $ headline_ids ->get_headline_anchor ( $ title );
495495 if ( ! $ exclude_headline ) {
@@ -526,7 +526,7 @@ function generate_toc( $headings, $attributes ) {
526526 $ html = add_hidden_markup_end ( $ html , $ attributes );
527527
528528 // return an emtpy string if stripped result is empty.
529- if ( empty ( trim ( strip_tags ( $ html ) ) ) ) {
529+ if ( empty ( trim ( wp_strip_all_tags ( $ html ) ) ) ) {
530530 $ html = '' ;
531531 }
532532
@@ -622,25 +622,25 @@ function close_list( &$list_to_append_to, $list_type, &$min_depth, $min_level, $
622622 for ( $ min_depth ; $ min_depth > $ next_depth ; $ min_depth -- ) {
623623 $ list_to_append_to .= "</li> \n</ " . $ list_type . "> \n" ;
624624 }
625- } else {
625+ } else { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedElse
626626 // SKIP CLOSING! Next heading won't be included in the ToC at all.
627627 }
628628 } elseif ( $ next_depth === $ this_depth ) {
629629 // Next heading is exactly as deep. Not going shallower or deeper in the ToC hierarchy.
630630 // E.g. this is h3, next is h3.
631- if ( $ next_depth < $ min_level ) {
631+ if ( $ next_depth < $ min_level ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
632632 // E.g. this is h3, next is h3, min is h2
633633 // This heading didn't open a ToC item. Nothing to close.
634634 } else {
635635 // SKIP CLOSING! Next heading will open a new sub-list in the ToC.
636636 $ list_to_append_to .= "</li> \n" ;
637637 }
638- } else {
638+ } else { // phpcs:ignore.
639639 // Next heading is deeper in the ToC.
640- if ( $ next_depth <= $ max_level ) {
640+ if ( $ next_depth <= $ max_level ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
641641 // Next deeper heading is within bounds and will open a new sub-list. Leave this one open.
642642 // E.g. this is h3, next is h4, min is h2, max is h5.
643- } else {
643+ } else { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedElse
644644 // Next heading is too deep and will be ignored. We'll close out coming up or finishing the ToC.
645645 // E.g. this is h3, next is h4, max is h3.
646646 }
@@ -697,7 +697,7 @@ function enqueue_accordion_frontend() {
697697 * @param int $itemcount The number of items in the table of contents.
698698 * @param string $alignclass The alignment class for the table of contents block.
699699 */
700- function add_hidden_markup_start ( $ html , $ attributes , $ itemcount , $ alignclass ) {
700+ function add_hidden_markup_start ( $ html , $ attributes , $ itemcount , $ alignclass ) { // phpcs:ignore.
701701 $ is_hidden_enabled = $ attributes ['hidden ' ];
702702
703703 if ( $ is_hidden_enabled ) {
0 commit comments