Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: AppPresser Metiza API code
- Plugin URI: http://apppresser.com
- Description: How to manipulate the WP-API for your app.
- Version: 0.1
- Author: AppPresser Team
- Author URI: http://apppresser.com
- License: GPLv2
- */
- /*
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly
- }
- /****************************************************************************************
- * How to use an AppPresser template hook
- ****************************************************************************************/
- add_action( 'rest_api_init', 'appp_register_template_hook' );
- function appp_register_template_hook() {
- register_rest_field( 'post', // any post type registered with API
- 'appp',
- array(
- 'get_callback' => 'appp_get_hook_data',
- 'update_callback' => null,
- 'schema' => null,
- )
- );
- }
- /**
- * Get the value of a meta field field
- *
- * @param array $object Details of current post.
- * @param string $field_name Name of field.
- * @param WP_REST_Request $request Current request
- *
- * @return mixed
- */
- function appp_get_hook_data( $object, $field_name, $request ) {
- $data = [];
- $data['post_list']['above_title'] = '<span class="date">' . get_post_meta( $object['id'], 'date', true) . '</span>';
- $data['post_detail']['above_title'] = '<div class="post-featured-wrap">' . get_the_post_thumbnail( $object['id'], 'large', array( 'class' => 'post-featured' ) ) . '</div>';
- return $data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement