TinyMCE Templates - Version 4.1.0

Version Description

Download this release

Release Info

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

Code changes from version 4.0.1 to 4.1.0

editor-style.css ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .mceContentBody table
2
+ {
3
+ border: 1px dashed #cccccc;
4
+ width: 100%;
5
+ }
6
+
7
+ .mceContentBody th,
8
+ .mceContentBody td
9
+ {
10
+ border: 1px dashed #cccccc;
11
+ height: 1em;
12
+ }
editor.css DELETED
@@ -1,7 +0,0 @@
1
- body#tinymce.wp-editor table {
2
- border: 1px dashed #cccccc;
3
- }
4
-
5
- body#tinymce.wp-editor th,td {
6
- border: 1px dashed #cccccc;
7
- }
 
 
 
 
 
 
 
mce_plugins/4.0/plugins/template/plugin.js CHANGED
@@ -45,7 +45,6 @@ tinymce.PluginManager.add('template', function(editor) {
45
  id: template.id,
46
  url: template.url,
47
  content: template.content,
48
- description: template.description,
49
  is_shortcode: template.is_shortcode
50
  }
51
  });
@@ -60,6 +59,7 @@ tinymce.PluginManager.add('template', function(editor) {
60
 
61
  tinymce.each(editor.contentCSS, function(url) {
62
  contentCssLinks += '<link type="text/css" rel="stylesheet" href="' + editor.documentBaseURI.toAbsolute(url) + '">';
 
63
  });
64
 
65
  html = (
@@ -68,7 +68,7 @@ tinymce.PluginManager.add('template', function(editor) {
68
  '<head>' +
69
  contentCssLinks +
70
  '</head>' +
71
- '<body>' +
72
  html +
73
  '</body>' +
74
  '</html>'
@@ -102,7 +102,6 @@ tinymce.PluginManager.add('template', function(editor) {
102
  label = '\u00a0';
103
  }
104
 
105
- win.find('#description')[0].text(e.control.value().description);
106
  win.find('#is_shortcode')[0].text(label);
107
  }
108
 
@@ -120,7 +119,7 @@ tinymce.PluginManager.add('template', function(editor) {
120
  type: 'listbox', label: 'Templates', name: 'template', values: values, onselect: onSelectTemplate
121
  }}
122
  ]},
123
- {type: 'label', name: 'description', label: 'Description', text: '\u00a0'},
124
  {type: 'iframe', flex: 1, border: 1},
125
  {type: 'label', name: 'is_shortcode', label: '', text: '\u00a0'},
126
  ],
45
  id: template.id,
46
  url: template.url,
47
  content: template.content,
 
48
  is_shortcode: template.is_shortcode
49
  }
50
  });
59
 
60
  tinymce.each(editor.contentCSS, function(url) {
61
  contentCssLinks += '<link type="text/css" rel="stylesheet" href="' + editor.documentBaseURI.toAbsolute(url) + '">';
62
+ console.log(contentCssLinks);
63
  });
64
 
65
  html = (
68
  '<head>' +
69
  contentCssLinks +
70
  '</head>' +
71
+ '<body class="mceContentBody">' +
72
  html +
73
  '</body>' +
74
  '</html>'
102
  label = '\u00a0';
103
  }
104
 
 
105
  win.find('#is_shortcode')[0].text(label);
106
  }
107
 
119
  type: 'listbox', label: 'Templates', name: 'template', values: values, onselect: onSelectTemplate
120
  }}
121
  ]},
122
+
123
  {type: 'iframe', flex: 1, border: 1},
124
  {type: 'label', name: 'is_shortcode', label: '', text: '\u00a0'},
125
  ],
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.0.1
7
 
8
  TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
9
  You can edit and share this template with WordPress users.
3
  Tags: tinymce, Visual Editor, template
4
  Requires at least: 4.0
5
  Tested up to: 4.1
6
+ Stable tag: 4.1.0
7
 
8
  TinyMCE Template plugin will enable to use HTML template on WordPress Visual Editor.
9
  You can edit and share this template with WordPress users.
tinymce-templates.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: TinyMCE Templates
4
  Plugin URI: https://github.com/miya0001/tinymce-templates
5
  Description: TinyMCE Templates plugin will enable to use HTML template on WordPress Visual Editor.
6
  Author: Takayuki Miyauchi
7
- Version: 4.0.1
8
  Author URI: https://github.com/miya0001/
9
  Domain Path: /languages
10
  Text Domain: tinymce_templates
@@ -32,14 +32,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32
  THE SOFTWARE.
33
  */
34
 
35
- $tinymce_templates = new tinymceTemplates();
36
  $tinymce_templates->register();
37
 
38
- class tinymceTemplates {
39
 
40
- private $version = '2.9.0';
41
  private $post_type = 'tinymcetemplates';
42
- private $table = 'mce_template';
43
  private $base_url;
44
  private $translators = array(
45
  'Takayuki Miyauchi' => array(
@@ -111,7 +109,7 @@ class tinymceTemplates {
111
  load_plugin_textdomain(
112
  'tinymce_templates',
113
  false,
114
- dirname(plugin_basename(__FILE__)).'/languages'
115
  );
116
 
117
  $this->register_post_type();
@@ -119,6 +117,7 @@ class tinymceTemplates {
119
  add_filter( 'post_row_actions', array( $this, 'row_actions' ), 10, 2 );
120
  add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
121
  add_filter( 'wp_mce_translation', array( $this, 'wp_mce_translation' ) );
 
122
 
123
  add_action( 'admin_head', array( $this, 'admin_head' ) );
124
  add_action( 'admin_footer-post-new.php', array( $this, 'admin_footer' ) );
@@ -136,23 +135,34 @@ class tinymceTemplates {
136
  * @param array $p Shortcode parameters.
137
  * @return none Shortcode output.
138
  */
139
- public function template_shortcode( $p )
140
  {
141
  if ( isset( $p['id'] ) && intval( $p['id'] ) ) {
142
  $args = array(
143
  'ID' => $p['id'],
144
  'post_status' => 'publish',
145
- 'post_type' => 'tinymcetemplates'
146
  );
147
 
148
  $post = get_post( $p['id'] );
149
 
150
  if ( $post && get_post_meta( $p['id'], 'insert_as_shortcode', true ) ) {
151
- return apply_filters( 'the_content', $post->post_content );
152
  }
153
  }
154
  }
155
 
 
 
 
 
 
 
 
 
 
 
 
156
  /**
157
  * Fires on wp_before_admin_bar_render hook.
158
  *
@@ -167,9 +177,9 @@ class tinymceTemplates {
167
  */
168
  $wp_admin_bar->add_menu( array(
169
  'parent' => 'edit',
170
- 'id' => 'new_template',
171
- 'title' => __( 'Copy to a new template', 'tinymce_templates' ),
172
- 'href' => $this->get_copy_template_url( get_the_ID() )
173
  ) );
174
  }
175
  }
@@ -182,10 +192,10 @@ class tinymceTemplates {
182
  */
183
  public function wp_mce_translation( $mce_translation )
184
  {
185
- $mce_translation['Insert template'] = __( "Insert template", "tinymce_templates" );
186
- $mce_translation['Templates'] = __( "Templates", "tinymce_templates" );
187
- $mce_translation['No templates defined'] = __( "No templates defined", "tinymce_templates" );
188
- $mce_translation['Note: The template will be inserted as shortcode.'] = __( "Note: The template will be inserted as shortcode.", "tinymce_templates" );
189
 
190
  return $mce_translation;
191
  }
@@ -219,7 +229,7 @@ class tinymceTemplates {
219
  ?>
220
  <div id="duplicate-action">
221
  <a class="submitduplicate duplication"
222
- href="<?php echo $this->get_copy_template_url($_GET['post']) ?>"><?php _e('Copy to a new template', 'tinymce_templates'); ?></a>
223
  </div>
224
  <?php
225
  }
@@ -237,18 +247,18 @@ class tinymceTemplates {
237
  * Load and setup tinymce plugin.
238
  */
239
  $url = admin_url( 'admin-ajax.php' );
240
- $nonce = wp_create_nonce( "tinymce_templates" );
241
 
242
  $args = array(
243
  'action' => 'tinymce_templates',
244
  'nonce' => $nonce,
245
  );
246
 
247
- $url = add_query_arg( $args, $url);
248
 
249
  $inits['templates'] = $url;
250
 
251
- require_once( dirname(__FILE__) . '/includes/mceplugins.class.php' );
252
 
253
  new tinymcePlugins(
254
  'template',
@@ -263,7 +273,7 @@ class tinymceTemplates {
263
  echo '<style type="text/css">';
264
  printf(
265
  'span.mceIcon.mce_template{background-image: url(%s) !important; background-position: center center !important;background-repeat: no-repeat;}',
266
- plugins_url('mce_plugins/3.5/plugins/template/img/icon.png', __FILE__)
267
  );
268
  echo '</style>';
269
 
@@ -272,7 +282,7 @@ class tinymceTemplates {
272
  */
273
  if ( get_post_type() === $this->post_type ) {
274
  global $hook_suffix;
275
- if ( $hook_suffix === 'post.php' || $hook_suffix === 'post-new.php' ) {
276
  remove_meta_box( 'slugdiv', $this->post_type, 'normal' );
277
  echo '<style>#visibility{display:none;} #message a{display: none;}</style>';
278
  }
@@ -281,7 +291,9 @@ class tinymceTemplates {
281
  /**
282
  * Add editor style to the editor.
283
  */
284
- add_editor_style( plugins_url( 'editor.css', __FILE__ ) );
 
 
285
  }
286
 
287
  /**
@@ -319,7 +331,7 @@ class tinymceTemplates {
319
  'No templates found in Trash.',
320
  'tinymce_templates'
321
  ),
322
- 'search_items' => __('Search Templates', 'tinymce_templates'),
323
  ),
324
  'public' => false,
325
  'publicly_queryable' => false,
@@ -334,7 +346,6 @@ class tinymceTemplates {
334
  'supports' => array(
335
  'title',
336
  'editor',
337
- 'excerpt',
338
  'revisions',
339
  'author',
340
  )
@@ -352,8 +363,8 @@ class tinymceTemplates {
352
  {
353
  add_meta_box(
354
  'tinymce_templates-is-shortcode',
355
- __('Insert as Shortcode', 'tinymce_templates'),
356
- array($this, 'insert_as_shortcode_meta_box'),
357
  $this->post_type,
358
  'side',
359
  'low'
@@ -377,7 +388,7 @@ class tinymceTemplates {
377
  */
378
  public function insert_as_shortcode_meta_box( $post, $box )
379
  {
380
- $res = get_post_meta($post->ID, 'insert_as_shortcode', true);
381
  if ( $res ) {
382
  echo '<label><input type="radio" name="is_shortcode" value="1" checked> '.__( 'Yes' ).'</label><br />';
383
  echo '<label><input type="radio" name="is_shortcode" value="0"> '.__( 'No' ).'</label>';
@@ -423,20 +434,20 @@ class tinymceTemplates {
423
  */
424
  public function save_post( $id )
425
  {
426
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
427
  return $id;
428
  }
429
 
430
- if (isset($_POST['action']) && $_POST['action'] == 'inline-save') {
431
  return $id;
432
  }
433
 
434
- $p = get_post($id);
435
 
436
  /**
437
  * Save post_meta
438
  */
439
- if ($p->post_type === $this->post_type) {
440
  if ( isset( $_POST['is_shortcode'] ) && $_POST['is_shortcode'] ) {
441
  update_post_meta( $id, 'insert_as_shortcode', true );
442
  } else {
@@ -454,8 +465,8 @@ class tinymceTemplates {
454
  public function admin_footer()
455
  {
456
  if ( get_post_type() === $this->post_type ) {
457
- if ( isset($_GET['origin']) && intval($_GET['origin']) ) {
458
- $origin = get_post( intval($_GET['origin']) );
459
  if ( $origin ) {
460
  $template = array(
461
  'post_title' => $origin->post_title,
@@ -484,17 +495,17 @@ EOL;
484
  {
485
  nocache_headers();
486
 
487
- if ( ! wp_verify_nonce($_GET['nonce'], 'tinymce_templates') ) {
488
  return;
489
  }
490
 
491
  header( 'Content-Type: application/javascript; charset=UTF-8' );
492
 
493
- if ( isset($_GET['template_id']) && intval($_GET['template_id']) ) {
494
  $p = get_post( $_GET['template_id'] );
495
  if ( $p->post_status === 'publish' ) {
496
  echo apply_filters(
497
- "tinymce_templates",
498
  wpautop( $p->post_content ),
499
  stripslashes( $p->post_content )
500
  );
@@ -505,21 +516,21 @@ EOL;
505
  $p = array(
506
  'post_status' => 'publish',
507
  'post_type' => $this->post_type,
508
- 'orderby' => 'date',
509
- 'order' => 'DESC',
510
  'numberposts' => -1,
511
  );
512
 
513
  $posts = get_posts( $p );
514
- $url = admin_url( 'admin-ajax.php' );
515
- $nonce = wp_create_nonce( "tinymce_templates" );
516
 
517
  $arr = array();
518
 
519
  foreach ( $posts as $p ) {
520
  $ID = intval( $p->ID );
521
- $name = esc_html( apply_filters('tinymce_template_title', $p->post_title) );
522
- $desc = esc_html( apply_filters('tinymce_template_excerpt', $p->post_excerpt) );
523
  $args = array(
524
  'action' => 'tinymce_templates',
525
  'template_id' => $ID,
@@ -527,10 +538,9 @@ EOL;
527
  );
528
  $url = add_query_arg( $args, $url );
529
  $arr[] = array(
530
- 'id' => $ID,
531
- 'title' => $name,
532
- 'url' => $url,
533
- 'description' => $desc,
534
  'is_shortcode' => get_post_meta( $ID, 'insert_as_shortcode', true ),
535
  );
536
  }
@@ -548,7 +558,7 @@ EOL;
548
  */
549
  private function get_copy_template_url( $id )
550
  {
551
- return admin_url( 'post-new.php?post_type=tinymcetemplates&origin='.intval($id) );
552
  }
553
 
554
 
4
  Plugin URI: https://github.com/miya0001/tinymce-templates
5
  Description: TinyMCE Templates plugin will enable to use HTML template on WordPress Visual Editor.
6
  Author: Takayuki Miyauchi
7
+ Version: 4.1.0
8
  Author URI: https://github.com/miya0001/
9
  Domain Path: /languages
10
  Text Domain: tinymce_templates
32
  THE SOFTWARE.
33
  */
34
 
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(
109
  load_plugin_textdomain(
110
  'tinymce_templates',
111
  false,
112
+ dirname( plugin_basename( __FILE__ ) ).'/languages'
113
  );
114
 
115
  $this->register_post_type();
117
  add_filter( 'post_row_actions', array( $this, 'row_actions' ), 10, 2 );
118
  add_filter( 'page_row_actions', array( $this, 'row_actions' ), 10, 2 );
119
  add_filter( 'wp_mce_translation', array( $this, 'wp_mce_translation' ) );
120
+ add_filter( 'tinymce_templates_content', array( $this, 'tinymce_templates_content' ) );
121
 
122
  add_action( 'admin_head', array( $this, 'admin_head' ) );
123
  add_action( 'admin_footer-post-new.php', array( $this, 'admin_footer' ) );
135
  * @param array $p Shortcode parameters.
136
  * @return none Shortcode output.
137
  */
138
+ public function template_shortcode( $p, $content )
139
  {
140
  if ( isset( $p['id'] ) && intval( $p['id'] ) ) {
141
  $args = array(
142
  'ID' => $p['id'],
143
  'post_status' => 'publish',
144
+ 'post_type' => 'tinymcetemplates',
145
  );
146
 
147
  $post = get_post( $p['id'] );
148
 
149
  if ( $post && get_post_meta( $p['id'], 'insert_as_shortcode', true ) ) {
150
+ return apply_filters( 'tinymce_templates_content', $post->post_content, $p, $content );
151
  }
152
  }
153
  }
154
 
155
+ /**
156
+ * Filters tinymce_templates_content.
157
+ *
158
+ * @param string $template Template contents.
159
+ * @return string Template contents.
160
+ */
161
+ public function tinymce_templates_content( $template )
162
+ {
163
+ return wpautop( $template );
164
+ }
165
+
166
  /**
167
  * Fires on wp_before_admin_bar_render hook.
168
  *
177
  */
178
  $wp_admin_bar->add_menu( array(
179
  'parent' => 'edit',
180
+ 'id' => 'new_template',
181
+ 'title' => __( 'Copy to a new template', 'tinymce_templates' ),
182
+ 'href' => $this->get_copy_template_url( get_the_ID() )
183
  ) );
184
  }
185
  }
192
  */
193
  public function wp_mce_translation( $mce_translation )
194
  {
195
+ $mce_translation['Insert template'] = __( 'Insert template', 'tinymce_templates' );
196
+ $mce_translation['Templates'] = __( 'Templates', 'tinymce_templates' );
197
+ $mce_translation['No templates defined'] = __( 'No templates defined', 'tinymce_templates' );
198
+ $mce_translation['Note: The template will be inserted as shortcode.'] = __( 'Note: The template will be inserted as shortcode.', 'tinymce_templates' );
199
 
200
  return $mce_translation;
201
  }
229
  ?>
230
  <div id="duplicate-action">
231
  <a class="submitduplicate duplication"
232
+ href="<?php echo esc_url( $this->get_copy_template_url( $_GET['post'] ) ) ?>"><?php _e( 'Copy to a new template', 'tinymce_templates' ); ?></a>
233
  </div>
234
  <?php
235
  }
247
  * Load and setup tinymce plugin.
248
  */
249
  $url = admin_url( 'admin-ajax.php' );
250
+ $nonce = wp_create_nonce( 'tinymce_templates' );
251
 
252
  $args = array(
253
  'action' => 'tinymce_templates',
254
  'nonce' => $nonce,
255
  );
256
 
257
+ $url = add_query_arg( $args, $url );
258
 
259
  $inits['templates'] = $url;
260
 
261
+ require_once( dirname( __FILE__ ) . '/includes/mceplugins.class.php' );
262
 
263
  new tinymcePlugins(
264
  'template',
273
  echo '<style type="text/css">';
274
  printf(
275
  'span.mceIcon.mce_template{background-image: url(%s) !important; background-position: center center !important;background-repeat: no-repeat;}',
276
+ plugins_url( 'mce_plugins/3.5/plugins/template/img/icon.png', __FILE__ )
277
  );
278
  echo '</style>';
279
 
282
  */
283
  if ( get_post_type() === $this->post_type ) {
284
  global $hook_suffix;
285
+ if ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) {
286
  remove_meta_box( 'slugdiv', $this->post_type, 'normal' );
287
  echo '<style>#visibility{display:none;} #message a{display: none;}</style>';
288
  }
291
  /**
292
  * Add editor style to the editor.
293
  */
294
+ $ver = filemtime( dirname( __FILE__ ) . '/editor-style.css' );
295
+ $editor_style = plugins_url( 'editor-style.css?ver=' . $ver, __FILE__ );
296
+ add_editor_style( $editor_style );
297
  }
298
 
299
  /**
331
  'No templates found in Trash.',
332
  'tinymce_templates'
333
  ),
334
+ 'search_items' => __( 'Search Templates', 'tinymce_templates' ),
335
  ),
336
  'public' => false,
337
  'publicly_queryable' => false,
346
  'supports' => array(
347
  'title',
348
  'editor',
 
349
  'revisions',
350
  'author',
351
  )
363
  {
364
  add_meta_box(
365
  'tinymce_templates-is-shortcode',
366
+ __( 'Insert as Shortcode', 'tinymce_templates' ),
367
+ array( $this, 'insert_as_shortcode_meta_box' ),
368
  $this->post_type,
369
  'side',
370
  'low'
388
  */
389
  public function insert_as_shortcode_meta_box( $post, $box )
390
  {
391
+ $res = get_post_meta( $post->ID, 'insert_as_shortcode', true );
392
  if ( $res ) {
393
  echo '<label><input type="radio" name="is_shortcode" value="1" checked> '.__( 'Yes' ).'</label><br />';
394
  echo '<label><input type="radio" name="is_shortcode" value="0"> '.__( 'No' ).'</label>';
434
  */
435
  public function save_post( $id )
436
  {
437
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
438
  return $id;
439
  }
440
 
441
+ if ( isset( $_POST['action'] ) && $_POST['action'] == 'inline-save' ) {
442
  return $id;
443
  }
444
 
445
+ $p = get_post( $id );
446
 
447
  /**
448
  * Save post_meta
449
  */
450
+ if ( $p->post_type === $this->post_type ) {
451
  if ( isset( $_POST['is_shortcode'] ) && $_POST['is_shortcode'] ) {
452
  update_post_meta( $id, 'insert_as_shortcode', true );
453
  } else {
465
  public function admin_footer()
466
  {
467
  if ( get_post_type() === $this->post_type ) {
468
+ if ( isset( $_GET['origin'] ) && intval( $_GET['origin'] ) ) {
469
+ $origin = get_post( intval( $_GET['origin'] ) );
470
  if ( $origin ) {
471
  $template = array(
472
  'post_title' => $origin->post_title,
495
  {
496
  nocache_headers();
497
 
498
+ if ( ! wp_verify_nonce( $_GET['nonce'], 'tinymce_templates' ) ) {
499
  return;
500
  }
501
 
502
  header( 'Content-Type: application/javascript; charset=UTF-8' );
503
 
504
+ if ( isset( $_GET['template_id'] ) && intval( $_GET['template_id'] ) ) {
505
  $p = get_post( $_GET['template_id'] );
506
  if ( $p->post_status === 'publish' ) {
507
  echo apply_filters(
508
+ 'tinymce_templates',
509
  wpautop( $p->post_content ),
510
  stripslashes( $p->post_content )
511
  );
516
  $p = array(
517
  'post_status' => 'publish',
518
  'post_type' => $this->post_type,
519
+ 'orderby' => 'date',
520
+ 'order' => 'DESC',
521
  'numberposts' => -1,
522
  );
523
 
524
  $posts = get_posts( $p );
525
+ $url = admin_url( 'admin-ajax.php' );
526
+ $nonce = wp_create_nonce( 'tinymce_templates' );
527
 
528
  $arr = array();
529
 
530
  foreach ( $posts as $p ) {
531
  $ID = intval( $p->ID );
532
+ $name = esc_html( apply_filters( 'tinymce_template_title', $p->post_title ) );
533
+ $desc = esc_html( apply_filters( 'tinymce_template_excerpt', $p->post_excerpt ) );
534
  $args = array(
535
  'action' => 'tinymce_templates',
536
  'template_id' => $ID,
538
  );
539
  $url = add_query_arg( $args, $url );
540
  $arr[] = array(
541
+ 'id' => $ID,
542
+ 'title' => $name,
543
+ 'url' => $url,
 
544
  'is_shortcode' => get_post_meta( $ID, 'insert_as_shortcode', true ),
545
  );
546
  }
558
  */
559
  private function get_copy_template_url( $id )
560
  {
561
+ return admin_url( 'post-new.php?post_type=tinymcetemplates&origin='.intval( $id ) );
562
  }
563
 
564