Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Individual site activation not enabled with multi-site #192

Open
5 tasks done
AmibeWebsites opened this issue Jun 5, 2024 · 1 comment
Open
5 tasks done

Individual site activation not enabled with multi-site #192

AmibeWebsites opened this issue Jun 5, 2024 · 1 comment
Assignees
Labels

Comments

@AmibeWebsites
Copy link

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest stable version of Code Snippets.

Type of Bug

A Code Snippet

Description

In a multi-site, the option to 'Allow this snippet to be activated on individual sites on the network' does not save (and automatically disables the snippet on any individual site where it was activated for that site).

What I would expect is that the snippet would be available for activation on individual sites in that network, and that if it had previously already been active prior to saving the snippet, that it would remain active.

What happens is that the snippet is not made available to be activated on individual sites in the network, and if it had been activated for any individual site, it is now deactivated.

My work-around is to directly edit the 'shared_network_snippets' meta_key in the database for the network. And then I go and re-enable for all individual sites that use it.

Steps to reproduce

Steps to reproduce, in a multi-site setup, with multiple networks:

  1. Add new or edit an existing snippet
  2. Tick the option 'Allow this snippet to be activated on individual sites on the network'
  3. Save changes
  4. Refresh the page to see that the option is no longer ticked

Isolating the problem

  • This bug happens with only the Code Snippets plugin active (Free or Pro).
  • This bug happens with a Blank WordPress theme active. For example: (Hello theme).
  • I can reproduce this bug consistently following the steps above.

Comment

My actual environment is a multi-network setup, in other words, many multi-sites.

There is a slight complexity in that while the snippet is the same across all networks (in other words... if it gets edited through one network all networks reflect the same change), the option to 'Allow this snippet to be activated on individual sites on the network' can however be different per network.

I did checked with multi-network functionality turned off and the issue still occurred, so I'm guessing it's a multi-site issue, rather than being unique to a multi-network setup.
@llicour
Copy link

llicour commented Jun 21, 2024

same issue for me (v3.6.5)
I try some patchs that seems to work, waiting for an official bugfix
(not sure it cover all cases, but for basic snippet edition), seems ok

patch php/snippet-ops.php

--- a/wp-content/plugins/code-snippets-pro/php/snippet-ops.php
+++ b/wp-content/plugins/code-snippets-pro/php/snippet-ops.php
@@ -230,11 +230,11 @@ function update_shared_network_snippets( array $snippets ): bool {

        foreach ( $snippets as $snippet ) {
                if ( $snippet->shared_network ) {
-                       if ( $snippet->active ) {
+                       //if ( $snippet->active ) {
                                $shared_ids[] = $snippet->id;
                        } else {
                                $unshared_ids[] = $snippet->id;
-                       }
+                       //}
                }
        }

add new filter

add_filter("code_snippets/get_snippet", function($snippet, $id, $network) {
	if ($network) {
		$shared_network_snippets = get_site_option( 'shared_network_snippets', array() );
		$snippet->shared_network = in_array( $snippet->fields['id'], $shared_network_snippets, true );
	}
	return $snippet;
}, 10, 3);

@sheabunge sheabunge self-assigned this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants