Support » Plugin: Code Snippets » Code Snippet not working on fresh WordPress installation

  • Resolved frontdeskivc

    (@frontdeskivc)


    I just installed a fresh WordPress on my webhosting to test Code Snippet plugin and inserted the following snippet:

    `
    // Modify text in WP Admin footer
    function modify_footer_admin () {
    echo ‘Created by Your name here. Powered by WordPress‘;
    }
    add_filter(‘admin_footer_text’, ‘modify_footer_admin’);

    However, the snippet is NOT working. The site has no other plugin. The snippet above is working on a fresh WordPress installation in localhost. Therefore, it must be a setting in my webhosting that’s blocking it.

    Do you have any idea what sort of setting in my webhosting that could potentially block ‘Code Snippet’?

Viewing 9 replies - 1 through 9 (of 9 total)
  • FYI, I’m using PLESK with WordPress toolkit. I have disabled all security settings in wordpress toolkit.

    Plugin Author Shea Bunge

    (@bungeshea)

    admin_filter_text is a filter, not an action, so you should be returning a value instead of printing one out:

    function modify_footer_admin( $text ) {
    	return 'Created by Your name here. Powered by WordPress';
    }
    add_filter( 'admin_footer_text', 'modify_footer_admin' );

    I would also recommend rewriting the snippet to avoid named functions:

    add_filter( 'admin_footer_text', function ( $text ) {
    	return 'Created by Your name here. Powered by WordPress';
    } );

    Hi Shea,

    Thank you very much for your time to reply my question. I really appreciate it. I have tried the snippet that you provided. Unfortunately it still doesn’t work.

    I’ve tried different basic snippets just to test my theory that some sort of setting in my webhosting is blocking the plugin and none of the snippets that I tried working. The snippet that I posted above is working in my local host but not on my web hosting.

    Is it possible that some sort of setting in my web hosting is blocking the plugin ?

    Plugin Author Shea Bunge

    (@bungeshea)

    Possibly? I’ve heard stories about certain server modules like Apache’s mod_security module interfering with features of Code Snippets, but I don’t know enough about all the different options out there to say for sure.

    Hi Shea,

    I’m not a programer and only learn basic PHP 10+ years ago in uni. However, after spending hours trying different things to investigate the problem, I found the following interesting possible cause:

    in code-snippets\php\snippet-ops.php in function execute_active_snippets()

    /* Fetch snippets from site table */
    	if ( $wpdb->get_var( "SHOW TABLES LIKE '$db->table'" ) === $db->table ) {
    		echo "FETCH SNIPPETS";
    		$queries[ $db->table ] = $wpdb->prepare( sprintf( $sql_format, $db->table ) . 'AND active=1 ' . $order, $current_scope );
    		
    	}

    The above statement was not executed despite having active snippets in database because the value are not the same.
    The value of $wpdb->get_var( “SHOW TABLES LIKE ‘$db->table'” ) is m**2*k**_snippets while the value of $db->table is m**2*K**_snippets (upper case K VS lower case k). The correct prefix is all lower case.

    Do you think this is a problem? why is this problem happening only on my site ? I used wordpress toolkit to change the database prefix a few months ago.

    Thank you very much for your help!

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @frontdeskivc,

    I really appreciate you taking the time to work out what was actually going on!

    Are you able to check what the $table_prefix variable is set to in wp-config.php? It sounds like it might be set to the uppercase version.

    I’ll investigate what a good fix for this in the main plugin might be.

    Hi Shea,

    It’s upper case K in wp-config.php. Is this a bug from wordpress toolkit when I changed my database table prefix?

    Thanks,
    Monica

    Plugin Author Shea Bunge

    (@bungeshea)

    I’m not familiar with WordPress Toolkit, but it seems like it might be a bug in that process.

    Changing the $table_prefix variable to be the lowercase version (that matches the actual table name) should fix this problem.

    frontdeskivc

    (@frontdeskivc)

    Thank you Shea for your time to help me. I think it is a PLESK windows bug. I found an article that describes steps to fix it just in case anyone needs it:

    https://support.plesk.com/hc/en-us/articles/115001866273

    I can now use the amazing ‘Code Snippets’ plugin again!

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.