| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPCoder\Dashboard; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
use WPCoder\WOW_Plugin; |
| 8 |
|
| 9 |
class Settings { |
| 10 |
|
| 11 |
public static function init(): void { |
| 12 |
$pages = DashboardHelper::get_files( 'settings' ); |
| 13 |
|
| 14 |
$i = 0; |
| 15 |
echo '<h3 class="nav-tab-wrapper wowp-tab" id="settings-tab">'; |
| 16 |
foreach ( $pages as $key => $page ) { |
| 17 |
$current = ( $i === 0 ) ? 'nav-tab nav-tab-active' : 'nav-tab'; |
| 18 |
echo '<a class="' . esc_attr( $current ) . '" data-tab="' . esc_attr( $page['file'] ) . '">' . esc_html( $page['name'] ) . '</a>'; |
| 19 |
$i ++; |
| 20 |
} |
| 21 |
echo '</h3>'; |
| 22 |
|
| 23 |
$i = 0; |
| 24 |
|
| 25 |
echo '<div class="tab-content-wrapper wowp-tab-content" id="settings-content">'; |
| 26 |
foreach ( $pages as $key => $page ) { |
| 27 |
$current = ( $i === 0 ) ? 'tab-content tab-content-active' : 'tab-content'; |
| 28 |
$file = DashboardHelper::get_folder_path( 'settings' ) . '/' . $key . '.' . $page['file'] . '.php'; |
| 29 |
|
| 30 |
if ( file_exists( $file ) ) { |
| 31 |
echo '<div class="' . esc_attr( $current ) . '" data-content="' . esc_attr( $page['file'] ) . '">'; |
| 32 |
require_once $file; |
| 33 |
echo '</div>'; |
| 34 |
} |
| 35 |
$i ++; |
| 36 |
} |
| 37 |
echo '</div>'; |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
public static function save_item() { |
| 42 |
|
| 43 |
if ( empty( $_POST['submit_settings'] ) ) { |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
$id = absint( $_POST['tool_id'] ); |
| 48 |
$settings = apply_filters( WOW_Plugin::PREFIX . '_save_settings', [ 'data' => [], 'formats' => [] ], $_POST ); |
| 49 |
|
| 50 |
if ( empty( $id ) ) { |
| 51 |
$id_item = DBManager::insert( $settings['data'], $settings['formats'] ); |
| 52 |
} else { |
| 53 |
$where = [ |
| 54 |
'id' => absint( $id ), |
| 55 |
]; |
| 56 |
DBManager::update( $settings['data'], $where, $settings['formats'] ); |
| 57 |
$id_item = $id; |
| 58 |
} |
| 59 |
|
| 60 |
FolderManager::update_files( $settings['data'], $id_item ); |
| 61 |
|
| 62 |
wp_safe_redirect( Link::save_item( $id_item ) ); |
| 63 |
exit; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
public static function deactivate_item($id = 0): void { |
| 68 |
$id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id; |
| 69 |
|
| 70 |
if ( ! empty( $id ) ) { |
| 71 |
DBManager::update( [ 'status' => '1' ], [ 'ID' => $id ], [ '%d' ] ); |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
public static function activate_item($id = 0): void { |
| 77 |
$id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id; |
| 78 |
|
| 79 |
if ( ! empty( $id ) ) { |
| 80 |
DBManager::update( [ 'status' => '' ], [ 'ID' => $id ], [ '%d' ] ); |
| 81 |
} |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
public static function deactivate_mode($id = 0): void { |
| 86 |
$id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id; |
| 87 |
|
| 88 |
if ( ! empty( $id ) ) { |
| 89 |
DBManager::update( [ 'mode' => '' ], [ 'ID' => $id ], [ '%d' ] ); |
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
public static function activate_mode($id = 0): void { |
| 95 |
$id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id; |
| 96 |
|
| 97 |
if ( ! empty( $id ) ) { |
| 98 |
DBManager::update( [ 'mode' => '1' ], [ 'ID' => $id ], [ '%d' ] ); |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
} |