/**
* Plugin Name: Code Blocks
* Plugin URI: http://subinsb.com/posting-code-blocks-on-wordpress
* Description: Add Code Blocks To Your posts and pages in the Visual Editor or Text Editor.
* Version: 0.3
* Author: Subin Siby
* Author URI: http://subinsb.com
* License: GPLv3
*/
function CBS_adminMenu() {
add_submenu_page('edit.php', __('Code Blocks'), __('Code Blocks'), 'manage_options', 'CBS_admin', 'CBS_optPage');
}
add_action('admin_menu', 'CBS_adminMenu');
function CBSmakeItPretty($s){
$s=str_replace('\"','"',$s);
$s=str_replace("\'",'"',$s);
return $s;
}
function CBS_optPage(){
if(isset($_POST['submit'])){
$isV=isset($_POST['visual']) ? "":"off";
update_option("CBS_InVisual",$isV);
$isTx=isset($_POST['text']) ? "":"off";
update_option("CBS_InText",$isTx);
update_option("CBS_StartCode",$_POST['before']);
update_option("CBS_EndCode",$_POST['after']);
$isPt=isset($_POST['ptag']) ? "":"off";
update_option("CBS_PTag",$isPt);
if(!file_put_contents(WP_PLUGIN_DIR. '/code-blocks/editor-style.css', $_POST['css']) && $_POST['css']!=""){
echo '
Failed To Save Custom CSS. Make Sure you have Write permission in wp-contents/plugins folder.
';
}else{
echo '';
}
}
$startCode=get_option("CBS_StartCode")=="" ? "":get_option("CBS_StartCode");
$endCode=get_option("CBS_EndCode")=="" ? "
":get_option("CBS_EndCode");
$vchecked=get_option("CBS_InVisual")=="" ? "checked='checked'":"";
$tchecked=get_option("CBS_InText")=="" ? "checked='checked'":"";
$pchecked=get_option("CBS_PTag")=="" ? "checked='checked'":"";
?>
Configure Code Blocks
Donate
I'm 14 and I need donations to create more plugins.
Please consider a donation for the improvement of this plugin and for future awesome plugins.
}
/* Visual Editor */
add_action('admin_init', 'CBS_add_button');
function CBS_add_button() {
if(current_user_can('edit_posts') && current_user_can('edit_pages') && get_user_option('rich_editing') == 'true' && get_option("CBS_InVisual")!="off"){
add_filter('mce_external_plugins', 'CBS_add_plugin');
add_filter('mce_buttons', 'CBS_register_button');
}
}
function CBS_register_button( $buttons ) {
array_push($buttons, "CBSbutton");
return $buttons;
}
function CBS_add_plugin( $plugin_array ) {
$url = plugins_url()."/code-blocks";
$startCode=get_option("CBS_StartCode")=="" ? "":get_option("CBS_StartCode");
$endCode=get_option("CBS_EndCode")=="" ? "
":get_option("CBS_EndCode");
$plugin_array["CBSbutton"] = $url.'/button.php?start='.urlencode(CBSmakeItPretty($startCode)).'&end='.urlencode(CBSmakeItPretty($endCode))."&nop=".get_option("CBS_PTag");
return $plugin_array;
}
/* HTML Text Editor */
function CBS_teButton(){
//Remove Linebreaks
$startCode=get_option("CBS_StartCode")=="" ? "":get_option("CBS_StartCode");
$endCode=get_option("CBS_EndCode")=="" ? "
":get_option("CBS_EndCode");
$right_tag = CBSmakeItPretty(str_replace("\r\n","",$endCode));
$left_tag = CBSmakeItPretty(str_replace("\r\n","",$startCode));
if(get_option("CBS_InText")!="off" && get_current_screen()->base!="" && get_current_screen()->base=="post"){
$content = '";
echo $content;
}
}
/* Text Editor functions */
function CBS_init(){
if (current_user_can('edit_posts') && current_user_can('edit_pages')) {
add_action('admin_print_footer_scripts', 'CBS_teButton');
}
}
add_action("admin_init", "CBS_init");
function CBS_custom_css($wp) {
$url = plugins_url()."/code-blocks";
$wp .= ',' . $url.'/editor-style.css';
return $wp;
}
add_filter('mce_css','CBS_custom_css');
?>
http://bigbird.0xff.com
Random blatherings of a sickish mind.
Wed, 02 Mar 2016 20:40:29 +0000
en-US
hourly
1
https://wordpress.org/?v=4.4.2
-
Git in an isolated environment
http://bigbird.0xff.com/?p=248
http://bigbird.0xff.com/?p=248#respond
Wed, 02 Mar 2016 20:37:56 +0000
http://bigbird.0xff.com/?p=248
Continue reading Git in an isolated environment →]]>
http://bigbird.0xff.com/?feed=rss2&p=248
0
-
Syslog and NetCat
http://bigbird.0xff.com/?p=240
http://bigbird.0xff.com/?p=240#respond
Wed, 22 Jul 2015 15:50:33 +0000
http://bigbird.0xff.com/?p=240
Continue reading Syslog and NetCat →]]>
http://bigbird.0xff.com/?feed=rss2&p=240
0
-
Blackberries from over the fence!
http://bigbird.0xff.com/?p=170
http://bigbird.0xff.com/?p=170#respond
Fri, 25 Jul 2014 03:20:14 +0000
http://bigbird.0xff.com/?p=170
http://bigbird.0xff.com/?feed=rss2&p=170
0
-
lil’bot
http://bigbird.0xff.com/?p=150
http://bigbird.0xff.com/?p=150#respond
Thu, 17 Jul 2014 17:22:00 +0000
http://bigbird.0xff.com/?p=150
Continue reading lil’bot →]]>
http://bigbird.0xff.com/?feed=rss2&p=150
0
-
Watermelon Salad!
http://bigbird.0xff.com/?p=137
http://bigbird.0xff.com/?p=137#respond
Wed, 16 Jul 2014 00:07:07 +0000
http://bigbird.0xff.com/?p=137
Continue reading Watermelon Salad! →]]>
http://bigbird.0xff.com/?feed=rss2&p=137
0
-
Litany against fear by Bene Gesserit
http://bigbird.0xff.com/?p=134
http://bigbird.0xff.com/?p=134#respond
Sun, 22 Jun 2014 01:05:05 +0000
http://bigbird.0xff.com/?p=134
Continue reading Litany against fear by Bene Gesserit →]]>
http://bigbird.0xff.com/?feed=rss2&p=134
0
-
Marathon world record broken!
http://bigbird.0xff.com/?p=125
http://bigbird.0xff.com/?p=125#respond
Sun, 29 Sep 2013 09:24:51 +0000
http://bigbird.0xff.com/?p=125
]]>
http://bigbird.0xff.com/?feed=rss2&p=125
0
-
Temperature Update
http://bigbird.0xff.com/?p=108
http://bigbird.0xff.com/?p=108#respond
Tue, 10 Sep 2013 20:55:26 +0000
http://bigbird.0xff.com/?p=108
Continue reading Temperature Update →]]>
http://bigbird.0xff.com/?feed=rss2&p=108
0
-
Enclosures…
http://bigbird.0xff.com/?p=103
http://bigbird.0xff.com/?p=103#comments
Sun, 11 Aug 2013 17:59:50 +0000
http://bigbird.0xff.com/?p=103
Continue reading Enclosures… →]]>
http://bigbird.0xff.com/?feed=rss2&p=103
1
-
Control those shoelaces!
http://bigbird.0xff.com/?p=99
http://bigbird.0xff.com/?p=99#respond
Fri, 28 Jun 2013 23:47:46 +0000
http://bigbird.0xff.com/?p=99
Continue reading Control those shoelaces! →]]>
http://bigbird.0xff.com/?feed=rss2&p=99
0