Problem :
Simple test :
response=requests.get('https://wordpress.site/wp-json/wc/v3/products/attributes',headers=hdr,
auth=requests.auth.HTTPBasicAuth('login', 'password'))
But for any reason I received a 403 command.
Same command with curl works :
curl -vvvv -u login:password https://wordpress.site/wp-json/wc/v3/products/attributes
Well…
Solution :
Simple, but don't know why.
Default user agent for Python :
User-Agent: python-requests/2.28.1
Default user agent for curl
user-agent: curl/7.86.0
Well it works with (add a space before the /) :
User-Agent: python-requests /2.28.1
Still a mystery. Not from python side, maybe from planethoster.com side or wordpress ? One day, I will have time to go further…
Lire la suite de Wordpress API refuse python rest request
Problem :
A wordpress site with OceanWP theme, Woocommerce plugin.
The requirement was to have 3 parts in the website :
- Each parts has a different menu
- Each parts has a different colors for menu and header
With OceanWP, you can set for each page : menu, custom header, colors...
A bit tedious to maintain from my point of view, but works, except for Woocommerce pages, especially categories.
Solution :
As everything in wordpress works with extensions, even OceanWP andWoocommerce have their own set of paid extensions... A world of business here (as 50% of the websites run wordpress...). Paid extension could be really usefull in some cases, for my simple task, I simply do it like that :
- Export OceanWP parameters
- Create a child theme of OceanWP and activate it
- Import OceanWP parameters
- Advantages :
- You can copy / paste of the parent theme in the child theme to modify it
- You can add custom functions
- Here is the main part, as OceanWP is very customizable (to authorize paid plugins), they already have a lot of hook ready
- ocean_custom_header_template : a hook to select the template
- ocean_custom_menu : a hook to select the menu
Adding hook to select the right theme for Woocommerce page :
function my_custom_header_function($template) {
$result=$template;
if ( is_shop() || is_product() || is_product_category() ) {
if ('<name-of-my-slug>' == get_queried_object()->slug) {
// Exception for one category
// We have created custom OceanWP header in OceanWP Theme Library, here is the ID (shown in the URL when editing the custom header)
$result=10849;
} else {
// All others categories have another header
$result=10244;
}
}
return $result;
}
add_filter( 'ocean_custom_header_template', 'my_custom_header_function' );
And for the menu :
function my_custom_menu($menu) {
if ( is_shop() || is_product() || is_product_category() ) {
if ('<name-of-my-slug>' != get_queried_object()->slug) {
// Except for one category, I return the custom menu to display
return '493';
}
}
return $menu;
}
add_filter( 'ocean_custom_menu', 'my_custom_menu');
Well, done, not perfect but done thanks to OceanWP possible customization and Wordpress ecosystem of paid plugins.
Could be done :
- Suggest a pull request to OceanWP with an GUI to select the custom header/menu for a given slug
- Select the custom header in a list instead of putting direct ID...
But no time today !
And I tried a mix of extensions :
But as everything, they are designed to work for a given use case and OceanWP+Woocommerce for categories was not in the scope.