Skip to content

Instantly share code, notes, and snippets.

View bappi-d-great's full-sized avatar

Bappi D great bappi-d-great

View GitHub Profile
@bappi-d-great
bappi-d-great / code.php
Created October 24, 2018 13:23
WPMU DEV Forminator phone number validation
<?php
// Assuming one phone field in a form
add_filter( 'forminator_custom_form_submit_errors', 'check_form_data', 99, 3 );
function check_form_data( $submit_errors, $form_id, $field_data_array ) {
$valid = false;
foreach( $field_data_array as $val ) {
if( $val['name'] == 'phone-1' ) {
$phone = $val['value'];
@bappi-d-great
bappi-d-great / How to load a wordpress plugin at very last.php
Created September 6, 2014 14:47
How to load a wordpress plugin at very last - change plugin order to load last
<?php
/*
*
* Use the code at the beginning of a plugin that you want to be laoded at last
*
*/
function this_plugin_last() {
$wp_path_to_this_file = preg_replace('/(.*)plugins\/(.*)$/', WP_PLUGIN_DIR."/$2", __FILE__);
$this_plugin = plugin_basename(trim($wp_path_to_this_file));
$active_plugins = get_option('active_plugins');
@bappi-d-great
bappi-d-great / WordPress Multisite - only allow one site per user.php
Last active September 21, 2022 18:31
WordPress Multisite - only allow one site per user
<?php
function wpms_one_blog_only($active_signup) {
// get the array of the current user's blogs
$blogs = get_blogs_of_user( get_current_user_id() );
// all users may be members of blog 1 so remove it from the count, could be a "Dashboard" blog as well
if ($blogs["1"]) unset($blogs["1"]);
//if the user still has blogs, disable signup else continue with existing active_signup rules at SiteAdmin->Options
$n = count($blogs);
if(n > 0){
@bappi-d-great
bappi-d-great / code.php
Created September 8, 2015 19:32
Create subsite when the site name is reserved in multisite
<?php
add_filter( 'wpmu_validate_blog_signup', 'wpmu_validate_blog_signup_cb' );
function wpmu_validate_blog_signup_cb( $result ) {
$current_site = get_current_site();
if ( ! domain_exists( $result['domain'], $result['path'], $current_site->id) ) {
if ( username_exists( $result['blogname'] ) ) {
if ( ! is_object( $result['user'] ) || ( is_object($result['user']) && ( $result['user']->user_login != $blogname ) ) ) {
$errors = $result['errors'];
$errors->remove( 'blogname' );
@bappi-d-great
bappi-d-great / add_form_entry.php
Last active April 14, 2021 17:52
Method: add_form_entry()
<?php
$form_id = 7;
$entry_meta= array(
'name' => 'text-1',
'value' => 'Text Input Value'
);
Forminator_API::add_form_entry( $form_id, $entry_meta );
@bappi-d-great
bappi-d-great / code.php
Created February 4, 2015 09:53
User Registration to Subscription (wpmu)
<?php
/*
Plugin Name: User Registration to Subscription (wpmu)
Plugin URI: http://bappi-d-great.com
Description: This plugin allows your users to auto subscribe when registered
Author: WPMU DEV
Version: 1.0.1
Author URI: http://bappi-d-great.com
*/
@bappi-d-great
bappi-d-great / code.php
Created June 14, 2020 12:48
Simple Model Class
<?php
class Model {
protected function __construct() {
parent::__construct();
}
public static function get_instance() {
static $Inst = null;
@bappi-d-great
bappi-d-great / code.php
Created June 14, 2020 12:10
Passing php data to external JS file
<?php
class Localize {
private $_data = [];
private function __construct () {}
static public function get_instance() {
static $Inst = null;
@bappi-d-great
bappi-d-great / code.php
Created July 4, 2018 08:23
Use country list in forminator
<?php
add_filter( 'forminator_field_single_markup', function( $html, $id, $required, $options, $value_type ) {
$countries = array
(
'AF' => 'Afghanistan',
'AX' => 'Aland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
<?php
$wrappers = array(
array(
'wrapper_id' => 'wrapper-1511378776546-9087',
'fields' => array(
array(
'element_id' => 'name-1',
'type' => 'name',
'cols' => '12',