Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
evgrezanov committed Jun 13, 2021
1 parent fb80016 commit e5d5905
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* General functions
*/
function bp_api_request($endpoint, $params, $type)
function bpwp_api_request($endpoint, $params, $type)
{
if (empty($endpoint) || empty($type))
return;
Expand Down Expand Up @@ -44,15 +44,15 @@ function bp_api_request($endpoint, $params, $type)
/**
* Return customer billing phone
*/
function bp_api_get_customer_phone($customer_id = '')
function bpwp_api_get_customer_phone($customer_id = '')
{
if (empty($customer_id)) {
$customer_id = get_current_user_id();
}

$phone = get_user_meta($customer_id, 'billing_phone', true);

$phone = apply_filters('bp_api_filter_get_customer_phone', $phone);
$phone = apply_filters('bpwp_api_filter_get_customer_phone', $phone);

return $phone;
}
Expand Down
8 changes: 4 additions & 4 deletions inc/my-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public static function bpwp_account_links($menu_links)
*/
public static function bpwp_render_customer_info()
{
$phone = bp_api_get_customer_phone();
$phone = bpwp_api_get_customer_phone();

if (!empty($phone)) {

$res = bp_api_request(
$res = bpwp_api_request(
'customer',
array(
'phone' => $phone
Expand Down Expand Up @@ -106,11 +106,11 @@ public static function bpwp_customer_login($user_login, $user)

if (empty($bonuses) || $bonuses == '0') {

$phone = bp_api_get_customer_phone($user->ID);
$phone = bpwp_api_get_customer_phone($user->ID);

if (!empty($phone)) {

$res = bp_api_request(
$res = bpwp_api_request(
'customer',
array(
'phone' => $phone
Expand Down
32 changes: 16 additions & 16 deletions inc/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ class WooBonusPlus_Profile

public static function init()
{
add_action('init', [__CLASS__, 'bp_api_bonus_card_shortcode_init']);
add_action('woocommerce_account_bonus-plus_endpoint', [__CLASS__, 'bp_api_print_user_info']);
add_action('init', [__CLASS__, 'bpwp_api_bonus_card_shortcode_init']);
add_action('woocommerce_account_bonus-plus_endpoint', [__CLASS__, 'bpwp_api_print_user_info']);
}

/**
* Shortcode init
*/
public static function bp_api_bonus_card_shortcode_init()
public static function bpwp_api_bonus_card_shortcode_init()
{
add_shortcode('bp_api_customer_bonus_card', [__CLASS__, 'bp_api_render_customer_bonus_card']);
add_shortcode('bpwp_api_customer_bonus_card', [__CLASS__, 'bpwp_api_render_customer_bonus_card']);
}

/**
* Print customer info from bonusplus
*/
public static function bp_api_print_user_info()
public static function bpwp_api_print_user_info()
{
$phone = bp_api_get_customer_phone();
$phone = bpwp_api_get_customer_phone();
if (!empty($phone)) {

$res = bp_api_request(
$res = bpwp_api_request(
'customer',
array(
'phone' => $phone
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function bp_api_print_user_info()
</a>

<a class="card4" href="#">
<small>Следующий уровень:</small>
<small>Следующий уровень</small>
<h3>**** **** ****</h3>
<p class="small"><?= $nextCardName ?></p>
<div class="dimmer"></div>
Expand All @@ -112,14 +112,14 @@ public static function bp_api_print_user_info()
/**
* Return available bonuses for customer
*/
public static function bp_customer_get_available_bonuses($customer_id = '')
public static function bpwp_customer_get_available_bonuses($customer_id = '')
{
if ($customer_id == '') {
$customer_id = get_current_user_id();
}
$availableBonuses = get_user_meta($customer_id, 'bpw_availableBonuses', true);

$availableBonuses = apply_filters('bp_api_filter_client_available_bonuses', $availableBonuses);
$availableBonuses = apply_filters('bpwp_api_filter_client_available_bonuses', $availableBonuses);

return $availableBonuses;
}
Expand All @@ -128,10 +128,10 @@ public static function bp_customer_get_available_bonuses($customer_id = '')
/**
* Render client bonus card
*/
public static function bp_api_render_customer_bonus_card()
public static function bpwp_api_render_customer_bonus_card()
{
//todo заменить на apply_filter
$customer_bonuses = self::bp_api_prepare_customer_bonuses_data();
$customer_bonuses = self::bpwp_api_prepare_customer_bonuses_data();
/*if (!empty($customer_bonuses)){
var_dump($customer_bonuses);
die();
Expand Down Expand Up @@ -166,9 +166,9 @@ public static function bp_api_render_customer_bonus_card()
/**
* Render my-profile client bonus cards and loyal
*/
public static function bp_api_render_myprofile_bonus_card()
public static function bpwp_api_render_myprofile_bonus_card()
{
$customer_bonuses = self::bp_api_prepare_customer_bonuses_data();
$customer_bonuses = self::bpwp_api_prepare_customer_bonuses_data();
/*if (!empty($customer_bonuses)){
var_dump($customer_bonuses);
die();
Expand Down Expand Up @@ -224,7 +224,7 @@ public static function bp_api_render_myprofile_bonus_card()
/**
* Prepare customer data for display bonus card
*/
public static function bp_api_prepare_customer_bonuses_data($customer_id = '')
public static function bpwp_api_prepare_customer_bonuses_data($customer_id = '')
{
if (empty($customer_id) && is_user_logged_in()) {
$customer_id = get_current_user_id();
Expand All @@ -243,7 +243,7 @@ public static function bp_api_prepare_customer_bonuses_data($customer_id = '')

} elseif (is_user_logged_in()) {
//var_dump(2);
$bonuses = self::bp_customer_get_available_bonuses($customer_id);
$bonuses = self::bpwp_customer_get_available_bonuses($customer_id);
//$billing_phone = bp_api_get_customer_phone($customer_id);
// Если у пользователя нет бонусов или = 0
if (empty($bonuses) || $bonuses == 0) {
Expand Down
42 changes: 21 additions & 21 deletions inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@

class WooBonusPlus_Settings
{
private $woobonusplus_options;
private $bpwp_options;

public function __construct()
{
add_action('admin_menu', array($this, 'woobonusplus_add_plugin_page'));
add_action('admin_init', array($this, 'woobonusplus_page_init'));
add_action('admin_menu', array($this, 'bpwp_add_plugin_page'));
add_action('admin_init', array($this, 'bpwp_page_init'));
}

public function woobonusplus_add_plugin_page()
public function bpwp_add_plugin_page()
{
add_menu_page(
'WooBonusPlus',
'WooBonusPlus',
'manage_options',
'woobonusplus-settings',
array($this, 'woobonusplus_create_admin_page'),
'bpwp-settings',
array($this, 'bpwp_create_admin_page'),
'dashicons-admin-generic',
2,
);
}

public function woobonusplus_create_admin_page()
public function bpwp_create_admin_page()
{
$this->woobonusplus_options = get_option('woobonusplus_option_name');
$this->bpwp_options = get_option('woobonusplus_option_name');

?>

Expand All @@ -39,7 +39,7 @@ public function woobonusplus_create_admin_page()
<p>https://bonusplus.pro/lk</p>
<?php
settings_errors();
$res = bp_api_request(
$res = bpwp_api_request(
'account',
'',
'GET'
Expand Down Expand Up @@ -74,7 +74,7 @@ public function woobonusplus_create_admin_page()
<?php
}

public function woobonusplus_page_init()
public function bpwp_page_init()
{
register_setting(
'woobonusplus_option_group', // option_group
Expand Down Expand Up @@ -164,39 +164,39 @@ public function _0_callback()
{
printf(
'<input class="regular-text" type="text" name="woobonusplus_option_name[_0]" id="_0" value="%s">',
isset($this->woobonusplus_options['_0']) ? esc_attr($this->woobonusplus_options['_0']) : ''
isset($this->bpwp_options['_0']) ? esc_attr($this->bpwp_options['_0']) : ''
);
}

public function _1_callback()
{
printf(
'<input class="regular-text" type="text" name="woobonusplus_option_name[_1]" id="_1" value="%s">',
isset($this->woobonusplus_options['_1']) ? esc_attr($this->woobonusplus_options['_1']) : ''
isset($this->bpwp_options['_1']) ? esc_attr($this->bpwp_options['_1']) : ''
);
}

public function _api_2_callback()
{
printf(
'<input class="regular-text" type="text" name="woobonusplus_option_name[_api_2]" id="_api_2" value="%s">',
isset($this->woobonusplus_options['_api_2']) ? esc_attr($this->woobonusplus_options['_api_2']) : ''
isset($this->bpwp_options['_api_2']) ? esc_attr($this->bpwp_options['_api_2']) : ''
);
}

public function ____3_callback()
{
printf(
'<input class="regular-text" type="text" name="woobonusplus_option_name[____3]" id="____3" value="%s">',
isset($this->woobonusplus_options['____3']) ? esc_attr($this->woobonusplus_options['____3']) : ''
isset($this->bpwp_options['____3']) ? esc_attr($this->bpwp_options['____3']) : ''
);
}

public function ___4_callback()
{
printf(
'<textarea class="large-text" rows="5" name="woobonusplus_option_name[___4]" id="___4">%s</textarea>',
isset($this->woobonusplus_options['___4']) ? esc_attr($this->woobonusplus_options['___4']) : ''
isset($this->bpwp_options['___4']) ? esc_attr($this->bpwp_options['___4']) : ''
);
}
}
Expand All @@ -206,10 +206,10 @@ public function ___4_callback()

/*
* Retrieve this value with:
* $woobonusplus_options = get_option( 'woobonusplus_option_name' ); // Array of All Options
* $_0 = $woobonusplus_options['_0']; // Логин
* $_1 = $woobonusplus_options['_1']; // Пароль
* $_api_2 = $woobonusplus_options['_api_2']; // Ключ API
* $____3 = $woobonusplus_options['____3']; // Заголовок вкладки в профиле
* $___4 = $woobonusplus_options['___4']; // Инструкция для пользователя
* $bpwp_options = get_option( 'woobonusplus_option_name' ); // Array of All Options
* $_0 = $bpwp_options['_0']; // Логин
* $_1 = $bpwp_options['_1']; // Пароль
* $_api_2 = $bpwp_options['_api_2']; // Ключ API
* $____3 = $bpwp_options['____3']; // Заголовок вкладки в профиле
* $___4 = $bpwp_options['___4']; // Инструкция для пользователя
*/

0 comments on commit e5d5905

Please sign in to comment.