Skip to content

Commit

Permalink
Merge pull request #327 from codersaiful/3.4.8.0
Browse files Browse the repository at this point in the history
3.4.8.0
  • Loading branch information
codersaiful authored Apr 29, 2024
2 parents fa985bf + 7680bbd commit 1778967
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 50 deletions.
2 changes: 1 addition & 1 deletion admin/action-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ function wpt_configure_basic_part( $settings,$current_config_value,$field_name )
<select name="<?php echo esc_attr( $field_name ); ?>[popup_notice]" id="wpt_table_popup_notice" class="wpt_fullwidth ua_input" >
<?php wpt_default_option( $page ) ?>
<option value="1" <?php wpt_selected( 'popup_notice', '1', $current_config_value ); ?>><?php esc_html_e( 'Show', 'woo-product-table' ); ?></option>
<option value="0" <?php wpt_selected( 'popup_notice', '0', $current_config_value ); ?>><?php esc_html_e( 'Hide', 'woo-product-table' ); ?></option>
<option value="no" <?php wpt_selected( 'popup_notice', 'no', $current_config_value ); ?>><?php esc_html_e( 'Hide', 'woo-product-table' ); ?></option>
</select>
</div>
</div>
Expand Down
177 changes: 177 additions & 0 deletions admin/handle/column-doc-link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
namespace WOO_PRODUCT_TABLE\Admin\Handle;

use WOO_PRODUCT_TABLE\Core\Base;

/**
* To add documentation links in the column basic form.
*
* specially from 3.4.8.0
* If we want to Doc or tutorial link for any column,
* You have to add link using $links array.
* see inside run method.
*
* there is also an example available for Custom Link.
*
* @author Saiful Islam <[email protected]>
*
* @since 3.4.8.0
*
* @package WOO_PRODUCT_TABLE
*/
class Column_Doc_Link extends Base
{
public $links = [];

/**
* Initializes the links array and adds an action to display the document links in the column basic form.
*
* @return void
*/
public function run()
{
$this->links = [
'audio' => [
[
'title' => 'Tutorial - How can create?',
'url' => 'https://wooproducttable.com/docs/doc/tutorials/how-to-create-a-audio-table-using-woo-product-table/',
],
[
'title' => 'Demo Table',
'url' => 'https://demo.wooproducttable.com/demo-list/audio-table/',
]
],

'all_content' => [
[
'title' => 'Tutorial - How to use?',
'url' => 'https://wooproducttable.com/docs/doc/advance-uses/add-multiple-content-column/',
],
],

'single_variation' => [
[
'title' => 'Tutorial - How to use Single Variation?',
'url' => 'https://wooproducttable.com/docs/doc/table-options/show-variation-name-in-a-single-column/',
'position' => 'inside', //Position inside and front available //front//inside
],
[
'title' => 'Demo',
'url' => 'https://demo.wooproducttable.com/show-variation-name-in-a-single-column',
'position' => 'inside',
],
],
'variation_name' => [
[
'title' => 'Tutorial - How to use Variation Names column?',
'url' => 'https://wooproducttable.com/docs/doc/table-options/woocommerce-products-variables-show-as-individual-row/',
],
[
'title' => 'Demo',
'url' => 'https://demo.wooproducttable.com/product-variant-in-separate-row/',
],
],
'audio_player' => [
[
'title' => 'Tutorial - How to create audio player table?',
'url' => 'https://wooproducttable.com/docs/doc/tutorials/create-an-audio-player-table/',
],
[
'title' => 'Demo',
'url' => 'https://demo.wooproducttable.com/demo-list/online-music-sale/',
],
],

'category' => [
[
'title' => 'Helper doc',
'url' => 'https://wooproducttable.com/docs/doc/table-options/show-products-by-categories-tag/',
'position' => 'inside',
],
[
'title' => 'Tutorial - Sort products by category',
'url' => 'https://wooproducttable.com/docs/doc/search-and-filter/how-to-sort-products-using-tags-or-custom-taxonomy/',
'position' => 'inside',
],
],

// ekhane column type or column keyword diye dite hobe

//Example for Custom Link
// 'type_or_column_keyword' => [
// [
// 'title' => 'Tutoiral Doc',
// 'url' => 'https://wooproducttable.com/sample-doc/',
// ]
// ],

// 'product_title' => [
// [
// 'title' => 'Tutoiral - How can create?',
// 'message' => 'This is test message', //It will display at the begining of the link
// 'url' => 'https://wooproducttable.com/docs/doc/tutorials/how-to-create-a-audio-table-using-woo-product-table/',
// ],
// [
// 'title' => 'Demo Table',
// 'url' => 'https://demo.wooproducttable.com/demo-list/audio-table/',
// ]
// ],
];
add_action( 'wpto_column_basic_form', [$this, 'add_doc_link'], 10, 3 );
add_action( 'wpto_column_setting_form', [$this, 'add_inside_doc_link'], 10, 3 );

}

public function add_doc_link( $keyword, $_device_name, $column_settings )
{
if( empty( $column_settings['type'] )) return;
$target_keyword = $column_settings['type'] == 'default' ? $keyword : $column_settings['type'];


$this->manage_doc_link( $target_keyword, 'front' );
}

public function add_inside_doc_link( $keyword, $_device_name, $column_settings )
{
$settings = $column_settings[$keyword] ?? [];

if( empty( $settings['type'] )) return;
$target_keyword = $settings['type'] == 'default' ? $keyword : $settings['type'];


$this->manage_doc_link( $target_keyword, 'inside' );
}
public function manage_doc_link( $target_keyword, $position = 'front' )
{

if( ! isset($this->links[$target_keyword]) || ! is_array( $this->links[$target_keyword] ) ) return;

if( empty( $this->links[$target_keyword] ) ) return;

$docs = $this->links[$target_keyword];
if( ! isset( $docs[0]['title'] ) ) return;
?>
<div class="wpt-doc-column-link <?php echo esc_attr( $position ); ?>">
<?php
foreach( $docs as $doc ) {
$link_position = $doc['position'] ?? 'front';
if( $position != $link_position ) continue;
$title = $doc['title'] ?? 'Doc';
$url = $doc['url'] ?? '#';
$message = $doc['message'] ?? '';
if( ! empty( $message )){
$message = '<span>' . $message . '</span>';
echo wp_kses_post( $message );
}
?>
<a href="<?php echo esc_url( $url ); ?>" title="Tutorial for <?php echo esc_attr( $target_keyword ); ?>" target="_blank">
🌐 <?php echo esc_html( $title ); ?>
</a>
<?php

}
?>
</div>
<?php
}
}
10 changes: 10 additions & 0 deletions admin/handle/feature-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@ public function run()
*/
$action = new Action_Feature();
$action->run();

/**
* I have added new Column Doc Link
* now added for column: my_extream_adio
* in next time, we will add more one by one
*
* @author Saiful Islam <[email protected]>
*/
$doc_link = new Column_Doc_Link();
$doc_link->run();
}
}
50 changes: 50 additions & 0 deletions admin/post_metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,56 @@ function wpt_array_filter_recursive($array) {
return $array;
}

add_filter('redirect_post_location', 'wpt_redirect_after_save', 10, 2);

/**
* actually redirect to last active tab, we will use this.
* See from post_metabox.php file and admin.js file
* using: setLastActiveTab(tabName); from js code
*
* value taken from <input type="text" name="wpt_last_active_tab" id="wpt-last-active-tab" value=""> file post_metabox_form.php
*
* @since 3.4.8.0
* @link https://github.com/codersaiful/woo-product-table/issues/321
*
* Redirects the user after saving a post based on specific conditions.
* @author Saiful Islam <[email protected]>
*
* @param string $location The URL to redirect to.
* @param int $post_id The ID of the post being saved.
* @return string The updated redirect URL.
*/
function wpt_redirect_after_save($location, $post_id) {
/*
* We need to verify this came from our screen and with proper authorization,
* because the save_post action can be triggered at other times.
*/

if ( ! isset( $_POST['wpt_shortcode_nonce_value'] ) ) { // Check if our nonce is set.
return;
}

// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if( ! wp_verify_nonce( $_POST['wpt_shortcode_nonce_value'], plugin_basename(__FILE__) ) ) {
return;
}

$wpt_last_active_tab = $_POST['wpt_last_active_tab'] ?? 'column_settings';
if( empty( $wpt_last_active_tab ) ){
$wpt_last_active_tab = 'column_settings';
}

// Check if it's the desired post type
if (get_post_type($post_id) == 'wpt_product_table') {
// Append the desired anchor to the redirect location
$location = add_query_arg('message', 'updated', $location) . '#' . $wpt_last_active_tab;
$location = add_query_arg('wpt_active_tab', $wpt_last_active_tab, $location);
}
return $location;
}


if( ! function_exists( 'wpt_shortcode_configuration_metabox_save_meta' ) ){

function wpt_shortcode_configuration_metabox_save_meta( $post_id, $post ) { // save the data
Expand Down
19 changes: 15 additions & 4 deletions admin/post_metabox_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,29 @@
);
$additional_data = apply_filters( 'wpto_additional_variable', $additional_variable, $post );

$wpt_active_tab = $_GET['wpt_active_tab'] ?? 'column_settings';
if( empty( $wpt_active_tab ) ){
$wpt_active_tab = 'column_settings';
}
echo '<nav class="nav-tab-wrapper">';
$active_nav = 'nav-tab-active';

foreach ($tab_array as $nav => $title) {
$active_nav = $nav == $wpt_active_tab ? 'nav-tab-active' : '';
echo "<a href='#{$nav}' data-tab='{$nav}' class='wpt_nav_for_{$nav} wpt_nav_tab nav-tab " . esc_attr( $active_nav ) . "'>" . wp_kses_post( $title ). "</a>";
$active_nav = false;
}
echo '</nav>';

?>
<!-- actually to store last active tab, we will use this.
See from post_metabox.php file and admin.js file
using: setLastActiveTab(tabName); from js code
-->
<!-- add_filter('redirect_post_location', 'wpt_redirect_after_save', 10, 2); see from post_metabox.php file -->
<input type="hidden" name="wpt_last_active_tab" id="wpt-last-active-tab" value="">
<?php
//Now start for Tab Content
$active_tab_content = 'tab-content-active';
foreach ($tab_array as $tab => $title) {
$active_tab_content = $tab == $wpt_active_tab ? 'tab-content-active' : '';
echo '<div class="wpt_tab_content tab-content ' . esc_attr( $active_tab_content ) . '" id="' . esc_attr( $tab ) . '">';
echo '<div class="fieldwrap">';

Expand Down Expand Up @@ -95,7 +107,6 @@

echo '</div>'; //End of .fieldwrap
echo '</div>'; //End of Tab content div
$active_tab_content = false; //Active tab content only for First
}
?>

Expand Down
22 changes: 22 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -2428,6 +2428,28 @@ a.wpt-doc-lick{
color: #42b9cc;
font-style: oblique;
}
.wpt-doc-column-link.front {
margin-top: -10px !important;
}
.wpt-doc-column-link>span {
color: #bfbfbf;
}
.wpt-doc-column-link a{
text-decoration: none;
color: #9E9E9E;
font-style: oblique;
font-size: 13px;
}
/* make more deep: .wpt-doc-column-link a */

.wpt-doc-column-link a:hover {
color: #525252;
}

.wpt-doc-column-link {
display: flex;
gap: 10px;
}
.add-new-column-doc>a{
color: #23282d;
text-decoration: underline;
Expand Down
35 changes: 34 additions & 1 deletion assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ jQuery.fn.extend({
var selectLinkTab = $(selectLinkTabSelector);
var selectTabContent = $(selectTabContentSelector);
var tabName = window.location.hash.substr(1);
setLastActiveTab(tabName);
if (tabName) {
removingActiveClass();
$('body.wpt_admin_body #wpt_configuration_form #' + tabName).addClass('tab-content-active');
Expand All @@ -398,17 +399,49 @@ jQuery.fn.extend({
$('body.wpt_admin_body').on('click','#wpt_configuration_form a.wpt_nav_tab',function(e){
e.preventDefault(); //Than prevent for click action of hash keyword
var targetTabContent = $(this).data('tab');//getting data value from data-tab attribute

setLastActiveTab(targetTabContent);
// Detect if pushState is available
if(history.pushState) {
history.pushState(null, null, $(this).attr('href'));
}

removingActiveClass();
$(this).addClass('nav-tab-active');
$('body.wpt_admin_body #wpt_configuration_form #' + targetTabContent).addClass('tab-content-active');
return false;
});

/**
* Sets the value of the input element with the ID 'wpt-last-active-tab' to the provided tabName.
*
* related code:
* 1. post_metabox.php
* 2. post_metabox_form.php
*
* Hooked: add_filter('redirect_post_location', 'wpt_redirect_after_save', 10, 2);
*
* @param {string} tabName - The name of the tab to set as the last active tab.
* @return {void} This function does not return anything.
*/
function setLastActiveTab(tabName) {

$('input#wpt-last-active-tab').attr('value',tabName);
//and
if( tabName == '' ){
return;
}
// Get the current URL
var currentUrl = window.location.href;

// Replace the value of 'wpt_active_tab'
var newUrl = currentUrl.replace(/(wpt_active_tab=)[^\&]+/, '$1' + tabName);

// Replace the current URL with the new URL
// Change the URL without reloading the page
history.replaceState(null, null, newUrl);
}


/**
* Removing current active nav_tab and tab_content element
*
Expand Down
Loading

0 comments on commit 1778967

Please sign in to comment.