← All changes
|
includes/abilities/code-snippets/wdesignkit-get-snippet.php
+22
-8
2.5.5
→
2.7.0
View file →
| @@ -9,12 +9,12 @@ | ||
| 9 | 9 | exit(); |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | wp_register_ability('wdesignkit/get-snippet-info', [ |
| 13 | - 'label' => __('Get WDesignKit Snippet Info', 'sprout-mcp'), | |
| 13 | + 'label' => __('Get WDesignKit Snippet Info', 'wdesignkit'), | |
| 14 | 14 | 'description' => __( |
| 15 | 15 | 'Returns the title and description of a locally stored code snippet by its WordPress post ID. Works with both post-based and file-based (Nexter Pro) snippet storage. No cloud login required.', |
| 16 | - 'sprout-mcp', | |
| 16 | + 'wdesignkit', | |
| 17 | 17 | ), |
| 18 | 18 | 'category' => 'wdesignkit', |
| 19 | 19 | 'input_schema' => [ |
| 20 | 20 | 'type' => 'object', |
| @@ -39,10 +39,11 @@ | ||
| 39 | 39 | 'data' => ['type' => 'object'], |
| 40 | 40 | ], |
| 41 | 41 | ], |
| 42 | 42 | 'execute_callback' => 'wdesignkit_mcp_get_snippet_info', |
| 43 | - 'permission_callback' => 'sprout_mcp_permission_callback', | |
| 43 | + 'permission_callback' => 'wdesignkit_mcp_permission_callback', | |
| 44 | 44 | 'meta' => [ |
| 45 | + 'public' => true, | |
| 45 | 46 | 'show_in_rest' => true, |
| 46 | 47 | 'mcp' => ['public' => true], |
| 47 | 48 | 'annotations' => [ |
| 48 | 49 | 'instructions' => implode("\n", [ |
| @@ -59,12 +60,12 @@ | ||
| 59 | 60 | ], |
| 60 | 61 | ]); |
| 61 | 62 | |
| 62 | 63 | wp_register_ability('wdesignkit/get-existing-snippet', [ |
| 63 | - 'label' => __('Get Existing WDesignKit Cloud Snippets', 'sprout-mcp'), | |
| 64 | + 'label' => __('Get Existing WDesignKit Cloud Snippets', 'wdesignkit'), | |
| 64 | 65 | 'description' => __( |
| 65 | 66 | 'Fetches the current user\'s previously uploaded cloud snippets. Used when saving a snippet to check whether it already exists on the cloud and to obtain the cloud snippet ID for an update. Requires cloud login.', |
| 66 | - 'sprout-mcp', | |
| 67 | + 'wdesignkit', | |
| 67 | 68 | ), |
| 68 | 69 | 'category' => 'wdesignkit', |
| 69 | 70 | 'input_schema' => [ |
| 70 | 71 | 'type' => 'object', |
| @@ -95,10 +96,11 @@ | ||
| 95 | 96 | 'response' => ['type' => ['object', 'array']], |
| 96 | 97 | ], |
| 97 | 98 | ], |
| 98 | 99 | 'execute_callback' => 'wdesignkit_mcp_get_existing_snippet', |
| 99 | - 'permission_callback' => 'sprout_mcp_permission_callback', | |
| 100 | + 'permission_callback' => 'wdesignkit_mcp_permission_callback', | |
| 100 | 101 | 'meta' => [ |
| 102 | + 'public' => true, | |
| 101 | 103 | 'show_in_rest' => true, |
| 102 | 104 | 'mcp' => ['public' => true], |
| 103 | 105 | 'annotations' => [ |
| 104 | 106 | 'instructions' => implode("\n", [ |
| @@ -130,8 +132,14 @@ | ||
| 130 | 132 | $file_based = new \Nexter_Code_Snippets_File_Based(); |
| 131 | 133 | $file_code_list = $file_based->getSnippetData($file_id); |
| 132 | 134 | |
| 133 | 135 | if (!empty($file_code_list) && is_array($file_code_list)) { |
| 136 | + $lang_code = (string) ($file_code_list['langCode'] ?? ''); | |
| 137 | + $type = strtolower((string) ($file_code_list['type'] ?? '')); | |
| 138 | + if ($type === 'php' && $lang_code !== '' && !preg_match('/^\s*<\?php/i', $lang_code)) { | |
| 139 | + $lang_code = "<?php\n" . $lang_code; | |
| 140 | + } | |
| 141 | + | |
| 134 | 142 | return [ |
| 135 | 143 | 'success' => true, |
| 136 | 144 | 'message' => '', |
| 137 | 145 | 'source' => 'file', |
| @@ -142,9 +150,9 @@ | ||
| 142 | 150 | 'type' => $file_code_list['type'] ?? '', |
| 143 | 151 | 'status' => $file_code_list['status'] ?? 0, |
| 144 | 152 | 'tags' => $file_code_list['tags'] ?? [], |
| 145 | 153 | 'codeExecute' => $file_code_list['codeExecute'] ?? '', |
| 146 | - 'langCode' => $file_code_list['langCode'] ?? '', | |
| 154 | + 'langCode' => $lang_code, | |
| 147 | 155 | ], |
| 148 | 156 | ]; |
| 149 | 157 | } |
| 150 | 158 | |
| @@ -157,8 +165,14 @@ | ||
| 157 | 165 | if (class_exists('Nexter_Code_Snippets_File_Based')) { |
| 158 | 166 | $file_based = new \Nexter_Code_Snippets_File_Based(); |
| 159 | 167 | $file_code_list = $file_based->getSnippetData((string) $post_id); |
| 160 | 168 | if (!empty($file_code_list) && is_array($file_code_list)) { |
| 169 | + $lang_code = (string) ($file_code_list['langCode'] ?? ''); | |
| 170 | + $type = strtolower((string) ($file_code_list['type'] ?? '')); | |
| 171 | + if ($type === 'php' && $lang_code !== '' && !preg_match('/^\s*<\?php/i', $lang_code)) { | |
| 172 | + $lang_code = "<?php\n" . $lang_code; | |
| 173 | + } | |
| 174 | + | |
| 161 | 175 | return [ |
| 162 | 176 | 'success' => true, |
| 163 | 177 | 'message' => '', |
| 164 | 178 | 'source' => 'file', |
| @@ -169,9 +183,9 @@ | ||
| 169 | 183 | 'type' => $file_code_list['type'] ?? '', |
| 170 | 184 | 'status' => $file_code_list['status'] ?? 0, |
| 171 | 185 | 'tags' => $file_code_list['tags'] ?? [], |
| 172 | 186 | 'codeExecute' => $file_code_list['codeExecute'] ?? '', |
| 173 | - 'langCode' => $file_code_list['langCode'] ?? '', | |
| 187 | + 'langCode' => $lang_code, | |
| 174 | 188 | ], |
| 175 | 189 | ]; |
| 176 | 190 | } |
| 177 | 191 | } |