开发者 | souptik |
---|---|
更新时间 | 2024年10月27日 16:19 |
PHP版本: | 5.6 及以上 |
WordPress版本: | 6.6.2 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
xyz
provider for SMS, I want to use pqr
, can I have that? Yes it provides you with lot of pre implemented providers for all email, sms and push-notification.yxr
you haven't heard the name of. Now what? 🧐\Souptik\AllPathMessaging\Email\send( [ 'dev2@souptik.dev' ], 'Yay its working!', 'This is some long mail body.', 'Souptik', 'dev1@souptik.dev', [ 'cc' => [ [ 'name' => 'CC Test', 'email' => 'cc@souptik.dev', ], ], 'attachments' => [ trailingslashit( WP_CONTENT_DIR ) . '/mu-plugins/test-all-path-messaging.php', 'SameFileDifferentName.php' => trailingslashit( WP_CONTENT_DIR ) . '/mu-plugins/test-all-path-messaging.php', ], ], 'mailgun' );
Just remove the last parameter! And now it uses the default selected adapter -
\Souptik\AllPathMessaging\Email\send( [ 'dev2@souptik.dev' ], 'Yay its working!', 'This is some long mail body.', 'Souptik', 'dev1@souptik.dev', [ 'cc' => [ [ 'name' => 'CC Test', 'email' => 'cc@souptik.dev', ], ], 'attachments' => [ trailingslashit( WP_CONTENT_DIR ) . '/mu-plugins/test-all-path-messaging.php', 'SameFileDifferentName.php' => trailingslashit( WP_CONTENT_DIR ) . '/mu-plugins/test-all-path-messaging.php', ], ], );
Checked the override wp_mail
checkbox? Try a simple wp_mail
! -
wp_mail( [ 'dev2@souptik.dev' ], 'Yay its working!', 'This is some long mail body - from <strong>wp_mail</strong>.', [], [] );
SMS 📲
Send a SMS through a particular adapter -
\Souptik\AllPathMessaging\SMS\send( [ '+xxxxxxxxxxxx' ], 'Yay its working!', 'twilio' );
Just remove the last parameter! And now it uses the default selected adapter -
\Souptik\AllPathMessaging\SMS\send( [ '+xxxxxxxxxxxx' ], 'Yay its working!' );
Creating your own adapter 🛠️
Here comes the cool part fellow developers! 💻
Tip: I have provided a dummy adapter for each service at inc/<service>/adapters/dummy/
.
Consider that as the starting point and let's understand what each file does.
namespace.php
. It is the entry point of your adapter.bootstrap
function.EMAIL_SLUG . '_adapters'
and registering our adapter.slug
name
adapter
class object.options
- An array defining the settings required for this adapter, which will be used to automatically display the options on the settings page.class-adapter.php
, which is the Adapter class, which we initialized in the above file and passed it to adapter
. It contains three simple functions -get_settings_fields
- This is the function which returns the array of options, which we used in the above file for options
. Each option, will have -label
- Label to display in the settings page beside the input.type
- Type of the field.sanitize_callback
get_settings
- This function returns an associative array, whose keys are the name of the options and the value as the value of the options.get_adapter
- This function will just return the core provider class, which is responsible for processing the message.Utopia Messaging
already provides the provider or not here, for example Utopia\Messaging\Adapter\Email\Mailgun
.Utopia Messaging
makes it so easy to create a new adapter!class-dummy.php
is for that purpose, assuming you don't get a provider already present in Utopia Messaging
.EmailAdapter
or SMSAdapter
, which abstract a lot of stuff for us!_construct
and process
. Rest of the functions and properties are self-explanatory! 😉_construct
function just put the arguments which you want to accept. That's it! And now they will be available everywhere else as $this->param_name
!process
function is the place where you have to write the main logic of calling your providers API to send the message.$this->param_name
.body
and the headers
.$this->request
function as demonstrated in the dummy!Response
class.wp_mail
. Do I need to make any changes to the codebase after installing this plugin?Good news - no!
You just have to check the Override wp_mail functionality checkbox
in the settings and that's it! All your mails you are triggering through wp_mail
will be sent through your selected provider!
Absolutely!
The plugin is made for that only! Keep using your existing email marketing plugin and just set the email provider as default (i.e it should use wp_mail
). And that's it the emails will be send through the desired provider you select in this plugin.
xyz
, which is not present currently in this plugin. Do I have to ask you to integrate that?If you know coding! - You don't have to wait for it! Go ahead and create your own adapter in your plugin by extending this plugin. If you are non-tech! - Please create an issue over here, and I will try to integrate the provider ASAP.