first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,253 @@
<?php
/**
* Integrations for buddypress
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class PUM_BuddyPress_Integration
*/
class PUM_BuddyPress_Integration {
/**
*
*/
public static function init() {
add_filter( 'pum_registered_conditions', [ __CLASS__, 'registered_conditions' ] );
add_filter( 'pum_condition_sort_order', [ __CLASS__, 'condition_sort_order' ] );
}
/**
* @param array $conditions
*
* @return array
*/
public static function registered_conditions( $conditions = [] ) {
$conditions = array_merge(
$conditions,
[
// Add Additional Conditions
'is_buddypress' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is a BuddyPress Page', 'popup-maker' ),
'callback' => 'is_buddypress',
],
'bp_is_user' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is User Page', 'popup-maker' ),
'callback' => 'bp_is_user',
],
'bp_is_group' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Group Page', 'popup-maker' ),
'callback' => 'bp_is_group',
],
'bp_is_user_messages' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is User Messages Page', 'popup-maker' ),
'callback' => 'bp_is_user_messages',
],
'bp_is_activation_page' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Activation Page', 'popup-maker' ),
'callback' => 'bp_is_activation_page',
],
'bp_is_register_page' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Register Page', 'popup-maker' ),
'callback' => 'bp_is_register_page',
],
'bp_is_item_admin' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Item Admin', 'popup-maker' ),
'callback' => 'bp_is_item_admin',
],
'bp_is_item_mod' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Item Mod', 'popup-maker' ),
'callback' => 'bp_is_item_mod',
],
'bp_is_directory' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Directory', 'popup-maker' ),
'callback' => 'bp_is_directory',
],
'bp_is_current_component' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Current Component', 'popup-maker' ),
'fields' => [
'selected' => [
'type' => 'select',
'multiple' => true,
'as_array' => true,
'select2' => true,
'options' => self::component_option_list(),
'label' => __( 'Which components?' ),
],
],
'callback' => [ __CLASS__, 'bp_is_current_component' ],
],
'bp_is_current_action' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Current Action', 'popup-maker' ),
'fields' => [
'selected' => [
'type' => 'text',
'label' => __( 'Which actions?' ),
],
],
'callback' => [ __CLASS__, 'bp_is_current_action' ],
],
'bp_is_action_variable' => [
'group' => __( 'BuddyPress', 'buddypress' ),
'name' => __( 'BP: Is Action Variable', 'popup-maker' ),
'fields' => [
'selected' => [
'type' => 'text',
'label' => __( 'Which action variables?' ),
],
],
'callback' => [ __CLASS__, 'bp_is_action_variable' ],
],
]
);
return $conditions;
}
/**
* @return array
*/
public static function component_option_list() {
global $bp;
$components = [];
foreach ( $bp->active_components as $component => $key ) {
$components[ $component ] = ucfirst( $component );
}
return $components;
}
/**
* Checks if the current page is the selected bp components.
*
* @param array $settings
*
* @return bool
*/
public static function bp_is_current_component( $settings = [] ) {
global $bp;
if ( empty( $settings['selected'] ) ) {
return false;
}
if ( ! is_array( $settings['selected'] ) ) {
$settings['selected'] = [ $settings['selected'] ];
}
$found = false;
foreach ( $settings['selected'] as $component ) {
if ( ! array_key_exists( $component, $bp->active_components ) ) {
continue;
}
if ( bp_is_current_component( $component ) ) {
$found = true;
}
}
return $found;
}
/**
* Checks if the current page is the selected bp action.
*
* @param array $settings
*
* @return bool
*/
public static function bp_is_current_action( $settings = [] ) {
if ( empty( $settings['selected'] ) ) {
return false;
}
if ( ! is_array( $settings['selected'] ) ) {
$settings['selected'] = array_map( 'trim', explode( ',', $settings['selected'] ) );
}
$found = false;
foreach ( $settings['selected'] as $action ) {
if ( bp_is_current_action( $action ) ) {
$found = true;
}
}
return $found;
}
/**
* Checks if the current page is the selected bp action variable.
*
* @param array $settings
*
* @return bool
*/
public static function bp_is_action_variable( $settings = [] ) {
if ( empty( $settings['selected'] ) ) {
return false;
}
if ( ! is_array( $settings['selected'] ) ) {
$settings['selected'] = array_map( 'trim', explode( ',', $settings['selected'] ) );
}
$found = false;
foreach ( $settings['selected'] as $variable ) {
if ( bp_is_action_variable( $variable ) ) {
$found = true;
}
}
return $found;
}
/**
* @param array $order
*
* @return array
*/
public static function condition_sort_order( $order = [] ) {
$order[ __( 'BuddyPress', 'buddypress' ) ] = 5.756;
return $order;
}
}

View File

@@ -0,0 +1,273 @@
<?php
/**
* Integrations for cf7
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class PUM_CF7_Integration
*/
class PUM_CF7_Integration {
/**
* Initialize if CF7 is active.
*/
public static function init() {
add_filter( 'pum_get_cookies', [ __CLASS__, 'register_cookies' ] );
add_filter( 'wpcf7_editor_panels', [ __CLASS__, 'editor_panels' ] );
add_action( 'wpcf7_after_save', [ __CLASS__, 'save' ] );
add_filter( 'wpcf7_form_elements', [ __CLASS__, 'form_elements' ] );
add_action( 'popmake_preload_popup', [ __CLASS__, 'preload' ] );
}
/**
* Check if the popups use CF7 Forms and force enqueue their assets.
*
* @param $popup_id
*/
public static function preload( $popup_id ) {
$popup = pum_get_popup( $popup_id );
if ( has_shortcode( $popup->post_content, 'contact-form-7' ) ) {
if ( defined( 'WPCF7_LOAD_JS' ) && ! WPCF7_LOAD_JS ) {
return;
}
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
wpcf7_enqueue_scripts();
}
if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
wpcf7_enqueue_styles();
}
}
}
/**
* Append a hidden meta html element with the forms popup settings.
*
* @param $elements
*
* @return string
*/
public static function form_elements( $elements ) {
$form = wpcf7_get_current_contact_form();
$settings = wp_json_encode( self::form_options( $form->id() ) );
return $elements . "<input type='hidden' class='wpcf7-pum' value='$settings' />";
}
/**
* Get a specific forms options.
*
* @param $id
*
* @return array
*/
public static function form_options( $id ) {
$settings = get_option( 'cf7_pum_' . $id, self::defaults() );
return wp_parse_args( $settings, self::defaults() );
}
/**
* Get default values.
*
* @return array
*/
public static function defaults() {
return [
'closepopup' => false,
'closedelay' => 0,
'openpopup' => false,
'openpopup_id' => 0,
];
}
/**
* Registers new cookie events.
*
* @param array $cookies
*
* @return array
*/
public static function register_cookies( $cookies = [] ) {
$cookies['cf7_form_success'] = [
'labels' => [
'name' => __( 'Contact Form 7 Success (deprecated. Use Form Submission instead.)', 'popup-maker' ),
],
'fields' => pum_get_cookie_fields(),
];
return $cookies;
}
/**
* Register new CF7 form editor tab.
*
* @param array $panels
*
* @return array
*/
public static function editor_panels( $panels = [] ) {
return array_merge(
$panels,
[
'popups' => [
'title' => __( 'Popup Settings', 'popup-maker' ),
'callback' => [ __CLASS__, 'editor_panel' ],
],
]
);
}
/**
* Render the popup tab.
*
* @param object $args
*/
public static function editor_panel( $args ) {
$settings = self::form_options( $args->id() ); ?>
<h2><?php _e( 'Popup Settings', 'popup-maker' ); ?></h2>
<p class="description"><?php _e( 'These settings control popups after successful form submissions.', 'popup-maker' ); ?></p>
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label for="wpcf7-pum-closepopup"><?php _e( 'Close Popup', 'popup-maker' ); ?></label>
</th>
<td>
<input type="checkbox" id="wpcf7-pum-closepopup" name="wpcf7-pum[closepopup]" value="true" <?php checked( $settings['closepopup'], true ); ?> />
</td>
</tr>
<tr id="wpcf7-pum-closedelay-wrapper">
<th scope="row">
<label for="wpcf7-pum-closedelay"><?php _e( 'Delay', 'popup-maker' ); ?></label>
</th>
<td>
<?php
if ( strlen( $settings['closedelay'] ) >= 3 ) {
$settings['closedelay'] = $settings['closedelay'] / 1000;
}
?>
<input type="number" id="wpcf7-pum-closedelay" min="0" step="1" name="wpcf7-pum[closedelay]" style="width: 100px;" value="<?php echo esc_attr( $settings['closedelay'] ); ?>" /><?php _e( 'seconds', 'popup-maker' ); ?>
</td>
</tr>
<tr>
<th scope="row">
<label for="wpcf7-pum-openpopup"><?php _e( 'Open Popup', 'popup-maker' ); ?></label>
</th>
<td>
<input type="checkbox" id="wpcf7-pum-openpopup" name="wpcf7-pum[openpopup]" value="true" <?php checked( $settings['openpopup'], true ); ?> />
</td>
</tr>
<tr id="wpcf7-pum-openpopup_id-wrapper">
<th scope="row">
<label for="wpcf7-pum-openpopup_id"><?php _e( 'Popup', 'popup-maker' ); ?></label>
</th>
<td>
<select id="wpcf7-pum-openpopup_id" name="wpcf7-pum[openpopup_id]">
<?php foreach ( self::get_popup_list() as $option ) { ?>
<option value="<?php echo esc_attr( $option['value'] ); ?>" <?php selected( $settings['openpopup_id'], $option['value'] ); ?>><?php echo $option['label']; ?></option>
<?php } ?>
</select>
</td>
</tr>
</tbody>
</table>
<script>
(function ($) {
var $open = $('#wpcf7-pum-openpopup'),
$close = $('#wpcf7-pum-closepopup'),
$popup_id_wrapper = $('#wpcf7-pum-openpopup_id-wrapper'),
$delay_wrapper = $('#wpcf7-pum-closedelay-wrapper');
function check_open() {
if ($open.is(':checked')) {
$popup_id_wrapper.show();
} else {
$popup_id_wrapper.hide();
}
}
function check_close() {
if ($close.is(':checked')) {
$delay_wrapper.show();
} else {
$delay_wrapper.hide();
}
}
check_open();
check_close();
$open.on('click', check_open);
$close.on('click', check_close);
}(jQuery));
</script>
<?php
}
/**
* Get a list of popups for a select box.
*
* @return array
*/
public static function get_popup_list() {
$popup_list = [
[
'value' => 0,
'label' => __( 'Select a popup', 'popup-maker' ),
],
];
$popups = get_posts(
[
'post_type' => 'popup',
'post_status' => [ 'publish' ],
'posts_per_page' => - 1,
]
);
foreach ( $popups as $popup ) {
$popup_list[] = [
'value' => $popup->ID,
'label' => $popup->post_title,
];
}
return $popup_list;
}
/**
* Save form popup options.
*
* @param $args
*/
public static function save( $args ) {
if ( ! empty( $_POST['wpcf7-pum'] ) ) {
$settings = $_POST['wpcf7-pum'];
// Sanitize values.
$settings['openpopup'] = ! empty( $settings['openpopup'] );
$settings['openpopup_id'] = ! empty( $settings['openpopup_id'] ) ? absint( $settings['openpopup_id'] ) : 0;
$settings['closepopup'] = ! empty( $settings['closepopup'] );
$settings['closedelay'] = ! empty( $settings['closedelay'] ) ? absint( $settings['closedelay'] ) : 0;
update_option( 'cf7_pum_' . $args->id(), $settings );
} else {
delete_option( 'cf7_pum_' . $args->id() );
}
}
}

View File

@@ -0,0 +1,305 @@
<?php
/**
* Gravity-forms Integrations class
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
class PUM_Gravity_Forms_Integation {
public static function init() {
add_filter( 'gform_form_settings_menu', [ __CLASS__, 'settings_menu' ] );
add_action( 'gform_form_settings_page_popup-maker', [ __CLASS__, 'render_settings_page' ] );
add_filter( 'pum_get_cookies', [ __CLASS__, 'register_cookies' ] );
add_filter( 'gform_get_form_filter', [ __CLASS__, 'get_form' ], 10, 2 );
add_action( 'popmake_preload_popup', [ __CLASS__, 'preload' ] );
add_action( 'popmake_popup_before_inner', [ __CLASS__, 'force_ajax' ] );
add_action( 'popmake_popup_after_inner', [ __CLASS__, 'force_ajax' ] );
}
public static function force_ajax() {
if ( current_action() === 'popmake_popup_before_inner' ) {
add_filter( 'shortcode_atts_gravityforms', [ __CLASS__, 'gfrorms_shortcode_atts' ] );
}
if ( current_action() === 'popmake_popup_after_inner' ) {
remove_filter( 'shortcode_atts_gravityforms', [ __CLASS__, 'gfrorms_shortcode_atts' ] );
}
}
public static function gfrorms_shortcode_atts( $out ) {
$out['ajax'] = 'true';
return $out;
}
public static function preload( $popup_id ) {
if ( function_exists( 'gravity_form_enqueue_scripts' ) ) {
$popup = pum_get_popup( $popup_id );
if ( has_shortcode( $popup->post_content, 'gravityform' ) ) {
$regex = "/\[gravityform.*id=[\'\"]?([0-9]*)[\'\"]?.*/";
$popup = get_post( $popup_id );
preg_match_all( $regex, $popup->post_content, $matches );
foreach ( $matches[1] as $form_id ) {
add_filter( "gform_confirmation_anchor_{$form_id}", '__return_false' );
gravity_form_enqueue_scripts( $form_id, true );
}
}
}
}
public static function settings_menu( $setting_tabs ) {
$setting_tabs['998.002'] = [
'name' => 'popup-maker',
'label' => __( 'Popup Maker', 'popup-maker' ),
];
return $setting_tabs;
}
public static function get_form( $form_string, $form ) {
$settings = wp_json_encode( self::form_options( $form['id'] ) );
$field = "<input type='hidden' class='gforms-pum' value='$settings' />";
$form_string = preg_replace( '/(<form.*>)/', "$1 \r\n " . $field, $form_string );
return $form_string;
}
/**
* Get default values.
*
* @return array
*/
public static function defaults() {
return [
'closepopup' => false,
'closedelay' => 0,
'openpopup' => false,
'openpopup_id' => 0,
];
}
/**
* Get a specific forms options.
*
* @param $id
*
* @return array
*/
public static function form_options( $id ) {
$settings = get_option( 'gforms_pum_' . $id, self::defaults() );
return wp_parse_args( $settings, self::defaults() );
}
/**
* Registers new cookie events.
*
* @param array $cookies
*
* @return array
*/
public static function register_cookies( $cookies = [] ) {
$cookies['gforms_form_success'] = [
'labels' => [
'name' => __( 'Gravity Form Success (deprecated. Use Form Submission instead.)', 'popup-maker' ),
],
'fields' => pum_get_cookie_fields(),
];
return $cookies;
}
public static function render_settings_page() {
$form_id = rgget( 'id' );
self::save();
$settings = self::form_options( $form_id );
GFFormSettings::page_header( __( 'Popup Settings', 'popup-maker' ) );
?>
<div id="popup_settings-editor">
<form id="popup_settings_edit_form" method="post">
<table class="form-table gforms_form_settings">
<tr>
<th scope="row">
<label for="gforms-pum-closepopup"><?php _e( 'Close Popup', 'popup-maker' ); ?></label>
</th>
<td>
<input type="checkbox" id="gforms-pum-closepopup" name="gforms-pum[closepopup]" value="true" <?php checked( $settings['closepopup'], true ); ?> />
</td>
</tr>
<tr id="gforms-pum-closedelay-wrapper">
<th scope="row">
<label for="gforms-pum-closedelay"><?php _e( 'Delay', 'popup-maker' ); ?></label>
</th>
<td>
<?php
if ( strlen( $settings['closedelay'] ) >= 3 ) {
$settings['closedelay'] = $settings['closedelay'] / 1000;
}
?>
<input type="number" id="gforms-pum-closedelay" min="0" step="1" name="gforms-pum[closedelay]" style="width: 100px;" value="<?php echo esc_attr( $settings['closedelay'] ); ?>" /><?php _e( 'seconds', 'popup-maker' ); ?>
</td>
</tr>
<tr>
<th scope="row">
<label for="gforms-pum-openpopup"><?php _e( 'Open Popup', 'popup-maker' ); ?></label>
</th>
<td>
<input type="checkbox" id="gforms-pum-openpopup" name="gforms-pum[openpopup]" value="true" <?php checked( $settings['openpopup'], true ); ?> />
</td>
</tr>
<tr id="gforms-pum-openpopup_id-wrapper">
<th scope="row">
<label for="gforms-pum-openpopup_id"><?php _e( 'Popup', 'popup-maker' ); ?></label>
</th>
<td>
<select id="gforms-pum-openpopup_id" name="gforms-pum[openpopup_id]">
<?php foreach ( self::get_popup_list() as $option ) { ?>
<option value="<?php echo esc_attr( $option['value'] ); ?>" <?php selected( $settings['openpopup_id'], $option['value'] ); ?>><?php echo $option['label']; ?></option>
<?php } ?>
</select>
</td>
</tr>
</table>
<input type="hidden" id="form_id" name="form_id" value="<?php echo esc_attr( $form_id ); ?>" />
<p class="submit">
<input type="submit" name="save" value="<?php _e( 'Save', 'popup-maker' ); ?>" class="button-primary">
</p>
<?php wp_nonce_field( 'gform_popup_settings_edit', 'gform_popup_settings_edit' ); ?>
</form>
<script type="text/javascript">
(function ($) {
var $open = $('#gforms-pum-openpopup'),
$close = $('#gforms-pum-closepopup'),
$popup_id_wrapper = $('#gforms-pum-openpopup_id-wrapper'),
$delay_wrapper = $('#gforms-pum-closedelay-wrapper');
function check_open() {
if ($open.is(':checked')) {
$popup_id_wrapper.show();
} else {
$popup_id_wrapper.hide();
}
}
function check_close() {
if ($close.is(':checked')) {
$delay_wrapper.show();
} else {
$delay_wrapper.hide();
}
}
check_open();
check_close();
$open.on('click', check_open);
$close.on('click', check_close);
}(jQuery));
</script>
</div> <!-- / popup-editor -->
<?php
GFFormSettings::page_footer();
}
/**
* Get a list of popups for a select box.
*
* @return array
*/
public static function get_popup_list() {
$popup_list = [
[
'value' => '',
'label' => __( 'Select a popup', 'popup-maker' ),
],
];
$popups = get_posts(
[
'post_type' => 'popup',
'post_status' => [ 'publish' ],
'posts_per_page' => - 1,
]
);
foreach ( $popups as $popup ) {
$popup_list[] = [
'value' => $popup->ID,
'label' => $popup->post_title,
];
}
return $popup_list;
}
/**
* Save form popup options.
*/
public static function save() {
if ( empty( $_POST ) || ! check_admin_referer( 'gform_popup_settings_edit', 'gform_popup_settings_edit' ) ) {
return;
}
$form_id = rgget( 'id' );
if ( ! empty( $_POST['gforms-pum'] ) ) {
$settings = $_POST['gforms-pum'];
// Sanitize values.
$settings['openpopup'] = ! empty( $settings['openpopup'] );
$settings['openpopup_id'] = ! empty( $settings['openpopup_id'] ) ? absint( $settings['openpopup_id'] ) : 0;
$settings['closepopup'] = ! empty( $settings['closepopup'] );
$settings['closedelay'] = ! empty( $settings['closedelay'] ) ? absint( $settings['closedelay'] ) : 0;
update_option( 'gforms_pum_' . $form_id, $settings );
} else {
delete_option( 'gforms_pum_' . $form_id );
}
}
}
/**
*
* add_action( 'gform_loaded', array( 'PUM_Gravity_Forms_Integration', 'load' ), 5 );
*
* class PUM_Gravity_Forms_Integration {
*
* public static function load() {
* if ( ! method_exists( 'GFForms', 'include_feed_addon_framework' ) ) {
* return;
* }
* require_once 'gravity-forms/class-pum-gf-popup-addon.php';
* GFAddOn::register( 'PUM_GF_Popup_Addon' );
* }
* }
*
* function pum_gf_addon() {
* return PUM_GF_Popup_Addon::get_instance();
* }
*/

View File

@@ -0,0 +1,178 @@
<?php
/**
* Integrations for ninja-forms
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class NF_PUM
*/
final class NF_PUM {
const PREFIX = 'NF_PUM';
/**
* @var NF_PUM
* @since 3.0
*/
private static $instance;
/**
* Plugin Directory
*
* @since 3.0
* @var string $dir
*/
public static $dir = '';
/**
* Plugin URL
*
* @since 3.0
* @var string $url
*/
public static $url = '';
/**
* Main Plugin Instance
*
* Insures that only one instance of a plugin class exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 3.0
* @static
* @static var array $instance
* @return NF_PUM Highlander Instance
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof NF_PUM ) ) {
spl_autoload_register( [ __CLASS__, 'autoloader' ] );
self::$instance = new NF_PUM();
self::$dir = plugin_dir_path( __FILE__ );
self::$url = plugin_dir_url( __FILE__ );
}
return self::$instance;
}
public function __construct() {
$this->register_actions();
add_filter( 'pum_registered_cookies', [ $this, 'register_cookies' ] );
}
/**
* Register Actions
*
* Register custom form actions to integrate with popups.
*/
public function register_actions() {
Ninja_Forms()->actions['closepopup'] = new NF_PUM_Actions_ClosePopup();
Ninja_Forms()->actions['openpopup'] = new NF_PUM_Actions_OpenPopup();
}
/**
* Optional. If your extension creates a new field interaction or display template...
*/
public function register_cookies( $cookies ) {
$cookies['ninja_form_success'] = [
'labels' => [
'name' => __( 'Ninja Form Success (deprecated. Use Form Submission instead.)', 'popup-maker' ),
],
'fields' => pum_get_cookie_fields(),
];
return $cookies;
}
/*
* Optional methods for convenience.
*/
public static function autoloader( $class_name ) {
if ( class_exists( $class_name ) ) {
return;
}
if ( false === strpos( $class_name, self::PREFIX ) ) {
return;
}
$class_name = str_replace( self::PREFIX, '', $class_name );
$classes_dir = realpath( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'ninja-forms' . DIRECTORY_SEPARATOR;
$class_file = str_replace( '_', DIRECTORY_SEPARATOR, $class_name ) . '.php';
if ( file_exists( $classes_dir . $class_file ) ) {
require_once $classes_dir . $class_file;
}
}
/**
* Template
*
* @param string $file_name
* @param array $data
*/
public static function template( $file_name = '', array $data = [] ) {
if ( ! $file_name ) {
return;
}
extract( $data );
include self::$dir . 'includes/Templates/' . $file_name;
}
/**
* Config
*
* @param $file_name
*
* @return mixed
*/
public static function config( $file_name ) {
return include self::$dir . 'includes/Config/' . $file_name . '.php';
}
}
/**
* The main function responsible for returning The Highlander Plugin
* Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* @since 3.0
* @return {class} Highlander Instance
*/
function NF_PUM() {
return NF_PUM::instance();
}
/**
*
*/
function pum_nf_should_init() {
if ( ! class_exists( 'Ninja_Forms' ) ) {
return;
}
if ( version_compare( get_option( 'ninja_forms_version', '0.0.0' ), '3.0', '<' ) || get_option( 'ninja_forms_load_deprecated', false ) ) {
return;
}
NF_PUM();
}
add_action( 'init', 'pum_nf_should_init', 0 );

View File

@@ -0,0 +1,101 @@
<?php
/**
* Integrations for woocommerce
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class PUM_Woocommerce_Integration {
public static function init() {
add_filter( 'pum_registered_conditions', [ __CLASS__, 'register_conditions' ] );
add_filter( 'pum_condition_sort_order', [ __CLASS__, 'condition_sort_order' ] );
}
public static function is_wc_endpoint_url( $settings = [] ) {
$results = [];
foreach ( $settings['selected'] as $key ) {
$results[] = is_wc_endpoint_url( $key );
}
return in_array( true, $results );
}
public static function register_conditions( $conditions = [] ) {
// Add Additional Conditions
$conditions['is_woocommerce'] = [
'group' => __( 'WooCommerce', 'woocommerce' ),
'name' => __( 'All WooCommerce', 'popup-maker' ),
'callback' => 'is_woocommerce',
];
$conditions['is_shop'] = [
'group' => __( 'WooCommerce', 'woocommerce' ),
'name' => __( 'Shop Page', 'popup-maker' ),
'callback' => 'is_shop',
];
$conditions['is_cart'] = [
'group' => __( 'WooCommerce', 'woocommerce' ),
'name' => __( 'Cart Page', 'popup-maker' ),
'callback' => 'is_cart',
];
$conditions['is_checkout'] = [
'group' => __( 'WooCommerce', 'woocommerce' ),
'name' => __( 'Checkout Page', 'popup-maker' ),
'callback' => 'is_checkout',
];
$conditions['is_account_page'] = [
'group' => __( 'WooCommerce', 'woocommerce' ),
'name' => __( 'Account Page', 'popup-maker' ),
'callback' => 'is_account_page',
];
$conditions['is_wc_endpoint_url'] = [
'group' => __( 'WooCommerce', 'woocommerce' ),
'name' => __( 'Is Endpoint', 'popup-maker' ),
'fields' => [
'selected' => [
'placeholder' => __( 'Selected Endpoints', 'popup-maker' ),
'type' => 'select',
'select2' => true,
'multiple' => true,
'as_array' => true,
'options' => [
'order-pay' => 'order-pay',
'order-received' => 'order-received',
// My account actions.
'orders' => 'orders',
'view-order' => 'view-order',
'downloads' => 'downloads',
'edit-account' => 'edit-account',
'edit-address' => 'edit-address',
'payment-methods' => 'payment-methods',
'lost-password' => 'lost-password',
'customer-logout' => 'customer-logout',
'add-payment-method' => 'add-payment-method',
'delete-payment-method' => 'delete-payment-method',
'set-default-payment-method' => 'set-default-payment-method',
'subscriptions' => 'subscriptions',
],
],
],
'callback' => [ __CLASS__, 'is_wc_endpoint_url' ],
];
return $conditions;
}
public static function condition_sort_order( $order = [] ) {
$order[ __( 'WooCommerce', 'woocommerce' ) ] = 5.256;
return $order;
}
}

View File

@@ -0,0 +1,377 @@
<?php
/**
* Integrations for wpml
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class PUM_WPML_Integration
*/
class PUM_WPML_Integration {
/**
*
*/
public static function init() {
add_action( 'icl_make_duplicate', [ __CLASS__, 'duplicate_post' ], 10, 4 );
/*
add_filter( 'pum_popup', array( __CLASS__, 'pum_popup' ), 10, 2 );
TODO Further testing of this filter may prove 80+% of the following unneeded.
*/
add_filter( 'pum_popup_get_display', [ __CLASS__, 'popup_get_display' ], 10, 2 );
add_filter( 'pum_popup_get_close', [ __CLASS__, 'popup_get_close' ], 10, 2 );
add_filter( 'pum_popup_get_triggers', [ __CLASS__, 'popup_get_triggers' ], 10, 2 );
add_filter( 'pum_popup_get_cookies', [ __CLASS__, 'popup_get_cookies' ], 10, 2 );
add_filter( 'pum_popup_get_conditions', [ __CLASS__, 'popup_get_conditions' ], 10, 2 );
add_filter( 'pum_popup_get_theme_id', [ __CLASS__, 'popup_get_theme_id' ], 10, 2 );
add_filter( 'pum_popup_mobile_disabled', [ __CLASS__, 'popup_mobile_disabled' ], 10, 2 );
add_filter( 'pum_popup_tablet_disabled', [ __CLASS__, 'popup_tablet_disabled' ], 10, 2 );
}
/**
* @param $popup
* @param null $popup_id
*
* @return \PUM_Model_Popup
*/
public static function pum_popup( $popup, $popup_id = null ) {
if ( self::is_new_popup_translation( $popup_id ) ) {
remove_filter( 'pum_popup', [ __CLASS__, 'pum_popup' ], 10 );
$popup = pum_get_popup( self::source_id( $popup_id ) );
add_filter( 'pum_popup', [ __CLASS__, 'pum_popup' ], 10, 2 );
}
return $popup;
}
/**
* @param int $post_id
*
* @return bool
*/
public static function is_new_popup_translation( $post_id = 0 ) {
global $pagenow, $sitepress;
return is_admin() && 'post-new.php' === $pagenow && ! empty( $_GET['post_type'] ) && 'popup' === $_GET['post_type'] && self::source_id( $post_id ) > 0;
}
/**
* @param int $post_id
*
* @return int
*/
public static function source_id( $post_id = 0 ) {
global $sitepress;
static $source_id;
if ( ! isset( $source_id ) && ! empty( $sitepress ) && method_exists( $sitepress, 'get_new_post_source_id' ) ) {
$source_id = absint( $sitepress->get_new_post_source_id( $post_id ) );
}
return $source_id;
}
/**
* @param int $post_id
*/
public static function source_lang( $post_id = 0 ) {
}
/**
* @param int $post_id
*
* @return int
*/
public static function trid( $post_id = 0 ) {
global $sitepress;
static $trid;
if ( ! isset( $trid ) && ! empty( $sitepress ) && method_exists( $sitepress, 'get_element_trid' ) ) {
$trid = absint( $sitepress->get_element_trid( $post_id, 'post_popup' ) );
}
return $trid;
}
/**
* @param $disabled
* @param $post_id
*
* @return bool
*/
public static function popup_mobile_disabled( $disabled, $post_id ) {
if ( self::is_new_popup_translation( $post_id ) ) {
remove_filter( 'pum_popup_mobile_disabled', [ __CLASS__, 'popup_mobile_disabled' ], 10 );
$disabled = pum_get_popup( self::source_id( $post_id ) )->mobile_disabled();
add_filter( 'pum_popup_mobile_disabled', [ __CLASS__, 'popup_mobile_disabled' ], 10, 2 );
}
return $disabled;
}
/**
* @param $disabled
* @param $post_id
*
* @return bool
*/
public static function popup_tablet_disabled( $disabled, $post_id ) {
if ( self::is_new_popup_translation( $post_id ) ) {
remove_filter( 'pum_popup_tablet_disabled', [ __CLASS__, 'popup_tablet_disabled' ], 10 );
$disabled = pum_get_popup( self::source_id( $post_id ) )->tablet_disabled();
add_filter( 'pum_popup_tablet_disabled', [ __CLASS__, 'popup_tablet_disabled' ], 10, 2 );
}
return $disabled;
}
/**
* @param $triggers
* @param $post_id
*
* @return array
*/
public static function popup_get_triggers( $triggers, $post_id ) {
if ( self::is_new_popup_translation( $post_id ) ) {
remove_filter( 'pum_popup_get_triggers', [ __CLASS__, 'popup_get_triggers' ], 10 );
$triggers = pum_get_popup( self::source_id( $post_id ) )->get_triggers();
add_filter( 'pum_popup_get_triggers', [ __CLASS__, 'popup_get_triggers' ], 10, 2 );
}
return $triggers;
}
/**
* @param $display
* @param $post_id
*
* @return mixed
*/
public static function popup_get_display( $display, $post_id ) {
if ( self::is_new_popup_translation( $post_id ) ) {
remove_filter( 'pum_popup_get_display', [ __CLASS__, 'popup_get_display' ], 10 );
$display = pum_get_popup( self::source_id( $post_id ) )->get_display();
add_filter( 'pum_popup_get_display', [ __CLASS__, 'popup_get_display' ], 10, 2 );
}
return $display;
}
/**
* @param $close
* @param $post_id
*
* @return mixed
*/
public static function popup_get_close( $close, $post_id ) {
if ( self::is_new_popup_translation( $post_id ) ) {
remove_filter( 'pum_popup_get_close', [ __CLASS__, 'popup_get_close' ], 10 );
$close = pum_get_popup( self::source_id( $post_id ) )->get_close();
add_filter( 'pum_popup_get_close', [ __CLASS__, 'popup_get_close' ], 10, 2 );
}
return $close;
}
/**
* @param $cookies
* @param $post_id
*
* @return array
*/
public static function popup_get_cookies( $cookies, $post_id ) {
if ( self::is_new_popup_translation( $post_id ) ) {
remove_filter( 'pum_popup_get_cookies', [ __CLASS__, 'popup_get_cookies' ], 10 );
$cookies = pum_get_popup( self::source_id( $post_id ) )->get_cookies();
add_filter( 'pum_popup_get_cookies', [ __CLASS__, 'popup_get_cookies' ], 10, 2 );
}
return $cookies;
}
/**
* @param $theme_id
* @param $post_id
*
* @return int
*/
public static function popup_get_theme_id( $theme_id, $post_id ) {
if ( self::is_new_popup_translation( $post_id ) ) {
remove_filter( 'pum_popup_get_theme_id', [ __CLASS__, 'popup_get_theme_id' ], 10 );
$theme_id = pum_get_popup( self::source_id( $post_id ) )->get_theme_id();
add_filter( 'pum_popup_get_theme_id', [ __CLASS__, 'popup_get_theme_id' ], 10, 2 );
}
return $theme_id;
}
/**
* @param $conditions
* @param null $new_lang
*
* @return mixed
*/
public static function remap_conditions( $conditions, $new_lang = null ) {
if ( ! isset( $new_lang ) && empty( $_GET['lang'] ) ) {
return $conditions;
}
if ( ! isset( $new_lang ) ) {
$new_lang = $_GET['lang'];
}
foreach ( $conditions as $group_key => $group ) {
foreach ( $group as $key => $condition ) {
$target = $condition['target'];
$tests = [
strpos( $target, '_selected' ) !== false,
strpos( $target, '_ID' ) !== false,
strpos( $target, '_children' ) !== false,
strpos( $target, '_ancestors' ) !== false,
strpos( $target, '_w_' ) !== false,
];
if ( ! in_array( true, $tests ) ) {
continue;
}
// Taxonomy
if ( strpos( $target, 'tax_' ) === 0 ) {
$t = explode( '_', $target );
// Remove the tax_ prefix.
array_shift( $t );
// Assign the last key as the modifier _all, _selected
$modifier = array_pop( $t );
// Whatever is left is the taxonomy.
$type = implode( '_', $t );
} // Post by Tax
elseif ( strpos( $target, '_w_' ) !== false ) {
$t = explode( '_w_', $target );
// First key is the post type.
$post_type = array_shift( $t );
// Last Key is the taxonomy
$type = array_pop( $t );
} // Post Type
else {
$t = explode( '_', $target );
// Modifier should be the last key.
$modifier = array_pop( $t );
// Post type is the remaining keys combined.
$type = implode( '_', $t );
}
// To hold the newly remapped selection.
$selected = [];
foreach ( wp_parse_id_list( $condition['selected'] ) as $object_id ) {
// Insert the translated post_id or the original if no translation exists.
$selected[] = wpml_object_id_filter( $object_id, $type, true, $new_lang );
}
// Replace the original conditions with the new remapped ones.
$conditions[ $group_key ][ $key ]['selected'] = $selected;
}
}
return $conditions;
}
/**
* @param $conditions
* @param $post_id
*
* @return array|mixed
*/
public static function popup_get_conditions( $conditions, $post_id ) {
if ( self::is_new_popup_translation( $post_id ) ) {
remove_filter( 'pum_popup_get_conditions', [ __CLASS__, 'popup_get_conditions' ], 10 );
$popup = pum_get_popup( self::source_id( $post_id ) );
$conditions = $popup->get_conditions();
$conditions = self::remap_conditions( $conditions, $post_id );
add_filter( 'pum_popup_get_conditions', [ __CLASS__, 'popup_get_conditions' ], 10, 2 );
}
return $conditions;
}
/**
* @return mixed|void
*/
public static function untranslatable_meta_keys() {
return apply_filters(
'pum_wpml_untranslatable_meta_keys',
[
'popup_display',
'popup_theme',
'popup_triggers',
'popup_cookies',
'popup_conditions',
'popup_mobile_disabled',
'popup_tablet_disabled',
]
);
}
/**
* @return mixed|void
*/
public static function translatable_meta_keys() {
return apply_filters(
'pum_wpml_translatable_meta_keys',
[
'popup_close',
'popup_title',
]
);
}
/**
* Copies post_meta for popups on duplication.
*
* Only copies untranslatable data.
*
* @param $master_post_id int Original post_ID.
* @param $lang string The new language.
* @param post_array array The $post array for the new/duplicate post.
* @param $id int The post_ID for the new/duplicate post.
*/
public static function duplicate_post( $master_post_id, $lang, $post_array, $id ) {
// Only do this for popups.
if ( get_post_type( $master_post_id ) !== 'popup' ) {
return;
}
foreach ( self::untranslatable_meta_keys() as $key ) {
$value = get_post_meta( $master_post_id, $key, true );
if ( ! $value ) {
continue;
}
if ( 'popup_conditions' === $key ) {
$value = self::remap_conditions( $value, $lang );
}
update_post_meta( $id, $key, $value );
}
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Integrations for ninja-forms actions close popup
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class NF_Action_SuccessMessage
*/
final class NF_PUM_Actions_ClosePopup extends NF_Abstracts_Action {
/**
* @var string
*/
protected $_name = 'closepopup';
/**
* @var array
*/
protected $_tags = [];
/**
* @var string
*/
protected $_timing = 'late';
/**
* @var int
*/
protected $_priority = 10;
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->_nicename = __( 'Close Popup', 'popup-maker' );
$settings = [
'close_delay' => [
'name' => 'close_delay',
'type' => 'number',
'group' => 'primary',
'label' => __( 'Delay', 'popup-maker' ) . ' (' . __( 'seconds', 'popup-maker' ) . ')',
'placeholder' => '',
'width' => 'full',
'value' => __( '0', 'popup-maker' ),
],
];
$this->_settings = array_merge( $this->_settings, $settings );
}
/*
* PUBLIC METHODS
*/
public function save( $action_settings ) {
}
public function process( $action_settings, $form_id, $data ) {
if ( ! isset( $data['actions'] ) || ! isset( $data['actions']['closepopup'] ) ) {
$data['actions']['closepopup'] = true;
}
if ( isset( $action_settings['close_delay'] ) ) {
$data['actions']['closedelay'] = intval( $action_settings['close_delay'] );
if ( strlen( $data['actions']['closedelay'] ) >= 3 ) {
$data['actions']['closedelay'] = $data['actions']['closedelay'] / 1000;
}
$data['actions']['closepopup'] = $data['actions']['closedelay'];
}
return $data;
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Integrations for ninja-forms actions open popup
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;}
/**
* Class NF_Action_SuccessMessage
*/
final class NF_PUM_Actions_OpenPopup extends NF_Abstracts_Action {
/**
* @var string
*/
protected $_name = 'openpopup';
/**
* @var array
*/
protected $_tags = [];
/**
* @var string
*/
protected $_timing = 'late';
/**
* @var int
*/
protected $_priority = 10;
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->_nicename = __( 'Open Popup', 'popup-maker' );
$settings = [
'popup' => [
'name' => 'popup',
'type' => 'select',
'group' => 'primary',
'label' => __( 'Popup ID', 'popup-maker' ),
'placeholder' => '',
'width' => 'full',
'options' => isset( $_GET['page'] ) && 'ninja-forms' === $_GET['page'] && ! empty( $_GET['form_id'] ) ? $this->get_popup_list() : [],
],
];
$this->_settings = array_merge( $this->_settings, $settings );
}
/*
* PUBLIC METHODS
*/
public function save( $action_settings ) {
}
public function process( $action_settings, $form_id, $data ) {
if ( ! isset( $data['actions'] ) || ! isset( $data['actions']['openpopup'] ) ) {
$data['actions']['openpopup'] = false;
}
if ( isset( $action_settings['popup'] ) ) {
$data['actions']['openpopup'] = intval( $action_settings['popup'] );
}
return $data;
}
public function get_popup_list() {
$popup_list = [
[
'value' => '',
'label' => __( 'Select a popup', 'popup-maker' ),
],
];
$popups = pum_get_all_popups();
foreach ( $popups as $popup ) {
$popup_list[] = [
'value' => $popup->ID,
'label' => $popup->post_title,
];
}
return $popup_list;
}
}