Plugin Directory

Changeset 1293687


Ignore:
Timestamp:
11/24/2015 06:49:48 PM (10 years ago)
Author:
RylanH
Message:

Adds better error messages to publish post action from Storyform editor

Location:
storyform/trunk
Files:
2 edited

Legend:

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

    r1265358 r1293687  
    348348
    349349    public function storyform_publish_post(){
    350        
    351 
    352         $nonce = isset( $_GET['_wpnonce'] ) ? $_GET[ '_wpnonce' ] : FALSE;
     350        if( !isset( $_GET['_wpnonce'] ) || !isset( $_GET['id'] ) || !isset( $_GET['name'] ) ) {
     351            die( 'Invalid parameters. Nonce, id and name required' );
     352        }
     353
     354        $nonce = $_GET[ '_wpnonce' ];
    353355        $id = intval( $_GET['id'] );
    354356        $name = sanitize_title( $_GET['name'] );
     
    362364
    363365        // Update post with revision if already published, keep name
    364         $post = get_post( $id )->to_array();
     366        $post_obj = get_post( $id );
     367        if( !$post_obj ){
     368            die( 'Cannot find post with id: ' . $id );
     369        }
     370
     371        $post = $post_obj->to_array();
    365372        $revisions = array_values( wp_get_post_revisions( $id ) );
    366373
    367         if( $post['post_status'] === 'publish' && count( $revisions ) > 0 ){
    368             $revision = $revisions[0]->to_array();
    369             $post = array(
    370                 'ID' => $id,
    371                 'post_content'  => $revision['post_content'],
    372                 'post_excerpt'  => $revision['post_excerpt'],
    373                 'post_title'    => $revision['post_title']
    374             );
     374        if( $post['post_status'] === 'publish' && count( $revisions ) ){
     375            $revision = $revisions[0];
     376            $post = array( 'ID' => $id );
     377            if( $revision->post_content ){
     378                $post['post_content'] = $revision->post_content;
     379            }
     380            if( $revision->post_excerpt ){
     381                $post['post_excerpt'] = $revision->post_excerpt;
     382            }
     383            if( $revision->post_title ){
     384                $post['post_title'] = $revision->post_title;
     385            }
    375386
    376387        } else {
     
    382393        }
    383394
    384         wp_update_post( $post );
     395        $update_result = wp_update_post( $post );
     396        if( !$update_result ){
     397            die( 'Unable to update post with changes' );
     398        }
     399       
    385400        wp_publish_post( $id );
    386401
    387         wp_redirect( get_permalink( $id ) );
     402        $permalink = get_permalink( $id );
     403        if( !$permalink ){
     404            die( 'Post is published, but cannot find permalink.' );
     405        }
     406
     407        wp_redirect( $permalink );
    388408        die();
    389409    }
  • storyform/trunk/editor/editor.js

    r1261349 r1293687  
    682682        _classCallCheck(this, ThenPromise);
    683683
     684        _PromiseStateMachine.call(this);
    684685        if (tagWithStack && (tagWithStack === true || tagWithStack & tag.thenPromise)) {
    685686            this._stack = Promise._getStack();
     
    850851        _classCallCheck(this, ExceptionPromise);
    851852
     853        _ErrorPromise.call(this);
    852854        if (tagWithStack && (tagWithStack === true || tagWithStack & tag.exceptionPromise)) {
    853855            this._stack = Promise._getStack();
     
    10301032        /// </param>
    10311033        /// </signature>
    1032 
     1034        _PromiseStateMachine2.call(this);
    10331035        if (tagWithStack && (tagWithStack === true || tagWithStack & tag.promise)) {
    10341036            this._stack = Promise._getStack();
     
    15141516        _classCallCheck(this, SignalPromise);
    15151517
     1518        _PromiseStateMachine3.call(this);
    15161519        this._oncancel = cancel;
    15171520        this._setState(state_created);
     
    16301633        /// <returns type="Error" locid=".ErrorFromName_returnValue">Error instance with .name and .message properties populated</returns>
    16311634        /// </signature>
     1635        _Error.call(this);
    16321636        this.name = name;
    16331637        this.message = message || name;
     
    22812285
    22822286},{}],6:[function(require,module,exports){
     2287(function (global){
    22832288/*
    22842289 * classList.js: Cross-browser full element.classList implementation.
     
    22962301"use strict";
    22972302
    2298 if ("document" in self) {
     2303if ("document" in global) {
    22992304
    23002305    // Full polyfill for browsers with no classList support
     
    24432448                elemCtrProto.__defineGetter__(classListProp, classListGetter);
    24442449            }
    2445         })(self);
     2450        })(global);
    24462451    } else {
    24472452        // There is full or partial native classList support, so just check if we need
     
    24962501}
    24972502
     2503}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
    24982504},{}],7:[function(require,module,exports){
    24992505"use strict";
     
    25572563var F = _interopRequireWildcard(require("./array-find"));
    25582564
    2559 },{"./array-find":4,"./canvas-to-blob":5,"./element-classlist":6,"./nodelist-foreach":7,"./object-assign":8,"./set-immediate":10}],10:[function(require,module,exports){
     2565var G = _interopRequireWildcard(require("./typedarray"));
     2566
     2567},{"./array-find":4,"./canvas-to-blob":5,"./element-classlist":6,"./nodelist-foreach":7,"./object-assign":8,"./set-immediate":10,"./typedarray":11}],10:[function(require,module,exports){
    25602568"use strict";
    25612569
     
    25732581
    25742582},{}],11:[function(require,module,exports){
     2583"use strict";
     2584
     2585if (Uint8Array && !Uint8Array.prototype.sort) {
     2586    Object.defineProperty(Uint8Array.prototype, "sort", {
     2587        enumerable: false,
     2588        value: function value() {
     2589            return Array.prototype.sort.call(this, function (a, b) {
     2590                return a - b;
     2591            });
     2592        }
     2593    });
     2594}
     2595if (Uint16Array && !Uint16Array.prototype.sort) {
     2596    Object.defineProperty(Uint16Array.prototype, "sort", {
     2597        enumerable: false,
     2598        value: function value() {
     2599            return Array.prototype.sort.call(this, function (a, b) {
     2600                return a - b;
     2601            });
     2602        }
     2603    });
     2604}
     2605if (Uint32Array && !Uint32Array.prototype.sort) {
     2606    Object.defineProperty(Uint32Array.prototype, "sort", {
     2607        enumerable: false,
     2608        value: function value() {
     2609            return Array.prototype.sort.call(this, function (a, b) {
     2610                return a - b;
     2611            });
     2612        }
     2613    });
     2614}
     2615if (Uint8ClampedArray && !Uint8ClampedArray.prototype.sort) {
     2616    Object.defineProperty(Uint8ClampedArray.prototype, "sort", {
     2617        enumerable: false,
     2618        value: function value() {
     2619            return Array.prototype.sort.call(this, function (a, b) {
     2620                return a - b;
     2621            });
     2622        }
     2623    });
     2624}
     2625
     2626},{}],12:[function(require,module,exports){
    25752627(function (global){
    25762628"use strict";
     
    27162768
    27172769}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
    2718 },{"Promise":1,"event-utils":2,"object":3}],12:[function(require,module,exports){
     2770},{"Promise":1,"event-utils":2,"object":3}],13:[function(require,module,exports){
    27192771(function (global){
    27202772"use strict";
     
    29963048
    29973049}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
    2998 },{"window-messages":11}]},{},[9,12]);
     3050},{"window-messages":12}]},{},[9,13]);
Note: See TracChangeset for help on using the changeset viewer.