Skip to content

Instantly share code, notes, and snippets.

@srsgores
Created June 14, 2014 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srsgores/7e57d67782bead67c3b3 to your computer and use it in GitHub Desktop.
Save srsgores/7e57d67782bead67c3b3 to your computer and use it in GitHub Desktop.
Custom TinyMCE Wordpress Configuration
<?php
/**
* @package Mantaray Theme
* @author Sean Goresht http://seangoresht.com
* @copyright Copyright (2014) Sean Goresht
* @license http://www.gnu.org/licenses/gpl.html GNU/GPL
*/
// load config
require_once(dirname(__FILE__) . "/config.php");
/**
* Converts an integer to its textual representation.
* @param num the number to convert to a textual representation
* @param depth the number of times this has been recursed
*/
function readNumber($num, $depth = 0) {
$num = (int)$num;
$retval = "";
if ($num < 0) // if it"s any other negative, just flip it and call again
{
return "negative " + readNumber(-$num, 0);
}
if ($num > 99) // 100 and above
{
if ($num > 999) // 1000 and higher
{
$retval .= readNumber($num / 1000, $depth + 3);
}
$num %= 1000; // now we just need the last three digits
if ($num > 99) // as long as the first digit is not zero
{
$retval .= readNumber($num / 100, 2) . " hundred\n";
}
$retval .= readNumber($num % 100, 1); // our last two digits
}
else // from 0 to 99
{
$mod = floor($num / 10);
if ($mod == 0) // ones place
{
if ($num == 1) {
$retval .= "one";
}
else if ($num == 2) {
$retval .= "two";
}
else if ($num == 3) {
$retval .= "three";
}
else if ($num == 4) {
$retval .= "four";
}
else if ($num == 5) {
$retval .= "five";
}
else if ($num == 6) {
$retval .= "six";
}
else if ($num == 7) {
$retval .= "seven";
}
else if ($num == 8) {
$retval .= "eight";
}
else if ($num == 9) {
$retval .= "nine";
}
}
else if ($mod == 1) // if there"s a one in the ten"s place
{
if ($num == 10) {
$retval .= "ten";
}
else if ($num == 11) {
$retval .= "eleven";
}
else if ($num == 12) {
$retval .= "twelve";
}
else if ($num == 13) {
$retval .= "thirteen";
}
else if ($num == 14) {
$retval .= "fourteen";
}
else if ($num == 15) {
$retval .= "fifteen";
}
else if ($num == 16) {
$retval .= "sixteen";
}
else if ($num == 17) {
$retval .= "seventeen";
}
else if ($num == 18) {
$retval .= "eighteen";
}
else if ($num == 19) {
$retval .= "nineteen";
}
}
else // if there"s a different number in the ten"s place
{
if ($mod == 2) {
$retval .= "twenty ";
}
else if ($mod == 3) {
$retval .= "thirty ";
}
else if ($mod == 4) {
$retval .= "forty ";
}
else if ($mod == 5) {
$retval .= "fifty ";
}
else if ($mod == 6) {
$retval .= "sixty ";
}
else if ($mod == 7) {
$retval .= "seventy ";
}
else if ($mod == 8) {
$retval .= "eighty ";
}
else if ($mod == 9) {
$retval .= "ninety ";
}
if (($num % 10) != 0) {
$retval = rtrim($retval); //get rid of space at end
$retval .= "-";
}
$retval .= readNumber($num % 10, 0);
}
}
if ($num != 0) {
if ($depth == 3) {
$retval .= " thousand\n";
}
else if ($depth == 6) {
$retval .= " million\n";
}
if ($depth == 9) {
$retval .= " billion\n";
}
}
return $retval;
}
function beginColumn($atts) {
return "<section class = 'row'" . $atts . ">";
}
add_shortcode("columns_begin", "beginColumn");
/*for ($i = 0; $i < 12; $i ++) {
$num_representation = readNumber($i);
$function_name = "generate_" . $num_representation . "col";
add_shortcode($num_representation . "col", $function_name);
function $function_name($defaultArray, $atts)
{
return "desired output" . $atts;
}
}*/
add_shortcode("onecol", "generate_onecol");
function generate_onecol($atts, $content) {
return "<div class = 'onecol'" . $atts . ">" . $content . "</div>";
}
add_shortcode("twocol", "generate_twocol");
function generate_twocol($atts, $content) {
return "<div class = 'twocol'" . $atts . ">" . $content . "</div>";
}
add_shortcode("threecol", "generate_threecol");
function generate_threecol($atts, $content) {
return "<div class = 'threecol'" . $atts . ">" . $content . "</div>";
}
add_shortcode("fourcol", "generate_fourcol");
function generate_fivecol($atts, $content) {
return "<div class = 'fivecol'" . $atts . ">" . $content . "</div>";
}
add_shortcode("sixcol", "generate_sixcol");
function generate_sevencol($atts, $content) {
return "<div class = 'sevencol'" . $atts . ">" . $content . "</div>";
}
add_shortcode("onecol", "generate_onecol");
function generate_eightcol($atts, $content) {
return "<div class = 'eightcol'" . $atts . ">" . $content . "</div>";
}
add_shortcode("ninecol", "generate_onecol");
function generate_ninecol($atts, $content) {
return "<div class = 'ninecol'" . $atts . ">" . $content . "</div>";
}
add_shortcode("onecol", "generate_onecol");
function generate_tencol($atts, $content) {
return "<div class = 'tencol'" . $atts . ">" . $content . "</div>";
}
//add buttons to TinyMCE
function register_button($buttons) {
array_push($buttons, "|", "shortcodes");
return $buttons;
}
function add_plugin($plugin_array) {
$plugin_array["shortcodes"] = get_template_directory_uri() . "/js/shortcodes.js";
return $plugin_array;
}
function shortcodes_button() {
if (!current_user_can("edit_posts") && !current_user_can("edit_pages")) {
return;
}
if (get_user_option("rich_editing") == "true") {
add_filter("mce_external_plugins", "add_plugin");
add_filter("mce_buttons", "register_button");
}
}
add_action("init", "shortcodes_button");
// Callback function to insert "styleselect" into the $buttons array
function my_mce_buttons_2($buttons) {
array_unshift($buttons, "styleselect");
return $buttons;
}
// Register our callback to the appropriate filter
add_filter("mce_buttons_2", "my_mce_buttons_2");
function my_mce_before_init_insert_formats($init_array) {
// Define the style_formats array
$style_formats = array(
// Each array child is a format with it"s own settings
array(
"title" => "Small", "block" => "p", "classes" => "small", "wrapper" => true,
), array(
"title" => "Large", "block" => "p", "classes" => "large", "wrapper" => true,
), array(
"title" => "Medium", "block" => "p", "classes" => "medium", "wrapper" => true,
), array(
"title" => "Hidden only on Phones", "classes" => "hidden-phone", "block" => "div", "wrapper" => false,
), array(
"title" => "Centred", "classes" => "centred", "block" => "div", "wrapper" => false,
), array(
"title" => "Inline-block element", "classes" => "inline", "block" => "div", "wrapper" => false,
), array(
"title" => "Visually Hidden Element", "classes" => "visuallyhidden", "block" => "div", "wrapper" => false,
), array(
"title" => "Absolutely-Positioned Element", "classes" => "absolute", "block" => "div", "wrapper" => false,
),
array(
"title" => "Title Element", "classes" => "title", "selector" => "h1,h2,h3,h4,h5,h6,p,span",
"wrapper" => false,
), array(
"title" => "Float Left", "classes" => "pull-left", "block" => "div", "wrapper" => false,
),
array(
"title" => "Float Right", "classes" => "pull-right", "block" => "div", "wrapper" => false,
), array(
"title" => "Centred", "classes" => "centred", "block" => "div", "wrapper" => false,
)
);
// Insert the array, JSON ENCODED, into "style_formats"
$init_array["style_formats"] = json_encode($style_formats);
return $init_array;
}
// Attach callback to "tiny_mce_before_init"
add_filter("tiny_mce_before_init", "my_mce_before_init_insert_formats");
//add styles to editor
function my_theme_add_editor_styles() {
add_editor_style("css/style.css");
}
function add_thumbnail_support() { //for custom gallery plugin
if (function_exists("add_theme_support")) {
add_theme_support("post-thumbnails");
}
add_image_size("admin-list-thumb", 80, 80, true); //admin thumbnail
}
add_thumbnail_support();
add_action("init", "my_theme_add_editor_styles");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment