Skip to content

Instantly share code, notes, and snippets.

View techjewel's full-sized avatar
🎯
Focusing

Shahjahan Jewel techjewel

🎯
Focusing
View GitHub Profile
@techjewel
techjewel / fluencrm-contact-status-change.php
Last active June 14, 2021 12:58
FluentCRM update contact status programatically
<?php
function fcrmUpdateContactStatus($contactEmail, $newStatus) {
$contact = FluentCrmApi('contacts')->getContact($contactEmail);
if($contact) {
$oldStatus = $contact->status;
if($newStatus != $oldStatus) {
$contact->status = $newStatus;
$contact->save();
do_action('fluentcrm_subscriber_status_to_' . $newStatus, $contact, $oldStatus);
@techjewel
techjewel / fluentcrm-postmark-support.php
Created May 3, 2021 17:35
Postmark SMTP header support for FluentCRM Emails
<?php
/*
* Postmark SMTP header support for FluentCRM Emails
*/
add_filter('fluentcrm_email_headers', function ($headers) {
$headers[] = 'X-PM-Message-Stream: broadcasts';
return $headers;
});
<?php
/*
* Fluent Forms Extra Smartcodes on form integration feeds
* This code will add a new item on the smartcode dropdown.
* if you don't want to show the smartcode then you may skip this.
*/
add_filter('fluentform_form_settings_smartcodes', function ($groups) {
$groups[0]['shortcodes']['{my_custom_smartcode}'] = 'Custom All Data';
@techjewel
techjewel / protect_login_for_admin_roles.php
Last active October 28, 2021 08:34
Code snippet to reject login for admin/authors from the regular login url
<?php
/*
* Code snippet to reject login for admin/authors from the regular login url
* In this example, people who have edit_posts permission is require special url string to login
* The URL need to be: https://yourdomain.com/wp-login.php?salt=your_random_url_string
* For normal users they can login without the special salt
* But If author or admin try to login it will reject the authentication
*
*/
<?php
/*
* Create custom smartcode for hidden field for the editor
* usage: {my_formatted_date_time}
* @return: current date time as d.m.Y H:i:s format
*/
add_filter('fluentform_editor_shortcode_callback_my_formatted_date_time', function ($value) {
return date('d.m.Y H:i:s');
});
<?php
/*
* Smartcode callback for smartcode: {sondre_post_selection_meta}
*/
add_filter('fluentform_shortcode_parser_callback_sondre_post_selection_meta', function ($returnValue, $instance) {
$userInputs = $instance::getInputs();
// from $userInputs you can access what user have provided information
// if your post selection input name is cpt_selection then you can access the post id as
$selectedPostId = $userInputs['cpt_selection'];
@techjewel
techjewel / fluentform-summary-email-hooks.php
Created March 1, 2021 19:39
Fluent Forms Summary Email Text Change
<?php
// changing summary email body text
add_filter('fluentform_email_summary_body_text', function ($text) {
return 'Your own Email Body Text';
});
// changing email footer text
add_filter('fluentform_email_summary_footer_text', function ($text) {
return 'Powered by your agency';
<?php
// add a tag to a current logged in or cookie based contact
// getCurrentContact() method will find the contact from logged in info or from the cookie from email link click
// For more api doc: https://github.com/FluentCRM/fluent-crm/wiki/PHP-API
$contact = FluentCrmApi('contacts')->getCurrentContact();
$tagsToAdd = [1,2];
if($contact) {
<?php
/*
* Disable users REST endpoint for public or not author users users
* To access the endpoint the user must need to be contributor
* aka need to have edit_posts permission
*/
add_filter( 'rest_endpoints', function ($endpoints) {
$endpoints_to_remove = array(
'/wp/v2/users'
@techjewel
techjewel / custom_shortcode_in_fluentforms.php
Created February 6, 2021 10:22
Create a custom shortcode for email / confirmation or other after form submit
<?php
/*
* Create a custom shortcode for email / confirmation or other after form submit
* Usage: {my_custom_shortcode}
* @param $value string original shortcode string
* @param $parser class \FluentForm\App\Services\FormBuilder\ShortCodeParser
*/
add_filter('fluentform_shortcode_parser_callback_my_custom_shortcode', function ($value, $parser) {