• Resolved toneburst

    (@toneburst)


    I’m working on a widget plugin, made using the method of extending the builtin WordPress Widget class, based on the tutorial here.

    My widget has a number of options, set using the following method of the extended widget class:

    public function update( $new_instance, $old_instance ) {
    
    	$instance = array();
    	$instance[ 'title' ]					= ( ! empty( $new_instance[ 'title' ] ) ) ? strip_tags( $new_instance[ 'title' ] ) : '';
    	$instance[ 'ellcv_category' ]			= ( ! empty( $new_instance[ 'ellcv_category' ] ) ) ? $new_instance[ 'ellcv_category' ] : '';
    	$instance[ 'ellcv_displayTitle' ]		= isset( $new_instance[ 'ellcv_displayTitle' ] ) && 'on' == $new_instance[ 'ellcv_displayTitle' ] ? true : false;
    	$instance[ 'ellcv_displayExcerpt' ]		= isset( $new_instance[ 'ellcv_displayExcerpt' ] ) && 'on' == $new_instance[ 'ellcv_displayExcerpt' ] ? true : false;
    	$instance[ 'ellcv_displayLink' ]		= isset( $new_instance[ 'ellcv_displayLink' ] ) && 'on' == $new_instance[ 'ellcv_displayLink' ] ? true : false;
    	$instance[ 'ellcv_excludeCategory' ]	= isset( $new_instance[ 'ellcv_excludeCategory' ] ) && 'on' == $new_instance[ 'ellcv_excludeCategory' ] ? true : false;
    	$instance[ 'ellcv_hideOnSinglePost' ]	= isset( $new_instance[ 'ellcv_hideOnSinglePost' ] ) && 'on' == $new_instance[ 'ellcv_hideOnSinglePost' ] ? true : false;
    	$instance[ 'ellcv_maxPosts' ]			= ( ! empty( $new_instance[ 'ellcv_maxPosts' ] ) ) ? intval( $new_instance[ 'ellcv_maxPosts' ] ) : 5;
    	$instance[ 'ellcv_maxPostAge' ]			= ( ! empty( $new_instance[ 'ellcv_maxPostAge' ] ) ) ? intval( $new_instance[ 'ellcv_maxPostAge' ] ) : null;
    	$instance[ 'ellcv_defMediaURL' ]		= ( ! empty( $new_instance[ 'ellcv_defMediaURL' ] ) ) ? esc_url_raw( $new_instance[ 'ellcv_defMediaURL' ] ) : null;
    
    	// Save site options (required so constructor function can get option before widget loaded)
    	update_option( 'ellcv_excludeCat', $instance[ 'ellcv_excludeCategory' ] );
    	update_option( 'ellcv_catID', $instance[ 'ellcv_category' ] );
    
    	return $instance;
    }

    I’d like to be able to remove plugin options on plugin uninstall.

    I’ve created an uninstall.php file for my plugin

    <?php
    // Exit if accessed directly
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    // Exit if we don't see the uninstall flag
    if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    	exit;
    }
    // Delete site options
    delete_option('ellcv_excludeCat');
    delete_option('ellcv_catID');
    ?>

    So, I’m able to delete the options set as site options from the database, but what I’m still unclear about is how to also delete the other options, saved/recalled as instance properties from the WP database. I don’t know how to get a handle on them to remove them, from my uninstall.php.

    I’m hazy on OOP techniques generally, unfortunately, being self-taught, and having been using functional programming techniques for many years.

    The code for the entire widget is quite long, so I don’t want to post it here, but it’s basically the same, structurally as the example I link to above.

    Any hints gratefully accepted.

    a|x

    Any tips

Viewing 1 replies (of 1 total)
  • Thread Starter toneburst

    (@toneburst)

    Think I’ve answered my own question:
    After doing a search of the database, it looks like the other options are stored in a serialised array in

    wp_options / ell_catvideo_widget

    So I just need to delete that option, presumably. Easier than I thought…

    a|x

Viewing 1 replies (of 1 total)
  • The topic ‘OOP Widget Delete Plugin Options on Uninstall’ is closed to new replies.