BoilWP / WooCommerce-Extension-Boilerplate-Light

This is a lighter version to the WooCommerce Extension Boilerplate.
19 stars 12 forks source link

Settings ... #4

Closed westaussie closed 9 years ago

westaussie commented 10 years ago

Hi ... I've just begun building my very first WC plugin using this boilerplate and have a question re: the admin settings setup.

I'm running WP 3.9.1 and WC 2.1.9 however the default admin settings seem to be coming from the 1.6.6 class.

I've looked at the create_options function from the install class and the logic looks correct and should NOT be loading the settings from the v1.6.6 folder however it seems it is ... I know this as I used a different title in each of the settings files to see which one was actually loading.

Am I missing something? Do I need to change something?

Thanks

seb86 commented 10 years ago

Is the WooCommerce version being called?

westaussie commented 10 years ago

It should be as the check_requirements function grabs the current version from the DB and if that isn't set it uses WOOCOMMERCE_VERSION which I traced back to being defined in the WC plugin itself.

Does the login in the following look correct given WC_EXTEND_WOOVERSION gets set to WOOCOMMERCE_VERSION and the current version is 2.1.9?

/**
     * Default options
     *
     * Sets up the default options used on the settings page
     *
     * @access public
     */
    function create_options() {
        /** 
         * This loads the settings for the plugin.
         * First checks what version of WooCommerce is active,
         * then loads the appropriate format.
         */
        if( version_compare(WC_EXTEND_WOOVERSION, "1.6.6", '<=') || version_compare(WC_EXTEND_WOOVERSION, "2.0.20", '<=') ) {

            if(version_compare(WC_EXTEND_WOOVERSION, "1.6.6", '<=')){
                include_once( 'settings/v1.6.6/class-woocommerce-jcurve-connector-admin-settings.php' );
            }
            else if(version_compare(WC_EXTEND_WOOVERSION, "2.0.20", '<=')){
                include_once( 'settings/v2.0.20/class-woocommerce-jcurve-connector-admin-settings.php' );
            }

            $this->settings = new WooCommerce_JCurve_Connector_Admin_Settings();
            $this->settings->get_settings();

            // Run through each settings to load the default settings.
            foreach ( $this->settings as $value ) {
                if ( isset( $value['default'] ) && isset( $value['id'] ) ) {
                    $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
                    add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
                }
            }
        }
        else{
            // Include settings so that we can run through defaults.
            include_once( 'class-woocommerce-jcurve-connector-admin-settings.php' );

            $settings = WooCommerce_JCurve_Connector_Admin_Settings::get_settings_pages();

            // Run through each section and settings to load the default settings.
            foreach ( $settings as $section ) {
                $section = $section->get_settings();
                foreach ( $section as $value ) {
                    if ( isset( $value['default'] ) && isset( $value['id'] ) ) {
                        $autoload = isset( $value['autoload'] ) ? (bool) $value['autoload'] : true;
                        add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
                    }
                }
            }
        }
    }

To my reading, if the WC version is 2.1.9 then the first if should be skipped to the else ... however it seems version_compare(WC_EXTEND_WOOVERSION, "1.6.6", '<=') is equating true for some reason.

What is the best way to see what value is in WC_EXTEND_WOOVERSION?

westaussie commented 10 years ago

OK got things to work correctly by manually defining WC_EXTEND_WOOVERSION with all the others.

Also the plugin fails with errors if WooCommerce is not active however I haven't had a chance to resolve this yet.

seb86 commented 10 years ago

@westaussie Sounds good. Please fork the repository and push your changes so that I can take a look.