內容簡介
這個外掛只針對開發者,它是使用 AngularJS 實現一個簡單的自定義前端發文編輯表單的努力。
我會通過 github 追蹤問題:
https://github.com/vimes1984/custompostedit/
它使用 AngularJS 進行表單,並要求您在表單的 URL 中傳遞一個 $_GET['posttoedit'] 變數,包含您想編輯的文章的 ID。
範例:
http://EXAMPLE.com/?posttoedit=POST_ID_TO_EDIT
你需要更新三個檔案才能啟動它,首先是表單:
這些欄位需要符合以下語法,這裡以 monthlysalary 為例是要傳遞給 PHP 函數的物件:
範例:
<input type="text" name="jobtitle" ng-model="formobject.monthlysalary" placeholder="Monthly Salary" />
檔案:
/includes/customedit.php
然後是 customPostEdit->post_edit_fac() 類別方法,第 237 至 262 行是實際更新文章的函數,並從 javascript 呼叫:
檔案:
customPostEdit.php
你需要填寫這些欄位以更新您想要的欄位,您可以在這裡找到預設欄位:
https://codex.wordpress.org/Database_Description#Table:_wp_posts
您可以像以下這樣更新文章 meta 欄位:
範例:
update_post_meta( $postID, 'wpcf-monthly-salary', $monthlysalary );
最後還有一個檔案您可能需要編輯,那就是 AngularJS 檔案,您可能需要更改:
範例:
$scope.formobject = {'jobID': '', 'title': '', 'jobcontent': '', 'monthlysalary': ''};
物件以符合您表單中的欄位:
檔案:
/js/custom-post-edit.js
這個檔案呼叫我們在第一個檔案中定義的 PHP 端點 post_edit_fac,並從表單將 formobject {} 傳遞到該函數。
您可以使用短代碼將表單放在任何您想要的地方:
短代碼:
[post_edit]
祝您好運,如果有任何問題,請發到 github,我很樂意提供幫助...
外掛標籤
開發者團隊
原文外掛簡介
This plugin is intented for Developers only it’s a effort to implement a simple custom front end post edit form using angularJS.
I’ll be tracking issues via github:
https://github.com/vimes1984/custompostedit/
It uses angularJS for the form and requires you pass a $_GET['posttoedit'] variable in the url to the form containing the post ID you want to edit.
Example:
http://EXAMPLE.com/?posttoedit=POST_ID_TO_EDIT
You are going to need to update three files to get this up and running first the form:
These fileds need to match the following syntax where in this case monthlysalary will be the object passed to the php function:
Example:
File:
/includes/customedit.php
Then the class customPostEdit->post_edit_fac() method, line 237-> 262 is the function that actually updates the post and is called from the javascript:
File:
customPostEdit.php
you are going to need to fill these in with the fields you want to update you can find the default fields here:
https://codex.wordpress.org/Database_Description#Table:_wp_posts
And you can update post meta fields like so:
Example:
update_post_meta( $postID, 'wpcf-monthly-salary', $monthlysalary );
There is one last file you may need to edit and that’s the AngularJS file you may need to change
Example:
$scope.formobject = {'jobID': '', 'title': '', 'jobcontent': '', 'monthlysalary': ''};
Object to match your form fields in this file:
File:
/js/custom-post-edit.js
This file calls the php endpoint we defined in the first file the post_edit_fac and sends the formobject {} to that function from the form.
You can place the form anywhere you want using the shortcode:
Shortcode:
[post_edit]
Good luck and post any issues to github I’ll gladly lend a hand…
