snipt

Ctrl+h for KB shortcuts

PHP

Quick WordPress maintenance mode

1
2
3
4
5
6
7
<?php
function cwc_maintenance_mode() {
    if(!current_user_can('administrator')) {
        wp_die('<div style="text-align:center!important;"><h1 style="font-family: \'Helvetica Neue\', \'HelveticaNeue\', Helvetica, Arial, sans-serif;margin-bottom:1em;border-bottom:0;font-weight:bold;">Our site is currently undergoing scheduled maintenance.</h1><p style="line-height:1.5;font-size:18px;color:#666;">We are sorry for the inconvenience.<br/>Please try again <strong>in 15 minutes</strong>.</p></div>','Scheduled Maintenance', array('response'=>503));
    }
}
add_action('get_header', 'cwc_maintenance_mode');
https://snipt.net/embed/32d385e6386aa4d534f72ac8f594bd63/
https://snipt.net/raw/32d385e6386aa4d534f72ac8f594bd63/
32d385e6386aa4d534f72ac8f594bd63
php
PHP
8
2016-09-21T20:28:50
True
False
False
Feb 16, 2016 at 12:13 PM
/api/public/snipt/144284/
quick-wordpress-maintenance-mode
<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> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">cwc_maintenance_mode</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">current_user_can</span><span class="p">(</span><span class="s1">&#39;administrator&#39;</span><span class="p">))</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">wp_die</span><span class="p">(</span><span class="s1">&#39;&lt;div style=&quot;text-align:center!important;&quot;&gt;&lt;h1 style=&quot;font-family: \&#39;Helvetica Neue\&#39;, \&#39;HelveticaNeue\&#39;, Helvetica, Arial, sans-serif;margin-bottom:1em;border-bottom:0;font-weight:bold;&quot;&gt;Our site is currently undergoing scheduled maintenance.&lt;/h1&gt;&lt;p style=&quot;line-height:1.5;font-size:18px;color:#666;&quot;&gt;We are sorry for the inconvenience.&lt;br/&gt;Please try again &lt;strong&gt;in 15 minutes&lt;/strong&gt;.&lt;/p&gt;&lt;/div&gt;&#39;</span><span class="p">,</span><span class="s1">&#39;Scheduled Maintenance&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;response&#39;</span><span class="o">=&gt;</span><span class="mi">503</span><span class="p">));</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span><span id="L-7"><a name="L-7"></a><span class="nx">add_action</span><span class="p">(</span><span class="s1">&#39;get_header&#39;</span><span class="p">,</span> <span class="s1">&#39;cwc_maintenance_mode&#39;</span><span class="p">);</span> </span></pre></div> </td></tr></table>
maintenance, wordpress

Bash

Switch maintenance mode ON / OFF with Drush

1
2
3
4
5
# Switch maintenance mode OFF
drush vset maintenance_mode 0

# Switch maintenance mode ON
drush vset maintenance_mode 1
https://snipt.net/embed/af518d02dd5759e199b79f287f7f4ae3/
https://snipt.net/raw/af518d02dd5759e199b79f287f7f4ae3/
af518d02dd5759e199b79f287f7f4ae3
bash
Bash
5
2016-09-25T22:35:13
True
False
False
Jan 23, 2013 at 10:29 AM
/api/public/snipt/54309/
switch-maintenance-mode-on-off-with-drush
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c"># Switch maintenance mode OFF</span> </span><span id="L-2"><a name="L-2"></a>drush vset maintenance_mode 0 </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># Switch maintenance mode ON</span> </span><span id="L-5"><a name="L-5"></a>drush vset maintenance_mode 1 </span></pre></div> </td></tr></table>
"drupal 7", drush, maintenance, mode, off, on, switch
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.