Support » Plugin: My Custom Functions » Parse error – cannot activate plugin after a mistake

  • Resolved franzi11

    (@franzi11)


    I entered an wrong code
    (should be:

    function fb_add_search_box ( $items, $args ) {
    	
    	// only on primary menu
    	if( 'primary' === $args -> theme_location )
    		$items .= '<li class="menu-item menu-item-search">' . get_search_form( FALSE ) . '</li>';
    	
    	return $items;
    }
    add_filter( 'wp_nav_menu_items', 'fb_add_search_box', 10, 2 );

    but in the last line I had an 8 instead of the 10.

    My site shut down when I saved the code, but I used the tipp from here, renamed the plugin folder and could login again.
    Then I deleted the renamed folder and installed your plugin again, but it could not be activated: “Parse error: syntax error, unexpected ‘,’ in /homepages/20/d181324704/htdocs/clickandbuilds/AndreaSusanNolte/wp-content/plugins/my-custom-functions/inc/php/functional.php(85) : eval()’d code on line 11”

    In the functional.php I find this.

    <?php
    
    /**
     * Prevent Direct Access
     */
    defined( 'ABSPATH' ) or die( "Restricted access!" );
    
    /**
     * Prepare the user entered code for execution
     */
    function spacexchimp_p001_prepare( $content ) {
    
        // Cleaning
        $content = trim( $content );
        $content = ltrim( $content, '<?php' );
        $content = rtrim( $content, '?>' );
    
        // Return prepared code
        return $content;
    }
    
    /**
     * Check the user entered code for duplicate names of snippets
     */
    function spacexchimp_p001_duplicates( $content ) {
    
        // Find names of user entered snippets and check for duplicates
        preg_match_all('/function[\s\n]+(\S+)[\s\n]*\(/i', $content, $user_func_names);
        $user_func_a = count( $user_func_names[1] );
        $user_func_b = count( array_unique( $user_func_names[1] ) );
    
        // Find all names of declared user snippets and mutch with names of user entered snippets
        $declared_func = get_defined_functions();
        $declared_func_user = array_intersect( $user_func_names[1], $declared_func['user'] );
        $declared_func_internal = array_intersect( $user_func_names[1], $declared_func['internal'] );
    
        // Update error status
        if ( $user_func_a != $user_func_b OR count( $declared_func_user ) != 0 OR count( $declared_func_internal ) != 0 ) {
            update_option( SPACEXCHIMP_P001_SETTINGS . '_error', '1' );   // ERROR
            $error_status = '1';
        } else {
            update_option( SPACEXCHIMP_P001_SETTINGS . '_error', '0' );   // RESET ERROR VALUE
            $error_status = '0';
        }
    
        // Return error status
        return $error_status;
    }
    
    /**
     * Execute the user entered code
     */
    function spacexchimp_p001_exec() {
    
        // If STOP file exist...
        if ( file_exists( SPACEXCHIMP_P001_PATH . 'STOP' ) ) {
            return;   // EXIT
        }
    
        // Read options from database and declare variables
        $options = get_option( SPACEXCHIMP_P001_SETTINGS . '_settings' );
        $content = !empty( $options['snippets'] ) ? $options['snippets'] : ' ';
        $enable = !empty( $options['enable'] ) ? $options['enable'] : ' ';
    
        // If the user entered code is disabled...
        if ( $enable != 'on') {
            return;   // EXIT
        }
    
        // Prepare the user entered snippets by calling the "prepare" function
        $content = spacexchimp_p001_prepare( $content );
    
        // If content is empty...
        if ( empty( $content ) OR $content == ' ' ) {
            return;   // EXIT
        }
    
        // If the duplicates snippets finded...
        $duplicates = spacexchimp_p001_duplicates( $content );
        if ( $duplicates != 0 ) {
            return;   // EXIT
        }
    
        // Parsing and execute by Eval
        if ( false === @eval( $content ) ) {
            update_option( SPACEXCHIMP_P001_SETTINGS . '_error', '1' );   // ERROR
            return;   // EXIT
        } else {
            update_option( SPACEXCHIMP_P001_SETTINGS . '_error', '0' );   // RESET ERROR VALUE
        }
    }
    spacexchimp_p001_exec();

    I deleted all caches, reopened my browser, nothing helps.

    I´m a bloody WP-Newbie (therefore I was so glad to find your plugin) and don´t know, what to do now, please help me.

    Thank you for answering and best regards,
    Franzi

    • This topic was modified 2 years, 1 month ago by franzi11.
    • This topic was modified 2 years, 1 month ago by franzi11.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Space X-Chimp

    (@arthur-gareginyan)

    Hi @franzi11,

    Sorry for the delay in response.

    Thank you for choosing my WordPress plugin! 🙂

    I’m sorry that you have this problem. This plugin has a built-in functions for checking the custom PHP code for syntax errors, duplicate functions names, and etc. But plugin is not perfect, so there are times when the entered custom PHP code causes an error and white screen. This is due to the fact that your custom PHP code has a syntax error that this plugin could not detect. When this happens with you just do the following and all will be fine.

    1. Via FTP, go to the plugin folder (in ‘wp-content/plugins/my-custom-functions/’).
    2. Rename the “START” file to “STOP”. This will stop the execution of your custom code.
    3. Return to the WordPress Admin Panel and activate the plugin. Now it should activate without problems.
    4. Go to the plugin settings page and edit/fix your custom PHP code that you entered before the crash.
    5. Rename the “STOP” file to “START” and you’re done!

    I’m already working on the function to automatically stop the plugin for cases when this plugin could not detect the error, and this caused the inaccessibility of the website.

    franzi11

    (@franzi11)

    Hi Arthur,
    no problem, thank you so much for answering. No reason for apologizing, it´s a great plugin for WP-Newbies.

    I followed your instruction, but unfortunatly at first it doesn´t work: I got the same error message: “Parse error: syntax error, unexpected ‘,’ in /homepages/20/d181324704/htdocs/clickandbuilds/AndreaSusanNolte/wp-content/plugins/my-custom-functions/inc/php/functional.php(85) : eval()’d code on line 11”.

    Then I deinstalled it, deleted the cache and installed it again. Before I tried to activate it, I had a look into the plugin-folder and there was not START but STOP. So I renamed it to START, deinstalled again and deleted cache, installed once more, then set on STOP and HOORAH, I could avtivate it!

    The I deleted the wrong code, saved and set on START. Put in the right code – eyerything works very well.

    I´m so glad! Thank you so much and best regards,
    Franzi

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Parse error – cannot activate plugin after a mistake’ is closed to new replies.