i use the plugin Front End PM
https://he.wordpress.org/plugins/front-end-pm/
And i wonder how can i make an private message throw the PHP code and not as a frontend user , i search all over here and the docs of the plugin and i found out that there is a function call 'fep_save_message' , but with no success on it...
can someone help ? , if you know other plugin that can help me throw code send a private message i want to know .
Thanks :) !
In last project we use BuddyPress and BuddyPress private message https://buddypress.org/about/private-messaging/ this work very nice.
You may try use https://wordpress.org/plugins/wp-recall/ but this is add not only PW.
You can use fep_send_message() function to send message. It supports directly post data or you can pass data as argument.
Example
$message = array(
'message_title' => 'Title of your message',
'message_content' => 'Content of your message',
'message_to_id' => 123, //Receiver id
);
$message_id = fep_send_message( $message );
Related
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.
I am trying to change the user activation email message in the above.
Searched and read lots of links which dont seem to be relevant to the new version.
The issue I have, is for some users, the activation link doesnt work correctly, and they are asked to input their activation key on the page they are directed to.
My fix at the moment (if i can get it working, ill change the fix to hook into the relevant action instead) involvs changing the 'bp-core-functions.php' file, modifying the messages to include a reference to the actual key, that the user can copy and paste if need be.
'core-user-registration' => array(
/* translators: do not remove {} brackets or translate its contents. */
'post_title' => __( '[{{{site.name}}}] Activate your account', 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_content' => __( "Thanks for registering!\n\nTo complete the activation of your account, go to the following link: {{{activate.url}}}. Or enter the following key if prompted: {{{key}}}", 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_excerpt' => __( "Thanks for registering!\n\nTo complete the activation of your account, go to the following link: {{{activate.url}}}. Or enter the following key if prompted: {{{key}}}", 'buddypress' ),
),
Ive also changed the same messages in the .pot file....just because the messages are also located within their...just to try to get this change to kick in.
Its not working. Anyone have any idea how i can change the activation related message that is sent to users?
thanks
Shaun
Try this code.
// Get the slug of the activation page
$slug = $bp->pages->{"activate"}->slug;
// Get username from the signup form just posted
$username = $bp->signup->username;
// SQL query to get activation key for that username
$sql = 'select meta_value from wp_usermeta where meta_key="activation_key" and user_id in (select ID from wp_users where user_login="' . $username . '" and user_status=2)';
// Getting the activation key from the database
$activation_key = $wpdb->get_var($sql);
// Custom message with activation key
$message = "Yayy! Thanks for signing up! Please confirm your account!\n\n$activation_key";
return $message;
}
?>
Paste it in bp-custom.php in plugin folder
I have the following code.
Login user and validation works, returns true.
The problem is seePageIs, it returns an error. But after posting the respons has to go to company lister page. So if i change the ->seePageIs('admin/company') to ->seePageIs('admin/company/create') it works.
What's wrong?
Error:
Failed asserting that two strings are equal.
Expected :'http://localhost/admin/company'
Actual :'http://localhost/admin/company/create'
Test:
public function testExample()
{
$this->be(User::find(4));
$rules = array(
'companyname' => 'required',
'email' => 'required|email',
);
$data = [
'companyname' => 'aa',
'email' => 'aaaa#aa.nl']
;
$v = $this->app['validator']->make( $data, $rules);
$this->visit('admin/company/create')
->press('Create')
->assertTrue($v->passes())
->seePageIs('admin/company');
}
I'm not sure I understand your code very well and your question, but maybe it is this line:
$this->visit('admin/company/create')
->press('Create')
->assertTrue($v->passes())
->seePageIs('admin/company/create');
I just changed the line seePageIs() to add create at the end. Maybe that is the problem?
Try it.
If not, can you show your code for assertEquals(...)... Thanks!
EDIT #2
Hi there Bas; based on your comments and what I think you are trying to do:
If after creating the company, then you want to check it, then you probably need to do this instead:
$this->visit('admin/company')
->seePageIs('admin/company');
Which just goes to the company page an verifies that is the correct page.
I'm new in Yii2 and I'm not able to find something to do a back button in Yii2,
I found the solution in Yii1 is:
echo CHtml::link('Back',Yii::app()->request->urlReferrer);
but I'm not able to find a solution in Yii2,
can you help me?
Try:
echo \yii\helpers\Html::a( 'Back', Yii::$app->request->referrer);
Yii2 provides remember URLs functionality:
// Remember current URL
Url::remember();
// Remember URL specified. See Url::to() for argument format.
Url::remember(['product/view', 'id' => 42]);
// Remember URL specified with a name given
Url::remember(['product/view', 'id' => 42], 'product');
In the next request we can get URL remembered in the following way:
$url = Url::previous();
$productUrl = Url::previous('product');
I m trying to create a paypal order programmatically but I need the redirection key. The paypal WPS module gets this data from the $order->data['payment_redirect_key'] like this:
// Return to the payment redirect page for processing successful payments
'return' => url('checkout/' . $order->order_id . '/payment/return/' . $order->data['payment_redirect_key'], array('absolute' => TRUE)),
However i cannot find where the payment_redirect_key is created (i.e. which function creates it) in order to create it programmatically. Any help is appreciated.
My goal is to bypass the default drupal commerce checkout mechanism
I'm trying to do the same with no luck yet, but I find out where the payment_redirect_key is created. You can found it in the function commerce_payment_redirect_pane_checkout_form in the commerce/modules/commerce_payment/includes/commerce_payment.checkout_pane.inc function commerce_payment_redirect_pane_checkout_form, line 360 of the current version (http://cgit.drupalcode.org/commerce/tree/modules/payment/includes/commerce_payment.checkout_pane.inc#n360)
Basically, is this:
$order->data['payment_redirect_key'] = drupal_hash_base64(time());
commerce_order_save($order);
EDIT
After a couple days working on this, I found the solution in just a few lines of code. I use this function as a page callback of a menu item (something like product/%sku). Here is the code:
<?php
function custom_module_create_order($sku) {
global $user;
$product = commerce_product_load_by_sku($sku);
$order = ($user->uid) ? commerce_order_new($user->uid, 'checkout_checkout') : commerce_cart_order_new();
// Save to get the Order ID.
commerce_order_save($order);
$line_item = commerce_product_line_item_new($product, 1, $order->order_id);
commerce_line_item_save($line_item);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
// Select here the payment method. Usually something like:
// [module_name]|commerce_payment_[module_name]
$order->data['payment_method'] = 'commerce_sermepa|commerce_payment_commerce_sermepa';
commerce_order_save($order);
// Set status to order checkout to go to the payment platform redirect.
commerce_order_status_update($order, 'checkout_payment');
drupal_goto('checkout/' . $order->order_id);
}