Change WordPress user roles and capabilities Forums How to or FAQ Problem with shortcodes after moving WP to a new server

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #2441
    kardon
    Participant

    I am working with the hosting provider on this however it may be something you can provide direction quickly.

    All worked fine in my Multisite install. It was converted from one server to another over the weekend and now my pages using the content control shortcode are showing the shortcodes. For example: [user_role_editor roles=”k-comply”] some content that those users should see [/user_role_editor] is actually displayed on the page when we go to it instead of not showing it to us as it used to do.

    Any ideas would be appreciated. We have removed the plugin and reinstalled it. The license shows active but not sure where else to go from here myself.

    #2443
    Vladimir
    Keymaster

    Check if ‘Activate [user_role_editor roles=”role1, role2, …”] shortcode’ checkbox at URE’s settings ‘Additional modules’ tab is turned ON at ‘Network Admin’ if URE is network activated or for the site to which this page is belongs.

    #2445
    kardon
    Participant

    It was not on. I set it to ON. But, the problem persists.

    Hosting tech seems to think this error is related:
    Failed to load resource: the server responded with a status of 500 (Internal Server Error)
    jquery-migrate.min.js:2 JQMIGRATE: Migrate is installed, version 1.4.1

    https://kardonhq.net/wp-content/plugins/media/style.css?ver=e6fbd43a92cc6bc14580501f0ea9497f Failed to load resource: the server responded with a status of 500 (Internal Server Error)

    Because wp-content/plugins/media folder doesn’t exist the error happens.

    #2447
    kardon
    Participant

    I have discovered the issue is only on subsites, not the main network site. Is there a way I can reset that or check to see if the subsites are set to use the shortcode?

    #2451
    Vladimir
    Keymaster

    Is URE network activated or per the single subsites?

    #2452
    kardon
    Participant

    It is Network Activated and the box for Activate [user_role_editor roles=”role1, role2, …”] shortcode is checked.

    #2453
    Vladimir
    Keymaster

    Could you compare the output from WordPress (adding this code to the functions.php, for example):

    
    global $current_site;
    
    echo 'Main site ID: '. $current_site->blog_id;
    

    and from this SQL query:

    
    select blog_id from wp_blogs order by blog_id asc limit 0, 1;
    

    use your own DB prefix instead of a default ‘wp_’ if you changed it.

    #2454
    kardon
    Participant

    Main site ID: 1

    blog_id 1

    #2458
    kardon
    Participant

    Is there any way to force the sub-sites to see the shortcodes?

    #2459
    kardon
    Participant

    OK, I found shortcodes.php and made a change to force it ON

    class URE_Shortcodes {

    private $lib = null;

    public function __construct(Ure_Lib_Pro $lib) {

    $this->lib = $lib;
    $activate_content_for_roles_shortcode = $this->lib->get_option(‘activate_content_for_roles_shortcode’, false);
    $activate_content_for_roles_shortcode = true;
    if ($activate_content_for_roles_shortcode) {
    add_action(‘init’, array($this, ‘add_content_shortcode_for_roles’));
    }
    }
    // end of __construct()

    I did do an echo on that before and after setting it to test it. When it did the get_option the variable returned was blank.

    So, this is the problem. How can I fix the get to the db to return the value of ON. I checked once again and that box is checked on the network settings for URE.

    #2460
    Vladimir
    Keymaster

    If URE is network activated it uses options data from the main blog for all subsites.
    Your site new installation differs somehow. Try to debug code related for work with options data to understand what’s going wrong with your setup and enhance the URE’s code.

    Main blog ID is defined at includes/classes/base-lib.php constructor:

    
    $this->main_blog_id = $this->blog_ids[0][0];
    

    Let’s replace it with this line:

    
    $this->main_blog_id = $this->get_main_site();
    

    and add a new public method to URE_Base_Lib class:

    
        public function get_main_site() {
            global $current_site;
            
            return $current_site->blog_id;
        }
        // end of get_main_site()
    
    

    This way we will relay on WordPress in a question of main site ID definition.

    Test shortcodes after this update. Just in case debug data you showed yesterday was not actual somehow and main site ID is not 1.

    If it will not help, let’s proceed with debugging of init_options method at includes/classes/ure-lib.php, line #154.

    User Role Editor takes its configuration/options data from there. As you can see it switches to the main blog before to get data if it’s network wide activated under WP multisite.

    #2466
    kardon
    Participant

    OK, here is what I have learned.

    I put thIS code in the theme functions.php
    echo '</br> Main site ID theme functions.php: '. $current_site->blog_id;

    and then also added it to the ure-lib.php.

        protected function init_options($options_id) {
            
            global $wpdb;
    
            if ($this->multisite) { 
                if ( ! function_exists( 'is_plugin_active_for_network' ) ) {    // Be sure the function is defined before trying to use it
                    require_once( ABSPATH . '/wp-admin/includes/plugin.php' );                
                }
          
                $this->active_for_network = is_plugin_active_for_network(URE_PLUGIN_BASE_NAME);
            }
            $current_blog = $wpdb->blogid;
            if ($this->multisite && $current_blog!=$this->main_blog_id) {   
                if ($this->active_for_network) {   // plugin is active for whole network, so get URE options from the main blog
                    switch_to_blog($this->main_blog_id);  
                }
            }
         
         echo '</br> Main site ID ure-lib: '. $current_site->blog_id.'  ';       
            $this->options_id = $options_id;
            $this->options = get_option($options_id);
            
            if ($this->multisite && $current_blog!=$this->main_blog_id) {
                if ($this->active_for_network) {   // plugin is active for whole network, so return back to the current blog
                    restore_current_blog();
                }
            }

    This is what it returns:

    Main site ID ure-lib:
    Main site ID theme functions.php: 1

    I don’t know why it knows the value in one place and not the other. If you give me more direction I will do further analysis, though.

    Thanks so very much for all your help with this!!

    #2468
    Vladimir
    Keymaster

    You have to add a line

    
    global $current_site;
    

    inside init_options() functions before check property value of this object. This variable is unavailable in other case.

    #2478
    kardon
    Participant
    protected function init_options($options_id) {
            
            global $wpdb;
    
            if (ç) { 
                if ( ! function_exists( 'is_plugin_active_for_network' ) ) {    // Be sure the function is defined before trying to use it
                    require_once( ABSPATH . '/wp-admin/includes/plugin.php' );                
                }
          
                $this->active_for_network = is_plugin_active_for_network(URE_PLUGIN_BASE_NAME);
            }
            $current_blog = $wpdb->blogid;
            if ($this->multisite && $current_blog!=$this->main_blog_id) {   
                if ($this->active_for_network) {   // plugin is active for whole network, so get URE options from the main blog
                    switch_to_blog($this->main_blog_id);  
                }
            }
         
                
            $this->options_id = $options_id;
            $this->options = get_option($options_id);
            
            if ($this->multisite && $current_blog!=$this->main_blog_id) {
                if ($this->active_for_network) {   // plugin is active for whole network, so return back to the current blog
                    restore_current_blog();
                }
            }
             <strong>echo '</br> ure-lib:$this->multisite '. $this->multisite;
             echo '</br> ure-lib:$current_blog: '. $current_blog;
             echo '</br> ure-lib:$this->main_blog_id: '. $this->main_blog_id;
             echo '</br> ure-lib:this->active_for_network: '. $this->active_for_network;</strong>
    
        }
        // end of init_options()

    This code that echos the exact variable names used in the function returns this:
    ure-lib:$this->multisite 1
    ure-lib:$current_blog: 38
    ure-lib:$this->main_blog_id:
    ure-lib:this->active_for_network: 1

    I then added the global line you mentioned and the echo of it.
    ure-lib:$current_site->blog_id 1
    ure-lib:$this->multisite 1
    ure-lib:$current_blog: 38
    ure-lib:$this->main_blog_id:
    ure-lib:this->active_for_network: 1

    Does this provide any clue to the problem?

    #2481
    Vladimir
    Keymaster

    Problem is that $this->main_blog_id property is empty for some reason, but it should contain 1 (main site ID) to work correctly.

    Let’s return to the includes/classes/base-lib.php and check if you edited it as I asked at reply #2460

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.