TinyMCE Templates - Version 4.3.2

Version Description

  • Fix closing modal window problem.
  • Set same width with preview and content_width.
  • Update js modal potision absolute to fixed.
Download this release

Release Info

Developer miyauchi
Plugin Icon 128x128 TinyMCE Templates
Version 4.3.2
Comparing to
See all releases

Code changes from version 4.3.1 to 4.3.2

editor-style.css → css/editor-style.css RENAMED
File without changes
css/tinymce-templates.css CHANGED
@@ -12,16 +12,16 @@
12
  }
13
  #tinymce-templates-wrap {
14
  display: none;
15
- position: absolute;
16
- width: 100%;
17
  z-index: 999999;
 
 
 
 
18
  }
19
  #tinymce-templates-wrap .modal {
20
- width: 90%;
21
- max-width: 800px;
22
- background-color: #ffffff;
23
- margin: 0 auto;
24
- box-sizing: border-box;
25
  }
26
  #tinymce-templates-wrap .modal .header {
27
  background-color: #f5f5f5;
@@ -42,6 +42,7 @@
42
  }
43
  #tinymce-templates-wrap .modal .container {
44
  padding: 10px 20px;
 
45
  }
46
  #tinymce-templates-wrap .modal .footer {
47
  padding: 20px;
@@ -50,6 +51,7 @@
50
  overflow: auto;
51
  }
52
  #tinymce-templates-wrap #tinymce-templates-preview {
 
53
  border: none;
54
  margin: 10px 0;
55
  padding: 0;
12
  }
13
  #tinymce-templates-wrap {
14
  display: none;
15
+ position: fixed;
16
+ width: 90%;
17
  z-index: 999999;
18
+ background-color: #ffffff;
19
+ margin: auto;
20
+ left: 0px;
21
+ right: 0px;
22
  }
23
  #tinymce-templates-wrap .modal {
24
+ width: 100%;
 
 
 
 
25
  }
26
  #tinymce-templates-wrap .modal .header {
27
  background-color: #f5f5f5;
42
  }
43
  #tinymce-templates-wrap .modal .container {
44
  padding: 10px 20px;
45
+ margin: 0 auto;
46
  }
47
  #tinymce-templates-wrap .modal .footer {
48
  padding: 20px;
51
  overflow: auto;
52
  }
53
  #tinymce-templates-wrap #tinymce-templates-preview {
54
+ display: block;
55
  border: none;
56
  margin: 10px 0;
57
  padding: 0;
css/tinymce-templates.less CHANGED
@@ -15,17 +15,17 @@
15
  #tinymce-templates-wrap
16
  {
17
  display: none;
18
- position: absolute;
19
- width: 100%;
20
  z-index: 999999;
 
 
 
 
21
 
22
  .modal
23
  {
24
- width: 90%;
25
- max-width: 800px;
26
- background-color: #ffffff;
27
- margin: 0 auto;
28
- box-sizing: border-box;
29
 
30
  .header
31
  {
@@ -53,6 +53,7 @@
53
  .container
54
  {
55
  padding: 10px 20px;
 
56
  }
57
 
58
  .footer
@@ -66,6 +67,7 @@
66
 
67
  #tinymce-templates-preview
68
  {
 
69
  border: none;
70
  margin: 10px 0;
71
  padding: 0;
15
  #tinymce-templates-wrap
16
  {
17
  display: none;
18
+ position: fixed;
19
+ width: 90%;
20
  z-index: 999999;
21
+ background-color: #ffffff;
22
+ margin: auto;
23
+ left: 0px;
24
+ right: 0px;
25
 
26
  .modal
27
  {
28
+ width: 100%;
 
 
 
 
29
 
30
  .header
31
  {
53
  .container
54
  {
55
  padding: 10px 20px;
56
+ margin: 0 auto;
57
  }
58
 
59
  .footer
67
 
68
  #tinymce-templates-preview
69
  {
70
+ display: block;
71
  border: none;
72
  margin: 10px 0;
73
  padding: 0;
js/tinymce-templates.js CHANGED
@@ -40,6 +40,13 @@ var tinymceTemplates;
40
  $('#tinymce-templates-list').bind('change', function(){
41
  tinymceTemplates.set_content();
42
  });
 
 
 
 
 
 
 
43
  },
44
 
45
  insert: function()
@@ -58,7 +65,7 @@ var tinymceTemplates;
58
  for (var i=0; i<tags.length; i++) {
59
  var tag = tags[i].match(/[a-zA-Z0-9_]+/);
60
  if ('content' === tag[0]) {
61
- is_content = 'Hello World![/template]';
62
  continue;
63
  }
64
  args.push(tag[0] + '=""');
@@ -103,6 +110,10 @@ var tinymceTemplates;
103
  {
104
  $('#tinymce-templates-insert').attr('disabled', true);
105
 
 
 
 
 
106
  tinymceTemplates.template_id = $('#tinymce-templates-list').val();
107
 
108
  // I don't like reference here!!
@@ -120,13 +131,14 @@ var tinymceTemplates;
120
  var styles = content_css.replace(/(\s+)/g, "").split(',');
121
 
122
  var html = '<!DOCTYPE html><html><head>';
 
123
  for (var i=0; i<styles.length; i++) {
124
  var link = $('<link rel="stylesheet" type="text/css" media="all" />');
125
  link.attr('href', styles[i]);
126
  html += $('<div />').html(link).html(); // getting innerHTML
127
  }
128
  html += '</head><body class="mceContentBody">';
129
- html += data.content;
130
  html += '</body></html>';
131
 
132
  var iframe = document.getElementById('tinymce-templates-preview');
@@ -179,10 +191,10 @@ var tinymceTemplates;
179
  $('#tinymce-templates-preview').css('height', windowHeight * 0.5);
180
 
181
  var height = $('#tinymce-templates-wrap').height();
182
-
183
  var top = (windowHeight / 2) - (height / 2) - ($('#wpadminbar').height() / 2);
184
- if (top < (0 - $('#wpadminbar').height() + 8)) {
185
- top = (0 - $('#wpadminbar').height() + 8);
 
186
  } else if (top > 100) {
187
  top = 100;
188
  }
40
  $('#tinymce-templates-list').bind('change', function(){
41
  tinymceTemplates.set_content();
42
  });
43
+
44
+ $(window).keyup(function(e){
45
+ if(e.keyCode == 27){
46
+ e.preventDefault();
47
+ tinymceTemplates.close();
48
+ }
49
+ });
50
  },
51
 
52
  insert: function()
65
  for (var i=0; i<tags.length; i++) {
66
  var tag = tags[i].match(/[a-zA-Z0-9_]+/);
67
  if ('content' === tag[0]) {
68
+ is_content = '</p><p>[/template]';
69
  continue;
70
  }
71
  args.push(tag[0] + '=""');
110
  {
111
  $('#tinymce-templates-insert').attr('disabled', true);
112
 
113
+ if (!$('#tinymce-templates-list').val()) {
114
+ return;
115
+ }
116
+
117
  tinymceTemplates.template_id = $('#tinymce-templates-list').val();
118
 
119
  // I don't like reference here!!
131
  var styles = content_css.replace(/(\s+)/g, "").split(',');
132
 
133
  var html = '<!DOCTYPE html><html><head>';
134
+ html += '<style>body{ padding: 0 !important; margin: 20px !important; }</style>';
135
  for (var i=0; i<styles.length; i++) {
136
  var link = $('<link rel="stylesheet" type="text/css" media="all" />');
137
  link.attr('href', styles[i]);
138
  html += $('<div />').html(link).html(); // getting innerHTML
139
  }
140
  html += '</head><body class="mceContentBody">';
141
+ html += data.preview;
142
  html += '</body></html>';
143
 
144
  var iframe = document.getElementById('tinymce-templates-preview');
191
  $('#tinymce-templates-preview').css('height', windowHeight * 0.5);
192
 
193
  var height = $('#tinymce-templates-wrap').height();
 
194
  var top = (windowHeight / 2) - (height / 2) - ($('#wpadminbar').height() / 2);
195
+
196
+ if (top < 16) {
197
+ top = 16;
198
  } else if (top > 100) {
199
  top = 100;
200
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: miyauchi
3
  Tags: tinymce, Visual Editor, template
4
  Requires at least: 4.0
5
  Tested up to: 4.1
6
- Stable tag: 4.3.1
7
 
8
  TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
9
 
@@ -11,7 +11,7 @@ TinyMCE Template plugin will enable to use HTML template on WordPress Visual Edi
11
 
12
  TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
13
 
14
- * [Support Site](http://miya0001.github.io/tinymce-templates/)
15
  * [GitHub](https://github.com/miya0001/tinymce-templates)
16
 
17
  = Some features: =
@@ -55,6 +55,12 @@ You can send your own language pack to me.
55
 
56
  == Changelog ==
57
 
 
 
 
 
 
 
58
  = 4.3.1 =
59
 
60
  * Bug fix on quick tags view.
3
  Tags: tinymce, Visual Editor, template
4
  Requires at least: 4.0
5
  Tested up to: 4.1
6
+ Stable tag: 4.3.2
7
 
8
  TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
9
 
11
 
12
  TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
13
 
14
+ * [Website](http://miya0001.github.io/tinymce-templates/)
15
  * [GitHub](https://github.com/miya0001/tinymce-templates)
16
 
17
  = Some features: =
55
 
56
  == Changelog ==
57
 
58
+ = 4.3.2 =
59
+
60
+ * Fix closing modal window problem.
61
+ * Set same width with preview and content_width.
62
+ * Update js modal potision absolute to fixed.
63
+
64
  = 4.3.1 =
65
 
66
  * Bug fix on quick tags view.
tinymce-templates.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: TinyMCE Templates
4
  Plugin URI: http://miya0001.github.io/tinymce-templates/
5
  Description: TinyMCE Templates plugin will enable to use HTML template on WordPress Visual Editor.
6
  Author: Takayuki Miyauchi
7
- Version: 4.3.1
8
  Author URI: http://miya0001.github.io/tinymce-templates/
9
  Domain Path: /languages
10
  Text Domain: tinymce_templates
@@ -35,9 +35,9 @@ THE SOFTWARE.
35
  $tinymce_templates = new TinyMCE_Templates();
36
  $tinymce_templates->register();
37
 
38
- class TinyMCE_Templates {
39
-
40
- private $post_type = 'tinymcetemplates';
41
  private $base_url;
42
  private $translators = array(
43
  'Takayuki Miyauchi' => array(
@@ -120,12 +120,13 @@ class TinyMCE_Templates {
120
 
121
  add_filter( 'post_row_actions', array( $this, 'row_actions' ), 10, 2 );
122
  add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
123
- add_filter( 'wp_mce_translation', array( $this, 'wp_mce_translation' ) );
124
- add_filter( 'tinymce_templates_content', array( $this, 'tinymce_templates_content' ) );
125
 
126
- add_action( 'admin_head', array( $this, 'admin_head' ) );
 
 
127
  add_action( 'admin_footer-post-new.php', array( $this, 'admin_footer' ) );
128
  add_action( 'admin_footer-post.php', array( $this, 'admin_footer' ) );
 
129
  add_action( 'wp_ajax_tinymce_templates', array( $this, 'wp_ajax_tinymce_templates' ) );
130
  add_action( 'post_submitbox_start', array( $this, 'post_submitbox_start' ) );
131
  add_action( 'wp_before_admin_bar_render', array( $this, 'wp_before_admin_bar_render' ) );
@@ -133,9 +134,35 @@ class TinyMCE_Templates {
133
  add_action( 'media_buttons', array( $this, 'media_buttons' ), 11 );
134
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  add_shortcode( 'template', array( $this, 'template_shortcode' ) );
137
  }
138
 
 
 
 
 
 
 
139
  public function admin_enqueue_scripts( $hook_suffix )
140
  {
141
  if ( 'post-new.php' === $hook_suffix || 'post.php' === $hook_suffix ) {
@@ -156,13 +183,26 @@ class TinyMCE_Templates {
156
  }
157
  }
158
 
 
 
 
 
 
 
159
  public function media_buttons( $editor_id = 'content' )
160
  {
161
  if ( 'content' === $editor_id ) {
 
 
 
162
  printf(
163
- '<a id="button-tinymce-templates" class="button" href="#" data-editor="%s" title="%s">%s</a>',
 
 
164
  esc_attr( $editor_id ),
165
  esc_attr( __( 'Insert Template', 'tinymce_templates' ) ),
 
 
166
  esc_html( __( 'Insert Template', 'tinymce_templates' ) )
167
  );
168
  }
@@ -187,25 +227,16 @@ class TinyMCE_Templates {
187
 
188
  $post = get_post( $p['id'] );
189
 
190
- if ( $post && get_post_meta( $p['id'], 'insert_as_shortcode', true ) ) {
191
- $post_content = $post->post_content;
 
 
192
  }
193
  }
194
 
195
  return apply_filters( 'tinymce_templates_content', $post_content, $p, $content );
196
  }
197
 
198
- /**
199
- * Filters tinymce_templates_content.
200
- *
201
- * @param string $template Template contents.
202
- * @return string Template contents.
203
- */
204
- public function tinymce_templates_content( $template )
205
- {
206
- return wpautop( $template );
207
- }
208
-
209
  /**
210
  * Fires on wp_before_admin_bar_render hook.
211
  *
@@ -227,22 +258,6 @@ class TinyMCE_Templates {
227
  }
228
  }
229
 
230
- /**
231
- * Translates tinymce plugin.
232
- *
233
- * @param array $mce_translation Translates of the tinymce.
234
- * @return array Translates of the tinymce templates plugin.
235
- */
236
- public function wp_mce_translation( $mce_translation )
237
- {
238
- $mce_translation['Insert template'] = __( 'Insert template', 'tinymce_templates' );
239
- $mce_translation['Templates'] = __( 'Templates', 'tinymce_templates' );
240
- $mce_translation['No templates defined'] = __( 'No templates defined', 'tinymce_templates' );
241
- $mce_translation['Note: The template will be inserted as shortcode.'] = __( 'Note: The template will be inserted as shortcode.', 'tinymce_templates' );
242
-
243
- return $mce_translation;
244
- }
245
-
246
  /**
247
  * Filters the pages/posts list menu in admin.
248
  *
@@ -279,56 +294,41 @@ class TinyMCE_Templates {
279
  }
280
 
281
  /**
282
- * Fires on admin_head hook.
283
  *
284
  * @param none
285
  * @return none
286
  */
287
  public function admin_head()
288
  {
289
- // /**
290
- // * Load and setup tinymce plugin.
291
- // */
292
- // $url = admin_url( 'admin-ajax.php' );
293
- // $nonce = wp_create_nonce( 'tinymce_templates' );
294
- //
295
- // $args = array(
296
- // 'action' => 'tinymce_templates',
297
- // 'nonce' => $nonce,
298
- // );
299
- //
300
- // $url = add_query_arg( $args, $url );
301
- //
302
- // $inits['templates'] = $url;
303
- //
304
- // require_once( dirname( __FILE__ ) . '/includes/mceplugins.class.php' );
305
- //
306
- // new tinymcePlugins(
307
- // 'template',
308
- // $this->base_url.'/mce_plugins/4.0/plugins/template/plugin.js',
309
- // false,
310
- // $inits
311
- // );
312
-
313
  /**
314
  * Hide some stuff in the templates editor panel.
315
  */
316
- global $hook_suffix;
317
- if ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) {
318
- if ( get_post_type() === $this->post_type ) {
319
- remove_meta_box( 'slugdiv', $this->post_type, 'normal' );
320
- echo '<style>#visibility{display:none;} #message a{display: none;}</style>';
321
- } else {
322
- echo '<style>#button-tinymce-templates:before{content: "\f464"; font: 400 18px/1 dashicons; top:3px; margin-right: 3px; position: relative;}</style>';
323
- }
 
 
324
  }
325
 
326
- /**
327
- * Add editor style to the editor.
328
- */
329
- $ver = filemtime( dirname( __FILE__ ) . '/editor-style.css' );
330
- $editor_style = plugins_url( 'editor-style.css?ver=' . $ver, __FILE__ );
331
- add_editor_style( $editor_style );
 
 
 
 
 
 
 
332
  }
333
 
334
  /**
@@ -412,6 +412,7 @@ class TinyMCE_Templates {
412
  public function insert_as_shortcode_meta_box( $post, $box )
413
  {
414
  $res = get_post_meta( $post->ID, 'insert_as_shortcode', true );
 
415
  if ( $res ) {
416
  echo '<label><input type="radio" name="is_shortcode" value="1" checked> '.__( 'Yes' ).'</label><br />';
417
  echo '<label><input type="radio" name="is_shortcode" value="0"> '.__( 'No' ).'</label>';
@@ -554,12 +555,20 @@ class TinyMCE_Templates {
554
  {
555
  nocache_headers();
556
 
557
- if ( ! wp_verify_nonce( $_GET['nonce'], 'tinymce_templates' ) ) {
558
  return;
559
  }
560
 
561
  header( 'Content-Type: application/javascript; charset=UTF-8' );
562
 
 
 
 
 
 
 
 
 
563
  $p = array(
564
  'post_status' => 'publish',
565
  'post_type' => $this->post_type,
@@ -570,39 +579,42 @@ class TinyMCE_Templates {
570
 
571
  $posts = get_posts( $p );
572
 
573
- $arr = array();
574
 
575
  foreach ( $posts as $p ) {
576
  $ID = intval( $p->ID );
577
  $name = esc_html( apply_filters( 'tinymce_template_title', $p->post_title ) );
578
  $desc = esc_html( apply_filters( 'tinymce_template_excerpt', $p->post_excerpt ) );
579
- $arr[ $ID ] = array(
580
  'title' => $name,
581
  'is_shortcode' => get_post_meta( $ID, 'insert_as_shortcode', true ),
582
- 'content' => wpautop( $p->post_content ),
583
  );
584
  }
585
 
586
- $arr = apply_filters( 'tinymce_templates_post_objects', $arr );
587
 
588
  if ( isset( $_GET['template_id'] ) && $_GET['template_id'] ) {
589
- if ( isset( $arr[ $_GET['template_id'] ] ) && $arr[ $_GET['template_id'] ] ) {
590
- $p = $arr[ $_GET['template_id'] ];
591
  $content = apply_filters(
592
  'tinymce_templates',
593
  $p['content'],
594
  $p['content']
595
  );
596
- echo json_encode( array(
597
- 'content' => $content,
598
- 'is_shortcode' => $p['is_shortcode']
599
- ) );
 
 
 
 
 
600
  }
601
- exit;
602
  }
603
 
604
- echo json_encode( $arr );
605
- exit;
606
  }
607
 
608
  /**
4
  Plugin URI: http://miya0001.github.io/tinymce-templates/
5
  Description: TinyMCE Templates plugin will enable to use HTML template on WordPress Visual Editor.
6
  Author: Takayuki Miyauchi
7
+ Version: 4.3.2
8
  Author URI: http://miya0001.github.io/tinymce-templates/
9
  Domain Path: /languages
10
  Text Domain: tinymce_templates
35
  $tinymce_templates = new TinyMCE_Templates();
36
  $tinymce_templates->register();
37
 
38
+ class TinyMCE_Templates
39
+ {
40
+ private $post_type = 'tinymcetemplates';
41
  private $base_url;
42
  private $translators = array(
43
  'Takayuki Miyauchi' => array(
120
 
121
  add_filter( 'post_row_actions', array( $this, 'row_actions' ), 10, 2 );
122
  add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
 
 
123
 
124
+ add_action( 'admin_head-post-new.php', array( $this, 'admin_head' ) );
125
+ add_action( 'admin_head-post.php', array( $this, 'admin_head' ) );
126
+
127
  add_action( 'admin_footer-post-new.php', array( $this, 'admin_footer' ) );
128
  add_action( 'admin_footer-post.php', array( $this, 'admin_footer' ) );
129
+
130
  add_action( 'wp_ajax_tinymce_templates', array( $this, 'wp_ajax_tinymce_templates' ) );
131
  add_action( 'post_submitbox_start', array( $this, 'post_submitbox_start' ) );
132
  add_action( 'wp_before_admin_bar_render', array( $this, 'wp_before_admin_bar_render' ) );
134
  add_action( 'media_buttons', array( $this, 'media_buttons' ), 11 );
135
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
136
 
137
+ add_filter( 'tinymce_templates_content', 'wptexturize' );
138
+ add_filter( 'tinymce_templates_content', 'convert_smilies' );
139
+ add_filter( 'tinymce_templates_content', 'convert_chars' );
140
+ add_filter( 'tinymce_templates_content', 'wpautop' );
141
+ add_filter( 'tinymce_templates_content', 'shortcode_unautop' );
142
+ add_filter( 'tinymce_templates_content', 'prepend_attachment' );
143
+ add_filter( 'tinymce_templates_content', 'do_shortcode', 11 );
144
+ add_filter( 'tinymce_templates_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
145
+ add_filter( 'tinymce_templates_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
146
+
147
+ add_filter( 'tinymce_templates_preview', 'wptexturize' );
148
+ add_filter( 'tinymce_templates_preview', 'convert_smilies' );
149
+ add_filter( 'tinymce_templates_preview', 'convert_chars' );
150
+ add_filter( 'tinymce_templates_preview', 'wpautop' );
151
+ add_filter( 'tinymce_templates_preview', 'shortcode_unautop' );
152
+ add_filter( 'tinymce_templates_preview', 'prepend_attachment' );
153
+ add_filter( 'tinymce_templates_preview', 'do_shortcode', 11 );
154
+ // add_filter( 'tinymce_templates_preview', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
155
+ // add_filter( 'tinymce_templates_preview', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
156
+
157
  add_shortcode( 'template', array( $this, 'template_shortcode' ) );
158
  }
159
 
160
+ /**
161
+ * Fires on admin_enqueue_scripts hook
162
+ *
163
+ * @param none
164
+ * @return none
165
+ */
166
  public function admin_enqueue_scripts( $hook_suffix )
167
  {
168
  if ( 'post-new.php' === $hook_suffix || 'post.php' === $hook_suffix ) {
183
  }
184
  }
185
 
186
+ /**
187
+ * Fires on media_buttons hook
188
+ *
189
+ * @param none
190
+ * @return none
191
+ */
192
  public function media_buttons( $editor_id = 'content' )
193
  {
194
  if ( 'content' === $editor_id ) {
195
+ $button_html = '<a id="%s" class="%s" href="#" data-editor="%s" title="%s">';
196
+ $button_html .= '<span class="%s" style="%s"></span> %s';
197
+ $button_html .= '</a>';
198
  printf(
199
+ $button_html,
200
+ 'button-tinymce-templates',
201
+ 'button',
202
  esc_attr( $editor_id ),
203
  esc_attr( __( 'Insert Template', 'tinymce_templates' ) ),
204
+ 'dashicons dashicons-edit',
205
+ 'margin-top: 3px;',
206
  esc_html( __( 'Insert Template', 'tinymce_templates' ) )
207
  );
208
  }
227
 
228
  $post = get_post( $p['id'] );
229
 
230
+ if ( is_a( $post, 'WP_Post' ) ) {
231
+ if ( get_post_meta( $p['id'], 'insert_as_shortcode', true ) ) {
232
+ $post_content = $post->post_content;
233
+ }
234
  }
235
  }
236
 
237
  return apply_filters( 'tinymce_templates_content', $post_content, $p, $content );
238
  }
239
 
 
 
 
 
 
 
 
 
 
 
 
240
  /**
241
  * Fires on wp_before_admin_bar_render hook.
242
  *
258
  }
259
  }
260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  /**
262
  * Filters the pages/posts list menu in admin.
263
  *
294
  }
295
 
296
  /**
297
+ * Fires on admin_head-post.php or admin_head-post-new.php hook.
298
  *
299
  * @param none
300
  * @return none
301
  */
302
  public function admin_head()
303
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  /**
305
  * Hide some stuff in the templates editor panel.
306
  */
307
+ if ( get_post_type() === $this->post_type ) {
308
+ remove_meta_box( 'slugdiv', $this->post_type, 'normal' );
309
+ echo '<style>#visibility{display:none;} #message a{display: none;}</style>';
310
+
311
+ /**
312
+ * Add editor style to the editor.
313
+ */
314
+ $ver = filemtime( dirname( __FILE__ ) . '/css/editor-style.css' );
315
+ $editor_style = plugins_url( 'css/editor-style.css?ver=' . $ver, __FILE__ );
316
+ add_editor_style( $editor_style );
317
  }
318
 
319
+ global $content_width;
320
+
321
+ if ( isset( $content_width ) && intval( $content_width ) ) {
322
+ /**
323
+ * I want to set same width to preview with $content_width
324
+ */
325
+ echo '<style type="text/css">';
326
+ $preview_width = $content_width + 40; // should be same with padding * 2
327
+ echo '#tinymce-templates-preview{ max-width: '.$preview_width.'px; }';
328
+ $wrap_width = $content_width + 80; // should be same with padding * 4
329
+ echo '#tinymce-templates-wrap{ max-width: '.$wrap_width.'px; }';
330
+ echo '</style>';
331
+ }
332
  }
333
 
334
  /**
412
  public function insert_as_shortcode_meta_box( $post, $box )
413
  {
414
  $res = get_post_meta( $post->ID, 'insert_as_shortcode', true );
415
+
416
  if ( $res ) {
417
  echo '<label><input type="radio" name="is_shortcode" value="1" checked> '.__( 'Yes' ).'</label><br />';
418
  echo '<label><input type="radio" name="is_shortcode" value="0"> '.__( 'No' ).'</label>';
555
  {
556
  nocache_headers();
557
 
558
+ if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'tinymce_templates' ) ) {
559
  return;
560
  }
561
 
562
  header( 'Content-Type: application/javascript; charset=UTF-8' );
563
 
564
+ $templates = $this->get_templates();
565
+
566
+ echo json_encode( $templates );
567
+ exit;
568
+ }
569
+
570
+ public function get_templates()
571
+ {
572
  $p = array(
573
  'post_status' => 'publish',
574
  'post_type' => $this->post_type,
579
 
580
  $posts = get_posts( $p );
581
 
582
+ $templates = array();
583
 
584
  foreach ( $posts as $p ) {
585
  $ID = intval( $p->ID );
586
  $name = esc_html( apply_filters( 'tinymce_template_title', $p->post_title ) );
587
  $desc = esc_html( apply_filters( 'tinymce_template_excerpt', $p->post_excerpt ) );
588
+ $templates[ $ID ] = array(
589
  'title' => $name,
590
  'is_shortcode' => get_post_meta( $ID, 'insert_as_shortcode', true ),
591
+ 'content' => $p->post_content,
592
  );
593
  }
594
 
595
+ $templates = apply_filters( 'tinymce_templates_post_objects', $templates );
596
 
597
  if ( isset( $_GET['template_id'] ) && $_GET['template_id'] ) {
598
+ if ( isset( $templates[ $_GET['template_id'] ] ) && $templates[ $_GET['template_id'] ] ) {
599
+ $p = $templates[ $_GET['template_id'] ];
600
  $content = apply_filters(
601
  'tinymce_templates',
602
  $p['content'],
603
  $p['content']
604
  );
605
+ $preview = apply_filters(
606
+ 'tinymce_templates_preview',
607
+ $p['content']
608
+ );
609
+ return array(
610
+ 'content' => wpautop( $content ),
611
+ 'preview' => $preview,
612
+ 'is_shortcode' => $p['is_shortcode'],
613
+ );
614
  }
 
615
  }
616
 
617
+ return $templates;
 
618
  }
619
 
620
  /**