Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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 Apr 30 '13 at 8:03

1 Answer 1

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>';

    }

}
share|improve this answer
    
Hehe, my WPSE test plugin is named *ad hoc. Alphabetical sorting for the win! –  toscho Apr 28 '13 at 14:56
    
I should add an option to sort the plugins by installation date and set this sorting by default ;) –  Ralf912 Apr 29 '13 at 8:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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