Skip to content

Commit 9edbb3e

Browse files
authored
Merge pull request #144 from RRZE-Webteam/dev
2.1.7
2 parents 76b69ed + 4445f9d commit 9edbb3e

File tree

4 files changed

+40
-33
lines changed

4 files changed

+40
-33
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: shorturl, url shortener, redirect, link management
55
Requires at least: 6.4
66
Tested up to: 6.6
77
Requires PHP: 8.2
8-
Stable tag: 2.1.5
8+
Stable tag: 2.1.7
99
License: GPLv2 or later
1010
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1111
Author: RRZE Webteam

includes/Settings.php

+32-25
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,51 @@ public function add_options_page()
2727
);
2828
}
2929

30+
3031
public function update_idm_callback()
3132
{
3233
// Check if AJAX request to update allow_uri or allow_get
3334
check_ajax_referer('update_shorturl_idm_nonce', '_ajax_nonce');
3435

35-
global $wpdb;
36-
3736
// Validate and sanitize input
3837
if (!isset($_POST['id']) || !isset($_POST['field'])) {
3938
wp_send_json_error('Invalid request');
4039
return;
4140
}
4241

4342
$id = intval($_POST['id']);
44-
$allowed_fields = ['allow_uri', 'allow_get']; // List of valid fields
43+
$allowed_fields = ['allow_uri', 'allow_get', 'allow_utm']; // List of valid fields
4544
$field = sanitize_text_field(wp_unslash($_POST['field']));
4645

4746
if (!in_array($field, $allowed_fields)) {
4847
wp_send_json_error('Invalid field');
4948
return;
5049
}
5150

51+
// Convert the value to an integer 1 or 0 based on the input
5252
$value = isset($_POST['value']) && $_POST['value'] === 'true' ? 1 : 0;
5353

54-
// Update the allow_uri or allow_get field
55-
$wpdb->update(
56-
$wpdb->prefix . 'shorturl_idms',
57-
array($field => $value),
58-
array('id' => $id),
59-
array('%d'),
60-
array('%d')
61-
);
54+
// Check if the post with the given ID exists and is of the correct type
55+
if (get_post_type($id) !== 'shorturl_idm') {
56+
wp_send_json_error('Invalid post ID or post type');
57+
return;
58+
}
6259

63-
// Return success response
64-
wp_send_json_success();
60+
// Update the corresponding meta field for the Custom Post Type
61+
$result = update_post_meta($id, $field, $value);
62+
63+
// Check if the update was successful and return the appropriate response
64+
if (false === $result) {
65+
wp_send_json_error('Meta update failed');
66+
} else {
67+
wp_send_json_success(array(
68+
'message' => 'Field updated successfully',
69+
'updated_field' => $field,
70+
'new_value' => $value,
71+
));
72+
}
6573
}
6674

67-
68-
6975
// Register settings sections and fields
7076
public function register_settings()
7177
{
@@ -841,28 +847,29 @@ class="button button-primary"><?php echo esc_html__('Save Changes', 'rrze-shortu
841847
}
842848
}
843849

844-
public function render_statistic_section() {
850+
public function render_statistic_section()
851+
{
845852
// Determine the current sorting order and column
846853
$orderby = isset($_GET['orderby']) ? sanitize_text_field(wp_unslash($_GET['orderby'])) : 'hostname';
847854
$order = isset($_GET['order']) && in_array(sanitize_text_field(wp_unslash($_GET['order'])), ['asc', 'desc']) ? sanitize_text_field(wp_unslash($_GET['order'])) : 'asc';
848-
855+
849856
// Get all domains to count associated links
850857
$args = [
851858
'post_type' => 'shorturl_domain',
852859
'posts_per_page' => -1, // Fetch all domains
853860
'orderby' => 'title', // Sort by hostname (title)
854861
'order' => $order
855862
];
856-
863+
857864
$domain_query = new \WP_Query($args);
858865
$link_counts = [];
859-
866+
860867
if ($domain_query->have_posts()) {
861868
while ($domain_query->have_posts()) {
862869
$domain_query->the_post();
863870
$domain_id = get_the_ID();
864871
$hostname = get_the_title();
865-
872+
866873
// Query to count links associated with the current domain
867874
$link_args = [
868875
'post_type' => 'shorturl_link',
@@ -876,19 +883,19 @@ public function render_statistic_section() {
876883
'posts_per_page' => -1, // Count all links
877884
'fields' => 'ids' // Only retrieve post IDs for counting
878885
];
879-
886+
880887
$link_query = new \WP_Query($link_args);
881888
$link_count = $link_query->post_count; // Get the count of associated links
882-
889+
883890
$link_counts[] = (object) [
884891
'hostname' => $hostname,
885892
'link_count' => $link_count
886893
];
887894
}
888895
}
889-
896+
890897
wp_reset_postdata(); // Reset post data after query
891-
898+
892899
// Sort the results by link count if necessary
893900
if ($orderby === 'link_count') {
894901
usort($link_counts, function ($a, $b) use ($order) {
@@ -899,7 +906,7 @@ public function render_statistic_section() {
899906
}
900907
});
901908
}
902-
909+
903910
// Output the statistics table
904911
?>
905912
<div class="wrap">

package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rrze-shorturl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: RRZE ShortURL
55
Plugin URI: https://gitlab.rrze.fau.de/rrze-webteam/rrze-shorturl
66
Description: Plugin, um URLs zu verkürzen.
7-
Version: 2.1.5
7+
Version: 2.1.7
88
Requires at least: 6.4
99
Requires PHP: 8.2
1010
Author: RRZE Webteam

0 commit comments

Comments
 (0)