Changeset 3397401
- Timestamp:
- 11/17/2025 04:40:49 PM (5 months ago)
- Location:
- outrank/trunk
- Files:
-
- 3 edited
-
libs/api.php (modified) (5 diffs)
-
outrank.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
outrank/trunk/libs/api.php
r3364907 r3397401 46 46 'methods' => 'POST', 47 47 'callback' => 'outrank_receive_article', 48 'permission_callback' => function () { 49 $headers = getallheaders(); 50 $secretKey = $headers['X-Secret-Key'] ?? $headers['x-secret-key'] ?? null; 48 'permission_callback' => function ($request) { 49 $secretKey = $request->get_header('X-Secret-Key'); 50 if (!$secretKey) { 51 $secretKey = $request->get_header('x-secret-key'); 52 } 51 53 return $secretKey && hash_equals($secretKey, OUTRANK_API_SECRET); 52 54 } … … 140 142 } 141 143 144 // Check if slug exists in custom table and generate unique one if needed 145 $unique_slug = $slug; 146 $suffix = 2; 147 $max_attempts = 10; 148 149 while ($suffix <= $max_attempts) { 150 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery 151 $existing_in_custom = $wpdb->get_var( 152 $wpdb->prepare("SELECT COUNT(*) FROM {$table_name} WHERE slug = %s", $unique_slug) 153 ); 154 155 // Check if slug exists in WordPress posts 156 $existing_in_wp = get_page_by_path($unique_slug, OBJECT, 'post'); 157 158 if ($existing_in_custom == 0 && !$existing_in_wp) { 159 break; // Slug is unique in both tables 160 } 161 162 // Slug exists, try next suffix 163 $unique_slug = $slug . '-' . $suffix; 164 $suffix++; 165 } 166 167 // If we couldn't find a unique slug after max attempts, return error 168 if ($suffix > $max_attempts) { 169 return new WP_REST_Response([ 170 'error' => 'Too many posts with the same slug. Please use a different slug.' 171 ], 409); 172 } 173 142 174 remove_filter('content_save_pre', 'wp_filter_post_kses'); 143 175 144 176 $sanitized_content = sanitize_content($params['content'] ?? ''); 145 177 146 // Insert post 178 // Insert post with the unique slug 147 179 $post_id = wp_insert_post([ 148 180 'post_title' => $title, … … 150 182 'post_status' => get_option('outrank_post_as_draft', 'yes') === 'yes' ? 'draft' : 'publish', 151 183 'post_type' => 'post', 152 'post_name' => $ slug,184 'post_name' => $unique_slug, 153 185 'post_category' => $category_ids, 154 186 'tags_input' => isset($params['tags']) ? array_map('sanitize_text_field', $params['tags']) : [], … … 162 194 } 163 195 164 // Get the actual slug WordPress assigned (handles duplicates with -2, -3, etc.)165 $ actual_slug = get_post_field('post_name', $post_id);196 // Get the final slug and status 197 $final_slug = get_post_field('post_name', $post_id); 166 198 $post_status = get_post_field('post_status', $post_id); 167 199 … … 170 202 $inserted = $wpdb->insert($table_name, [ 171 203 'image' => $imageId, 172 'slug' => $ actual_slug, // Use WordPress-generatedslug204 'slug' => $final_slug, // Use unique slug 173 205 'title' => $title, 174 206 'meta_description' => sanitize_text_field($params['meta_description'] ?? ''), -
outrank/trunk/outrank.php
r3364907 r3397401 6 6 * Plugin URI: https://outrank.so 7 7 * Description: Get traffic and outrank competitors with automatic SEO-optimized content generation published to your WordPress site. 8 * Version: 1.0. 28 * Version: 1.0.3 9 9 * Author: Outrank 10 10 * License: GPLv2 or later -
outrank/trunk/readme.txt
r3364907 r3397401 5 5 Tested up to: 6.8 6 6 Requires PHP: 8.0 7 Stable tag: 1.0. 27 Stable tag: 1.0.3 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 74 74 == Changelog == 75 75 76 = 1.0.3 = 77 * Add custom duplicate slugs handling 78 76 79 = 1.0.2 = 77 80 * Fixed YouTube video embedding in synced articles
Note: See TracChangeset
for help on using the changeset viewer.