Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorSTM committed Jul 6, 2018
1 parent efe9bb9 commit 0ab08a8
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apirest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* @package APIREST
*/
/*
Plugin Name: APIREST WordCamp Sevilla 2018
Description: configurador de APIREST WordPress para WordCamp Sevilla 2018
Version: 0.0.5
Author: Víctor Sáenz & Paco Marchante
Author URI: http://www.mowomo.com
License: GPL2
*/

/* Copyright 2018 Víctor Sáenz (email : victor@mowomo.com) Paco Marchante (email : paco@mowomo.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/


define( 'APIREST', '0.0.5' );
define( 'APIREST__MINIMUM_WP_VERSION', '4.0' );
define( 'APIREST__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
//define( 'AKISMET_DELETE_LIMIT', 100000 );

require_once( APIREST__PLUGIN_DIR . 'funciones_propias.php' );

?>
58 changes: 58 additions & 0 deletions funciones-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

//CallBacks

function listar_noticias(){

$listado_noticias = array();

$args = array(
'numberposts' => 10
);
$posts_array = get_posts( $args );

foreach ($posts_array as $entrada){
array_push($listado_noticias,[
'ID' => $entrada -> ID,
'fechaEntrada' => $entrada ->post_date,
'tituloEntrada' => $entrada ->post_title,
'tituloExtracto' => $entrada ->post_excerpt,
'nombreAutor' => get_author_name( $entrada -> post_author),
]);
}
return $listado_noticias;

}

function noticia_por_id($data){

$datosNoticia=array();
$noticia=get_post($data['id']);

$datosNoticia=[
'fechaEntrada' => $noticia ->post_date,
'tituloEntrada' => $noticia ->post_title,
'extractoEntrada' => $noticia ->post_excerpt,
'nombreAutor' => get_author_name( $noticia -> post_author),
'avatarURL' => get_avatar_url( $noticia -> post_author ),
];

return $datosNoticia;
}



// Creamos los custom endpoints
add_action( 'rest_api_init', function () {
register_rest_route( 'wordapp/v1', '/noticias', array(
'methods' => 'GET',
'callback' => 'listar_noticias',
) );
register_rest_route( 'WordAPP/v1', '/noticia/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'noticia_por_id',
) );

} );

?>
5 changes: 5 additions & 0 deletions funciones_propias.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
//Funciones Genericas
require_once (APIREST__PLUGIN_DIR . '/functions.php');

require_once (APIREST__PLUGIN_DIR . '/funciones-api.php');
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php

0 comments on commit 0ab08a8

Please sign in to comment.