snipt

Ctrl+h for KB shortcuts

Text only

Wordpress plugin activation error capture

1
2
3
4
5
6
function tl_save_error() {
    update_option( 'plugin_error',  ob_get_contents() );
}
add_action( 'activated_plugin', 'tl_save_error' );
/* Then to display the error message: */
echo get_option( 'plugin_error' );
https://snipt.net/embed/b295acb7b1a32b379d7f56134267265c/
/raw/b295acb7b1a32b379d7f56134267265c/
b295acb7b1a32b379d7f56134267265c
text
Text only
6
2024-05-19T23:16:53
True
False
False
Jul 29, 2019 at 03:45 PM
/api/public/snipt/107/
wordpress-plugin-activation-error-capture
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>function tl_save_error() { </span><span id="L-2"><a name="L-2"></a> update_option( &#39;plugin_error&#39;, ob_get_contents() ); </span><span id="L-3"><a name="L-3"></a>} </span><span id="L-4"><a name="L-4"></a>add_action( &#39;activated_plugin&#39;, &#39;tl_save_error&#39; ); </span><span id="L-5"><a name="L-5"></a>/* Then to display the error message: */ </span><span id="L-6"><a name="L-6"></a>echo get_option( &#39;plugin_error&#39; ); </span></pre></div> </td></tr></table>
wordpress