PluginProbe
Code Snippets / 4.0.0-beta.3
Code Snippets v4.0.0-beta.3
4.0.0-beta.3 4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 All 66 releases
← All changes | php/snippet-ops.php +21 -4 4.0.0-beta.2 → 4.0.0-beta.3 View file →
@@ -454,8 +454,13 @@
454 454 if ( ! $result ) {
455 455 return __( 'Could not activate snippet.', 'code-snippets' );
456 456 }
457 457
458 + // Read back over a cleared cache, so what follows sees the snippet as
459 + // active rather than as it was fetched for validation above.
460 + clean_snippets_cache( $table_name );
461 + $snippet = get_snippet( $id, $network );
462 +
458 463 update_shared_network_snippets( [ $snippet ] );
459 464 do_action( 'code_snippets/activate_snippet', $snippet, $network );
460 465 clean_snippets_cache( $table_name );
461 466 return $snippet;
@@ -526,8 +531,10 @@
526 531 if ( ! $rows_updated ) {
527 532 return null;
528 533 }
529 534
535 + clean_snippets_cache( $table_name );
536 +
530 537 update_shared_network_snippets( $valid_snippets );
531 538 do_action( 'code_snippets/activate_snippets', $valid_snippets, $table_name );
532 539 clean_snippets_cache( $table_name );
533 540 return $valid_ids;
@@ -561,10 +568,14 @@
561 568 if ( ! $result ) {
562 569 return null;
563 570 }
564 571
572 + // Read back over a cleared cache, so the snippet is seen as inactive by
573 + // everything below rather than as it stood before the write.
574 + clean_snippets_cache( $table );
575 + $snippet = get_snippet( $id, $network );
576 +
565 577 // Update the recently active list.
566 - $snippet = get_snippet( $id );
567 578 $recently_active = get_self_option( $network, 'recently_active_snippets', [] );
568 579 $recently_active[ $id ] = time();
569 580 update_self_option( $network, 'recently_active_snippets', $recently_active );
570 581
@@ -604,10 +615,10 @@
604 615 array( '%d' )
605 616 );
606 617
607 618 if ( $result ) {
619 + clean_snippets_cache( $table );
608 620 do_action( 'code_snippets/delete_snippet', $snippet, $network );
609 - clean_snippets_cache( $table );
610 621
611 622 $recently_active = get_self_option( $network, 'recently_active_snippets', [] );
612 623
613 624 if ( isset( $recently_active[ $id ] ) ) {
@@ -643,10 +654,10 @@
643 654 }
644 655
645 656 $wpdb->update( $table, [ 'active' => '-1' ], [ 'id' => $id ], [ '%d' ] );
646 657
658 + clean_snippets_cache( $table );
647 659 do_action( 'code_snippets/trash_snippet', $snippet, $network );
648 - clean_snippets_cache( $table );
649 660
650 661 return true;
651 662 }
652 663
@@ -668,10 +679,10 @@
668 679
669 680 $result = $wpdb->update( $table, [ 'active' => '0' ], [ 'id' => $id ], [ '%d' ] );
670 681
671 682 if ( $result ) {
683 + clean_snippets_cache( $table );
672 684 do_action( 'code_snippets/restore_snippet', $id, $network );
673 - clean_snippets_cache( $table );
674 685 }
675 686
676 687 return (bool) $result;
677 688 }
@@ -808,8 +819,14 @@
808 819 $existing = get_snippet( $snippet->id, $snippet->network );
809 820
810 821 set_snippet_locked( $snippet->id, $snippet->locked, $snippet->network );
811 822 $wpdb->update( $table, $data, [ 'id' => $snippet->id ], null, [ '%d' ] );
823 +
824 + // The row has changed, so the cached list no longer describes it. It is
825 + // dropped before the snippet is read back, because everything below —
826 + // the value this returns and what its hooks are handed — has to be the
827 + // saved snippet rather than the one that was there beforehand.
828 + clean_snippets_cache( $table );
812 829
813 830 $updated = get_snippet( $snippet->id, $snippet->network );
814 831 $updated->code_error = $snippet->code_error;
815 832 $updated->code_error_trace = $snippet->code_error_trace;