Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Wpct Http Bridge
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
codeccoop
WordPress
plugins
Wpct Http Bridge
Commits
4b6b30c9
Commit
4b6b30c9
authored
1 year ago
by
Dani Quilez
Browse files
Options
Downloads
Patches
Plain Diff
change odoo post using native wp_post
parent
796bc6f9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/api-utils.php
+14
-30
14 additions, 30 deletions
includes/api-utils.php
includes/options-page.php
+25
-0
25 additions, 0 deletions
includes/options-page.php
with
39 additions
and
30 deletions
includes/api-utils.php
+
14
−
30
View file @
4b6b30c9
<?php
<?php
function
wpct_oc_post_odoo
(
$data
,
$endpoint
)
{
function
wpct_oc_post_odoo
(
$data
,
$endpoint
)
{
$post_data
=
json_encode
(
$data
);
$post_url
=
wpct_oc_get_odoo_base_url
()
.
$endpoint
;
$post_url
=
wpct_oc_get_odoo_base_url
()
.
$endpoint
;
// Prepare new cURL resource
$post_data
=
json_encode
(
$data
);
$crl
=
curl_init
();
$args
=
array
(
curl_setopt
(
$crl
,
CURLOPT_URL
,
$post_url
);
'headers'
=>
array
(
curl_setopt
(
$crl
,
CURLOPT_RETURNTRANSFER
,
true
);
'Content-Type'
=>
'application/json'
,
curl_setopt
(
$crl
,
CURLINFO_HEADER_OUT
,
true
);
'Connection'
=>
'keep-alive'
,
curl_setopt
(
$crl
,
CURLOPT_POST
,
true
);
'accept'
=>
'application/json'
,
curl_setopt
(
$crl
,
CURLOPT_POSTFIELDS
,
$post_data
);
'API-KEY'
=>
wpct_oc_get_api_key
()
// Set HTTP Header for POST request
),
curl_setopt
(
$crl
,
CURLOPT_HTTPHEADER
,
'body'
=>
$post_data
array
(
'Content-Type: application/json'
,
'Connection: keep-alive'
,
'accept: application/json'
,
'API-KEY: '
.
wpct_oc_get_api_key
()
)
);
);
// Submit the POST request
$response
=
wp_remote_post
(
$post_url
,
$args
);
$result
=
curl_exec
(
$crl
);
if
(
!
is_wp_error
(
$response
)
)
{
$success
=
true
;
return
$response
;
// handle curl error
if
(
$result
===
false
)
{
$success
=
false
;
}
// handle http error code
if
(
$success
){
$response
=
curl_getinfo
(
$crl
,
CURLINFO_HTTP_CODE
);
if
(
$response
!=
200
)
$success
=
false
;
}
}
curl_close
(
$crl
);
return
false
;
if
(
$success
)
return
json_decode
(
$result
,
true
);
return
$success
;
}
}
This diff is collapsed.
Click to expand it.
includes/options-page.php
+
25
−
0
View file @
4b6b30c9
...
@@ -73,6 +73,23 @@ function wpct_oc_settings_init(){
...
@@ -73,6 +73,23 @@ function wpct_oc_settings_init(){
'wpct_oc_options'
,
'wpct_oc_options'
,
'wpct_oc_api_settings'
'wpct_oc_api_settings'
);
);
// Admin notification receiver
register_setting
(
'wpct_oc_options'
,
'wpct_oc_admin_notification_receiver'
,
array
(
'type'
=>
'string'
,
'description'
=>
'Admin notification receiver'
,
'show_in_rest'
=>
false
,
)
);
add_settings_field
(
'wpct_oc_admin_notification_receiver'
,
__
(
'Admin notification receiver'
,
'wpct_odoo_connect'
),
'wpct_oc_admin_notification_receiver_render'
,
'wpct_oc_options'
,
'wpct_oc_api_settings'
);
}
}
/**
/**
...
@@ -86,6 +103,10 @@ function wpct_oc_odoo_base_url_render(){
...
@@ -86,6 +103,10 @@ function wpct_oc_odoo_base_url_render(){
function
wpct_oc_api_key_render
(){
function
wpct_oc_api_key_render
(){
echo
"<input type='text' name='wpct_oc_api_key' value='"
.
wpct_oc_get_api_key
()
.
"'> "
;
echo
"<input type='text' name='wpct_oc_api_key' value='"
.
wpct_oc_get_api_key
()
.
"'> "
;
}
}
// Admin notification receiver
function
wpct_oc_admin_notification_receiver_render
(){
echo
"<input type='text' name='wpct_oc_admin_notification_receiver' value='"
.
wpct_oc_get_admin_notification_receiver
()
.
"'> "
;
}
/**
/**
...
@@ -106,3 +127,7 @@ function wpct_oc_get_odoo_base_url(){
...
@@ -106,3 +127,7 @@ function wpct_oc_get_odoo_base_url(){
function
wpct_oc_get_api_key
(){
function
wpct_oc_get_api_key
(){
return
get_option
(
'wpct_oc_api_key'
)
?
get_option
(
'wpct_oc_api_key'
)
:
''
;
return
get_option
(
'wpct_oc_api_key'
)
?
get_option
(
'wpct_oc_api_key'
)
:
''
;
}
}
// Admin notification receiver
function
wpct_oc_get_admin_notification_receiver
(){
return
get_option
(
'wpct_oc_admin_notification_receiver'
)
?
get_option
(
'wpct_oc_admin_notification_receiver'
)
:
''
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment