Commit e7fc202d authored by Rafael Chaves Freitas's avatar Rafael Chaves Freitas

adds the guaraci namespace to the library/api.php file

parent 83a72b77
<?php
namespace guaraci;
require 'modules/facebook/index.php';
// Facebook
......@@ -14,7 +16,7 @@ function get_facebook_shares( $data ) {
$post_id = $data['post_id'];
if( guaraci\need_share_update( $post_id ) ) {
if( need_share_update( $post_id ) ) {
$response = wp_remote_get( add_query_arg( array(
//'id' => urlencode( get_permalink( $post_id ) ),
'id' => urlencode( 'https://www.google.com/' ),
......@@ -24,17 +26,17 @@ function get_facebook_shares( $data ) {
if ( !is_array($response) || is_wp_error( $response ) || $response['response']['code'] != 200){
return guaraci\get_post_shares( $post_id );
return get_post_shares( $post_id );
}
$body = json_decode( $response['body'] );
$count = intval( $body->engagement->share_count );
// Update post meta
guaraci\set_post_shares( $post_id, $count );
set_post_shares( $post_id, $count );
} else {
$count = guaraci\get_post_shares( $post_id );
$count = get_post_shares( $post_id );
}
......@@ -44,6 +46,6 @@ function get_facebook_shares( $data ) {
add_action( 'rest_api_init', function () {
register_rest_route( 'guaraci/facebook', '/shares/(?P<post_id>\d+)', array(
'methods' => 'GET',
'callback' => 'get_facebook_shares',
'callback' => 'guaraci\get_facebook_shares',
) );
} );
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment