i want simple-jwt-login plugin a function to generate jwt.
then i control user login in my custom endpoint and return this jwt if user logged in with mobile and otp successfully.
(mobile number is stored in usermeta. like digits plugin. i mean that no email or password is required to login.)
i also provide bellow ways to login:
– login with mobile number and otp.
– login with username and password.
– login with email and password.
function check_warranty()
{
echo 'please code here';
}
add_shortcode('check_warranty', 'check_warranty');
In my account page, I added a custom tab using this code:
add_action( 'init', 'register_new_item_endpoint');
function register_new_item_endpoint() {
add_rewrite_endpoint( 'warranty-check', EP_ROOT | EP_PAGES );
}
add_filter( 'query_vars', 'new_item_query_vars' );
function new_item_query_vars( $vars ) {
$vars[] = 'warranty-check';
return $vars;
}
add_filter( 'woocommerce_account_menu_items', 'add_new_item_tab' );
function add_new_item_tab( $items ) {
$items['warranty-check'] = 'Warranty Check';
return $items;
}
add_action( 'woocommerce_account_warranty-check_endpoint', 'add_new_item_content' );
function add_new_item_content() {
echo do_shortcode( ' [check_warranty] ' );
}
I created a page with slug “warranty-check” and I put in the shortcode:
[check_warranty]
In My Account page, when I click on “Warranty Check” tab, is loaded the page created, without my account left sidebar.
What am I doing wrong?
Thank you.
First of all, thank-you for this awesome plugin. I love it. I am using JSON API Plus plugin to have additional endpoints, because this is a plugin I have a custom route for this so it doesn’t interfere with the default wordpress routes. Here is what my custom routes look like:
https://mysite/api/${endpoint}
https://mysite/api/get_recent_posts/ -> returns recent posts
I have NO intention on using any of the default WordPress routes (wp-json/…), I am a bit confused on how I can add https://mysite/api/get_recent_posts/ to the rest api cache. I have tried changing route prefix and other things with no avail. Is there a simple way I can do this with a callback / function?
Any help would be very much appreciated.
]]>"acf_photo_gallery": [
{
"id": 82,
"title": "2018-07_large-yard-landscape-designers-daybreak",
"caption": "",
"full_image_url": "https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-scaled.jpg",
"thumbnail_image_url": "https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-150x150.jpg",
"large_srcset": "https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-1024x768.jpg 1024w, https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-300x225.jpg 300w, https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-768x576.jpg 768w, https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-1536x1152.jpg 1536w, https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-2048x1536.jpg 2048w",
"medium_srcset": "https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-300x225.jpg 300w, https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-1024x768.jpg 1024w, https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-768x576.jpg 768w, https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-1536x1152.jpg 1536w, https://olson-landscaping.local/wp-content/uploads/2020/04/2018-07_large-yard-landscape-designers-daybreak-2048x1536.jpg 2048w",
"url": "",
"target": ""
},
{
"id": 84,
"title": "647a097e8b23088f485a848284dae811",
"caption": "",
"full_image_url": "https://olson-landscaping.local/wp-content/uploads/2020/04/647a097e8b23088f485a848284dae811.jpg",
"thumbnail_image_url": "https://olson-landscaping.local/wp-content/uploads/2020/04/647a097e8b23088f485a848284dae811-150x150.jpg",
"large_srcset": "https://olson-landscaping.local/wp-content/uploads/2020/04/647a097e8b23088f485a848284dae811.jpg 1024w, https://olson-landscaping.local/wp-content/uploads/2020/04/647a097e8b23088f485a848284dae811-300x240.jpg 300w, https://olson-landscaping.local/wp-content/uploads/2020/04/647a097e8b23088f485a848284dae811-768x614.jpg 768w",
"medium_srcset": "https://olson-landscaping.local/wp-content/uploads/2020/04/647a097e8b23088f485a848284dae811-300x240.jpg 300w, https://olson-landscaping.local/wp-content/uploads/2020/04/647a097e8b23088f485a848284dae811-768x614.jpg 768w, https://olson-landscaping.local/wp-content/uploads/2020/04/647a097e8b23088f485a848284dae811.jpg 1024w",
"url": "",
"target": ""
},
{
"id": 85,
"title": "landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059",
"caption": "",
"full_image_url": "https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059.jpg",
"thumbnail_image_url": "https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-150x150.jpg",
"large_srcset": "https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-1024x682.jpg 1024w, https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-300x200.jpg 300w, https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-768x512.jpg 768w, https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-1536x1024.jpg 1536w, https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-2048x1365.jpg 2048w",
"medium_srcset": "https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-300x200.jpg 300w, https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-1024x682.jpg 1024w, https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-768x512.jpg 768w, https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-1536x1024.jpg 1536w, https://olson-landscaping.local/wp-content/uploads/2020/04/landscape-curb-appeal-retina_retina_f09021ca6edac80b70f3a5b5092c4059-2048x1365.jpg 2048w",
"url": "",
"target": ""
}
],
and i am trying to return it through a template literal with jquery, where everything else is pulling correctly except for this gallery section, which seems to always come back undefined or breaks my code. I am using
${item.acf_photo_gallery.full_image_url}
Here is my code through the functions.php file to add the endpoint as well:
$post_type = "project";
function my_rest_prepare_post($data, $post, $request) {
$_data = $data->data;
$fields = get_fields($post->ID);
foreach ($fields as $key => $value) {
$_data[$key] = get_field($key, $post->ID);
}
//The helper function acf_photo_gallery contains array. Append this array to your data array
$_data['acf_photo_gallery'] = acf_photo_gallery('gallery', $post->ID);
$data->data = $_data;
return $data;
}
add_filter("rest_prepare_{$post_type}", 'my_rest_prepare_post', 10, 3);
]]>First thanks for your plugin!
I have problem with your plugin when I activate it, it crushes my custom woocommerce API endpoint. It throws: “Critical error on your site”. I tried to turn on debugging but nothing is logged, also i go through the Nginx error logs, nothing is there too.
What could be the problem or how can I tell swift to do not touch that endpoint?
the endpoint is: wp-json/devlent/products
Kind regards,
Tomislav.
First I wanna thank you for this amazing plugin! I’ve been using it on couple of websites and it working just fine, but this is first time i had problem with it.
I created custom endpoint rest API for woocommerce using register_rest_route();
And it’s working great.
But after activating the plugin it crushes my endpoint. When I try to access my endpoint it throws “critical error on your site”. After deactivating the plugin it works again.
What could be the problem here?
And how can I resolve this?
Kind regards,
Tomislav.
I’m able to retrieve all the posts of the site, but I’d like to retrieve, in a similar way, the objects created by a third-party plugin.
Thank you very much
cld
]]>I’m using ACF with ACF Photo Gallery Field.
I would like to output the data from ACF Photo Gallery Field to REST API but get an empty array in postman.
My code is:
function albums_endpoint( $request_data ) {
// setup query argument
$args = array(
‘post_type’ => ‘albums’,
‘posts_per_page’=>-1,
‘numberposts’=>-1
);
// get posts
$posts = get_posts($args);
// add custom field data to posts array
foreach ($posts as $key => $post) {
$posts[$key]->acf = get_fields($post->ID);
$posts[$key]->link = get_permalink($post->ID);
$posts[$key]->image = get_the_post_thumbnail_url($post->ID);
$posts[$key]->gallery = acf_photo_gallery(‘ACF_FIELD_NAME’, $post->ID);
}
return $posts;
}
// register the endpoint
add_action( ‘rest_api_init’, function () {
register_rest_route( ‘albums/v1’, ‘/albums/’, array(
‘methods’ => ‘GET’,
‘callback’ => ‘albums_endpoint’,
)
);
});
Api output ==
[
{
“ID”: 33,
“post_author”: “1”,
“post_date”: “2019-01-05 18:45:06”,
“post_date_gmt”: “2019-01-05 18:45:06”,
“post_content”: “”,
“post_title”: “The first test album”,
“post_excerpt”: “”,
“post_status”: “publish”,
“comment_status”: “closed”,
“ping_status”: “closed”,
“post_password”: “”,
“post_name”: “brouillon-auto”,
“to_ping”: “”,
“pinged”: “”,
“post_modified”: “2019-01-05 20:39:26”,
“post_modified_gmt”: “2019-01-05 20:39:26”,
“post_content_filtered”: “”,
“post_parent”: 0,
“guid”: “https://gyuto.local/?post_type=albums&p=33”,
“menu_order”: 0,
“post_type”: “albums”,
“post_mime_type”: “”,
“comment_count”: “0”,
“filter”: “raw”,
“acf”: {
“album_title”: “The first test album”
},
“link”: “https://gyuto.local/albums/brouillon-auto/”,
“image”: false,
“gallery”: []
}
]
How can I solve this and get the gallery field to display?
]]>{
"code": "rest_no_route",
"message": "No route was found matching the URL and request method",
"data": {
"status": 404
}
}
Even the htaccess files in local installation and the server look identical. The plugin file look like this:
/*Function to get directory URL*/
function getContentUrl()
{
return WP_CONTENT_URL."/uploads/avatars/";
}
/*Function to get directory local path*/
function getContentDirectory(){
return WP_CONTENT_DIR."/uploads/avatars/";
}
/*Initializing Rest API Endpoint*/
add_action('rest_api_init',function(){
/*--Avatar Change Custom API--*/
register_rest_route('custom/v1', '/avatarchange/',array(
'methods' => 'POST',
'callback' => 'changeAvatar',
'args' => array(
'userid' => array(),
'fname' => array(),
'lname' => array(),
'image' => array(),
),
'permission_callback' => function(){
//return current_user_can( 'read' );
return true;
}
));
/*--Get Userid from Email Custom API--*/
register_rest_route('custom/v1', '/getuid/',array(
'methods' => 'POST',
'callback' => 'getUidFromEmail',
'args' => array(
'email' => array(),
),
'permission_callback' => function(){
return current_user_can( 'read' );
}
));
});
]]>