Add editor dropdown button for shortcodes
This commit is contained in:
@@ -72,4 +72,30 @@
|
||||
font-family: sportspress, dashicons !important;
|
||||
width: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.wp-media-buttons .add_sportspress span.wp-media-buttons-icon:before {
|
||||
font: normal 20px/1 sportspress, dashicons;
|
||||
speak: none;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
content: '\f111';
|
||||
}
|
||||
|
||||
i.mce-i-sp_shortcodes_button:before, span.mce_sp_shortcodes_button:before {
|
||||
font-family: 'sportspress';
|
||||
speak: none;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-variant: normal;
|
||||
text-transform: none;
|
||||
line-height: 1;
|
||||
|
||||
/* Better Font Rendering =========== */
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
|
||||
text-align: center;
|
||||
content: "\f111";
|
||||
font-size: 20px;
|
||||
}
|
||||
17
assets/js/admin/editor-lang.php
Normal file
17
assets/js/admin/editor-lang.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
$strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{
|
||||
sportspress:{
|
||||
insert: "' . esc_js( __( 'SportsPress shortcodes', 'sportspress' ) ) . '",
|
||||
countdown: "' . esc_js( __( 'Countdown', 'sportspress' ) ) . '",
|
||||
event_details: "' . esc_js( __( 'Event Details', 'sportspress' ) ) . '",
|
||||
event_results: "' . esc_js( __( 'Event Results', 'sportspress' ) ) . '",
|
||||
event_performance: "' . esc_js( __( 'Event Performance', 'sportspress' ) ) . '",
|
||||
event_calendar: "' . esc_js( __( 'Event Calendar', 'sportspress' ) ) . '",
|
||||
event_list: "' . esc_js( __( 'Event List', 'sportspress' ) ) . '",
|
||||
event_blocks: "' . esc_js( __( 'Event Blocks', 'sportspress' ) ) . '",
|
||||
league_table: "' . esc_js( __( 'League Table', 'sportspress' ) ) . '",
|
||||
player_list: "' . esc_js( __( 'Player List', 'sportspress' ) ) . '",
|
||||
player_gallery: "' . esc_js( __( 'Player Gallery', 'sportspress' ) ) . '"
|
||||
}
|
||||
}})';
|
||||
74
assets/js/admin/editor.js
Normal file
74
assets/js/admin/editor.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/* global tinymce */
|
||||
( function () {
|
||||
tinymce.PluginManager.add( 'sp_shortcodes_button', function( editor, url ) {
|
||||
var ed = tinymce.activeEditor;
|
||||
editor.addButton( 'sp_shortcodes_button', {
|
||||
title: ed.getLang('sportspress.insert'),
|
||||
text: false,
|
||||
icon: false,
|
||||
type: 'menubutton',
|
||||
menu: [
|
||||
{
|
||||
text: ed.getLang( 'sportspress.countdown' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[countdown id="" live=""]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.event_details' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[event_details id=""]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.event_results' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[event_results id=""]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.event_performance' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[event_performance id=""]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.event_calendar' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[event_calendar id="" status="default" show_all_events_link="0"]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.event_list' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[event_list id="" status="default" show_all_events_link="0"]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.event_blocks' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[event_blocks id="" status="default" show_all_events_link="0"]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.league_table' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[league_table id="" number="-1" show_team_logo="1" link_posts="0" show_full_table_link="0"]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.player_list' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[player_list id="" number="-1" orderby="default" order="ASC" show_all_players_link="0"]' );
|
||||
}
|
||||
},
|
||||
{
|
||||
text: ed.getLang( 'sportspress.player_gallery' ),
|
||||
onclick: function() {
|
||||
editor.insertContent( '[event_blocks id="" number="-1" columns="3" orderby="default" order="ASC" size="thumbnail" show_all_players_link="0"]' );
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
})();
|
||||
@@ -366,5 +366,4 @@ jQuery(document).ready(function($){
|
||||
$this.find('strong').html(event.strftime("%D "+localized_strings.days+" %H:%M:%S"));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -97,9 +97,20 @@ class SP_Admin_Assets {
|
||||
|
||||
wp_register_script( 'sportspress-admin-widgets', SP()->plugin_url() . '/assets/js/admin/widgets.js', array( 'jquery' ), SP_VERSION, true );
|
||||
|
||||
$strings = array(
|
||||
'none' => __( 'None', 'sportspress' ),
|
||||
'remove_text' => __( '— Remove —', 'sportspress' ),
|
||||
'days' => __( 'days', 'sportspress' ),
|
||||
'hrs' => __( 'hrs', 'sportspress' ),
|
||||
'mins' => __( 'mins', 'sportspress' ),
|
||||
'secs' => __( 'secs', 'sportspress' )
|
||||
);
|
||||
|
||||
// Localize scripts
|
||||
wp_localize_script( 'sportspress-admin', 'localized_strings', $strings );
|
||||
|
||||
// SportsPress admin pages
|
||||
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
wp_enqueue_script( 'chosen' );
|
||||
wp_enqueue_script( 'jquery-ui-core' );
|
||||
@@ -110,18 +121,6 @@ class SP_Admin_Assets {
|
||||
wp_enqueue_script( 'jquery-caret' );
|
||||
wp_enqueue_script( 'jquery-countdown' );
|
||||
wp_enqueue_script( 'sportspress-admin' );
|
||||
|
||||
$params = array(
|
||||
'none' => __( 'None', 'sportspress' ),
|
||||
'remove_text' => __( '— Remove —', 'sportspress' ),
|
||||
'days' => __( 'days', 'sportspress' ),
|
||||
'hrs' => __( 'hrs', 'sportspress' ),
|
||||
'mins' => __( 'mins', 'sportspress' ),
|
||||
'secs' => __( 'secs', 'sportspress' )
|
||||
);
|
||||
|
||||
// Localize scripts
|
||||
wp_localize_script( 'sportspress-admin', 'localized_strings', $params );
|
||||
}
|
||||
|
||||
if ( in_array( $screen->id, array( 'widgets' ) ) ) {
|
||||
|
||||
93
includes/admin/class-sp-admin-editor.php
Normal file
93
includes/admin/class-sp-admin-editor.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin Editor
|
||||
*
|
||||
* Methods which tweak the WP Editor.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 2.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* SP_Admin_Editor class.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class SP_Admin_Editor {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_head', array( $this, 'add_shortcode_button' ) );
|
||||
add_filter( 'tiny_mce_version', array( $this, 'refresh_mce' ) );
|
||||
add_filter( 'mce_external_languages', array( $this, 'add_tinymce_lang' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a button for shortcodes to the WP editor.
|
||||
*/
|
||||
public function add_shortcode_button() {
|
||||
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'true' == get_user_option( 'rich_editing' ) ) {
|
||||
add_filter( 'mce_external_plugins', array( $this, 'add_shortcode_tinymce_plugin' ) );
|
||||
add_filter( 'mce_buttons', array( $this, 'register_shortcode_button' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_tinymce_lang function.
|
||||
*
|
||||
* @param array $arr
|
||||
* @return array
|
||||
*/
|
||||
public function add_tinymce_lang( $arr ) {
|
||||
$arr['sp_shortcodes_button'] = SP()->plugin_path() . '/assets/js/admin/editor-lang.php';
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the shortcode button.
|
||||
*
|
||||
* @param array $buttons
|
||||
* @return array
|
||||
*/
|
||||
public function register_shortcode_button( $buttons ) {
|
||||
array_push( $buttons, '|', 'sp_shortcodes_button' );
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the shortcode button to TinyMCE
|
||||
*
|
||||
* @param array $plugin_array
|
||||
* @return array
|
||||
*/
|
||||
public function add_shortcode_tinymce_plugin( $plugin_array ) {
|
||||
$plugin_array['sp_shortcodes_button'] = SP()->plugin_url() . '/assets/js/admin/editor.js';
|
||||
return $plugin_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force TinyMCE to refresh.
|
||||
*
|
||||
* @param int $ver
|
||||
* @return int
|
||||
*/
|
||||
public function refresh_mce( $ver ) {
|
||||
$ver += 3;
|
||||
return $ver;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new SP_Admin_Editor();
|
||||
@@ -42,7 +42,7 @@ class SP_Admin {
|
||||
include( 'class-sp-admin-notices.php' );
|
||||
include( 'class-sp-admin-assets.php' );
|
||||
include( 'class-sp-admin-permalink-settings.php' );
|
||||
// include( 'class-sp-admin-editor.php' );
|
||||
include( 'class-sp-admin-editor.php' );
|
||||
|
||||
// Help
|
||||
// if ( apply_filters( 'sportspress_enable_admin_help_tab', true ) )
|
||||
|
||||
Reference in New Issue
Block a user