0
votes

this is likely a bit of a unique problem that I've been struggling with for the past few days. I have a WordPress multisite setup. I have a plugin activated on my root site that IS NOT activated on any subsite. due to conflicts, I cannot activate the plugin on any subsites. The plugin displays values via shortcodes. I am trying to write a function that gets the output value from the shortcode and stores it in a variable so that I can insert that value into a subsite using my own shortcode. I am using the switch_to_blog() function. The result of my code below ends up being [plugin-shortcode-on-root-site] wherever I use my custom shortcode on a subsite rather than being the value that [plugin-shortcode-on-root-site] should output.

I'm hoping this all makes sense. Any help would be greatly appreciated! Thanks!

function return_shorcode_output () {

    switch_to_blog(1);

    $output = do_shortcode('[plugin-shortcode-on-root-site]');

    restore_current_blog();

    return $output;
}

add_shortcode( 'Shortcode_On_Subsite', 'return_shortcode_output' );
1
Could you show the code for your shortcode? - WP Punk

1 Answers

0
votes

As far as I know you cannot access plugin functionality between sites like this using switch_to_blog. switch_to_blog lets you access database info from other sites. Something you could try doing is storing the values the plugins generate as an option in the database to access via other blogs. I realize this can get very unwieldy if the plugin generates a lot of values.