Plugin Directory

Changeset 1230971


Ignore:
Timestamp:
08/26/2015 05:18:51 AM (11 years ago)
Author:
RylanH
Message:

Fix for publishing in new tab

Location:
storyform/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • storyform/trunk/class-storyform-editor-page.php

    r1229586 r1230971  
    1212    public function __construct()
    1313    {
     14        add_action( 'init', array( $this, 'storyform_publish_post' ) );
    1415        add_action( 'admin_menu', array( $this, 'add_plugin_page' ), 500 );
    1516        add_action( 'wp_ajax_storyform_get_post', array( $this, 'storyform_get_post' ) );
    1617        add_action( 'wp_ajax_storyform_create_post', array( $this, 'storyform_create_post' ) );
    1718        add_action( 'wp_ajax_storyform_update_post', array( $this, 'storyform_update_post' ) );
    18         add_action( 'wp_ajax_storyform_publish_post', array( $this, 'storyform_publish_post' ) );
     19        add_action( 'wp_ajax_storyform_get_publish_url', array( $this, 'storyform_get_publish_url' ) );
    1920        add_action( 'wp_ajax_storyform_delete_post', array( $this, 'storyform_delete_post' ) );
    2021        add_action( 'wp_ajax_storyform_get_post_types', array( $this, 'storyform_get_post_types' ) );   
     
    4849        );
    4950
     51        add_submenu_page(
     52            null,
     53            'Publish post',
     54            'Publish post',
     55            'publish_posts',
     56            'storyform-publish-post',
     57            array( $this, 'storyform_publish_post' )
     58        );
     59
    5060        add_action( 'load-' . $hook_suffix , array( $this, 'hook_create_page' ), 99999 );
    5161    }
     
    240250    }
    241251
     252    public function storyform_get_publish_url(){
     253        check_ajax_referer( 'storyform-post-nonce' );
     254        $nonce = wp_create_nonce( 'storyform-post-nonce' );
     255        $id = intval( $_POST['id'] );
     256        $name = sanitize_title( $_POST['name'] );
     257
     258        $url = admin_url( "admin.php?page=storyform-publish-post&_wpnonce={$nonce}&id={$id}&name={$name}" );
     259
     260        echo json_encode( array( 'url' => $url ) );
     261        die();
     262    }
     263
    242264    public function storyform_publish_post(){
    243         check_ajax_referer( 'storyform-post-nonce' );
    244         $id = sanitize_text_field( $_POST['id'] );
    245         $name = sanitize_title( $_POST['name'] );
     265        if( !is_admin() || !isset( $_GET[ 'page' ] ) || $_GET[ 'page' ] !== 'storyform-publish-post' ){
     266            return;
     267        }
     268
     269        $nonce = isset( $_GET['_wpnonce'] ) ? $_GET[ '_wpnonce' ] : FALSE;
     270        $id = intval( $_GET['id'] );
     271        $name = sanitize_title( $_GET['name'] );
     272
     273        if ( ! wp_verify_nonce( $nonce, 'storyform-post-nonce' ) ) {
     274            die( 'Invalid Nonce' );
     275        }       
    246276
    247277        // Update post with revision if already published, keep name
     
    270300        wp_publish_post( $id );
    271301
    272         echo json_encode( array( 'url' => get_permalink( $id ) ) );
    273         die();
     302        wp_redirect( get_permalink( $id ) );
    274303    }
    275304
  • storyform/trunk/editor/editor.js

    r1229730 r1230971  
    27062706});
    27072707
    2708 WindowMessageManager.addEventListener("publish-post", function (ev) {
     2708WindowMessageManager.addEventListener("get-publish-url", function (ev) {
    27092709    var data = ev.detail.data;
    27102710
    27112711    jQuery.post(ajaxurl, {
    2712         action: "storyform_publish_post",
     2712        action: "storyform_get_publish_url",
    27132713        _ajax_nonce: storyform_nonce,
    27142714        id: data.id,
     
    27162716    }, function (data, textStatus, jqXHR) {
    27172717        data = JSON.parse(data);
    2718         data.action = "publish-post";
     2718        data.action = "get-publish-url";
    27192719        data.status = jqXHR.status;
    27202720        WindowMessageManager.postMessage(ev.detail.source, data);
     
    27402740WindowMessageManager.addEventListener("redirect", function (ev) {
    27412741    var data = ev.detail.data;
    2742     if (data.newTab) {
    2743         window.open(data.url, "_blank");
    2744     } else {
    2745         document.location.href = data.url;
    2746     }
     2742    document.location.href = data.url;
    27472743});
    27482744
  • storyform/trunk/src/js/editor.js

    r1229730 r1230971  
    6868});
    6969
    70 WindowMessageManager.addEventListener('publish-post', function(ev){
    71     var data = ev.detail.data;
    72 
    73     jQuery.post(ajaxurl, {
    74         action : 'storyform_publish_post',
     70WindowMessageManager.addEventListener('get-publish-url', function(ev){
     71    var data = ev.detail.data;
     72
     73    jQuery.post(ajaxurl, {
     74        action : 'storyform_get_publish_url',
    7575        _ajax_nonce: storyform_nonce,
    7676        id: data.id,
     
    7878    }, function(data, textStatus, jqXHR){
    7979        data = JSON.parse(data);
    80         data.action = 'publish-post';
     80        data.action = 'get-publish-url';
    8181        data.status = jqXHR.status;
    8282        WindowMessageManager.postMessage(ev.detail.source, data);
     
    102102WindowMessageManager.addEventListener('redirect', function(ev){
    103103    var data = ev.detail.data;
    104     if(data.newTab){
    105         window.open(data.url, '_blank');
    106     } else {
    107         document.location.href = data.url; 
    108     }
    109    
     104    document.location.href = data.url; 
    110105});
    111106
  • storyform/trunk/storyform.php

    r1229586 r1230971  
    55Plugin Name:  Storyform
    66Plugin URI:   http://storyform.co/docs/wordpress
    7 Version:      0.6.1
     7Version:      0.6.2
    88Description:  Plugin to enable Storyform on select posts. Works with both SEO and non-SEO permalinks.
    99Author:       Storyform
     
    1313
    1414global $storyform_version;
    15 $storyform_version = '0.6.1'; // The plugin version
     15$storyform_version = '0.6.2'; // The plugin version
    1616
    1717require_once( dirname( __FILE__ ) . '/config.php');
Note: See TracChangeset for help on using the changeset viewer.