Want more features on Pastebin? Sign Up, it's FREE!
Guest

window.php (TinyMCE modal window in a wordpress backend)

By: 5tefan on Jan 25th, 2013  |  syntax: None  |  size: 2.20 KB  |  views: 60  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. // look up for the path
  3. require_once('../../../../../../wp-config.php');
  4. // check for rights
  5. if ( !is_user_logged_in() && current_user_can('edit_posts') )
  6.         wp_die(__("You are not allowed to be here"));
  7.  
  8. $ajax_nonce = wp_create_nonce("nonce");
  9.  
  10. // more php blablabla ...
  11.  
  12. add_action('wp_ajax_my_action', 'add_post_meta_bs');
  13.  
  14. function add_post_meta_bs() {
  15.         global $wpdb;
  16.  
  17.         check_ajax_referer('nonce', $_POST['security'], true);
  18.  
  19.         add_post_meta((int)$_POST['post_id'], $_POST['key'], $_POST['val'], $_POST['unique']);
  20.         die();
  21. }
  22.  
  23. ?>
  24. <!DOCTYPE html>
  25. <html xmlns="http://www.w3.org/1999/xhtml">
  26. <head>
  27. <title>Bildstrecke</title>
  28. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  29. <script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script>
  30. <script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/utils/mctabs.js"></script>
  31. <script language="javascript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-includes/js/tinymce/utils/form_utils.js"></script>
  32. <script type="text/javascript" src="<?php echo get_option('siteurl') ?>/wp-admin/load-scripts.php?c=1&amp;load=jquery,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable&amp;ver=<?php bloginfo('version') ?>"></script>
  33. <script type="text/javascript">
  34. function ajaxSubmit(id, argstring) {
  35.         jQuery.post("../../../../../../wp-admin/admin-ajax.php", {
  36.                 action: 'wp_ajax_my_action',
  37.                 post_id: id,
  38.                 key: 'bildstrecke',
  39.                 val: 'true',
  40.                 unique: 'true',
  41.                 security: '<?php echo $ajax_nonce ?>'
  42.         }).success(function() {
  43.                 window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, "[bildstrecke imgs=\""+argstring+"\"]");
  44.                 tinyMCEPopup.editor.execCommand('mceRepaint');
  45.                 tinyMCEPopup.close();
  46.         }).error(function(e) {
  47.                 console.log(e)
  48.         });
  49.         return false;
  50. }
  51. // more js...
  52. jQuery(document).ready(function($) {
  53.         // js blablabla...
  54.         $("#enter").click(function() {
  55.                 if(window.tinyMCE) {
  56.                         // more js determining post_id, idstring...
  57.                         ajaxSubmit(post_id, idstring);
  58.                 }
  59.         })
  60. });
  61. </script>
  62. </head>
  63. <body>...</body>
  64. </html>
clone this paste RAW Paste Data