Integrating Wordpress BuddyPress fully with QTranslate-XT - wordpress

I hope to receive some helpful pointers to solve an issue with BuddyPress and Qtranslate-XT plugins for Wordpress. I have tried to ask for help on GitHub (qtranslate-xt) and on the BuddyPress forums, but it seems there is little interest in making BuddyPress multilingual.
Groups, Group Types, and Member Profile fields do not register for language switching buttons of qtranslate-xt in the backend. I am an absolute novice concerning integrating a plugin with qtranslate-xt so and all my attempts to add respective filters to the respective i18n-config.json failed.
Thus, I have given up in this regard but would really appreciate some hints on how I could fix the one element that is not working on the frontend: directory listings of group and member types.
Instead of showing only the current language for a displaying the type, the directory listing (e.g. on ../members/type/test/) shows the entry in all languages with tags (e.g., [:en]Test[:de]Versuch[:], see screenshot).
Screenshot: BuddyPress failing to integrate with QTranslate-XT
The respective text is generated in the group or members loop via the functions bp_current_group_directory_type_message or bp_current_member_type_message. For example, see the entry in bp-members-template.php
`
function bp_get_current_member_type_message() {
$type_object = bp_get_member_type_object( bp_get_current_member_type() );
/* translators: %s: member type singular name */
$message = sprintf( __( 'Viewing members of the type: %s', 'buddypress' ), '<strong>' . $type_object->labels['singular_name'] . '</strong>' );
/**
* Filters the current member type message.
*
* #since 2.3.0
*
* #param string $message Message to filter.
*/
return apply_filters( 'bp_get_current_member_type_message', $message );
}
`
I have tried adding a matching filter into the i18n-config.json but it does not work.
`
{
"vendor": {
"plugins/buddypress": "1.0"
},
"front-config": {
"all-pages": {
"filters": {
"text": {
"bp_get_activity_action": "20",
"bp_get_activity_content_body": "20",
"bp_get_activity_content": "20",
"bp_get_current_member_type_message": "20"
}
}
}
}
}
`
If someone has any ideas how to solve this issue, would be much appreciated!

Related

A Webhook contact form for Discord in wordpress

So I'll start out by saying, that I am a bit new to this.
So I have this website I'm currently making. It's a guild website for World of Warcraft, and we want to be able to have new people being able to apply for membership.
Making the contact form is easy enough through plugins, but this is in theory what I wish to make:
A contact form where when filled in, the application form will push a notification to a webhook set in Discord where when new applicants happen, a message in a channel will be made, notifying the leaders about it.
Do I need to create a plugin myself, or is there any plugin that can offer this functionality?
I had the same needs, after sometime i found a way to do it.
Its actually very simple with WPForms.
WPForms has hooks so you can easily track forms submitions with the wpforms_process_complete hook. This hook allows you to track ALL WPForms sumbission. But maybe you'd like to have different forms. If you wish to track only a specific form, you can add the form id to the end of the hook name.
In my case i had many different forms which are being handled in various different ways, so i had to split them. When a form is being created in WPForms, it receives an ID so does the fields of the named form.
In my case after my form was created it had the following id :
The hook function.
As explained on the Discord Webhook page, Webhooks are a low-effort way to post messages to channels in Discord. They do not require a bot user or authentication to use. The endpoint supports both JSON and form data bodies. In my case i went for JSON.
As explained here you just need to use one of the the content file or embeds field. On this example i will just send a message, so i'll be using the content field.
Once the above instructions applied, you should end up with something close to the following function :
if ( ! function_exists( 'discord_form_submission' ) ) :
/**
* This will fire at the very end of a (successful) form entry.
*
* #link https://wpforms.com/developers/wpforms_process_complete/
*
* #param array $fields Sanitized entry field values/properties.
* #param array $entry Original $_POST global.
* #param array $form_data Form data and settings.
* #param int $entry_id Entry ID. Will return 0 if entry storage is disabled or using WPForms Lite.
*/
function discord_form_submission( $fields, $entry, $form_data, $entry_id )
{
// You have to replace this url by your discord webhook.
$endpoint = 'https://discord.com/api/webhooks/{webhook.id}/{webhook.token}';
// This is the content you can put anything you wish.
// In my case i needed the Name, Class, and the Level of the players.
$content = "**Name :** " . $fields[1]['value'] . PHP_EOL;
$content .= "**Class :** " . $fields[2]['value'] . PHP_EOL;
$content .= "**Level :** " . $fields[3]['value'] . PHP_EOL;
// WP has its own tool to send remote POST request, better use it.
wp_remote_post( $endpoint , [
'headers' => [
'Content-Type' => 'application/json; charset=utf-8'
],
'body' => wp_json_encode([ // Same for the JSON encode.
'content' => $content,
]),
'method' => 'POST',
'data_format' => 'body'
]);
}
endif;
This function must be added in the functions.php file of your theme.
Last but not least, with the help of the WP add_action Function you need to hook up with the wpforms_process_complete hook. In my case since i want to only hook up to the form with the id 1862 i have added the id at the end of the hook which gives us the following code :
add_action( 'wpforms_process_complete_1862', 'discord_form_submission', 10, 4 );
This code must be added in the functions.php file of your theme after our newly added function.

Woocommerce API Show orders updated after a certain date

I'm looking for a way to get a list of orders that are updated after a certain specified date. I'm using the Woocommerce REST API to access these orders. In the API docs I find there is a 'after' parameter on a GET call, but this only filters for orders published after a certain date, not updated.
Thanks a lot!
Updated Answer:
Add the following code in a custom plugin.
function modify_orders_after_query($request) {
$request['date_query'][0]['column'] = 'post_modified';
return $request;
}
add_filter( "woocommerce_rest_shop_order_query", 'modify_orders_after_query' );
Then you can make GET request to your API url, Something like this:
http://example.com/wp-json/wc/v1/orders?after=2016-10-10T10:10:10Z
Notice: Please test before using this method.
Legacy:
This can be achieved with updated_at_min.
Please check wp-content\plugins\woocommerce\includes\api\class-wc-api-resource.php: Line 157 and wp-content\plugins\woocommerce\includes\api\class-wc-api-orders.php: Line 723
I've managed to solve the problem using the tips from above. Added a folder with a file in plugin folder, with the same name and the following content:
<?php
/**
* Plugin Name: wooCommerceFilter
* Description: Change the ORDER API endpoint to consider date_modified.
* Version: 1.0
*/
function modify_orders_after_query($request) {
$request['date_query'][0]['column'] = 'post_modified';
return $request;
}
add_filter( "woocommerce_rest_orders_prepare_object_query", 'modify_orders_after_query' );
?>

How to change the default value (-Any-) of an exposed filter in Drupal Views, when using Hierarchical Select?

I've made a view with an exposed filter. This filter is taxonomy based, and I'm using Hierarchical Select as the widget because this taxonomy is deeply nested.
This question is greatly similar to:
How to change the label of the default value (-Any-) of an exposed filter in Drupal Views?
However, the poster of that question was not using HS, and so I cannot use the answers there, specifically this one: https://stackoverflow.com/a/5975294/443219
Where exactly should I place the '#options' key in the $form array when using hook_form_alter, to make this work? I've tried pasting the relevant line of code blindly in different places throughout the array, but I believe HS works a tad different to FAPI...
I have a horrible answer to this.
I changed line 402 in sites/all/modules/hierarchical_select/hs_taxonomy_views.module from:
$any_label = variable_get('views_exposed_filter_any_label', 'old_any') === 'old_any' ? '<'. t('Any') .'>' : '- '. t('Any') .' -';
to
$any_label = variable_get('views_exposed_filter_any_label', 'old_any') === 'old_any' ? 'Worldwide' : '- '. t('Any') .' -';
This works because: in this site, I need the filter on only view - and nowhere else.
This can never be a general solution because:
The unholy sin of hacking the core of a module will haunt me forever because I cannot ever use drush to update this module again.
If I ever make another view in this site, and decide to have a hs taxonomy exposed filter, it's "Any" option will be displayed as "Worldwide", even if there is no such context: weird.
I would greatly appreciate if anyone can point me in a direction that will allow me to solve this cleanly. But I'm going with my hack for now.
You can use following code any drupal module. this will work.
/**
* hook_views_pre_view
* #param type $view
* #param type $display_id
* #param type $args
*/
function MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'VIEW_NAME') {
$filters = $view->display_handler->get_option('filters');
$view->display_handler->override_option('filters', $filters);
}
}
/**
* hook__views_pre_build
* #param type $view
* #return type
*/
function MODULE_NAME_views_pre_build($view) {
if ($view->name=='VIEW_NAME') {
$view->display['page']->handler->handlers['filter']['filter_field']->value['value'] = 8;
return $view;
}
}

Facing problems in creating video library using Brightcove Media API

I am facing a problem related to making a video library on my Drupal website using brightcove media API . Can someone please tell me how do I pull out the details of author, date posted and details about the video which I need to display along with the video on my page. I have somehow managed to display the video on my page but I am still struggling with pulling out other details and displaying it along with my video on the page. For your information, I am working in Drupal 6. Can someone please help me out with this??
You might want to check out the following helpful links:
http://opensource.brightcove.com/project/PHP-MAPI-Wrapper/
http://developer.brightcove.com/en/documentation
I'm not sure I understand what you mean by "author", Brightcove currently does not track audit trail type info. For example you cannot query who uploaded the video. Only metadata that belongs to the video.
Assuming "Author" is a custom field, you can obtain that info by doing a call something like:
/**
* function custom_search() - search specified field for given value
* #param string [$term] - Required. The value to search for.
* #param string [$criteria] - any, all, or none. Default: any.
* #param string [$search_field] - Specify the field to look for the search term in. Default: search_text.
*/
/** Available search fields: display_name, reference_id, tag, custom_fields, search_text.
* Using search_text is the equivalent of searching displayName, shortDescription and longDescription fields
* and is also the same as omitting the field name altogether
*/
function custom_search($term, $criteria = 'any', $search_field = 'search_text') {
$bc = create_bcmapi();
$params = array(
'video_fields' => 'id,name,shortDescription,referenceId,tags,custom_fields'
);
$terms = array($criteria => $search_field.':'.$term);
$data['videos'] = $bc->search('video', $terms, $params);
return $data;
}
Sorry this is late, but maybe it will help someone else.

Easiest way to hide (some) WordPress plugins from users?

I'm using WordPress to make my users make their own website/blog. I have a set up that I'm cloning out to all the users with some special user-roles and standard plugins.
However, some of the plugins are not supposed to be changed or inactivated by the users.
Is their any way to select which plugins different user roles are allowed to use? Or a easy way to hide some plugins in the plugins-page but still have them working as normal?
Maybe there's some plugin that helps me to do this?
You could write a plugin that uses the "all_plugins" filter hook to remove from the array plugins that you don't want displaying for a certain user. Something like this:
$plugin_credentials = array(
'bob' => array(
'Hello Dolly' => 1
),
'jim' => array(
'Akismet' => 1,
'Hello Dolly' => 1,
),
'admin' => "**ALL**"
);
function plugin_permissions($plugins)
{
global $current_user, $plugin_credentials;
$username = $current_user->user_login;
if ($plugin_credentials[$username] == "**ALL**")
return $plugins;
$viewable_plugins = array();
foreach ($plugins as $plugin) {
if (isset($plugin_credentials[$username]) &&
isset($plugin_credentials[$username][$plugin['Name']]) &&
$plugin_credentials[$username][$plugin['Name']] == 1) {
array_push($viewable_plugins, $plugin);
}
}
return $viewable_plugins;
}
add_filter('all_plugins', 'plugin_permissions');
Managing the user permissions in the plugin itself is not ideal, but it is probably easiest. You can expand on that idea to create admin pages for managing the users and their viewable plugins in a database table somewhere.
Each plugin will usually specify their own role/permission, which you can see if you look at their add_submenu_page() or such function calls. You can create new roles for those plugins and replace the one specified by the author, but it will also break the changes if you upgrade the plugins.
You should stratify the users. Make sure that the Admin user(s) are trusted and know not to fiddle with what they don't understand. The others should be limited to their roles. Authors, editors, etc. For example, if they're just a part of the site to write articles, then they don't need to see the rest of it. Make them an author and be done with it.
This is part of client education. If its a smaller client with less stratified roles, then make them two accounts. Tell them "this is the account you administer the site with, you'll be using this rarely. And this is the account that you'll use most of the time to write and edit. You can do all of your daily tasks here and will most likely never need the administrator account". You won't always have luck with this approach, but its less time and effort invested in crap you shouldn't be wasting time on.
I've done a new version based on #spuriousdata Answer. This one uses the plugin slugs (file name minus the extension) to build the list of restrictions. This way is easier as we can unset the array using the first level $keys.
Configuration instructions in the code itself.
<?php
/**
* Plugin Name: Limit Plugins by User
* Plugin URI: http://stackoverflow.com/q/14340131/1287812
* Description: Show selected plugins for specific users.
* Based on the code by spuriousdata, http://stackoverflow.com/a/3713985.
* Author: brasofilo
* Author URI: http://wordpress.stackexchange.com/users/12615/brasofilo
* Version: 1.0
* License: GPLv2 or later
*/
add_filter( 'all_plugins', 'plugin_permissions_so_3707134' );
/**
* Filter the list of plugins according to user_login
*
* Usage: configure the variable $plugin_credentials, which holds a list of users and their plugins.
* To give full access, put a simple string "ALL"
* To grant only for some plugins, create an array with the Plugin Slug,
* which is the file name without extension (akismet.php, hello.php)
*
* #return array List of plugins
*/
function plugin_permissions_so_3707134( $plugins )
{
// Config
$plugin_credentials = array(
'admin' => "ALL",
'other-admin' => array(
'akismet',
),
'another-admin' => array(
'akismet',
'hello',
),
);
// Current user
global $current_user;
$username = $current_user->user_login;
// Super admin, return everything
if ( "ALL" == $plugin_credentials[ $username ] )
return $plugins;
// Filter the plugins of the user
foreach ( $plugins as $key => $value )
{
// Get the file name minus extension
$plugin_slug = basename( $key, '.php' );
// If not in the list of allowed plugins, remove from array
if( !in_array( $plugin_slug, $plugin_credentials[ $username ] ) )
unset( $plugins[ $key ] );
}
return $plugins;
}

Resources