Skip to content

Commit 9e623a6

Browse files
add new chart link in the admin menu
1 parent b31f08f commit 9e623a6

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ public function registerAdminMenu() {
591591
'edit_posts',
592592
admin_url( 'admin.php?page=' . Visualizer_Plugin::NAME )
593593
);
594+
add_submenu_page(
595+
Visualizer_Plugin::NAME,
596+
__( 'Add New Chart', 'visualizer' ),
597+
__( 'Add New Chart', 'visualizer' ),
598+
'edit_posts',
599+
admin_url( 'admin.php?page=' . Visualizer_Plugin::NAME . '&addnew' )
600+
);
594601
add_submenu_page(
595602
Visualizer_Plugin::NAME,
596603
__( 'Support', 'visualizer' ),
@@ -751,20 +758,22 @@ public function renderLibraryPage() {
751758
'map_api_key' => get_option( 'visualizer-map-api-key' ),
752759
'charts' => $charts,
753760
'urls' => array(
754-
'base' => add_query_arg( 'vpage', false ),
761+
'base' => add_query_arg( array( 'vpage' => false, 'addnew' => false ) ),
755762
'create' => add_query_arg(
756763
array(
757764
'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
758765
'library' => 'yes',
759766
'type' => isset( $_GET['type'] ) ? $_GET['type'] : '',
760767
'chart-library' => isset( $_GET['chart-library'] ) ? $_GET['chart-library'] : '',
768+
'addnew' => false,
761769
),
762770
$ajaxurl
763771
),
764772
'edit' => add_query_arg(
765773
array(
766774
'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
767775
'library' => 'yes',
776+
'addnew' => false,
768777
),
769778
$ajaxurl
770779
),
@@ -781,7 +790,7 @@ public function renderLibraryPage() {
781790
$render->custom_css = $css;
782791
$render->pagination = paginate_links(
783792
array(
784-
'base' => add_query_arg( 'vpage', '%#%' ),
793+
'base' => add_query_arg( array( 'vpage' => '%#%', 'addnew' => false ) ),
785794
'format' => '',
786795
'current' => $page,
787796
'total' => $query->max_num_pages,

classes/Visualizer/Module/Chart.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ public function deleteChart() {
380380
)
381381
);
382382
}
383-
wp_redirect( wp_get_referer() );
383+
wp_redirect( remove_query_arg( 'addnew', wp_get_referer() ) );
384384
exit;
385385
}
386386

@@ -1040,7 +1040,7 @@ public function cloneChart() {
10401040
$success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
10411041
}
10421042
}
1043-
$redirect = wp_get_referer();
1043+
$redirect = remove_query_arg( 'addnew', wp_get_referer() );
10441044
if ( $success ) {
10451045
$new_chart_id = wp_insert_post(
10461046
array(
@@ -1061,6 +1061,7 @@ public function cloneChart() {
10611061
array(
10621062
'page' => 'visualizer',
10631063
'type' => filter_input( INPUT_GET, 'type' ),
1064+
'addnew' => false,
10641065
),
10651066
admin_url( 'upload.php' )
10661067
);

classes/Visualizer/Render/Library.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private function _renderLibrary() {
8282
echo '<div id="visualizer-types" class="visualizer-clearfix">';
8383
echo '<ul class="subsubsub">';
8484
// All tab.
85-
echo '<li class="visualizer-list-item all"><a class="' . ( ! isset( $_GET['type'] ) || empty( $_GET['type'] ) ? 'current' : '' ) . '" href="', esc_url( add_query_arg( array( 'vpage' => false, 'type' => false, 's' => false ) ) ), '">' . __( 'All', 'visualizer' ) . '</a> | </li>';
85+
echo '<li class="visualizer-list-item all"><a class="' . ( ! isset( $_GET['type'] ) || empty( $_GET['type'] ) ? 'current' : '' ) . '" href="', esc_url( add_query_arg( array( 'vpage' => false, 'type' => false, 'addnew' => false, 's' => false ) ) ), '">' . __( 'All', 'visualizer' ) . '</a> | </li>';
8686
foreach ( $this->types as $type => $array ) {
8787
if ( ! is_array( $array ) ) {
8888
// support for old pro
@@ -94,6 +94,7 @@ private function _renderLibrary() {
9494
array(
9595
'type' => $type,
9696
'vpage' => false,
97+
'addnew' => false,
9798
's' => false,
9899
)
99100
)

js/library.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
// remove the 'type' while refreshing the library page on creation of a new chart.
7777
// this is to avoid cases where users have filtered for chart type A and end up creating chart type B
7878
wnd.send_to_editor = function () {
79-
wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '');
79+
wnd.location.href = vu.base.replace(/type=[a-zA-Z]*/, '').replace(/addnew/, '');
8080
};
8181
view.open();
8282

@@ -88,7 +88,7 @@
8888
view = new vmv.Chart({action: vu.edit + '&chart=' + $(this).attr('data-chart')});
8989

9090
wnd.send_to_editor = function () {
91-
wnd.location.reload();
91+
wnd.location.href = wnd.location.href.replace(/addnew/, '');
9292
};
9393

9494
view.open();

0 commit comments

Comments
 (0)