Last active
August 29, 2015 14:20
-
-
Save danielpataki/d240ae31c7db17db7e30 to your computer and use it in GitHub Desktop.
Showing code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<strong>bold text</bold> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre class="line-numbers"><code class='language-php'>add_action( 'admin_notices', 'show_mot_text' ); | |
function show_mot_text() { | |
$text = get_motivation_text(); | |
echo "<p id='wp-admin-motivation'>$text</p>"; | |
}</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To add the motivation text to the top area, simply hook a function into admin_notices, like so: | |
<pre>add_action( 'admin_notices', 'show_mot_text' ); | |
function show_mot_text() { | |
$text = get_motivation_text(); | |
echo "<p id='wp-admin-motivation'>$text</p>"; | |
}</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: Smart Code Escape | |
* Plugin URI: https://github.com/danielpataki/Smart-Code-Escape | |
* Description: Converts less than, greater than and ampersand characters to their HTML | |
entities within pre tags before they are output on the page. You will always see the | |
non-escaped version in the editor, making code easy to modify. It Will not convert code | |
tags directly within pre tags to support Prism-style highlighting. | |
* Version: 1.1 | |
* Author: Daniel Pataki | |
* Author URI: http://danielpataki.com | |
* License: GPL v2 | |
* Licence URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
*/ | |
function smart_code_escape_pre( $data ) { | |
preg_match('@(<code.*>)(.*)(<\/code>)@isU', $data[2], $matches ); | |
if( !empty( $matches ) ) { | |
return $data[1] . $matches[1] . str_replace( array( '&', '<', '>' ), array( '&', '<', '>' ), $matches[2] ) . $matches[3] . $data[3]; | |
} | |
else { | |
return $data[1] . str_replace( array( '&', '<', '>' ), array( '&', '<', '>' ), $data[2] ) . $data[3]; | |
} | |
} | |
add_filter( 'the_content', 'smart_code_escape_content', 9 ); | |
function smart_code_escape_content( $content ) { | |
$content = preg_replace_callback('@(<pre.*>)(.*)(<\/pre>)@isU', 'smart_code_escape_pre', $content ); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment