This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from xwp/feature/create-full-posts-instead-of…
…-stubs-from-nav-menu-items Insert full posts instead of stubs via nav menus
- Loading branch information
Showing
4 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(function( api, $ ) { | ||
'use strict'; | ||
|
||
if ( api.Menus.insertAutoDraftPost ) { | ||
|
||
/** | ||
* Insert a new `auto-draft` post. | ||
* | ||
* @param {object} params - Parameters for the draft post to create. | ||
* @param {string} params.post_type - Post type to add. | ||
* @param {string} params.post_title - Post title to use. | ||
* @return {jQuery.promise} Promise resolved with the added post. | ||
*/ | ||
api.Menus.insertAutoDraftPost = function insertAutoDraftPost( params ) { | ||
|
||
var insertPromise, deferred = $.Deferred(); | ||
|
||
insertPromise = api.Posts.insertAutoDraftPost( params.post_type ); | ||
|
||
insertPromise.done( function insertAutoDraftPostDone( data ) { | ||
var postData; | ||
|
||
postData = _.clone( data.setting.get() ); | ||
postData.post_title = params.post_title; | ||
postData.post_status = 'publish'; | ||
data.setting.set( postData ); | ||
|
||
deferred.resolve( { | ||
post_id: data.postId, | ||
url: api.Posts.getPostUrl( { post_id: data.postId, post_type: params.post_type } ) | ||
} ); | ||
} ); | ||
insertPromise.fail( function insertAutoDraftPostFail( failure ) { | ||
deferred.reject( failure ); | ||
} ); | ||
|
||
return deferred.promise(); | ||
}; | ||
} | ||
|
||
})( wp.customize, jQuery ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters