| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* This class responsible for database work |
| 5 |
* using wordpress functionality |
| 6 |
* get_option and update_option. |
| 7 |
*/ |
| 8 |
class BetterPayment_Helper |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Check if elementor plugin is activated |
| 12 |
* |
| 13 |
* @since v1.0.0 |
| 14 |
*/ |
| 15 |
public function elementor_not_loaded() |
| 16 |
{ |
| 17 |
if (!current_user_can('activate_plugins')) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
$elementor = 'elementor/elementor.php'; |
| 22 |
|
| 23 |
if ($this->is_plugin_installed($elementor)) { |
| 24 |
$activation_url = wp_nonce_url('plugins.php?action=activate&plugin=' . $elementor . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $elementor); |
| 25 |
|
| 26 |
$message = sprintf(__('%1$sBetterPayment%2$s requires %1$sElementor%2$s plugin to be active. Please activate Elementor to continue.', 'better-payment'), "<strong>", "</strong>"); |
| 27 |
|
| 28 |
$button_text = __('Activate Elementor', 'better-payment'); |
| 29 |
} else { |
| 30 |
$activation_url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=elementor'), 'install-plugin_elementor'); |
| 31 |
|
| 32 |
$message = sprintf(__('%1$sBetterPayment%2$s requires %1$sElementor%2$s plugin to be installed and activated. Please install Elementor to continue.', 'better-payment'), '<strong>', '</strong>'); |
| 33 |
$button_text = __('Install Elementor', 'better-payment'); |
| 34 |
} |
| 35 |
|
| 36 |
$button = '<p><a href="' . esc_url_raw($activation_url) . '" class="button-primary">' . $button_text . '</a></p>'; |
| 37 |
|
| 38 |
printf('<div class="error"><p>%1$s</p>%2$s</div>', __($message), $button); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Check if a plugin is installed |
| 43 |
* |
| 44 |
* @since 3.0.0 |
| 45 |
*/ |
| 46 |
public function is_plugin_installed($basename) |
| 47 |
{ |
| 48 |
if (!function_exists('get_plugins')) { |
| 49 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 50 |
} |
| 51 |
|
| 52 |
$plugins = get_plugins(); |
| 53 |
|
| 54 |
return isset($plugins[$basename]); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* check is plugin active or not |
| 59 |
* |
| 60 |
* @since v4.3.5 |
| 61 |
* @param $plugin |
| 62 |
* @return bool |
| 63 |
*/ |
| 64 |
public function is_plugin_active($plugin) { |
| 65 |
if ( !function_exists( 'is_plugin_active' ) ){ |
| 66 |
require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 67 |
} |
| 68 |
|
| 69 |
return is_plugin_active( $plugin ); |
| 70 |
} |
| 71 |
|
| 72 |
public static function sanitize_bp_field($key, $arr, $default_value='', $type='text'){ |
| 73 |
$value = $default_value; |
| 74 |
|
| 75 |
if( !empty( $arr[ $key ] ) ) { |
| 76 |
$value = $arr[ $key ]; |
| 77 |
|
| 78 |
switch($type){ |
| 79 |
case 'text': |
| 80 |
$value = sanitize_text_field( $value ); |
| 81 |
break; |
| 82 |
case 'email': |
| 83 |
$value = sanitize_email( $value ); |
| 84 |
break; |
| 85 |
case 'textarea': |
| 86 |
$value = sanitize_textarea_field( $value ); |
| 87 |
break; |
| 88 |
default: |
| 89 |
$value = sanitize_text_field( $value ); |
| 90 |
break; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
return $value; |
| 95 |
} |
| 96 |
|
| 97 |
public function get_betterpayment_widget_settings( $page_id, $widget_id ) { |
| 98 |
$document = \Elementor\Plugin::$instance->documents->get( $page_id ); |
| 99 |
$settings = []; |
| 100 |
if ( $document ) { |
| 101 |
$elements = \Elementor\Plugin::instance()->documents->get( $page_id )->get_elements_data(); |
| 102 |
$widget_data = $this->find_element_recursive( $elements, $widget_id ); |
| 103 |
$widget = \Elementor\Plugin::instance()->elements_manager->create_element_instance( $widget_data ); |
| 104 |
if ( $widget ) { |
| 105 |
$settings = $widget->get_settings_for_display(); |
| 106 |
} |
| 107 |
} |
| 108 |
return $settings; |
| 109 |
} |
| 110 |
|
| 111 |
public function find_element_recursive( $elements, $form_id ) { |
| 112 |
|
| 113 |
foreach ( $elements as $element ) { |
| 114 |
if ( $form_id === $element[ 'id' ] ) { |
| 115 |
return $element; |
| 116 |
} |
| 117 |
|
| 118 |
if ( !empty( $element[ 'elements' ] ) ) { |
| 119 |
$element = $this->find_element_recursive( $element[ 'elements' ], $form_id ); |
| 120 |
|
| 121 |
if ( $element ) { |
| 122 |
return $element; |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
return false; |
| 128 |
} |
| 129 |
} |
| 130 |
|