dtcuv8044 2014-07-01 12:11
浏览 45

Wordpress tinyMCE不会在生产服务器上打开窗口

Ok so here's the deal. Using the code below, I have created a custom button in the tinyMCE editor which opens a modal window and loads a php file I created. This is NOT a plugin for Wordpress, I've built the functionality directly into my theme.

It works perfectly on my local environment (Ubuntu running LAMP with a vhost file loading the site as wordpress.loc if any of this helps) but on my production server, running cpanel the modal window cant seem to find the php file. It 404s. So I guess the WP routing system is getting in the way.. but I'm having this issue with both the latest version of WP and tinyMCE and the last.

Here is how Im setting it up:

function register_button($buttons) {  
   array_push($buttons,"|" ,"kjdShortCodeInjection");  
   return $buttons;  
}  

function add_plugin($plugin_array) {  
    $admin_dir = get_stylesheet_directory_uri().'/lib/admin';
    $mce_plugin_js = $admin_dir.'/functions/shortcode-injector/mcePlugin.js';

    $plugin_array['kjdShortCodeInjection'] = $mce_plugin_js;  
    return $plugin_array;  
} 

     add_filter('mce_external_plugins', 'add_plugin');  
     add_filter('mce_buttons', 'register_button');  

And the JS which I need for tinyMCE:

    init : function(ed, url) {
        ed.addCommand('mcekjdShortCodeInjection', function() {
            ed.windowManager.open({
                file : url+'/shortcode_window.php',
                title: "Select a shortcode",
                popup_css: "bootstrap.css",
                width : 900 + ed.getLang('kjdShortCodeInjection.delta_width', 0),
                height : 600 + ed.getLang('kjdShortCodeInjection.delta_height', 0),
                inline : 1
            }, {
                plugin_url : url // Plugin absolute URL
            });
        });

Almost every example or tutorial I've found has the button added as a plugin, and therefor is using WP_PLUGIN_URL or plugins_url

Is there a way I can get the accessible absolute path?

  • 写回答

3条回答 默认 最新

  • dtxa49711 2014-07-08 12:19
    关注

    Here is how you can get the Absolute Path in mcePlugin.js

    Add the following code in your functions.php file

    add_action('admin_head','my_js_var_admin');
    function my_js_var_admin() {
    
        if ( is_admin() ) {
        ?>
        <script type="text/javascript">
        var ABSURL = '<?php echo __DIR__; ?>';
        </script>
        <?php
        }
    }
    

    Now this is how you can user the ABSURL in your mcePlugin.js file

    file : ABSURL+'/shortcode_window.php',  // Assign your File Path here
    

    Hope this is help you.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法