Plugin Directory

Changeset 3490768


Ignore:
Timestamp:
03/25/2026 10:50:50 AM (7 days ago)
Author:
markai
Message:

Update to version 1.0.6 from GitHub

Location:
mark-ai
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • mark-ai/tags/1.0.6/mark-ai.php

    r3486488 r3490768  
    33 * Plugin Name: Mark AI
    44 * Description: Publish content directly from Mark AI, the platform to create on-brand content at scale.
    5  * Version: 1.0.5
     5 * Version: 1.0.6
    66 * Requires at least: 5.6
    77 * Requires PHP: 7.4
     
    3737
    3838// Define plugin constants
    39 define('MARKAI_VERSION', '1.0.5');
     39define('MARKAI_VERSION', '1.0.6');
    4040define('MARKAI_PLUGIN_DIR', plugin_dir_path(__FILE__));
    4141define('MARKAI_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    285285        $body = $this->verify_request();
    286286        if ($body === false) {
    287             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     287            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    288288        }
    289289
     
    293293            $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']);
    294294            $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);
    296296        }
    297297
     
    301301        if (json_last_error() !== JSON_ERROR_NONE) {
    302302            $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);
    304304        }
    305305
     
    355355        // Classic editor publishing - validate required fields
    356356        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);
    358358        }
    359359        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);
    361361        }
    362362        $content = wp_kses_post($data['content']);
     
    452452                'post_type' => $post_type,
    453453            ]);
    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);
    455455        }
    456456
     
    535535        $body = $this->verify_request();
    536536        if ($body === false) {
    537             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     537            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    538538        }
    539539
     
    541541        if (empty($integration_id)) {
    542542            $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);
    544545        }
    545546
     
    608609        $body = $this->verify_request();
    609610        if ($body === false) {
    610             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     611            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    611612        }
    612613
     
    614615        if (empty($integration_id)) {
    615616            $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);
    617619        }
    618620
     
    669671        $body = $this->verify_request();
    670672        if ($body === false) {
    671             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     673            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    672674        }
    673675
     
    675677        if (empty($integration_id)) {
    676678            $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);
    678681        }
    679682
     
    871874        $body = $this->verify_request();
    872875        if ($body === false) {
    873             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     876            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    874877        }
    875878
     
    877880        if (empty($integration_id)) {
    878881            $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);
    880884        }
    881885
     
    895899
    896900        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);
    898902        }
    899903
    900904        $post = get_post($post_id);
    901905        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);
    903907        }
    904908
     
    907911        $allowed_statuses = ['publish', 'draft', 'pending'];
    908912        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);
    910914        }
    911915
     
    945949        $body = $this->verify_request();
    946950        if ($body === false) {
    947             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     951            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    948952        }
    949953
     
    951955        if (empty($integration_id)) {
    952956            $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);
    954959        }
    955960
     
    10691074        $body = $this->verify_request();
    10701075        if ($body === false) {
    1071             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     1076            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    10721077        }
    10731078
     
    10751080        if (empty($integration_id)) {
    10761081            $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);
    10781084        }
    10791085
     
    11261132        $body = $this->verify_request();
    11271133        if ($body === false) {
    1128             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     1134            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    11291135        }
    11301136
     
    11321138        if (empty($integration_id)) {
    11331139            $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);
    11351142        }
    11361143
     
    11501157
    11511158        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);
    11531160        }
    11541161
    11551162        $post = get_post($post_id);
    11561163        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);
    11581165        }
    11591166
     
    11611168        $allowed_statuses = ['publish', 'draft', 'pending'];
    11621169        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);
    11641171        }
    11651172
     
    17781785        // Validate required fields
    17791786        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);
    17811788        }
    17821789
    17831790        $reference_post_id = isset($data['reference_post_id']) ? absint($data['reference_post_id']) : 0;
    17841791        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);
    17861793        }
    17871794
    17881795        $reference_post = get_post($reference_post_id);
    17891796        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);
    17911798        }
    17921799
     
    17941801        $allowed_statuses = ['publish', 'draft', 'pending'];
    17951802        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);
    17971804        }
    17981805
     
    18191826        $elementor_data = get_post_meta($reference_post_id, '_elementor_data', true);
    18201827        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);
    18221829        }
    18231830
    18241831        $elements = json_decode($elementor_data, true);
    18251832        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);
    18271834        }
    18281835
     
    18621869            ]);
    18631870            $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);
    18651872        }
    18661873
     
    22032210        $reference_content = get_post_field('post_content', $reference_post_id);
    22042211        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);
    22062213        }
    22072214
     
    22562263            ]);
    22572264            $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);
    22592266        }
    22602267
     
    29532960     */
    29542961    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)) {
    29572963            return;
    29582964        }
     
    29622968            : 'https://api.markcopy.ai';
    29632969
     2970        $integration_id = get_option('markai_integration_id');
     2971
    29642972        $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(),
    29662976            'errors' => [
    29672977                [
     
    29692979                    'message'   => $message,
    29702980                    'context'   => array_merge($context, [
    2971                         'site_url'       => get_site_url(),
    29722981                        'plugin_version' => MARKAI_VERSION,
    29732982                    ]),
  • mark-ai/tags/1.0.6/readme.txt

    r3486488 r3490768  
    44Requires at least: 5.6
    55Tested up to: 6.9
    6 Stable tag: 1.0.5
     6Stable tag: 1.0.6
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    8181
    8282== Changelog ==
     83
     84= 1.0.6 =
     85* Improved error reporting and diagnostics
    8386
    8487= 1.0.5 =
  • mark-ai/trunk/mark-ai.php

    r3486488 r3490768  
    33 * Plugin Name: Mark AI
    44 * Description: Publish content directly from Mark AI, the platform to create on-brand content at scale.
    5  * Version: 1.0.5
     5 * Version: 1.0.6
    66 * Requires at least: 5.6
    77 * Requires PHP: 7.4
     
    3737
    3838// Define plugin constants
    39 define('MARKAI_VERSION', '1.0.5');
     39define('MARKAI_VERSION', '1.0.6');
    4040define('MARKAI_PLUGIN_DIR', plugin_dir_path(__FILE__));
    4141define('MARKAI_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    285285        $body = $this->verify_request();
    286286        if ($body === false) {
    287             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     287            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    288288        }
    289289
     
    293293            $this->log_activity('auth_failed', null, ['error' => 'Connection not authorized']);
    294294            $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);
    296296        }
    297297
     
    301301        if (json_last_error() !== JSON_ERROR_NONE) {
    302302            $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);
    304304        }
    305305
     
    355355        // Classic editor publishing - validate required fields
    356356        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);
    358358        }
    359359        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);
    361361        }
    362362        $content = wp_kses_post($data['content']);
     
    452452                'post_type' => $post_type,
    453453            ]);
    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);
    455455        }
    456456
     
    535535        $body = $this->verify_request();
    536536        if ($body === false) {
    537             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     537            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    538538        }
    539539
     
    541541        if (empty($integration_id)) {
    542542            $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);
    544545        }
    545546
     
    608609        $body = $this->verify_request();
    609610        if ($body === false) {
    610             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     611            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    611612        }
    612613
     
    614615        if (empty($integration_id)) {
    615616            $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);
    617619        }
    618620
     
    669671        $body = $this->verify_request();
    670672        if ($body === false) {
    671             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     673            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    672674        }
    673675
     
    675677        if (empty($integration_id)) {
    676678            $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);
    678681        }
    679682
     
    871874        $body = $this->verify_request();
    872875        if ($body === false) {
    873             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     876            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    874877        }
    875878
     
    877880        if (empty($integration_id)) {
    878881            $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);
    880884        }
    881885
     
    895899
    896900        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);
    898902        }
    899903
    900904        $post = get_post($post_id);
    901905        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);
    903907        }
    904908
     
    907911        $allowed_statuses = ['publish', 'draft', 'pending'];
    908912        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);
    910914        }
    911915
     
    945949        $body = $this->verify_request();
    946950        if ($body === false) {
    947             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     951            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    948952        }
    949953
     
    951955        if (empty($integration_id)) {
    952956            $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);
    954959        }
    955960
     
    10691074        $body = $this->verify_request();
    10701075        if ($body === false) {
    1071             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     1076            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    10721077        }
    10731078
     
    10751080        if (empty($integration_id)) {
    10761081            $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);
    10781084        }
    10791085
     
    11261132        $body = $this->verify_request();
    11271133        if ($body === false) {
    1128             wp_send_json_error(__('Unauthorized', 'mark-ai'), 403);
     1134            wp_send_json_error(['code' => 'unauthorized', 'message' => __('Unauthorized', 'mark-ai')], 403);
    11291135        }
    11301136
     
    11321138        if (empty($integration_id)) {
    11331139            $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);
    11351142        }
    11361143
     
    11501157
    11511158        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);
    11531160        }
    11541161
    11551162        $post = get_post($post_id);
    11561163        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);
    11581165        }
    11591166
     
    11611168        $allowed_statuses = ['publish', 'draft', 'pending'];
    11621169        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);
    11641171        }
    11651172
     
    17781785        // Validate required fields
    17791786        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);
    17811788        }
    17821789
    17831790        $reference_post_id = isset($data['reference_post_id']) ? absint($data['reference_post_id']) : 0;
    17841791        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);
    17861793        }
    17871794
    17881795        $reference_post = get_post($reference_post_id);
    17891796        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);
    17911798        }
    17921799
     
    17941801        $allowed_statuses = ['publish', 'draft', 'pending'];
    17951802        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);
    17971804        }
    17981805
     
    18191826        $elementor_data = get_post_meta($reference_post_id, '_elementor_data', true);
    18201827        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);
    18221829        }
    18231830
    18241831        $elements = json_decode($elementor_data, true);
    18251832        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);
    18271834        }
    18281835
     
    18621869            ]);
    18631870            $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);
    18651872        }
    18661873
     
    22032210        $reference_content = get_post_field('post_content', $reference_post_id);
    22042211        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);
    22062213        }
    22072214
     
    22562263            ]);
    22572264            $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);
    22592266        }
    22602267
     
    29532960     */
    29542961    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)) {
    29572963            return;
    29582964        }
     
    29622968            : 'https://api.markcopy.ai';
    29632969
     2970        $integration_id = get_option('markai_integration_id');
     2971
    29642972        $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(),
    29662976            'errors' => [
    29672977                [
     
    29692979                    'message'   => $message,
    29702980                    'context'   => array_merge($context, [
    2971                         'site_url'       => get_site_url(),
    29722981                        'plugin_version' => MARKAI_VERSION,
    29732982                    ]),
  • mark-ai/trunk/readme.txt

    r3486488 r3490768  
    44Requires at least: 5.6
    55Tested up to: 6.9
    6 Stable tag: 1.0.5
     6Stable tag: 1.0.6
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    8181
    8282== Changelog ==
     83
     84= 1.0.6 =
     85* Improved error reporting and diagnostics
    8386
    8487= 1.0.5 =
Note: See TracChangeset for help on using the changeset viewer.