2

I placed HTML in several text widgets which where lost after i deleted all inactive widgets and changed themes but i have found the data in the tables.

The only problem, its mixed in with all this other crap code and i only want the HTML or text.

All the export options don't allow for export of text or HTML even though that's what i entered into the text widgets in the first place.

1
  • Thanks Ralf. Not sure what happened but the text widget content returned after i changed themes and removed the code which was added beforehand to remove the default widgets. The plugin code you provided returned an error.
    – Haymanpl
    Commented Apr 30, 2013 at 8:03

1 Answer 1

2

The data in the options table is stored as serialized arrays. Use get_option() to get the data and unserialize them.

array_walk(
    get_option( 'widget_text' ),
    function( $d ){
        if ( ! empty( $d['title'] ) ) {
            printf( '<p>Title: %s<br>Text: %s</p>', $d['title'], htmlentities( $d['text'] ) );
        }
    }
);

If you need a complete plugin, use this. It's a simple debug-plugin. Upload, activate and go to the dashboard. After activation there should be a Debug-Widget. If not, open the screen options and activate the Debug-Widget.

<?php
/*
Plugin Name: __WPSE__
Description: Testing plugincode
*/

add_action( 'plugins_loaded', function(){ new TestPlugin; } );

class TestPlugin {

    public function __construct(){

        add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widget' ) );

    }

    public function add_dashboard_widget(){

        wp_add_dashboard_widget(
            'debug-widget',
            'Debug Widget',
            array( $this, 'output' ),
            $control_callback = null
        );

    }

    public function output(){

        echo '<div class="wrap">';

        array_walk(
            get_option( 'widget_text' ),
            function( $d ){
                if ( ! empty( $d['title'] ) )
                    printf( '<p>Title: %s<br>Text: %s</p>', $d['title'], htmlentities( $d['text'] ) );
            }
        );

        echo '</div>';

    }

}
2
  • Hehe, my WPSE test plugin is named *ad hoc. Alphabetical sorting for the win!
    – fuxia
    Commented Apr 28, 2013 at 14:56
  • I should add an option to sort the plugins by installation date and set this sorting by default ;)
    – Ralf912
    Commented Apr 29, 2013 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.