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
/* | |
* Applies to: since WP-AppKit 0.1 | |
* Goal: Use wpak_post_data to add post terms to the web service response and display them in app | |
You may want to look at https://codex.wordpress.org/Function_Reference/wp_get_post_terms | |
* Usage: WordPress: in the app's theme PHP folder or a separate plugin. | |
* App: single.html or archive.html | |
*/ | |
add_filter( 'wpak_post_data', 'add_terms_to_my_app_posts', 10, 3 ); | |
function add_terms_to_my_app_posts ( $post_data, $post, $component ) { | |
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
/** | |
* WP-AppKit User Authentication API example: | |
* example of how to build a secured file download link. | |
* | |
* For example in your app theme's functions.js : | |
*/ | |
/** | |
* Builds a secured download link | |
* |
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
//In app's theme (functions.js) | |
/** | |
The following allows to create a custom screen on app side only | |
(meaning it does not correspond to an existing WordPress page or post). | |
In this example, the page is accessed at the "url" #my-page-route and | |
uses the template 'my-page-template' to render. Last arguments allows to pass | |
custom data to the template. | |
*/ | |
App.addCustomRoute( 'my-page-route', 'my-page-template', { some_data : 'for the template' } ); |
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
/** | |
Use a custom 'archive-my-category.html' template only for the | |
'my-category' category post list : | |
*/ | |
App.filter( 'template', function( template, current_screen ) { | |
if ( TemplateTags.isCategory( 'my-category', current_screen ) ) { | |
template = 'archive-my-category'; //Don't need .html here. | |
} | |
return template; | |
} ); |
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
//In theme's functions.js | |
/** | |
Use a custom 'my-component-template.html' template only for the | |
'my-component-slug' component : | |
*/ | |
App.filter( 'template', function( template, current_screen ) { | |
if ( current_screen.component_id == 'my-component-slug' ) { | |
template = 'my-component-template'; //Don't need .html here. |
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
add_filter( 'wpak_posts_list_posts_per_page', 'wpak_set_nb_posts', 10, 2 ); | |
function wpak_set_nb_posts( $nb_items, $component ) { | |
//Check component slug to apply only to some of the "post list" components: | |
//(don't do this check to apply to all "post list" components) | |
if ( $component->slug === 'my-component-slug' ) { | |
$nb_items = 100; //Post number you want | |
} | |
return $nb_items; |
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
/** | |
* WP-AppKit has no webservice dedicated to data update yet (this is one of the things on our roadmap). | |
* The now native WP Rest API can be used to achieve that by implementing your own ajax calls to the Rest API | |
* that you would call manually from your WP-AppKit app. | |
* But if you want to stay within WP-AppKit possibilities, you can use the WP-AppKit's "liveQuery" web service | |
* which is designed to retrieve custom content from server but can also work to update data. | |
* | |
* The example here shows how to update a post meta from the app, but it can be transposed to update any WordPress data. | |
* Note: Sent data is not secured here. If you're on https, it's ok. If not, just be aware that the data sent is not encrypted, | |
* just like when you submit a form on a non https website. |
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
/** | |
* WP-AppKit has no webservice dedicated to data update yet (this is one of the things on our roadmap). | |
* For now a workaround is to used the "liveQuery" webservice that was designed to retrieve custom | |
* content from server but can also work to update data. | |
* | |
* The example here shows how to use liveQuery to send data from the app to the server | |
* and handle this data on server side. | |
* | |
* The App.liveQuery() webservice used here is pretty convenient to handle any custom request from app to server. | |
* We haven't found time to write doc about it yet but we have hope it will come soon ;) |
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
<?php | |
// Write the following in a WP plugin of yours | |
// or in the php directory of your WP-AppKit theme. | |
/** | |
* For this example we use the "wpak_posts_list_query_args" hook | |
* to customize the query to sort the posts of our | |
* "my-component-slug" component by alphabetical order. | |
* | |
* Internally the component's query is a WP_Query object: see |