| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/* |
| 6 |
Description: Adds a PB subpage where you can Import and Export settings of Profile Builder. |
| 7 |
*/ |
| 8 |
|
| 9 |
/* include content of Import and Export tabs */ |
| 10 |
require_once 'pbie-import.php'; |
| 11 |
require_once 'pbie-export.php'; |
| 12 |
|
| 13 |
/* add submenu page */ |
| 14 |
add_action( 'admin_menu', 'wppb_pbie_register_submenu_page', 18 ); |
| 15 |
|
| 16 |
function wppb_pbie_register_submenu_page() { |
| 17 |
add_submenu_page( 'profile-builder', __( 'Import and Export', 'profile-builder' ), __( 'Import and Export', 'profile-builder' ), 'manage_options', 'pbie-import-export', 'wppb_pbie_submenu_page_callback' ); |
| 18 |
} |
| 19 |
|
| 20 |
function wppb_pbie_submenu_page_callback() { |
| 21 |
wppb_pbie_page(); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* adds Import and Export tab |
| 26 |
* |
| 27 |
* @param string $current tab to display. default 'import'. |
| 28 |
*/ |
| 29 |
function wppb_pbie_tabs( $current = 'import' ) { |
| 30 |
$tabs = array( |
| 31 |
'import' => __( 'Import', 'profile-builder' ), |
| 32 |
'export' => __( 'Export', 'profile-builder' ) |
| 33 |
); |
| 34 |
|
| 35 |
echo '<nav class="nav-tab-wrapper cozmoslabs-nav-tab-wrapper">'; |
| 36 |
foreach( $tabs as $tab => $name ) { |
| 37 |
$class = ( $tab == $current ) ? ' nav-tab-active' : ''; |
| 38 |
echo "<a class='nav-tab". esc_attr( $class )."' href='?page=pbie-import-export&tab=". esc_attr( $tab ) ."'>". esc_html( $name ) ."</a>"; |
| 39 |
} |
| 40 |
echo '</nav>'; |
| 41 |
} |
| 42 |
|
| 43 |
/* PB Import and Export subpage content function */ |
| 44 |
function wppb_pbie_page() { |
| 45 |
global $pagenow; |
| 46 |
|
| 47 |
?> |
| 48 |
<div class="wrap cozmoslabs-wrap"> |
| 49 |
|
| 50 |
<h1></h1> |
| 51 |
<!-- WordPress Notices are added after the h1 tag --> |
| 52 |
|
| 53 |
<div class="cozmoslabs-page-header"> |
| 54 |
<div class="cozmoslabs-section-title"> |
| 55 |
|
| 56 |
<h2 class="cozmoslabs-page-title"> |
| 57 |
<?php esc_html_e( 'Import and Export', 'profile-builder' ); ?> |
| 58 |
<a href="https://www.cozmoslabs.com/docs/profile-builder/add-ons/import-export-pb-settings/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help" style="margin-left: 5px;"></a> |
| 59 |
</h2> |
| 60 |
|
| 61 |
</div> |
| 62 |
</div> |
| 63 |
|
| 64 |
<?php |
| 65 |
if( isset ( $_GET['tab'] ) ) wppb_pbie_tabs( sanitize_text_field( $_GET['tab'] ) ); |
| 66 |
else wppb_pbie_tabs( 'import' ); |
| 67 |
?> |
| 68 |
|
| 69 |
<form method="post" action="<?php admin_url( 'admin.php?page=pbie-import-export' ); ?>" enctype= "multipart/form-data"> |
| 70 |
<?php |
| 71 |
if( $pagenow == 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] === 'pbie-import-export' ) { |
| 72 |
if( isset ( $_GET['tab'] ) ) $tab = sanitize_text_field( $_GET['tab'] ); |
| 73 |
else $tab = 'import'; |
| 74 |
|
| 75 |
switch ( $tab ) { |
| 76 |
case 'export' : |
| 77 |
wppb_pbie_export(); |
| 78 |
break; |
| 79 |
case 'import' : |
| 80 |
wppb_pbie_import(); |
| 81 |
break; |
| 82 |
} |
| 83 |
} |
| 84 |
?> |
| 85 |
</form> |
| 86 |
</div> |
| 87 |
<?php |
| 88 |
} |
| 89 |
|