How do i export the HTML from text widgets?

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.

Read More

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.

Related posts

Leave a Reply

1 comment

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