Front-End Post Create Plugin troubleshoot (API POST REQUEST)Mixing PHP and HTML in variableHow to trigger jquery plugins after ajax has loaded a page in WordPress?Add Link to sub menuWordpress Pre Fill content in PostsJSON API Error - You need to login with a user that has 'edit_posts' capacityCompletely custom page in WordPress generated by a pluginHow to show content without featured imageWordpress (WP ecommerce) add publish/unpublish to row actionsHow to add inline css in WordPress plugin/theme generated by shortcode in page content?Copy content of One CPT to Another automatically
Why Does Mama Coco Look Old After Going to the Other World?
Difference templates and layouts
Should I put programming books I wrote a few years ago on my resume?
Tikz-cd diagram arrow passing under a node - not crossing it
Does a (nice) centerless group always have a centerless profinite completion?
Was Self-modifying-code possible just using BASIC?
Zig-zag function - coded solution
If there's something that implicates the president why is there then a national security issue? (John Dowd)
Use 1 9 6 2 in this order to make 75
Housemarks (superimposed & combined letters, heraldry)
Ability To Change Root User Password (Vulnerability?)
Does the Nuka-Cola bottler actually generate nuka cola?
Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?
Do you need to let the DM know when you are multiclassing?
What should I discuss with my DM prior to my first game?
Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?
Make Gimbap cutter
How can one's career as a reviewer be ended?
What's the meaning of the expression "short circuit" in the text bellow?
Why did the World Bank set the global poverty line at $1.90?
Do empty drive bays need to be filled?
Why isn't Bash trap working if output is redirected to stdout?
Was planting UN flag on Moon ever discussed?
That's not my X, its Y is too Z
Front-End Post Create Plugin troubleshoot (API POST REQUEST)
Mixing PHP and HTML in variableHow to trigger jquery plugins after ajax has loaded a page in WordPress?Add Link to sub menuWordpress Pre Fill content in PostsJSON API Error - You need to login with a user that has 'edit_posts' capacityCompletely custom page in WordPress generated by a pluginHow to show content without featured imageWordpress (WP ecommerce) add publish/unpublish to row actionsHow to add inline css in WordPress plugin/theme generated by shortcode in page content?Copy content of One CPT to Another automatically
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am currently building a plugin for wordpress that is supposed to allow the user to create a new post from the front end of their site. When I click the Create Post button nothing happens. Please take a look at my code below:
the plugin uses a JavaScript function with pHp to make a POST request to the API. Iam working on a local server(MAMP) and do not currently use pretty permalinks so my url looks like this... http://localhost:9000/wordpress/?rest_route=/wp/v2/posts
which i have visited and seen the JSON data. I just can seem to get the button to make the actual post request.
php / html
// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) )
echo 'Hi there! I'm just a plugin, not much I can do when called directly.';
exit;
function postayge_front()
/* content variable */
$content = '';
$content .= '<div class="admin-quick-add">';
$content .= '<h3>Quick Add Post</h3>';
$content .= '<input type="text" name="title" placeholder="Title">';
$content .= '<textarea name="content" placeholder="Content"></textarea>';
$content .= '<button id="quick-add-button">Create Post</button>';
$content .= '</div>';
return $content;
add_shortcode('postayge','postayge_front');
/* Add scripts & styles */
function wp_postayge_adding_styles()
wp_register_style('postayge_style', plugins_url('main.css', __FILE__));
wp_enqueue_style('postayge_style');
wp_register_script('postayge_script', plugins_url('script.js', __FILE__));
wp_enqueue_script('postayge_script');
wp_localize_script('script.js', 'securityData', array(
'nonce' => wp_create_nonce('wp_rest')
));
add_action( 'wp_enqueue_scripts', 'wp_postayge_adding_styles' );
?>
js
//Quick add post AJAX
var quickAddButton = document.querySelector("#quick-add-button");
if (quickAddButton)
quickAddButton.addEventListener("click", function()
var postaygePostData =
"title": document.querySelector('.admin-quick-add[name="title"]').value,
"content": document.querySelector('.admin-quick-add[name="content"]').value,
"status": "publish"
var createPost = new XMLHttpRequest();
createPost.open("POST", "http://localhost:9000/wordpress/?rest_route=/wp/v2/posts");
createPost.setRequestHeader("X-WP-Nonce", securityData.nonce);
createPost.setRequestHeader("Content-Type", "applicaton/json;charset=UTF-8")
createPost.send(JSON.stringify(postaygePostData));
);
css
/** Quick Add Styles */
.admin-quick-add
background-color: inherit;
padding:15px;
margin-bottom: 15px;
.admin-quick-add input,
.admin-quick-add textarea
width: 100%;
border: none;
padding: 10px;
margin: 0 0 10px 0;
box-sizing: border-box;
wordpress api plugins
add a comment |
I am currently building a plugin for wordpress that is supposed to allow the user to create a new post from the front end of their site. When I click the Create Post button nothing happens. Please take a look at my code below:
the plugin uses a JavaScript function with pHp to make a POST request to the API. Iam working on a local server(MAMP) and do not currently use pretty permalinks so my url looks like this... http://localhost:9000/wordpress/?rest_route=/wp/v2/posts
which i have visited and seen the JSON data. I just can seem to get the button to make the actual post request.
php / html
// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) )
echo 'Hi there! I'm just a plugin, not much I can do when called directly.';
exit;
function postayge_front()
/* content variable */
$content = '';
$content .= '<div class="admin-quick-add">';
$content .= '<h3>Quick Add Post</h3>';
$content .= '<input type="text" name="title" placeholder="Title">';
$content .= '<textarea name="content" placeholder="Content"></textarea>';
$content .= '<button id="quick-add-button">Create Post</button>';
$content .= '</div>';
return $content;
add_shortcode('postayge','postayge_front');
/* Add scripts & styles */
function wp_postayge_adding_styles()
wp_register_style('postayge_style', plugins_url('main.css', __FILE__));
wp_enqueue_style('postayge_style');
wp_register_script('postayge_script', plugins_url('script.js', __FILE__));
wp_enqueue_script('postayge_script');
wp_localize_script('script.js', 'securityData', array(
'nonce' => wp_create_nonce('wp_rest')
));
add_action( 'wp_enqueue_scripts', 'wp_postayge_adding_styles' );
?>
js
//Quick add post AJAX
var quickAddButton = document.querySelector("#quick-add-button");
if (quickAddButton)
quickAddButton.addEventListener("click", function()
var postaygePostData =
"title": document.querySelector('.admin-quick-add[name="title"]').value,
"content": document.querySelector('.admin-quick-add[name="content"]').value,
"status": "publish"
var createPost = new XMLHttpRequest();
createPost.open("POST", "http://localhost:9000/wordpress/?rest_route=/wp/v2/posts");
createPost.setRequestHeader("X-WP-Nonce", securityData.nonce);
createPost.setRequestHeader("Content-Type", "applicaton/json;charset=UTF-8")
createPost.send(JSON.stringify(postaygePostData));
);
css
/** Quick Add Styles */
.admin-quick-add
background-color: inherit;
padding:15px;
margin-bottom: 15px;
.admin-quick-add input,
.admin-quick-add textarea
width: 100%;
border: none;
padding: 10px;
margin: 0 0 10px 0;
box-sizing: border-box;
wordpress api plugins
add a comment |
I am currently building a plugin for wordpress that is supposed to allow the user to create a new post from the front end of their site. When I click the Create Post button nothing happens. Please take a look at my code below:
the plugin uses a JavaScript function with pHp to make a POST request to the API. Iam working on a local server(MAMP) and do not currently use pretty permalinks so my url looks like this... http://localhost:9000/wordpress/?rest_route=/wp/v2/posts
which i have visited and seen the JSON data. I just can seem to get the button to make the actual post request.
php / html
// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) )
echo 'Hi there! I'm just a plugin, not much I can do when called directly.';
exit;
function postayge_front()
/* content variable */
$content = '';
$content .= '<div class="admin-quick-add">';
$content .= '<h3>Quick Add Post</h3>';
$content .= '<input type="text" name="title" placeholder="Title">';
$content .= '<textarea name="content" placeholder="Content"></textarea>';
$content .= '<button id="quick-add-button">Create Post</button>';
$content .= '</div>';
return $content;
add_shortcode('postayge','postayge_front');
/* Add scripts & styles */
function wp_postayge_adding_styles()
wp_register_style('postayge_style', plugins_url('main.css', __FILE__));
wp_enqueue_style('postayge_style');
wp_register_script('postayge_script', plugins_url('script.js', __FILE__));
wp_enqueue_script('postayge_script');
wp_localize_script('script.js', 'securityData', array(
'nonce' => wp_create_nonce('wp_rest')
));
add_action( 'wp_enqueue_scripts', 'wp_postayge_adding_styles' );
?>
js
//Quick add post AJAX
var quickAddButton = document.querySelector("#quick-add-button");
if (quickAddButton)
quickAddButton.addEventListener("click", function()
var postaygePostData =
"title": document.querySelector('.admin-quick-add[name="title"]').value,
"content": document.querySelector('.admin-quick-add[name="content"]').value,
"status": "publish"
var createPost = new XMLHttpRequest();
createPost.open("POST", "http://localhost:9000/wordpress/?rest_route=/wp/v2/posts");
createPost.setRequestHeader("X-WP-Nonce", securityData.nonce);
createPost.setRequestHeader("Content-Type", "applicaton/json;charset=UTF-8")
createPost.send(JSON.stringify(postaygePostData));
);
css
/** Quick Add Styles */
.admin-quick-add
background-color: inherit;
padding:15px;
margin-bottom: 15px;
.admin-quick-add input,
.admin-quick-add textarea
width: 100%;
border: none;
padding: 10px;
margin: 0 0 10px 0;
box-sizing: border-box;
wordpress api plugins
I am currently building a plugin for wordpress that is supposed to allow the user to create a new post from the front end of their site. When I click the Create Post button nothing happens. Please take a look at my code below:
the plugin uses a JavaScript function with pHp to make a POST request to the API. Iam working on a local server(MAMP) and do not currently use pretty permalinks so my url looks like this... http://localhost:9000/wordpress/?rest_route=/wp/v2/posts
which i have visited and seen the JSON data. I just can seem to get the button to make the actual post request.
php / html
// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) )
echo 'Hi there! I'm just a plugin, not much I can do when called directly.';
exit;
function postayge_front()
/* content variable */
$content = '';
$content .= '<div class="admin-quick-add">';
$content .= '<h3>Quick Add Post</h3>';
$content .= '<input type="text" name="title" placeholder="Title">';
$content .= '<textarea name="content" placeholder="Content"></textarea>';
$content .= '<button id="quick-add-button">Create Post</button>';
$content .= '</div>';
return $content;
add_shortcode('postayge','postayge_front');
/* Add scripts & styles */
function wp_postayge_adding_styles()
wp_register_style('postayge_style', plugins_url('main.css', __FILE__));
wp_enqueue_style('postayge_style');
wp_register_script('postayge_script', plugins_url('script.js', __FILE__));
wp_enqueue_script('postayge_script');
wp_localize_script('script.js', 'securityData', array(
'nonce' => wp_create_nonce('wp_rest')
));
add_action( 'wp_enqueue_scripts', 'wp_postayge_adding_styles' );
?>
js
//Quick add post AJAX
var quickAddButton = document.querySelector("#quick-add-button");
if (quickAddButton)
quickAddButton.addEventListener("click", function()
var postaygePostData =
"title": document.querySelector('.admin-quick-add[name="title"]').value,
"content": document.querySelector('.admin-quick-add[name="content"]').value,
"status": "publish"
var createPost = new XMLHttpRequest();
createPost.open("POST", "http://localhost:9000/wordpress/?rest_route=/wp/v2/posts");
createPost.setRequestHeader("X-WP-Nonce", securityData.nonce);
createPost.setRequestHeader("Content-Type", "applicaton/json;charset=UTF-8")
createPost.send(JSON.stringify(postaygePostData));
);
css
/** Quick Add Styles */
.admin-quick-add
background-color: inherit;
padding:15px;
margin-bottom: 15px;
.admin-quick-add input,
.admin-quick-add textarea
width: 100%;
border: none;
padding: 10px;
margin: 0 0 10px 0;
box-sizing: border-box;
wordpress api plugins
wordpress api plugins
asked Mar 24 at 21:57
Chris WoolfChris Woolf
14
14
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328964%2ffront-end-post-create-plugin-troubleshoot-api-post-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328964%2ffront-end-post-create-plugin-troubleshoot-api-post-request%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown