Advertisement
kespinoza

Untitled

Feb 24th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: AppPresser Metiza API code
  4. Plugin URI: http://apppresser.com
  5. Description: How to manipulate the WP-API for your app.
  6. Version: 0.1
  7. Author: AppPresser Team
  8. Author URI: http://apppresser.com
  9. License: GPLv2
  10. */
  11.  
  12. /*
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  26. */
  27.  
  28. if ( ! defined( 'ABSPATH' ) ) {
  29. exit; // Exit if accessed directly
  30. }
  31.  
  32.  
  33. /****************************************************************************************
  34. * How to use an AppPresser template hook
  35. ****************************************************************************************/
  36.  
  37. add_action( 'rest_api_init', 'appp_register_template_hook' );
  38. function appp_register_template_hook() {
  39. register_rest_field( 'post', // any post type registered with API
  40. 'appp',
  41. array(
  42. 'get_callback' => 'appp_get_hook_data',
  43. 'update_callback' => null,
  44. 'schema' => null,
  45. )
  46. );
  47. }
  48.  
  49.  
  50. /**
  51. * Get the value of a meta field field
  52. *
  53. * @param array $object Details of current post.
  54. * @param string $field_name Name of field.
  55. * @param WP_REST_Request $request Current request
  56. *
  57. * @return mixed
  58. */
  59. function appp_get_hook_data( $object, $field_name, $request ) {
  60.  
  61. $data = [];
  62.  
  63. $data['post_list']['above_title'] = '<span class="date">' . get_post_meta( $object['id'], 'date', true) . '</span>';
  64.  
  65. $data['post_detail']['above_title'] = '<div class="post-featured-wrap">' . get_the_post_thumbnail( $object['id'], 'large', array( 'class' => 'post-featured' ) ) . '</div>';
  66. return $data;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement