将插件链接到nextgen上传调用

时间:2017-10-28 06:59:35

标签: wordpress

我想将我的插件链接到nextgen上传。 当用户在nextgen图库中上传图片时,在上传过程中,我也想让它通过我们的插件。我们尝试了不同的钩子,但没有一个工作。任何想法都会很棒。

我试过这个

  function my_enqueue( $hook ) {
   if ( $hook == 'admin.php' || $hook=='wp_ajax_request-nextgen') {
   //some codes here
 }
  }

然后

 add_action( 'wp_ajax_request-nextgen', array( &$this, 'other_media_library_nextgen_ajax_callback' ), 9, 2 );

但是当我们将图片上传到nextgen画廊时它没有被触发

1 个答案:

答案 0 :(得分:0)

add_action( 'init', function() {
    if ( ! isset( $_REQUEST[ 'photocrati_ajax' ] ) || $_REQUEST['action'] !== 'upload_image' ) {
        # not an upload image request so
        return;
    }
    # process upload request here
}, 9 );

因为NextGen操作M_Ajax :: serve_ajax_request()调用exit(),所以在NextGen操作之后无法运行。如果您需要在NextGen操作之后运行您的操作,那么您可以先在操作中运行NextGen操作,然后再执行操作并退出。

add_action( 'init', function() {
    if ( ! isset( $_REQUEST[ 'photocrati_ajax' ] ) || $_REQUEST['action'] !== 'upload_image' ) {
        # not an upload image request so
        return;
    }
    # First do the NextGen action M_Ajax::serve_ajax_request() processing
    $controller = C_Ajax_Controller::get_instance();
    $controller->index_action();
    # Now do your image upload processing here
    # Finally, must exit otherwise NextGen action will be done twice
    exit;
}, 9 );

$ _REQUEST看起来像这样

[photocrati_ajax] => 1
[action] => upload_image
[gallery_id] => 0
[gallery_name] => gallery
[nextgen_upload_image_sec] => 496cc9951b
[name] => image.jpg