Changeset 3490768
- Timestamp:
- 03/25/2026 10:50:50 AM (7 days ago)
- Location:
- mark-ai
- Files:
-
- 4 edited
- 1 copied
-
tags/1.0.6 (copied) (copied from mark-ai/trunk)
-
tags/1.0.6/mark-ai.php (modified) (34 diffs)
-
tags/1.0.6/readme.txt (modified) (2 diffs)
-
trunk/mark-ai.php (modified) (34 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mark-ai/tags/1.0.6/mark-ai.php
r3486488 r3490768 3 3 * Plugin Name: Mark AI 4 4 * Description: Publish content directly from Mark AI, the platform to create on-brand content at scale. 5 * Version: 1.0. 55 * Version: 1.0.6 6 6 * Requires at least: 5.6 7 7 * Requires PHP: 7.4 … … 37 37 38 38 // Define plugin constants 39 define('MARKAI_VERSION', '1.0. 5');39 define('MARKAI_VERSION', '1.0.6'); 40 40 define('MARKAI_PLUGIN_DIR', plugin_dir_path(__FILE__)); 41 41 define('MARKAI_PLUGIN_URL', plugin_dir_url(__FILE__)); … … 285 285 $body = $this->verify_request(); 286 286 if ($body === false) { 287 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);287 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 288 288 } 289 289 … … 293 293 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 294 294 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 295 wp_send_json_error( __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403);295 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 296 296 } 297 297 … … 301 301 if (json_last_error() !== JSON_ERROR_NONE) { 302 302 $this->log_activity('parse_failed', null, ['error' => json_last_error_msg()]); 303 wp_send_json_error( __('Invalid JSON payload', 'mark-ai'), 400);303 wp_send_json_error(['code' => 'invalid_payload', 'message' => __('Invalid JSON payload', 'mark-ai')], 400); 304 304 } 305 305 … … 355 355 // Classic editor publishing - validate required fields 356 356 if (!$data || !isset($data['title'])) { 357 wp_send_json_error( 'Missing required field (title)', 400);357 wp_send_json_error(['code' => 'missing_title', 'message' => __('Missing required field (title)', 'mark-ai')], 400); 358 358 } 359 359 if (!isset($data['content'])) { 360 wp_send_json_error( 'Missing required field (content)', 400);360 wp_send_json_error(['code' => 'missing_content', 'message' => __('Missing required field (content)', 'mark-ai')], 400); 361 361 } 362 362 $content = wp_kses_post($data['content']); … … 452 452 'post_type' => $post_type, 453 453 ]); 454 wp_send_json_error( $post_id->get_error_message(), 500);454 wp_send_json_error(['code' => 'publish_failed', 'message' => $post_id->get_error_message()], 500); 455 455 } 456 456 … … 535 535 $body = $this->verify_request(); 536 536 if ($body === false) { 537 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);537 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 538 538 } 539 539 … … 541 541 if (empty($integration_id)) { 542 542 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 543 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 543 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 544 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 544 545 } 545 546 … … 608 609 $body = $this->verify_request(); 609 610 if ($body === false) { 610 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);611 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 611 612 } 612 613 … … 614 615 if (empty($integration_id)) { 615 616 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 616 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 617 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 618 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 617 619 } 618 620 … … 669 671 $body = $this->verify_request(); 670 672 if ($body === false) { 671 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);673 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 672 674 } 673 675 … … 675 677 if (empty($integration_id)) { 676 678 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 677 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 679 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 680 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 678 681 } 679 682 … … 871 874 $body = $this->verify_request(); 872 875 if ($body === false) { 873 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);876 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 874 877 } 875 878 … … 877 880 if (empty($integration_id)) { 878 881 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 879 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 882 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 883 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 880 884 } 881 885 … … 895 899 896 900 if (empty($post_id)) { 897 wp_send_json_error( __('Missing required field (post_id)', 'mark-ai'), 400);901 wp_send_json_error(['code' => 'missing_post_id', 'message' => __('Missing required field (post_id)', 'mark-ai')], 400); 898 902 } 899 903 900 904 $post = get_post($post_id); 901 905 if (!$post) { 902 wp_send_json_error( __('Post not found', 'mark-ai'), 404);906 wp_send_json_error(['code' => 'post_not_found', 'message' => __('Post not found', 'mark-ai')], 404); 903 907 } 904 908 … … 907 911 $allowed_statuses = ['publish', 'draft', 'pending']; 908 912 if (!in_array($post->post_status, $allowed_statuses, true)) { 909 wp_send_json_error( __('Post not accessible', 'mark-ai'), 403);913 wp_send_json_error(['code' => 'post_not_accessible', 'message' => __('Post not accessible', 'mark-ai')], 403); 910 914 } 911 915 … … 945 949 $body = $this->verify_request(); 946 950 if ($body === false) { 947 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);951 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 948 952 } 949 953 … … 951 955 if (empty($integration_id)) { 952 956 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 953 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 957 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 958 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 954 959 } 955 960 … … 1069 1074 $body = $this->verify_request(); 1070 1075 if ($body === false) { 1071 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);1076 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 1072 1077 } 1073 1078 … … 1075 1080 if (empty($integration_id)) { 1076 1081 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 1077 wp_send_json_error(__('Connection not authorized', 'mark-ai'), 403); 1082 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 1083 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 1078 1084 } 1079 1085 … … 1126 1132 $body = $this->verify_request(); 1127 1133 if ($body === false) { 1128 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);1134 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 1129 1135 } 1130 1136 … … 1132 1138 if (empty($integration_id)) { 1133 1139 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 1134 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 1140 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 1141 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 1135 1142 } 1136 1143 … … 1150 1157 1151 1158 if (empty($post_id)) { 1152 wp_send_json_error( __('Missing required field (post_id)', 'mark-ai'), 400);1159 wp_send_json_error(['code' => 'missing_post_id', 'message' => __('Missing required field (post_id)', 'mark-ai')], 400); 1153 1160 } 1154 1161 1155 1162 $post = get_post($post_id); 1156 1163 if (!$post) { 1157 wp_send_json_error( __('Post not found', 'mark-ai'), 404);1164 wp_send_json_error(['code' => 'post_not_found', 'message' => __('Post not found', 'mark-ai')], 404); 1158 1165 } 1159 1166 … … 1161 1168 $allowed_statuses = ['publish', 'draft', 'pending']; 1162 1169 if (!in_array($post->post_status, $allowed_statuses, true)) { 1163 wp_send_json_error( __('Post not accessible', 'mark-ai'), 403);1170 wp_send_json_error(['code' => 'post_not_accessible', 'message' => __('Post not accessible', 'mark-ai')], 403); 1164 1171 } 1165 1172 … … 1778 1785 // Validate required fields 1779 1786 if (!isset($data['title'])) { 1780 wp_send_json_error( __('Missing required field (title)', 'mark-ai'), 400);1787 wp_send_json_error(['code' => 'missing_title', 'message' => __('Missing required field (title)', 'mark-ai')], 400); 1781 1788 } 1782 1789 1783 1790 $reference_post_id = isset($data['reference_post_id']) ? absint($data['reference_post_id']) : 0; 1784 1791 if (empty($reference_post_id)) { 1785 wp_send_json_error( __('Missing required field (reference_post_id)', 'mark-ai'), 400);1792 wp_send_json_error(['code' => 'missing_reference_post_id', 'message' => __('Missing required field (reference_post_id)', 'mark-ai')], 400); 1786 1793 } 1787 1794 1788 1795 $reference_post = get_post($reference_post_id); 1789 1796 if (!$reference_post) { 1790 wp_send_json_error( __('Reference post not found', 'mark-ai'), 404);1797 wp_send_json_error(['code' => 'reference_not_found', 'message' => __('Reference post not found', 'mark-ai')], 404); 1791 1798 } 1792 1799 … … 1794 1801 $allowed_statuses = ['publish', 'draft', 'pending']; 1795 1802 if (!in_array($reference_post->post_status, $allowed_statuses, true)) { 1796 wp_send_json_error( __('Reference post not accessible', 'mark-ai'), 403);1803 wp_send_json_error(['code' => 'reference_not_accessible', 'message' => __('Reference post not accessible', 'mark-ai')], 403); 1797 1804 } 1798 1805 … … 1819 1826 $elementor_data = get_post_meta($reference_post_id, '_elementor_data', true); 1820 1827 if (empty($elementor_data)) { 1821 wp_send_json_error( __('Reference post is not an Elementor post', 'mark-ai'), 400);1828 wp_send_json_error(['code' => 'invalid_editor', 'message' => __('Reference post is not an Elementor post', 'mark-ai')], 400); 1822 1829 } 1823 1830 1824 1831 $elements = json_decode($elementor_data, true); 1825 1832 if (json_last_error() !== JSON_ERROR_NONE || !is_array($elements)) { 1826 wp_send_json_error( __('Invalid Elementor data in reference post', 'mark-ai'), 400);1833 wp_send_json_error(['code' => 'invalid_elementor_data', 'message' => __('Invalid Elementor data in reference post', 'mark-ai')], 400); 1827 1834 } 1828 1835 … … 1862 1869 ]); 1863 1870 $this->report_error_to_api('error', 'Elementor publish failed: ' . $post_id->get_error_message()); 1864 wp_send_json_error( $post_id->get_error_message(), 500);1871 wp_send_json_error(['code' => 'publish_failed', 'message' => $post_id->get_error_message()], 500); 1865 1872 } 1866 1873 … … 2203 2210 $reference_content = get_post_field('post_content', $reference_post_id); 2204 2211 if (empty($reference_content) || !has_blocks($reference_content)) { 2205 wp_send_json_error( __('Reference post is not a Gutenberg post', 'mark-ai'), 400);2212 wp_send_json_error(['code' => 'invalid_editor', 'message' => __('Reference post is not a Gutenberg post', 'mark-ai')], 400); 2206 2213 } 2207 2214 … … 2256 2263 ]); 2257 2264 $this->report_error_to_api('error', 'Gutenberg publish failed: ' . $post_id->get_error_message()); 2258 wp_send_json_error( $post_id->get_error_message(), 500);2265 wp_send_json_error(['code' => 'publish_failed', 'message' => $post_id->get_error_message()], 500); 2259 2266 } 2260 2267 … … 2953 2960 */ 2954 2961 private function report_error_to_api($level, $message, $context = []) { 2955 $integration_id = get_option('markai_integration_id'); 2956 if (empty($integration_id) || empty($this->api_key)) { 2962 if (empty($this->api_key)) { 2957 2963 return; 2958 2964 } … … 2962 2968 : 'https://api.markcopy.ai'; 2963 2969 2970 $integration_id = get_option('markai_integration_id'); 2971 2964 2972 $payload = [ 2965 'integration_id' => $integration_id, 2973 'integration_id' => !empty($integration_id) ? $integration_id : null, 2974 'association_id' => get_option('markai_association_id') ?: null, 2975 'site_url' => get_site_url(), 2966 2976 'errors' => [ 2967 2977 [ … … 2969 2979 'message' => $message, 2970 2980 'context' => array_merge($context, [ 2971 'site_url' => get_site_url(),2972 2981 'plugin_version' => MARKAI_VERSION, 2973 2982 ]), -
mark-ai/tags/1.0.6/readme.txt
r3486488 r3490768 4 4 Requires at least: 5.6 5 5 Tested up to: 6.9 6 Stable tag: 1.0. 56 Stable tag: 1.0.6 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later … … 81 81 82 82 == Changelog == 83 84 = 1.0.6 = 85 * Improved error reporting and diagnostics 83 86 84 87 = 1.0.5 = -
mark-ai/trunk/mark-ai.php
r3486488 r3490768 3 3 * Plugin Name: Mark AI 4 4 * Description: Publish content directly from Mark AI, the platform to create on-brand content at scale. 5 * Version: 1.0. 55 * Version: 1.0.6 6 6 * Requires at least: 5.6 7 7 * Requires PHP: 7.4 … … 37 37 38 38 // Define plugin constants 39 define('MARKAI_VERSION', '1.0. 5');39 define('MARKAI_VERSION', '1.0.6'); 40 40 define('MARKAI_PLUGIN_DIR', plugin_dir_path(__FILE__)); 41 41 define('MARKAI_PLUGIN_URL', plugin_dir_url(__FILE__)); … … 285 285 $body = $this->verify_request(); 286 286 if ($body === false) { 287 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);287 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 288 288 } 289 289 … … 293 293 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 294 294 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 295 wp_send_json_error( __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403);295 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 296 296 } 297 297 … … 301 301 if (json_last_error() !== JSON_ERROR_NONE) { 302 302 $this->log_activity('parse_failed', null, ['error' => json_last_error_msg()]); 303 wp_send_json_error( __('Invalid JSON payload', 'mark-ai'), 400);303 wp_send_json_error(['code' => 'invalid_payload', 'message' => __('Invalid JSON payload', 'mark-ai')], 400); 304 304 } 305 305 … … 355 355 // Classic editor publishing - validate required fields 356 356 if (!$data || !isset($data['title'])) { 357 wp_send_json_error( 'Missing required field (title)', 400);357 wp_send_json_error(['code' => 'missing_title', 'message' => __('Missing required field (title)', 'mark-ai')], 400); 358 358 } 359 359 if (!isset($data['content'])) { 360 wp_send_json_error( 'Missing required field (content)', 400);360 wp_send_json_error(['code' => 'missing_content', 'message' => __('Missing required field (content)', 'mark-ai')], 400); 361 361 } 362 362 $content = wp_kses_post($data['content']); … … 452 452 'post_type' => $post_type, 453 453 ]); 454 wp_send_json_error( $post_id->get_error_message(), 500);454 wp_send_json_error(['code' => 'publish_failed', 'message' => $post_id->get_error_message()], 500); 455 455 } 456 456 … … 535 535 $body = $this->verify_request(); 536 536 if ($body === false) { 537 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);537 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 538 538 } 539 539 … … 541 541 if (empty($integration_id)) { 542 542 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 543 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 543 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 544 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 544 545 } 545 546 … … 608 609 $body = $this->verify_request(); 609 610 if ($body === false) { 610 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);611 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 611 612 } 612 613 … … 614 615 if (empty($integration_id)) { 615 616 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 616 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 617 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 618 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 617 619 } 618 620 … … 669 671 $body = $this->verify_request(); 670 672 if ($body === false) { 671 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);673 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 672 674 } 673 675 … … 675 677 if (empty($integration_id)) { 676 678 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 677 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 679 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 680 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 678 681 } 679 682 … … 871 874 $body = $this->verify_request(); 872 875 if ($body === false) { 873 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);876 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 874 877 } 875 878 … … 877 880 if (empty($integration_id)) { 878 881 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 879 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 882 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 883 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 880 884 } 881 885 … … 895 899 896 900 if (empty($post_id)) { 897 wp_send_json_error( __('Missing required field (post_id)', 'mark-ai'), 400);901 wp_send_json_error(['code' => 'missing_post_id', 'message' => __('Missing required field (post_id)', 'mark-ai')], 400); 898 902 } 899 903 900 904 $post = get_post($post_id); 901 905 if (!$post) { 902 wp_send_json_error( __('Post not found', 'mark-ai'), 404);906 wp_send_json_error(['code' => 'post_not_found', 'message' => __('Post not found', 'mark-ai')], 404); 903 907 } 904 908 … … 907 911 $allowed_statuses = ['publish', 'draft', 'pending']; 908 912 if (!in_array($post->post_status, $allowed_statuses, true)) { 909 wp_send_json_error( __('Post not accessible', 'mark-ai'), 403);913 wp_send_json_error(['code' => 'post_not_accessible', 'message' => __('Post not accessible', 'mark-ai')], 403); 910 914 } 911 915 … … 945 949 $body = $this->verify_request(); 946 950 if ($body === false) { 947 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);951 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 948 952 } 949 953 … … 951 955 if (empty($integration_id)) { 952 956 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 953 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 957 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 958 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 954 959 } 955 960 … … 1069 1074 $body = $this->verify_request(); 1070 1075 if ($body === false) { 1071 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);1076 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 1072 1077 } 1073 1078 … … 1075 1080 if (empty($integration_id)) { 1076 1081 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 1077 wp_send_json_error(__('Connection not authorized', 'mark-ai'), 403); 1082 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 1083 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 1078 1084 } 1079 1085 … … 1126 1132 $body = $this->verify_request(); 1127 1133 if ($body === false) { 1128 wp_send_json_error( __('Unauthorized', 'mark-ai'), 403);1134 wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403); 1129 1135 } 1130 1136 … … 1132 1138 if (empty($integration_id)) { 1133 1139 $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']); 1134 wp_send_json_error(__('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai'), 403); 1140 $this->report_error_to_api('error', 'Connection not authorized — markai_integration_id is empty'); 1141 wp_send_json_error(['code' => 'not_connected', 'message' => __('Connection not authorized. Please authorize from your WordPress admin.', 'mark-ai')], 403); 1135 1142 } 1136 1143 … … 1150 1157 1151 1158 if (empty($post_id)) { 1152 wp_send_json_error( __('Missing required field (post_id)', 'mark-ai'), 400);1159 wp_send_json_error(['code' => 'missing_post_id', 'message' => __('Missing required field (post_id)', 'mark-ai')], 400); 1153 1160 } 1154 1161 1155 1162 $post = get_post($post_id); 1156 1163 if (!$post) { 1157 wp_send_json_error( __('Post not found', 'mark-ai'), 404);1164 wp_send_json_error(['code' => 'post_not_found', 'message' => __('Post not found', 'mark-ai')], 404); 1158 1165 } 1159 1166 … … 1161 1168 $allowed_statuses = ['publish', 'draft', 'pending']; 1162 1169 if (!in_array($post->post_status, $allowed_statuses, true)) { 1163 wp_send_json_error( __('Post not accessible', 'mark-ai'), 403);1170 wp_send_json_error(['code' => 'post_not_accessible', 'message' => __('Post not accessible', 'mark-ai')], 403); 1164 1171 } 1165 1172 … … 1778 1785 // Validate required fields 1779 1786 if (!isset($data['title'])) { 1780 wp_send_json_error( __('Missing required field (title)', 'mark-ai'), 400);1787 wp_send_json_error(['code' => 'missing_title', 'message' => __('Missing required field (title)', 'mark-ai')], 400); 1781 1788 } 1782 1789 1783 1790 $reference_post_id = isset($data['reference_post_id']) ? absint($data['reference_post_id']) : 0; 1784 1791 if (empty($reference_post_id)) { 1785 wp_send_json_error( __('Missing required field (reference_post_id)', 'mark-ai'), 400);1792 wp_send_json_error(['code' => 'missing_reference_post_id', 'message' => __('Missing required field (reference_post_id)', 'mark-ai')], 400); 1786 1793 } 1787 1794 1788 1795 $reference_post = get_post($reference_post_id); 1789 1796 if (!$reference_post) { 1790 wp_send_json_error( __('Reference post not found', 'mark-ai'), 404);1797 wp_send_json_error(['code' => 'reference_not_found', 'message' => __('Reference post not found', 'mark-ai')], 404); 1791 1798 } 1792 1799 … … 1794 1801 $allowed_statuses = ['publish', 'draft', 'pending']; 1795 1802 if (!in_array($reference_post->post_status, $allowed_statuses, true)) { 1796 wp_send_json_error( __('Reference post not accessible', 'mark-ai'), 403);1803 wp_send_json_error(['code' => 'reference_not_accessible', 'message' => __('Reference post not accessible', 'mark-ai')], 403); 1797 1804 } 1798 1805 … … 1819 1826 $elementor_data = get_post_meta($reference_post_id, '_elementor_data', true); 1820 1827 if (empty($elementor_data)) { 1821 wp_send_json_error( __('Reference post is not an Elementor post', 'mark-ai'), 400);1828 wp_send_json_error(['code' => 'invalid_editor', 'message' => __('Reference post is not an Elementor post', 'mark-ai')], 400); 1822 1829 } 1823 1830 1824 1831 $elements = json_decode($elementor_data, true); 1825 1832 if (json_last_error() !== JSON_ERROR_NONE || !is_array($elements)) { 1826 wp_send_json_error( __('Invalid Elementor data in reference post', 'mark-ai'), 400);1833 wp_send_json_error(['code' => 'invalid_elementor_data', 'message' => __('Invalid Elementor data in reference post', 'mark-ai')], 400); 1827 1834 } 1828 1835 … … 1862 1869 ]); 1863 1870 $this->report_error_to_api('error', 'Elementor publish failed: ' . $post_id->get_error_message()); 1864 wp_send_json_error( $post_id->get_error_message(), 500);1871 wp_send_json_error(['code' => 'publish_failed', 'message' => $post_id->get_error_message()], 500); 1865 1872 } 1866 1873 … … 2203 2210 $reference_content = get_post_field('post_content', $reference_post_id); 2204 2211 if (empty($reference_content) || !has_blocks($reference_content)) { 2205 wp_send_json_error( __('Reference post is not a Gutenberg post', 'mark-ai'), 400);2212 wp_send_json_error(['code' => 'invalid_editor', 'message' => __('Reference post is not a Gutenberg post', 'mark-ai')], 400); 2206 2213 } 2207 2214 … … 2256 2263 ]); 2257 2264 $this->report_error_to_api('error', 'Gutenberg publish failed: ' . $post_id->get_error_message()); 2258 wp_send_json_error( $post_id->get_error_message(), 500);2265 wp_send_json_error(['code' => 'publish_failed', 'message' => $post_id->get_error_message()], 500); 2259 2266 } 2260 2267 … … 2953 2960 */ 2954 2961 private function report_error_to_api($level, $message, $context = []) { 2955 $integration_id = get_option('markai_integration_id'); 2956 if (empty($integration_id) || empty($this->api_key)) { 2962 if (empty($this->api_key)) { 2957 2963 return; 2958 2964 } … … 2962 2968 : 'https://api.markcopy.ai'; 2963 2969 2970 $integration_id = get_option('markai_integration_id'); 2971 2964 2972 $payload = [ 2965 'integration_id' => $integration_id, 2973 'integration_id' => !empty($integration_id) ? $integration_id : null, 2974 'association_id' => get_option('markai_association_id') ?: null, 2975 'site_url' => get_site_url(), 2966 2976 'errors' => [ 2967 2977 [ … … 2969 2979 'message' => $message, 2970 2980 'context' => array_merge($context, [ 2971 'site_url' => get_site_url(),2972 2981 'plugin_version' => MARKAI_VERSION, 2973 2982 ]), -
mark-ai/trunk/readme.txt
r3486488 r3490768 4 4 Requires at least: 5.6 5 5 Tested up to: 6.9 6 Stable tag: 1.0. 56 Stable tag: 1.0.6 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later … … 81 81 82 82 == Changelog == 83 84 = 1.0.6 = 85 * Improved error reporting and diagnostics 83 86 84 87 = 1.0.5 =
Note: See TracChangeset
for help on using the changeset viewer.