WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] OOP Framework and update_options not working (2 posts)

  1. John Peden
    Member
    Posted 1 year ago #

    Hi folks,

    I'm using an OOP framework into which I've shoe-horned the code from a plugin I've built. Problem is, the framework offers a means of updating plugin options and although I'm successfully requesting a response from a third party API, I can't update the option 'status' of my plugin. Any thoughts on where I'm going wrong?

    Here is the update function:

    private function _admin_options_update() {
            // Verify submission for processing using wp_nonce
            if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-update-options" ) ) {
                $data = array();
                /**
                 * Loop through each POSTed value and sanitize it to protect against malicious code. Please
                 * note that rich text (or full HTML fields) should not be processed by this function and
                 * dealt with directly.
                 */
                foreach( $_POST['data'] as $key => $val ) {
                    $data[$key] = $this->_sanitize( $val );
                }
    
                /**
                 * Place your options processing and storage code here
                 */
    
                // Update the options value with the data submitted
                update_option( $this->option_name, $data );
    
                // Redirect back to the options page with the message flag to show the saved message
                wp_safe_redirect( $_REQUEST['_wp_http_referer'] . '&update=1' );
                exit;
            }
        }

    I'm trying to run this function:

    update_option( $WPBackitup->options['status'], $license_data->license );

  2. John Peden
    Member
    Posted 1 year ago #

    Not sure why this was already marked as resolved but I figured it out. The framework was passing variables from its pre-configured form to the DB as an array but was sanitizing the values first. As my license key wasn't being sanitized, it wasn't being passed so update_options failed.

    I solved the problem by manually adding an entry to the $data array just before the function above pulled the values from the form.

    Easy!

Topic Closed

This topic has been closed to new replies.

About this Topic