Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Guaraci WordPress Plugin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
Guaraci WordPress Plugin
Commits
e7fc202d
Commit
e7fc202d
authored
Apr 27, 2020
by
Rafael Chaves Freitas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds the guaraci namespace to the library/api.php file
parent
83a72b77
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
library/api.php
library/api.php
+7
-5
No files found.
library/api.php
View file @
e7fc202d
<?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
g
uaraci\g
et_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
=
g
uaraci\g
et_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'
=>
'g
uaraci\g
et_facebook_shares'
,
)
);
}
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment