Plugin Directory

Changeset 3265375


Ignore:
Timestamp:
04/02/2025 03:10:16 AM (12 months ago)
Author:
zeicaro
Message:

Versão 1.5: melhorias na interface administrativa, novo endpoint para busca de títulos semelhantes e otimizações nos campos de SEO.

Location:
wpraiz-content-api-tool
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • wpraiz-content-api-tool/tags/1.5/readme.txt

    r3178983 r3265375  
    11=== WPRaiz Content API Tool ===
    2 Contributors: zeicaro
    3 Donate link: https://ai.wpraiz.com.br
    4 Tags: REST API, Content, Post Creation, SEO, Image Upload, Automation
     2Contributors: wpraiz, joseicaro
     3Donate link: https://wpraiz.com.br
     4Tags: API, REST, SEO, Post, Categoria, WordPress, JSON, Image Upload
    55Requires at least: 5.0
    6 Tested up to: 6.6
    7 Stable tag: 1.4
     6Tested up to: 6.5
     7Requires PHP: 7.4
     8Stable tag: 1.5
    89License: GPLv3
    910License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1011
    11 Create WordPress posts via REST API with custom SEO fields, image uploads, primary category assignment, and integration with popular SEO plugins (SEOPress, Yoast SEO, and Rank Math).
     12Crie posts via API REST com SEO, imagem destacada, categorias e muito mais.
    1213
    1314== Description ==
    1415
    15 The WPRaiz Content API Tool is a powerful plugin that enables the creation of WordPress posts programmatically through a REST API. Ideal for developers and websites that need seamless content integration from external systems, this plugin supports:
     16O **WPRaiz Content API Tool** permite que você crie posts diretamente via requisições REST API no seu WordPress. Com suporte a título, conteúdo, imagem, categoria, e campos personalizados de SEO compatíveis com Yoast, Rank Math e SEOPress.
    1617
    17 - **Integration with Major SEO Plugins**: Set custom SEO fields for titles and descriptions, compatible with SEOPress, Yoast SEO, and Rank Math.
    18 - **Flexible Image Uploads**: Accept images via URL or Base64 encoding, with automatic attachment as the featured image.
    19 - **Automatic Category Management**: Assign an existing category or create a new one based on supplied category names.
    20 - **Installation Check Endpoint**: Verify plugin installation, authentication, and detect the installed SEO plugin.
     18Agora com interface administrativa interna e novos endpoints para monitoramento e integração.
     19
     20== Features ==
     21
     22- Criação de posts via API
     23- Suporte a SEO para Yoast, SEOPress e Rank Math
     24- Upload de imagem destacada via URL
     25- Criação automática da categoria principal (caso não exista)
     26- Substituição automática de imagens externas no conteúdo
     27- Interface visual com os principais endpoints
     28- Novo endpoint: listagem de categorias (`/get-categories`)
     29- Novo endpoint: verificação de status (`/check-status`)
     30- Novo endpoint: busca por títulos semelhantes (`/search-similar-posts?title=...`)
    2131
    2232== Installation ==
    2333
    24 1. Download the plugin zip file.
    25 2. In your WordPress dashboard, go to **Plugins > Add New**.
    26 3. Click on **Upload Plugin** and choose the zip file you downloaded.
    27 4. Click **Install Now** and activate the plugin.
    28 5. Use the REST API endpoint `/wp-json/api-post-creator/v1/create-post` to start creating posts programmatically.
     341. Faça upload da pasta do plugin para o diretório `/wp-content/plugins/`
     352. Ative o plugin através do menu "Plugins" no WordPress
     363. Acesse a aba "Ferramentas > WPRaiz Content API" para visualizar os endpoints e instruções de uso
    2937
    30 == Authentication ==
     38== Usage ==
    3139
    32 To authenticate API requests, you must use an application password, which can be generated from your user profile in the WordPress admin dashboard.
     40### Exemplo de requisição:
    3341
    34 1. **Generate Application Password**: Go to **Users > Profile** in the WordPress dashboard and create an application password.
    35 2. **Authorization Header**: Pass the application password in a Base64-encoded `Authorization` header in the format `Basic {base64_encode(username:application_password)}`.
     42    POST /wp-json/api-post-creator/v1/create-post
    3643
    37 == REST API Endpoints ==
     44    {
     45        "title": "Exemplo de Post",
     46        "content": "Conteúdo completo do post...",
     47        "status": "publish",
     48        "primary_category": "Geral",
     49        "seo_title": "Título para SEO",
     50        "seo_desc": "Descrição otimizada para buscadores",
     51        "image_url": "https://seudominio.com/imagem.jpg"
     52    }
    3853
    39 1. **Create Post Endpoint** 
    40    - **URL**: `/wp-json/api-post-creator/v1/create-post`
    41    - **Method**: POST
    42    - **Parameters**:
    43      - `title` (required): Title of the post.
    44      - `content` (required): Content of the post.
    45      - `status` (optional): Status of the post (default is draft).
    46      - `primary_category` (optional): Name of the primary category.
    47      - `seopress_title` (optional): Custom SEO title (SEOPress).
    48      - `seopress_desc` (optional): Custom SEO description (SEOPress).
    49      - `image_url` (optional): URL for the featured image.
     54### Autenticação:
     55Use **senhas de aplicativo** (Application Passwords) do WordPress.
    5056
    51 2. **Check Installation Endpoint** 
    52    - **URL**: `/wp-json/api-post-creator/v1/check`
    53    - **Method**: GET
    54    - **Purpose**: Validates plugin installation, authentication, and returns the installed SEO plugin (SEOPress, Yoast SEO, or Rank Math).
     57== Changelog ==
     58
     59= 1.5 =
     60- Adicionado endpoint `/get-categories` para listagem de categorias via API
     61- Adicionado endpoint `/check-status` para verificar ativação e plugin de SEO
     62- Adicionado endpoint `/search-similar-posts?title=...` para busca de títulos semelhantes
     63- Adicionado painel administrativo com tabela de endpoints e botões de cópia
     64- Adicionado preenchimento de SEO em todos os plugins simultaneamente (Yoast, SEOPress, Rank Math)
     65- Melhorias na segurança e organização do código
     66
     67= 1.4 =
     68- Versão inicial com criação de post, imagem destacada, e SEO (SEOPress)
     69
     70== Screenshots ==
     71
     721. Interface administrativa com tabela de endpoints
     732. Exemplo de chamada API
     743. Exibição da listagem de categorias via REST
    5575
    5676== Frequently Asked Questions ==
    5777
    58 = What is the REST API endpoint to create posts? =
    59 The main endpoint to create posts is `/wp-json/api-post-creator/v1/create-post`, which requires a POST request with the necessary parameters.
     78= Quais plugins de SEO são compatíveis? =
     79Yoast SEO, SEOPress e Rank Math — os campos são preenchidos automaticamente.
    6080
    61 = How do I check if the plugin is installed and authenticated? =
    62 Use the `/wp-json/api-post-creator/v1/check` endpoint with a GET request to validate installation, check authentication, and detect the active SEO plugin.
     81= A imagem destacada é salva na biblioteca de mídia? =
     82Sim, o plugin baixa a imagem via URL e associa ao post.
    6383
    64 = What parameters are required to create a post? =
    65 The `title` and `content` fields are required. Optional fields include `status`, `primary_category`, SEO metadata (such as `seopress_title`), and `image_url`.
     84= As categorias são criadas automaticamente? =
     85Sim, se a categoria primária não existir, ela é criada.
    6686
    67 = What formats are supported for image uploads? =
    68 You can upload images by providing a direct URL or Base64-encoded data. Supported formats are JPG, PNG, GIF, and JPEG.
    69 
    70 = How do I handle authentication for API requests? =
    71 Authentication requires an application password from the WordPress user profile, passed as a Basic Auth header.
    72 
    73 = Can I add categories programmatically? =
    74 Yes, the plugin automatically checks if the provided category exists. If it doesn’t, it will create it.
    75 
    76 == Screenshots ==
    77 
    78 1. **Settings Page** - Shows the WPRaiz Content API settings in the WordPress dashboard.
    79 2. **API Request Example** - Example of a JSON payload used to create a post.
    80 3. **Installation Check Response** - Shows the response for the check endpoint indicating the active SEO plugin and authentication status.
    81 
    82 == Changelog ==
    83 
    84 = 1.4 =
    85 * Added SEO metadata integration for SEOPress, Yoast SEO, and Rank Math.
    86 * Introduced `/check` endpoint to verify installation and authentication.
    87 * Enhanced error handling and response messages.
    88 
    89 = 1.3 =
    90 * Improved compatibility with WordPress 6.6.
    91 * Proper enqueuing of admin JavaScript and CSS files.
    92 * Added support for automatic category creation.
    93 * Enhanced image upload functionality.
    94 
    95 = 1.2 =
    96 * Added support for SEO metadata (SEOPress compatibility).
    97 * Fixed image upload issues.
    98 
    99 = 1.1 =
    100 * Initial public release with basic post creation via REST API.
     87= Como faço autenticação? =
     88Via senha de aplicativo do WordPress (recomendado).
    10189
    10290== Upgrade Notice ==
    10391
    104 = 1.4 =
    105 Critical update for SEO integration across multiple plugins and added verification endpoint. Please update to ensure full functionality.
     92= 1.5 =
     93Adiciona novos endpoints, interface melhorada e preenchimento completo de SEO.
    10694
    10795== License ==
    108 This plugin is licensed under GPLv3. See [GNU's official site](https://www.gnu.org/licenses/gpl-3.0.html) for details.
    10996
    110 == Support ==
    111 For questions or support, please visit [WPRaiz Support](https://ai.wpraiz.com.br).
     97Este plugin é licenciado sob a GPLv3. Veja https://www.gnu.org/licenses/gpl-3.0.html para mais detalhes.
  • wpraiz-content-api-tool/tags/1.5/wpraiz-content.php

    r3178987 r3265375  
    66 * Donate link: https://wpraiz.com.br
    77 * Description: Plugin para criar postagens via API REST com campos personalizados de SEO, upload de imagens e categoria principal.
    8  * Version: 1.4
     8 * Version: 1.5
    99 * Author: José caro
    1010 * License: GPLv3
     
    3333            'methods' => 'GET',
    3434            'callback' => [$this, 'check_status'],
    35             'permission_callback' => [$this, 'authenticate_user'],
     35            //'permission_callback' => [$this, 'authenticate_user'],
    3636        ]);
    3737    }
     
    9898
    9999    // Adiciona os campos de SEO com base no plugin ativo
    100     if (!empty($params['seo_title']) || !empty($params['seo_description'])) {
    101         // Verifica SEOPress
    102         if (is_plugin_active('wp-seopress/seopress.php')) {
    103             if (!empty($params['seopress_title'])) {
    104                 update_post_meta($post_id, '_seopress_titles_title', sanitize_text_field($params['seopress_title']));
    105             }
    106             if (!empty($params['seopress_desc'])) {
    107                 update_post_meta($post_id, '_seopress_titles_desc', sanitize_text_field($params['seopress_desc']));
    108             }
    109         }
    110         // Verifica Yoast SEO
    111         elseif (is_plugin_active('wordpress-seo/wp-seo.php')) {
    112             if (!empty($params['seopress_title'])) {
    113                 update_post_meta($post_id, '_yoast_wpseo_title', sanitize_text_field($params['seopress_title']));
    114             }
    115             if (!empty($params['seopress_desc'])) {
    116                 update_post_meta($post_id, '_yoast_wpseo_metadesc', sanitize_text_field($params['seopress_desc']));
    117             }
    118         }
    119         // Verifica Rank Math SEO
    120         elseif (is_plugin_active('seo-by-rank-math/rank-math.php')) {
    121             if (!empty($params['seopress_title'])) {
    122                 update_post_meta($post_id, 'rank_math_title', sanitize_text_field($params['seopress_title']));
    123             }
    124             if (!empty($params['seopress_desc'])) {
    125                 update_post_meta($post_id, 'rank_math_description', sanitize_text_field($params['seopress_desc']));
    126             }
    127         }
     100    // Adiciona os campos de SEO diretamente
     101    if (!empty($params['seo_title'])) {
     102        update_post_meta($post_id, '_seopress_titles_title', sanitize_text_field($params['seo_title']));
     103        update_post_meta($post_id, '_yoast_wpseo_title', sanitize_text_field($params['seo_title']));
     104        update_post_meta($post_id, 'rank_math_title', sanitize_text_field($params['seo_title']));
     105    }
     106
     107    if (!empty($params['seo_desc'])) {
     108        update_post_meta($post_id, '_seopress_titles_desc', sanitize_text_field($params['seo_desc']));
     109        update_post_meta($post_id, '_yoast_wpseo_metadesc', sanitize_text_field($params['seo_desc']));
     110        update_post_meta($post_id, 'rank_math_description', sanitize_text_field($params['seo_desc']));
    128111    }
    129112
     
    219202
    220203    public function render_admin_page() {
    221     $site_url = get_site_url();
    222     $endpoint_url = $site_url . '/wp-json/api-post-creator/v1/create-post';
    223     $check_url = $site_url . '/wp-json/api-post-creator/v1/check-status';
    224     ?>
    225     <div class="wrap">
    226         <h1>WPRaiz Content API</h1>
    227         <img src="<?php echo esc_url(plugins_url('assets/images/logo_wpraiz.png', __FILE__)); ?>" width="300" alt="WPRaiz Logo" />
    228 
    229         <h2>Endpoint da API</h2>
    230         <p>
    231             Este é o endpoint ativo para criar postagens via API:
    232             <input type="text" id="api-endpoint" value="<?php echo esc_url($endpoint_url); ?>" readonly style="width: 100%; max-width: 600px;" />
    233             <button onclick="copyToClipboard()" class="button button-primary">Copiar</button>
    234         </p>
    235        
    236         <h2>Verificar Status do Plugin</h2>
    237         <p>
    238             Utilize o endpoint abaixo para validar se o plugin está instalado corretamente e funcionando, além de verificar o plugin de SEO ativo:
    239             <input type="text" id="check-endpoint" value="<?php echo esc_url($check_url); ?>" readonly style="width: 100%; max-width: 600px;" />
    240             <button onclick="copyToClipboardCheck()" class="button button-primary">Copiar</button>
    241         </p>
    242        
    243         <h2>Instruções Iniciais</h2>
    244         <p>
    245             Este plugin permite criar postagens via API REST no WordPress. Para utilizá-lo, você deve fazer uma requisição POST para o endpoint acima.
    246             Abaixo está um exemplo de corpo (Body) da requisição:
    247         </p>
    248         <pre>
    249         {
    250             "title": "Título do Post",
    251             "content": "Este é o conteúdo do post",
    252             "status": "publish",
    253             "primary_category": "Geral",
    254             "seopress_title": "Título SEO",
    255             "seopress_desc": "Descrição SEO",
    256             "image_url": "https://seu-site.com/imagem.jpg"
    257         }
    258         </pre>
    259         <p>
    260             <strong>Importante:</strong> Para autenticar sua requisição, você deve usar a <em>senha de aplicativo</em> e não a senha principal do usuário.
    261         </p>
    262        
    263         <h2> Visite o WPRaiz</h2>
    264         <p>
     204        $site_url = get_site_url();
     205        $endpoint_url = $site_url . '/wp-json/api-post-creator/v1/create-post';
     206        $check_url = $site_url . '/wp-json/api-post-creator/v1/check-status';
     207        $categories_url = $site_url . '/wp-json/api-post-creator/v1/get-categories';
     208        $search_url = $site_url . '/wp-json/api-post-creator/v1/search-similar-posts?title=Exemplo';
     209        ?>
     210        <div class="wrap">
     211            <h1>WPRaiz Content API</h1>
     212            <img src="<?php echo esc_url(plugins_url('assets/images/logo_wpraiz.png', __FILE__)); ?>" width="300" alt="WPRaiz Logo" />
     213   
     214            <table class="widefat fixed" style="max-width: 900px; margin-top: 20px;">
     215                <thead>
     216                    <tr>
     217                        <th>Descrição</th>
     218                        <th>Endpoint</th>
     219                        <th>Ação</th>
     220                    </tr>
     221                </thead>
     222                <tbody>
     223                    <tr>
     224                        <td><strong>Criação de Post</strong><br><small>Envia um post com imagem e SEO.</small></td>
     225                        <td><input type="text" id="api-endpoint" value="<?php echo esc_url($endpoint_url); ?>" readonly style="width: 100%;" /></td>
     226                        <td><button onclick="copyToClipboard('api-endpoint')" class="button">Copiar</button></td>
     227                    </tr>
     228                    <tr>
     229                        <td><strong>Status do Plugin</strong><br><small>Verifica se o plugin e o SEO estão ativos.</small></td>
     230                        <td><input type="text" id="check-endpoint" value="<?php echo esc_url($check_url); ?>" readonly style="width: 100%;" /></td>
     231                        <td><button onclick="copyToClipboard('check-endpoint')" class="button">Copiar</button></td>
     232                    </tr>
     233                    <tr>
     234                        <td><strong>Listar Categorias</strong><br><small>Retorna categorias existentes no site.</small></td>
     235                        <td><input type="text" id="categories-endpoint" value="<?php echo esc_url($categories_url); ?>" readonly style="width: 100%;" /></td>
     236                        <td><button onclick="copyToClipboard('categories-endpoint')" class="button">Copiar</button></td>
     237                    </tr>
     238                    <tr>
     239                        <td><strong>Buscar Títulos Semelhantes</strong><br><small>Retorna posts parecidos com base no título.</small></td>
     240                        <td><input type="text" id="search-endpoint" value="<?php echo esc_url($search_url); ?>" readonly style="width: 100%;" /></td>
     241                        <td><button onclick="copyToClipboard('search-endpoint')" class="button">Copiar</button></td>
     242                    </tr>
     243                </tbody>
     244            </table>
     245   
     246            <h2 style="margin-top: 30px;">Exemplo de Requisição</h2>
     247            <pre>{
     248        "title": "Título do Post",
     249        "content": "Este é o conteúdo do post",
     250        "status": "publish",
     251        "primary_category": "Geral",
     252        "seo_title": "Título SEO",
     253        "seo_desc": "Descrição SEO",
     254        "image_url": "https://seu-site.com/imagem.jpg"
     255    }</pre>
     256            <p><strong>Importante:</strong> Use a senha de aplicativo do WordPress para autenticação via API.</p>
     257   
     258            <h2>Links Rápidos</h2>
    265259            <a href="https://wpraiz.com.br" target="_blank" class="button button-primary">Visitar WPRaiz</a>
    266             <a href="https://youtube.com/wpraiz" target="_blank" class="button button-primary">Visitar Youtube</a>
    267         </p>
    268     </div>
    269     <script type="text/javascript">
    270         function copyToClipboard() {
    271             var copyText = document.getElementById("api-endpoint");
    272             copyText.select();
    273             document.execCommand("copy");
    274             alert("Endpoint copiado: " + copyText.value);
    275         }
    276 
    277         function copyToClipboardCheck() {
    278             var copyText = document.getElementById("check-endpoint");
    279             copyText.select();
    280             document.execCommand("copy");
    281             alert("Endpoint de verificação copiado: " + copyText.value);
    282         }
    283     </script>
    284     <?php
     260            <a href="https://youtube.com/wpraiz" target="_blank" class="button button-primary">Canal no Youtube</a>
     261        </div>
     262   
     263        <script type="text/javascript">
     264            function copyToClipboard(id) {
     265                const el = document.getElementById(id);
     266                el.select();
     267                el.setSelectionRange(0, 99999);
     268                document.execCommand("copy");
     269                alert("Endpoint copiado: " + el.value);
     270            }
     271        </script>
     272        <?php
    285273    }
    286274
     
    305293    }
    306294    add_action('plugins_loaded', 'api_post_creator_with_image_and_menu_init');
     295    class API_Post_Creator_With_Categories {
     296
     297        public function __construct() {
     298            add_action('rest_api_init', [$this, 'register_routes']);
     299        }
     300
     301        public function register_routes() {
     302            register_rest_route('api-post-creator/v1', '/get-categories', [
     303                'methods' => 'GET',
     304                'callback' => [$this, 'get_categories'],
     305                //'permission_callback' => [$this, 'authenticate_user'],
     306            ]);
     307            register_rest_route('api-post-creator/v1', '/search-similar-posts', [
     308                'methods' => 'GET',
     309                'callback' => [$this, 'search_similar_posts'],
     310                'permission_callback' => '__return_true',
     311            ]);
     312        }
     313
     314        public function get_categories() {
     315            $categories = get_categories([
     316                'taxonomy' => 'category',
     317                'hide_empty' => false,
     318            ]);
     319
     320            $category_list = [];
     321            foreach ($categories as $category) {
     322                $category_list[] = [
     323                    'id' => $category->term_id,
     324                    'name' => $category->name,
     325                    'slug' => $category->slug,
     326                    'description' => $category->description,
     327                    'count' => $category->count,
     328                ];
     329            }
     330
     331            return new WP_REST_Response($category_list, 200);
     332        }
     333
     334        public function search_similar_posts($request) {
     335            $query_title = sanitize_text_field($request->get_param('title'));
     336
     337            if (empty($query_title)) {
     338                return new WP_REST_Response(['error' => 'Parâmetro "title" é obrigatório.'], 400);
     339            }
     340
     341            $posts = get_posts([
     342                'numberposts' => 100,
     343                'post_status' => 'publish',
     344                'post_type'   => 'post',
     345            ]);
     346
     347            $resultados = [];
     348
     349            foreach ($posts as $post) {
     350                similar_text(strtolower($query_title), strtolower($post->post_title), $percent);
     351                $categorias = get_the_category($post->ID);
     352                $categoria_principal = $categorias[0]->name ?? '';
     353                $categoria_secundaria = $categorias[1]->name ?? '';
     354
     355                $resultados[] = [
     356                    'title' => $post->post_title,
     357                    'score' => round($percent, 2),
     358                    'primary_category' => $categoria_principal,
     359                    'secondary_category' => $categoria_secundaria,
     360                    'url' => get_permalink($post->ID),
     361                ];
     362            }
     363
     364            usort($resultados, function($a, $b) {
     365                return $b['score'] <=> $a['score'];
     366            });
     367
     368            return new WP_REST_Response(array_slice($resultados, 0, 10), 200);
     369        }
     370
     371
     372        public function authenticate_user($request) {
     373            return current_user_can('edit_posts');
     374        }
     375    }
     376
     377    new API_Post_Creator_With_Categories();
  • wpraiz-content-api-tool/trunk/readme.txt

    r3178983 r3265375  
    11=== WPRaiz Content API Tool ===
    2 Contributors: zeicaro
    3 Donate link: https://ai.wpraiz.com.br
    4 Tags: REST API, Content, Post Creation, SEO, Image Upload, Automation
     2Contributors: wpraiz, joseicaro
     3Donate link: https://wpraiz.com.br
     4Tags: API, REST, SEO, Post, Categoria, WordPress, JSON, Image Upload
    55Requires at least: 5.0
    6 Tested up to: 6.6
    7 Stable tag: 1.4
     6Tested up to: 6.5
     7Requires PHP: 7.4
     8Stable tag: 1.5
    89License: GPLv3
    910License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1011
    11 Create WordPress posts via REST API with custom SEO fields, image uploads, primary category assignment, and integration with popular SEO plugins (SEOPress, Yoast SEO, and Rank Math).
     12Crie posts via API REST com SEO, imagem destacada, categorias e muito mais.
    1213
    1314== Description ==
    1415
    15 The WPRaiz Content API Tool is a powerful plugin that enables the creation of WordPress posts programmatically through a REST API. Ideal for developers and websites that need seamless content integration from external systems, this plugin supports:
     16O **WPRaiz Content API Tool** permite que você crie posts diretamente via requisições REST API no seu WordPress. Com suporte a título, conteúdo, imagem, categoria, e campos personalizados de SEO compatíveis com Yoast, Rank Math e SEOPress.
    1617
    17 - **Integration with Major SEO Plugins**: Set custom SEO fields for titles and descriptions, compatible with SEOPress, Yoast SEO, and Rank Math.
    18 - **Flexible Image Uploads**: Accept images via URL or Base64 encoding, with automatic attachment as the featured image.
    19 - **Automatic Category Management**: Assign an existing category or create a new one based on supplied category names.
    20 - **Installation Check Endpoint**: Verify plugin installation, authentication, and detect the installed SEO plugin.
     18Agora com interface administrativa interna e novos endpoints para monitoramento e integração.
     19
     20== Features ==
     21
     22- Criação de posts via API
     23- Suporte a SEO para Yoast, SEOPress e Rank Math
     24- Upload de imagem destacada via URL
     25- Criação automática da categoria principal (caso não exista)
     26- Substituição automática de imagens externas no conteúdo
     27- Interface visual com os principais endpoints
     28- Novo endpoint: listagem de categorias (`/get-categories`)
     29- Novo endpoint: verificação de status (`/check-status`)
     30- Novo endpoint: busca por títulos semelhantes (`/search-similar-posts?title=...`)
    2131
    2232== Installation ==
    2333
    24 1. Download the plugin zip file.
    25 2. In your WordPress dashboard, go to **Plugins > Add New**.
    26 3. Click on **Upload Plugin** and choose the zip file you downloaded.
    27 4. Click **Install Now** and activate the plugin.
    28 5. Use the REST API endpoint `/wp-json/api-post-creator/v1/create-post` to start creating posts programmatically.
     341. Faça upload da pasta do plugin para o diretório `/wp-content/plugins/`
     352. Ative o plugin através do menu "Plugins" no WordPress
     363. Acesse a aba "Ferramentas > WPRaiz Content API" para visualizar os endpoints e instruções de uso
    2937
    30 == Authentication ==
     38== Usage ==
    3139
    32 To authenticate API requests, you must use an application password, which can be generated from your user profile in the WordPress admin dashboard.
     40### Exemplo de requisição:
    3341
    34 1. **Generate Application Password**: Go to **Users > Profile** in the WordPress dashboard and create an application password.
    35 2. **Authorization Header**: Pass the application password in a Base64-encoded `Authorization` header in the format `Basic {base64_encode(username:application_password)}`.
     42    POST /wp-json/api-post-creator/v1/create-post
    3643
    37 == REST API Endpoints ==
     44    {
     45        "title": "Exemplo de Post",
     46        "content": "Conteúdo completo do post...",
     47        "status": "publish",
     48        "primary_category": "Geral",
     49        "seo_title": "Título para SEO",
     50        "seo_desc": "Descrição otimizada para buscadores",
     51        "image_url": "https://seudominio.com/imagem.jpg"
     52    }
    3853
    39 1. **Create Post Endpoint** 
    40    - **URL**: `/wp-json/api-post-creator/v1/create-post`
    41    - **Method**: POST
    42    - **Parameters**:
    43      - `title` (required): Title of the post.
    44      - `content` (required): Content of the post.
    45      - `status` (optional): Status of the post (default is draft).
    46      - `primary_category` (optional): Name of the primary category.
    47      - `seopress_title` (optional): Custom SEO title (SEOPress).
    48      - `seopress_desc` (optional): Custom SEO description (SEOPress).
    49      - `image_url` (optional): URL for the featured image.
     54### Autenticação:
     55Use **senhas de aplicativo** (Application Passwords) do WordPress.
    5056
    51 2. **Check Installation Endpoint** 
    52    - **URL**: `/wp-json/api-post-creator/v1/check`
    53    - **Method**: GET
    54    - **Purpose**: Validates plugin installation, authentication, and returns the installed SEO plugin (SEOPress, Yoast SEO, or Rank Math).
     57== Changelog ==
     58
     59= 1.5 =
     60- Adicionado endpoint `/get-categories` para listagem de categorias via API
     61- Adicionado endpoint `/check-status` para verificar ativação e plugin de SEO
     62- Adicionado endpoint `/search-similar-posts?title=...` para busca de títulos semelhantes
     63- Adicionado painel administrativo com tabela de endpoints e botões de cópia
     64- Adicionado preenchimento de SEO em todos os plugins simultaneamente (Yoast, SEOPress, Rank Math)
     65- Melhorias na segurança e organização do código
     66
     67= 1.4 =
     68- Versão inicial com criação de post, imagem destacada, e SEO (SEOPress)
     69
     70== Screenshots ==
     71
     721. Interface administrativa com tabela de endpoints
     732. Exemplo de chamada API
     743. Exibição da listagem de categorias via REST
    5575
    5676== Frequently Asked Questions ==
    5777
    58 = What is the REST API endpoint to create posts? =
    59 The main endpoint to create posts is `/wp-json/api-post-creator/v1/create-post`, which requires a POST request with the necessary parameters.
     78= Quais plugins de SEO são compatíveis? =
     79Yoast SEO, SEOPress e Rank Math — os campos são preenchidos automaticamente.
    6080
    61 = How do I check if the plugin is installed and authenticated? =
    62 Use the `/wp-json/api-post-creator/v1/check` endpoint with a GET request to validate installation, check authentication, and detect the active SEO plugin.
     81= A imagem destacada é salva na biblioteca de mídia? =
     82Sim, o plugin baixa a imagem via URL e associa ao post.
    6383
    64 = What parameters are required to create a post? =
    65 The `title` and `content` fields are required. Optional fields include `status`, `primary_category`, SEO metadata (such as `seopress_title`), and `image_url`.
     84= As categorias são criadas automaticamente? =
     85Sim, se a categoria primária não existir, ela é criada.
    6686
    67 = What formats are supported for image uploads? =
    68 You can upload images by providing a direct URL or Base64-encoded data. Supported formats are JPG, PNG, GIF, and JPEG.
    69 
    70 = How do I handle authentication for API requests? =
    71 Authentication requires an application password from the WordPress user profile, passed as a Basic Auth header.
    72 
    73 = Can I add categories programmatically? =
    74 Yes, the plugin automatically checks if the provided category exists. If it doesn’t, it will create it.
    75 
    76 == Screenshots ==
    77 
    78 1. **Settings Page** - Shows the WPRaiz Content API settings in the WordPress dashboard.
    79 2. **API Request Example** - Example of a JSON payload used to create a post.
    80 3. **Installation Check Response** - Shows the response for the check endpoint indicating the active SEO plugin and authentication status.
    81 
    82 == Changelog ==
    83 
    84 = 1.4 =
    85 * Added SEO metadata integration for SEOPress, Yoast SEO, and Rank Math.
    86 * Introduced `/check` endpoint to verify installation and authentication.
    87 * Enhanced error handling and response messages.
    88 
    89 = 1.3 =
    90 * Improved compatibility with WordPress 6.6.
    91 * Proper enqueuing of admin JavaScript and CSS files.
    92 * Added support for automatic category creation.
    93 * Enhanced image upload functionality.
    94 
    95 = 1.2 =
    96 * Added support for SEO metadata (SEOPress compatibility).
    97 * Fixed image upload issues.
    98 
    99 = 1.1 =
    100 * Initial public release with basic post creation via REST API.
     87= Como faço autenticação? =
     88Via senha de aplicativo do WordPress (recomendado).
    10189
    10290== Upgrade Notice ==
    10391
    104 = 1.4 =
    105 Critical update for SEO integration across multiple plugins and added verification endpoint. Please update to ensure full functionality.
     92= 1.5 =
     93Adiciona novos endpoints, interface melhorada e preenchimento completo de SEO.
    10694
    10795== License ==
    108 This plugin is licensed under GPLv3. See [GNU's official site](https://www.gnu.org/licenses/gpl-3.0.html) for details.
    10996
    110 == Support ==
    111 For questions or support, please visit [WPRaiz Support](https://ai.wpraiz.com.br).
     97Este plugin é licenciado sob a GPLv3. Veja https://www.gnu.org/licenses/gpl-3.0.html para mais detalhes.
  • wpraiz-content-api-tool/trunk/wpraiz-content.php

    r3178987 r3265375  
    66 * Donate link: https://wpraiz.com.br
    77 * Description: Plugin para criar postagens via API REST com campos personalizados de SEO, upload de imagens e categoria principal.
    8  * Version: 1.4
     8 * Version: 1.5
    99 * Author: José caro
    1010 * License: GPLv3
     
    3333            'methods' => 'GET',
    3434            'callback' => [$this, 'check_status'],
    35             'permission_callback' => [$this, 'authenticate_user'],
     35            //'permission_callback' => [$this, 'authenticate_user'],
    3636        ]);
    3737    }
     
    9898
    9999    // Adiciona os campos de SEO com base no plugin ativo
    100     if (!empty($params['seo_title']) || !empty($params['seo_description'])) {
    101         // Verifica SEOPress
    102         if (is_plugin_active('wp-seopress/seopress.php')) {
    103             if (!empty($params['seopress_title'])) {
    104                 update_post_meta($post_id, '_seopress_titles_title', sanitize_text_field($params['seopress_title']));
    105             }
    106             if (!empty($params['seopress_desc'])) {
    107                 update_post_meta($post_id, '_seopress_titles_desc', sanitize_text_field($params['seopress_desc']));
    108             }
    109         }
    110         // Verifica Yoast SEO
    111         elseif (is_plugin_active('wordpress-seo/wp-seo.php')) {
    112             if (!empty($params['seopress_title'])) {
    113                 update_post_meta($post_id, '_yoast_wpseo_title', sanitize_text_field($params['seopress_title']));
    114             }
    115             if (!empty($params['seopress_desc'])) {
    116                 update_post_meta($post_id, '_yoast_wpseo_metadesc', sanitize_text_field($params['seopress_desc']));
    117             }
    118         }
    119         // Verifica Rank Math SEO
    120         elseif (is_plugin_active('seo-by-rank-math/rank-math.php')) {
    121             if (!empty($params['seopress_title'])) {
    122                 update_post_meta($post_id, 'rank_math_title', sanitize_text_field($params['seopress_title']));
    123             }
    124             if (!empty($params['seopress_desc'])) {
    125                 update_post_meta($post_id, 'rank_math_description', sanitize_text_field($params['seopress_desc']));
    126             }
    127         }
     100    // Adiciona os campos de SEO diretamente
     101    if (!empty($params['seo_title'])) {
     102        update_post_meta($post_id, '_seopress_titles_title', sanitize_text_field($params['seo_title']));
     103        update_post_meta($post_id, '_yoast_wpseo_title', sanitize_text_field($params['seo_title']));
     104        update_post_meta($post_id, 'rank_math_title', sanitize_text_field($params['seo_title']));
     105    }
     106
     107    if (!empty($params['seo_desc'])) {
     108        update_post_meta($post_id, '_seopress_titles_desc', sanitize_text_field($params['seo_desc']));
     109        update_post_meta($post_id, '_yoast_wpseo_metadesc', sanitize_text_field($params['seo_desc']));
     110        update_post_meta($post_id, 'rank_math_description', sanitize_text_field($params['seo_desc']));
    128111    }
    129112
     
    219202
    220203    public function render_admin_page() {
    221     $site_url = get_site_url();
    222     $endpoint_url = $site_url . '/wp-json/api-post-creator/v1/create-post';
    223     $check_url = $site_url . '/wp-json/api-post-creator/v1/check-status';
    224     ?>
    225     <div class="wrap">
    226         <h1>WPRaiz Content API</h1>
    227         <img src="<?php echo esc_url(plugins_url('assets/images/logo_wpraiz.png', __FILE__)); ?>" width="300" alt="WPRaiz Logo" />
    228 
    229         <h2>Endpoint da API</h2>
    230         <p>
    231             Este é o endpoint ativo para criar postagens via API:
    232             <input type="text" id="api-endpoint" value="<?php echo esc_url($endpoint_url); ?>" readonly style="width: 100%; max-width: 600px;" />
    233             <button onclick="copyToClipboard()" class="button button-primary">Copiar</button>
    234         </p>
    235        
    236         <h2>Verificar Status do Plugin</h2>
    237         <p>
    238             Utilize o endpoint abaixo para validar se o plugin está instalado corretamente e funcionando, além de verificar o plugin de SEO ativo:
    239             <input type="text" id="check-endpoint" value="<?php echo esc_url($check_url); ?>" readonly style="width: 100%; max-width: 600px;" />
    240             <button onclick="copyToClipboardCheck()" class="button button-primary">Copiar</button>
    241         </p>
    242        
    243         <h2>Instruções Iniciais</h2>
    244         <p>
    245             Este plugin permite criar postagens via API REST no WordPress. Para utilizá-lo, você deve fazer uma requisição POST para o endpoint acima.
    246             Abaixo está um exemplo de corpo (Body) da requisição:
    247         </p>
    248         <pre>
    249         {
    250             "title": "Título do Post",
    251             "content": "Este é o conteúdo do post",
    252             "status": "publish",
    253             "primary_category": "Geral",
    254             "seopress_title": "Título SEO",
    255             "seopress_desc": "Descrição SEO",
    256             "image_url": "https://seu-site.com/imagem.jpg"
    257         }
    258         </pre>
    259         <p>
    260             <strong>Importante:</strong> Para autenticar sua requisição, você deve usar a <em>senha de aplicativo</em> e não a senha principal do usuário.
    261         </p>
    262        
    263         <h2> Visite o WPRaiz</h2>
    264         <p>
     204        $site_url = get_site_url();
     205        $endpoint_url = $site_url . '/wp-json/api-post-creator/v1/create-post';
     206        $check_url = $site_url . '/wp-json/api-post-creator/v1/check-status';
     207        $categories_url = $site_url . '/wp-json/api-post-creator/v1/get-categories';
     208        $search_url = $site_url . '/wp-json/api-post-creator/v1/search-similar-posts?title=Exemplo';
     209        ?>
     210        <div class="wrap">
     211            <h1>WPRaiz Content API</h1>
     212            <img src="<?php echo esc_url(plugins_url('assets/images/logo_wpraiz.png', __FILE__)); ?>" width="300" alt="WPRaiz Logo" />
     213   
     214            <table class="widefat fixed" style="max-width: 900px; margin-top: 20px;">
     215                <thead>
     216                    <tr>
     217                        <th>Descrição</th>
     218                        <th>Endpoint</th>
     219                        <th>Ação</th>
     220                    </tr>
     221                </thead>
     222                <tbody>
     223                    <tr>
     224                        <td><strong>Criação de Post</strong><br><small>Envia um post com imagem e SEO.</small></td>
     225                        <td><input type="text" id="api-endpoint" value="<?php echo esc_url($endpoint_url); ?>" readonly style="width: 100%;" /></td>
     226                        <td><button onclick="copyToClipboard('api-endpoint')" class="button">Copiar</button></td>
     227                    </tr>
     228                    <tr>
     229                        <td><strong>Status do Plugin</strong><br><small>Verifica se o plugin e o SEO estão ativos.</small></td>
     230                        <td><input type="text" id="check-endpoint" value="<?php echo esc_url($check_url); ?>" readonly style="width: 100%;" /></td>
     231                        <td><button onclick="copyToClipboard('check-endpoint')" class="button">Copiar</button></td>
     232                    </tr>
     233                    <tr>
     234                        <td><strong>Listar Categorias</strong><br><small>Retorna categorias existentes no site.</small></td>
     235                        <td><input type="text" id="categories-endpoint" value="<?php echo esc_url($categories_url); ?>" readonly style="width: 100%;" /></td>
     236                        <td><button onclick="copyToClipboard('categories-endpoint')" class="button">Copiar</button></td>
     237                    </tr>
     238                    <tr>
     239                        <td><strong>Buscar Títulos Semelhantes</strong><br><small>Retorna posts parecidos com base no título.</small></td>
     240                        <td><input type="text" id="search-endpoint" value="<?php echo esc_url($search_url); ?>" readonly style="width: 100%;" /></td>
     241                        <td><button onclick="copyToClipboard('search-endpoint')" class="button">Copiar</button></td>
     242                    </tr>
     243                </tbody>
     244            </table>
     245   
     246            <h2 style="margin-top: 30px;">Exemplo de Requisição</h2>
     247            <pre>{
     248        "title": "Título do Post",
     249        "content": "Este é o conteúdo do post",
     250        "status": "publish",
     251        "primary_category": "Geral",
     252        "seo_title": "Título SEO",
     253        "seo_desc": "Descrição SEO",
     254        "image_url": "https://seu-site.com/imagem.jpg"
     255    }</pre>
     256            <p><strong>Importante:</strong> Use a senha de aplicativo do WordPress para autenticação via API.</p>
     257   
     258            <h2>Links Rápidos</h2>
    265259            <a href="https://wpraiz.com.br" target="_blank" class="button button-primary">Visitar WPRaiz</a>
    266             <a href="https://youtube.com/wpraiz" target="_blank" class="button button-primary">Visitar Youtube</a>
    267         </p>
    268     </div>
    269     <script type="text/javascript">
    270         function copyToClipboard() {
    271             var copyText = document.getElementById("api-endpoint");
    272             copyText.select();
    273             document.execCommand("copy");
    274             alert("Endpoint copiado: " + copyText.value);
    275         }
    276 
    277         function copyToClipboardCheck() {
    278             var copyText = document.getElementById("check-endpoint");
    279             copyText.select();
    280             document.execCommand("copy");
    281             alert("Endpoint de verificação copiado: " + copyText.value);
    282         }
    283     </script>
    284     <?php
     260            <a href="https://youtube.com/wpraiz" target="_blank" class="button button-primary">Canal no Youtube</a>
     261        </div>
     262   
     263        <script type="text/javascript">
     264            function copyToClipboard(id) {
     265                const el = document.getElementById(id);
     266                el.select();
     267                el.setSelectionRange(0, 99999);
     268                document.execCommand("copy");
     269                alert("Endpoint copiado: " + el.value);
     270            }
     271        </script>
     272        <?php
    285273    }
    286274
     
    305293    }
    306294    add_action('plugins_loaded', 'api_post_creator_with_image_and_menu_init');
     295    class API_Post_Creator_With_Categories {
     296
     297        public function __construct() {
     298            add_action('rest_api_init', [$this, 'register_routes']);
     299        }
     300
     301        public function register_routes() {
     302            register_rest_route('api-post-creator/v1', '/get-categories', [
     303                'methods' => 'GET',
     304                'callback' => [$this, 'get_categories'],
     305                //'permission_callback' => [$this, 'authenticate_user'],
     306            ]);
     307            register_rest_route('api-post-creator/v1', '/search-similar-posts', [
     308                'methods' => 'GET',
     309                'callback' => [$this, 'search_similar_posts'],
     310                'permission_callback' => '__return_true',
     311            ]);
     312        }
     313
     314        public function get_categories() {
     315            $categories = get_categories([
     316                'taxonomy' => 'category',
     317                'hide_empty' => false,
     318            ]);
     319
     320            $category_list = [];
     321            foreach ($categories as $category) {
     322                $category_list[] = [
     323                    'id' => $category->term_id,
     324                    'name' => $category->name,
     325                    'slug' => $category->slug,
     326                    'description' => $category->description,
     327                    'count' => $category->count,
     328                ];
     329            }
     330
     331            return new WP_REST_Response($category_list, 200);
     332        }
     333
     334        public function search_similar_posts($request) {
     335            $query_title = sanitize_text_field($request->get_param('title'));
     336
     337            if (empty($query_title)) {
     338                return new WP_REST_Response(['error' => 'Parâmetro "title" é obrigatório.'], 400);
     339            }
     340
     341            $posts = get_posts([
     342                'numberposts' => 100,
     343                'post_status' => 'publish',
     344                'post_type'   => 'post',
     345            ]);
     346
     347            $resultados = [];
     348
     349            foreach ($posts as $post) {
     350                similar_text(strtolower($query_title), strtolower($post->post_title), $percent);
     351                $categorias = get_the_category($post->ID);
     352                $categoria_principal = $categorias[0]->name ?? '';
     353                $categoria_secundaria = $categorias[1]->name ?? '';
     354
     355                $resultados[] = [
     356                    'title' => $post->post_title,
     357                    'score' => round($percent, 2),
     358                    'primary_category' => $categoria_principal,
     359                    'secondary_category' => $categoria_secundaria,
     360                    'url' => get_permalink($post->ID),
     361                ];
     362            }
     363
     364            usort($resultados, function($a, $b) {
     365                return $b['score'] <=> $a['score'];
     366            });
     367
     368            return new WP_REST_Response(array_slice($resultados, 0, 10), 200);
     369        }
     370
     371
     372        public function authenticate_user($request) {
     373            return current_user_can('edit_posts');
     374        }
     375    }
     376
     377    new API_Post_Creator_With_Categories();
Note: See TracChangeset for help on using the changeset viewer.