Plugin Directory

Changeset 3057511


Ignore:
Timestamp:
03/24/2024 12:12:52 AM (2 years ago)
Author:
kekotron
Message:

Adding nonce to AJAX

Location:
ai-post-generator
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • ai-post-generator/tags/3.0/functions.php

    r2913274 r3057511  
    22
    33
    4 
     4if (!function_exists('ai_post_generator_verify_nonce')){
     5    function ai_post_generator_verify_nonce() {
     6        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'ai_post_generator_nonce')) {
     7            ai_post_generator_return_json(array('exito' => false, 'error' => 'Verificación de nonce fallida.'));
     8            die();
     9        }
     10    }
     11}
    512
    613
  • ai-post-generator/tags/3.0/inc/insert-head.php

    r3056060 r3057511  
    202202    function ai_post_generator_get_Posts()
    203203    {
     204        ai_post_generator_verify_nonce();
     205
    204206        if (!current_user_can('read_private_posts')) {
    205207            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    243245    function ai_post_generator_data_Publish()
    244246    {
     247        ai_post_generator_verify_nonce();
     248
    245249        if (!current_user_can('publish_posts')) {
    246250            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    346350    function ai_post_generator_data_Preview()
    347351    {
     352        ai_post_generator_verify_nonce();
    348353
    349354        if (!isset($_POST['text']) || !isset($_POST['id'])) {
     
    371376    function ai_post_generator_saveas_Publish()
    372377    {
     378        ai_post_generator_verify_nonce();
    373379
    374380        if (!isset($_POST['id'])) {
     
    402408    function ai_post_generator_delete_Post()
    403409    {
     410        ai_post_generator_verify_nonce();
    404411
    405412        if (!isset($_POST['id'])) {
     
    569576        wp_enqueue_script(
    570577
    571             'my-functions4',
     578            'main-functions',
    572579
    573580            trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/main.js",
     
    580587
    581588        );
     589        // Pasar parámetros a JavaScript
     590        wp_localize_script('main-functions', 'aiPostGenerator', array(
     591            'ajaxurl' => admin_url('admin-ajax.php'),
     592            'nonce' => wp_create_nonce('ai_post_generator_nonce')
     593        ));
    582594
    583595        //TABLE BOOTSTRAP
  • ai-post-generator/tags/3.0/js/main.js

    r2913104 r3057511  
    23572357        var concept_table = "";
    23582358        $.ajax({
    2359             url : 'admin-ajax.php',
    2360             type: 'get',
     2359            url : aiPostGenerator.ajaxurl,
     2360            type: 'POST',
    23612361            dataType: 'json',
    23622362            data: {
    2363               action: 'ai_post_generator_get_Posts'
     2363              action: 'ai_post_generator_get_Posts',
     2364              nonce: aiPostGenerator.nonce
    23642365            },
    23652366            success: function(data) {
     
    25222523    function create_post(post){
    25232524        $.ajax({
    2524             url : 'admin-ajax.php',
     2525            url : aiPostGenerator.ajaxurl,
    25252526            type: 'post',
    25262527            dataType: 'json',
    25272528            data: {
    2528               action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date
     2529              action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date,
     2530              nonce: aiPostGenerator.nonce
    25292531            },
    25302532            success: function(data) {
     
    25452547        if (confirm("Are you sure you want to delete that post?") == true) {
    25462548            $.ajax({
    2547                 url : 'admin-ajax.php',
     2549                url : aiPostGenerator.ajaxurl,
    25482550                type: 'post',
    25492551                dataType: 'json',
    25502552                data: {
    2551                 action: 'ai_post_generator_delete_Post', id: post.id
     2553                action: 'ai_post_generator_delete_Post', id: post.id,
     2554                nonce: aiPostGenerator.nonce
    25522555                },
    25532556                success: function(data) {
     
    37893792    }
    37903793        $.ajax({
    3791         url : 'admin-ajax.php',
     3794        url : aiPostGenerator.ajaxurl,
    37923795        type: 'post',
    37933796        dataType: 'json',
    37943797        data: {
    3795           action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im
     3798          action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im,
     3799          nonce: aiPostGenerator.nonce
    37963800        },
    37973801        success: function(data) {
     
    38283832
    38293833        $.ajax({
    3830         url : 'admin-ajax.php',
     3834        url : aiPostGenerator.ajaxurl,
    38313835        type: 'post',
    38323836        dataType: 'json',
    38333837        data: {
    3834           action: 'ai_post_generator_data_Preview', id: id, text: text
     3838          action: 'ai_post_generator_data_Preview', id: id, text: text,
     3839          nonce: aiPostGenerator.nonce
    38353840        },
    38363841        success: function(data) {
     
    38603865
    38613866    $.ajax({
    3862         url : 'admin-ajax.php',
     3867        url : aiPostGenerator.ajaxurl,
    38633868
    38643869        type: 'post',
     
    38683873        data: {
    38693874
    3870           action: 'ai_post_generator_saveas_Publish', id: id, text: text
     3875          action: 'ai_post_generator_saveas_Publish', id: id, text: text,
     3876          nonce: aiPostGenerator.nonce
    38713877
    38723878        },
  • ai-post-generator/tags/3.1/functions.php

    r2913278 r3057511  
    22
    33
    4 
     4if (!function_exists('ai_post_generator_verify_nonce')){
     5    function ai_post_generator_verify_nonce() {
     6        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'ai_post_generator_nonce')) {
     7            ai_post_generator_return_json(array('exito' => false, 'error' => 'Verificación de nonce fallida.'));
     8            die();
     9        }
     10    }
     11}
    512
    613
  • ai-post-generator/tags/3.1/inc/insert-head.php

    r3056060 r3057511  
    205205    function ai_post_generator_get_Posts()
    206206    {
     207        ai_post_generator_verify_nonce();
     208
    207209        if (!current_user_can('read_private_posts')) {
    208210            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    246248    function ai_post_generator_data_Publish()
    247249    {
     250        ai_post_generator_verify_nonce();
     251
    248252        if (!current_user_can('publish_posts')) {
    249253            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    349353    function ai_post_generator_data_Preview()
    350354    {
     355        ai_post_generator_verify_nonce();
     356
    351357        if (!current_user_can('read_private_posts')) {
    352358            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    378384    function ai_post_generator_saveas_Publish()
    379385    {
     386        ai_post_generator_verify_nonce();
     387
    380388        if (!current_user_can('publish_posts')) {
    381389            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    413421    function ai_post_generator_delete_Post()
    414422    {
     423        ai_post_generator_verify_nonce();
     424
    415425        if (!current_user_can('delete_posts')) {
    416426            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    606616        wp_enqueue_script(
    607617
    608             'my-functions4',
     618            'main-functions',
    609619
    610620            trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/main.js",
     
    617627
    618628        );
     629        // Pasar parámetros a JavaScript
     630        wp_localize_script('main-functions', 'aiPostGenerator', array(
     631            'ajaxurl' => admin_url('admin-ajax.php'),
     632            'nonce' => wp_create_nonce('ai_post_generator_nonce')
     633        ));
    619634
    620635        //DATATABLE
  • ai-post-generator/tags/3.1/js/main.js

    r2913278 r3057511  
    23572357        var concept_table = "";
    23582358        $.ajax({
    2359             url : 'admin-ajax.php',
    2360             type: 'get',
     2359            url : aiPostGenerator.ajaxurl,
     2360            type: 'POST',
    23612361            dataType: 'json',
    23622362            data: {
    2363               action: 'ai_post_generator_get_Posts'
     2363              action: 'ai_post_generator_get_Posts',
     2364              nonce: aiPostGenerator.nonce
    23642365            },
    23652366            success: function(data) {
     
    25222523    function create_post(post){
    25232524        $.ajax({
    2524             url : 'admin-ajax.php',
     2525            url : aiPostGenerator.ajaxurl,
    25252526            type: 'post',
    25262527            dataType: 'json',
    25272528            data: {
    2528               action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date
     2529              action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date,
     2530              nonce: aiPostGenerator.nonce
    25292531            },
    25302532            success: function(data) {
     
    25452547        if (confirm("Are you sure you want to delete that post?") == true) {
    25462548            $.ajax({
    2547                 url : 'admin-ajax.php',
     2549                url : aiPostGenerator.ajaxurl,
    25482550                type: 'post',
    25492551                dataType: 'json',
    25502552                data: {
    2551                 action: 'ai_post_generator_delete_Post', id: post.id
     2553                action: 'ai_post_generator_delete_Post', id: post.id,
     2554                nonce: aiPostGenerator.nonce
    25522555                },
    25532556                success: function(data) {
     
    37893792    }
    37903793        $.ajax({
    3791         url : 'admin-ajax.php',
     3794        url : aiPostGenerator.ajaxurl,
    37923795        type: 'post',
    37933796        dataType: 'json',
    37943797        data: {
    3795           action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im
     3798          action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im,
     3799          nonce: aiPostGenerator.nonce
    37963800        },
    37973801        success: function(data) {
     
    38283832
    38293833        $.ajax({
    3830         url : 'admin-ajax.php',
     3834        url : aiPostGenerator.ajaxurl,
    38313835        type: 'post',
    38323836        dataType: 'json',
    38333837        data: {
    3834           action: 'ai_post_generator_data_Preview', id: id, text: text
     3838          action: 'ai_post_generator_data_Preview', id: id, text: text,
     3839          nonce: aiPostGenerator.nonce
    38353840        },
    38363841        success: function(data) {
     
    38603865
    38613866    $.ajax({
    3862         url : 'admin-ajax.php',
     3867        url : aiPostGenerator.ajaxurl,
    38633868
    38643869        type: 'post',
     
    38683873        data: {
    38693874
    3870           action: 'ai_post_generator_saveas_Publish', id: id, text: text
     3875          action: 'ai_post_generator_saveas_Publish', id: id, text: text,
     3876          nonce: aiPostGenerator.nonce
    38713877
    38723878        },
  • ai-post-generator/tags/3.2/functions.php

    r2929202 r3057511  
    33
    44
    5 
     5if (!function_exists('ai_post_generator_verify_nonce')){
     6    function ai_post_generator_verify_nonce() {
     7        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'ai_post_generator_nonce')) {
     8            ai_post_generator_return_json(array('exito' => false, 'error' => 'Verificación de nonce fallida.'));
     9            die();
     10        }
     11    }
     12}
    613
    714if (!function_exists('ai_post_generator_return_json_2')){
  • ai-post-generator/tags/3.2/inc/insert-head.php

    r3056060 r3057511  
    205205    function ai_post_generator_get_Posts()
    206206    {
     207        ai_post_generator_verify_nonce();
     208
    207209        if (!current_user_can('read_private_posts')) {
    208210            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    246248    function ai_post_generator_data_Publish()
    247249    {
     250        ai_post_generator_verify_nonce();
     251
    248252        if (!current_user_can('publish_posts')) {
    249253            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    349353    function ai_post_generator_data_Preview()
    350354    {
     355        ai_post_generator_verify_nonce();
     356
    351357        if (!current_user_can('read_private_posts')) {
    352358            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    378384    function ai_post_generator_saveas_Publish()
    379385    {
     386        ai_post_generator_verify_nonce();
     387
    380388        if (!current_user_can('publish_posts')) {
    381389            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    413421    function ai_post_generator_delete_Post()
    414422    {
     423        ai_post_generator_verify_nonce();
     424
    415425        if (!current_user_can('delete_posts')) {
    416426            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    619629        wp_enqueue_script(
    620630
    621             'my-functions4',
     631            'main-functions',
    622632
    623633            trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/main.js",
     
    630640
    631641        );
     642        // Pasar parámetros a JavaScript
     643        wp_localize_script('main-functions', 'aiPostGenerator', array(
     644            'ajaxurl' => admin_url('admin-ajax.php'),
     645            'nonce' => wp_create_nonce('ai_post_generator_nonce')
     646        ));
    632647
    633648        //DATATABLE
  • ai-post-generator/tags/3.2/js/main.js

    r2929202 r3057511  
    23572357        var concept_table = "";
    23582358        $.ajax({
    2359             url : 'admin-ajax.php',
    2360             type: 'get',
     2359            url : aiPostGenerator.ajaxurl,
     2360            type: 'POST',
    23612361            dataType: 'json',
    23622362            data: {
    2363               action: 'ai_post_generator_get_Posts'
     2363              action: 'ai_post_generator_get_Posts',
     2364              nonce: aiPostGenerator.nonce
    23642365            },
    23652366            success: function(data) {
     
    25222523    function create_post(post){
    25232524        $.ajax({
    2524             url : 'admin-ajax.php',
     2525            url : aiPostGenerator.ajaxurl,
    25252526            type: 'post',
    25262527            dataType: 'json',
    25272528            data: {
    2528               action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date
     2529              action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date,
     2530              nonce: aiPostGenerator.nonce
    25292531            },
    25302532            success: function(data) {
     
    25452547        if (confirm("Are you sure you want to delete that post?") == true) {
    25462548            $.ajax({
    2547                 url : 'admin-ajax.php',
     2549                url : aiPostGenerator.ajaxurl,
    25482550                type: 'post',
    25492551                dataType: 'json',
    25502552                data: {
    2551                 action: 'ai_post_generator_delete_Post', id: post.id
     2553                action: 'ai_post_generator_delete_Post', id: post.id,
     2554                nonce: aiPostGenerator.nonce
    25522555                },
    25532556                success: function(data) {
     
    37893792    }
    37903793        $.ajax({
    3791         url : 'admin-ajax.php',
     3794        url : aiPostGenerator.ajaxurl,
    37923795        type: 'post',
    37933796        dataType: 'json',
    37943797        data: {
    3795           action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im
     3798          action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im,
     3799          nonce: aiPostGenerator.nonce
    37963800        },
    37973801        success: function(data) {
     
    38283832
    38293833        $.ajax({
    3830         url : 'admin-ajax.php',
     3834        url : aiPostGenerator.ajaxurl,
    38313835        type: 'post',
    38323836        dataType: 'json',
    38333837        data: {
    3834           action: 'ai_post_generator_data_Preview', id: id, text: text
     3838          action: 'ai_post_generator_data_Preview', id: id, text: text,
     3839          nonce: aiPostGenerator.nonce
    38353840        },
    38363841        success: function(data) {
     
    38603865
    38613866    $.ajax({
    3862         url : 'admin-ajax.php',
     3867        url : aiPostGenerator.ajaxurl,
    38633868
    38643869        type: 'post',
     
    38683873        data: {
    38693874
    3870           action: 'ai_post_generator_saveas_Publish', id: id, text: text
     3875          action: 'ai_post_generator_saveas_Publish', id: id, text: text,
     3876          nonce: aiPostGenerator.nonce
    38713877
    38723878        },
  • ai-post-generator/tags/3.3/functions.php

    r3015504 r3057511  
    33
    44
    5 
     5if (!function_exists('ai_post_generator_verify_nonce')){
     6    function ai_post_generator_verify_nonce() {
     7        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'ai_post_generator_nonce')) {
     8            ai_post_generator_return_json(array('exito' => false, 'error' => 'Verificación de nonce fallida.'));
     9            die();
     10        }
     11    }
     12}
    613
    714if (!function_exists('ai_post_generator_return_json_2')){
  • ai-post-generator/tags/3.3/inc/insert-head.php

    r3056060 r3057511  
    213213    function ai_post_generator_get_Posts()
    214214    {
     215        ai_post_generator_verify_nonce();
     216
    215217        if (!current_user_can('read_private_posts')) {
    216218            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    254256    function ai_post_generator_data_Publish()
    255257    {
     258        ai_post_generator_verify_nonce();
     259
    256260        if (!current_user_can('publish_posts')) {
    257261            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    357361    function ai_post_generator_data_Preview()
    358362    {
     363        ai_post_generator_verify_nonce();
     364
    359365        // Comprobar si el usuario tiene permiso para publicar posts
    360366        if (!current_user_can('read_private_posts')) {
     
    387393    function ai_post_generator_saveas_Publish()
    388394    {
     395        ai_post_generator_verify_nonce();
    389396
    390397        // Comprobar si el usuario tiene permiso para publicar posts
     
    423430    function ai_post_generator_delete_Post()
    424431    {
     432        ai_post_generator_verify_nonce();
     433       
    425434        // Comprobar si el usuario tiene permiso para publicar posts
    426435        if (!current_user_can('delete_posts')) {
     
    630639        wp_enqueue_script(
    631640
    632             'my-functions4',
     641            'main-functions',
    633642
    634643            trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/main.js",
     
    672681
    673682        );
     683        // Pasar parámetros a JavaScript
     684        wp_localize_script('main-functions', 'aiPostGenerator', array(
     685            'ajaxurl' => admin_url('admin-ajax.php'),
     686            'nonce' => wp_create_nonce('ai_post_generator_nonce')
     687        ));
    674688
    675689    }
  • ai-post-generator/tags/3.3/js/main.js

    r3015504 r3057511  
    23572357        var concept_table = "";
    23582358        $.ajax({
    2359             url : 'admin-ajax.php',
    2360             type: 'get',
     2359            url : aiPostGenerator.ajaxurl,
     2360            type: 'POST',
    23612361            dataType: 'json',
    23622362            data: {
    2363               action: 'ai_post_generator_get_Posts'
     2363              action: 'ai_post_generator_get_Posts',
     2364              nonce: aiPostGenerator.nonce
    23642365            },
    23652366            success: function(data) {
     
    25222523    function create_post(post){
    25232524        $.ajax({
    2524             url : 'admin-ajax.php',
     2525            url : aiPostGenerator.ajaxurl,
    25252526            type: 'post',
    25262527            dataType: 'json',
    25272528            data: {
    2528               action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date
     2529              action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date,
     2530              nonce: aiPostGenerator.nonce
    25292531            },
    25302532            success: function(data) {
     
    25452547        if (confirm("Are you sure you want to delete that post?") == true) {
    25462548            $.ajax({
    2547                 url : 'admin-ajax.php',
     2549                url : aiPostGenerator.ajaxurl,
    25482550                type: 'post',
    25492551                dataType: 'json',
    25502552                data: {
    2551                 action: 'ai_post_generator_delete_Post', id: post.id
     2553                action: 'ai_post_generator_delete_Post',
     2554                nonce: aiPostGenerator.nonce,
     2555                id: post.id
    25522556                },
    25532557                success: function(data) {
     
    37893793    }
    37903794        $.ajax({
    3791         url : 'admin-ajax.php',
     3795        url : aiPostGenerator.ajaxurl,
    37923796        type: 'post',
    37933797        dataType: 'json',
    37943798        data: {
    3795           action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im
     3799          action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im,
     3800          nonce: aiPostGenerator.nonce
    37963801        },
    37973802        success: function(data) {
     
    38283833
    38293834        $.ajax({
    3830         url : 'admin-ajax.php',
     3835        url : aiPostGenerator.ajaxurl,
    38313836        type: 'post',
    38323837        dataType: 'json',
    38333838        data: {
    3834           action: 'ai_post_generator_data_Preview', id: id, text: text
     3839          action: 'ai_post_generator_data_Preview', id: id, text: text,
     3840          nonce: aiPostGenerator.nonce
    38353841        },
    38363842        success: function(data) {
     
    38603866
    38613867    $.ajax({
    3862         url : 'admin-ajax.php',
     3868        url : aiPostGenerator.ajaxurl,
    38633869
    38643870        type: 'post',
     
    38683874        data: {
    38693875
    3870           action: 'ai_post_generator_saveas_Publish', id: id, text: text
     3876          action: 'ai_post_generator_saveas_Publish', id: id, text: text,
     3877          nonce: aiPostGenerator.nonce
    38713878
    38723879        },
  • ai-post-generator/tags/3.4/functions.php

    r3056020 r3057511  
    33
    44
    5 
     5if (!function_exists('ai_post_generator_verify_nonce')){
     6    function ai_post_generator_verify_nonce() {
     7        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'ai_post_generator_nonce')) {
     8            ai_post_generator_return_json(array('exito' => false, 'error' => 'Verificación de nonce fallida.'));
     9            die();
     10        }
     11    }
     12}
    613
    714if (!function_exists('ai_post_generator_return_json_2')){
  • ai-post-generator/tags/3.4/inc/insert-head.php

    r3056020 r3057511  
    213213    function ai_post_generator_get_Posts()
    214214    {
     215        ai_post_generator_verify_nonce();
     216
    215217        if (!current_user_can('read_private_posts')) {
    216218            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    254256    function ai_post_generator_data_Publish()
    255257    {
     258        ai_post_generator_verify_nonce();
     259
    256260        if (!current_user_can('publish_posts')) {
    257261            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    357361    function ai_post_generator_data_Preview()
    358362    {
     363        ai_post_generator_verify_nonce();
     364
    359365        // Comprobar si el usuario tiene permiso para publicar posts
    360366        if (!current_user_can('read_private_posts')) {
     
    387393    function ai_post_generator_saveas_Publish()
    388394    {
     395        ai_post_generator_verify_nonce();
    389396
    390397        // Comprobar si el usuario tiene permiso para publicar posts
     
    423430    function ai_post_generator_delete_Post()
    424431    {
     432        ai_post_generator_verify_nonce();
     433       
    425434        // Comprobar si el usuario tiene permiso para publicar posts
    426435        if (!current_user_can('delete_posts')) {
     
    630639        wp_enqueue_script(
    631640
    632             'my-functions4',
     641            'main-functions',
    633642
    634643            trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/main.js",
     
    672681
    673682        );
     683        // Pasar parámetros a JavaScript
     684        wp_localize_script('main-functions', 'aiPostGenerator', array(
     685            'ajaxurl' => admin_url('admin-ajax.php'),
     686            'nonce' => wp_create_nonce('ai_post_generator_nonce')
     687        ));
    674688
    675689    }
  • ai-post-generator/tags/3.4/js/main.js

    r3056020 r3057511  
    23572357        var concept_table = "";
    23582358        $.ajax({
    2359             url : 'admin-ajax.php',
    2360             type: 'get',
     2359            url : aiPostGenerator.ajaxurl,
     2360            type: 'POST',
    23612361            dataType: 'json',
    23622362            data: {
    2363               action: 'ai_post_generator_get_Posts'
     2363              action: 'ai_post_generator_get_Posts',
     2364              nonce: aiPostGenerator.nonce
    23642365            },
    23652366            success: function(data) {
     
    25222523    function create_post(post){
    25232524        $.ajax({
    2524             url : 'admin-ajax.php',
     2525            url : aiPostGenerator.ajaxurl,
    25252526            type: 'post',
    25262527            dataType: 'json',
    25272528            data: {
    2528               action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date
     2529              action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date,
     2530              nonce: aiPostGenerator.nonce
    25292531            },
    25302532            success: function(data) {
     
    25452547        if (confirm("Are you sure you want to delete that post?") == true) {
    25462548            $.ajax({
    2547                 url : 'admin-ajax.php',
     2549                url : aiPostGenerator.ajaxurl,
    25482550                type: 'post',
    25492551                dataType: 'json',
    25502552                data: {
    2551                 action: 'ai_post_generator_delete_Post', id: post.id
     2553                action: 'ai_post_generator_delete_Post',
     2554                nonce: aiPostGenerator.nonce,
     2555                id: post.id
    25522556                },
    25532557                success: function(data) {
     
    37893793    }
    37903794        $.ajax({
    3791         url : 'admin-ajax.php',
     3795        url : aiPostGenerator.ajaxurl,
    37923796        type: 'post',
    37933797        dataType: 'json',
    37943798        data: {
    3795           action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im
     3799          action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im,
     3800          nonce: aiPostGenerator.nonce
    37963801        },
    37973802        success: function(data) {
     
    38283833
    38293834        $.ajax({
    3830         url : 'admin-ajax.php',
     3835        url : aiPostGenerator.ajaxurl,
    38313836        type: 'post',
    38323837        dataType: 'json',
    38333838        data: {
    3834           action: 'ai_post_generator_data_Preview', id: id, text: text
     3839          action: 'ai_post_generator_data_Preview', id: id, text: text,
     3840          nonce: aiPostGenerator.nonce
    38353841        },
    38363842        success: function(data) {
     
    38603866
    38613867    $.ajax({
    3862         url : 'admin-ajax.php',
     3868        url : aiPostGenerator.ajaxurl,
    38633869
    38643870        type: 'post',
     
    38683874        data: {
    38693875
    3870           action: 'ai_post_generator_saveas_Publish', id: id, text: text
     3876          action: 'ai_post_generator_saveas_Publish', id: id, text: text,
     3877          nonce: aiPostGenerator.nonce
    38713878
    38723879        },
  • ai-post-generator/trunk/functions.php

    r2913274 r3057511  
    688688
    689689
    690 
     690if (!function_exists('ai_post_generator_verify_nonce')){
     691    function ai_post_generator_verify_nonce() {
     692        if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'ai_post_generator_nonce')) {
     693            ai_post_generator_return_json(array('exito' => false, 'error' => 'Verificación de nonce fallida.'));
     694            die();
     695        }
     696    }
     697}
    691698
    692699if (!function_exists('ai_post_generator_download_img')){
  • ai-post-generator/trunk/inc/insert-head.php

    r3056020 r3057511  
    213213    function ai_post_generator_get_Posts()
    214214    {
     215        ai_post_generator_verify_nonce();
     216
    215217        if (!current_user_can('read_private_posts')) {
    216218            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    254256    function ai_post_generator_data_Publish()
    255257    {
     258        ai_post_generator_verify_nonce();
     259
    256260        if (!current_user_can('publish_posts')) {
    257261            ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.'));
     
    357361    function ai_post_generator_data_Preview()
    358362    {
     363        ai_post_generator_verify_nonce();
     364
    359365        // Comprobar si el usuario tiene permiso para publicar posts
    360366        if (!current_user_can('read_private_posts')) {
     
    387393    function ai_post_generator_saveas_Publish()
    388394    {
     395        ai_post_generator_verify_nonce();
    389396
    390397        // Comprobar si el usuario tiene permiso para publicar posts
     
    423430    function ai_post_generator_delete_Post()
    424431    {
     432        ai_post_generator_verify_nonce();
     433       
    425434        // Comprobar si el usuario tiene permiso para publicar posts
    426435        if (!current_user_can('delete_posts')) {
     
    630639        wp_enqueue_script(
    631640
    632             'my-functions4',
     641            'main-functions',
    633642
    634643            trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/main.js",
     
    672681
    673682        );
     683        // Pasar parámetros a JavaScript
     684        wp_localize_script('main-functions', 'aiPostGenerator', array(
     685            'ajaxurl' => admin_url('admin-ajax.php'),
     686            'nonce' => wp_create_nonce('ai_post_generator_nonce')
     687        ));
    674688
    675689    }
  • ai-post-generator/trunk/js/main.js

    r2895022 r3057511  
    23572357        var concept_table = "";
    23582358        $.ajax({
    2359             url : 'admin-ajax.php',
    2360             type: 'get',
     2359            url : aiPostGenerator.ajaxurl,
     2360            type: 'POST',
    23612361            dataType: 'json',
    23622362            data: {
    2363               action: 'ai_post_generator_get_Posts'
     2363              action: 'ai_post_generator_get_Posts',
     2364              nonce: aiPostGenerator.nonce
    23642365            },
    23652366            success: function(data) {
     
    25222523    function create_post(post){
    25232524        $.ajax({
    2524             url : 'admin-ajax.php',
     2525            url : aiPostGenerator.ajaxurl,
    25252526            type: 'post',
    25262527            dataType: 'json',
    25272528            data: {
    2528               action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date
     2529              action: 'ai_post_generator_data_Publish', title: post.title, text: post.text, type : "draft", im : post.cover, date : post.date,
     2530              nonce: aiPostGenerator.nonce
    25292531            },
    25302532            success: function(data) {
     
    25452547        if (confirm("Are you sure you want to delete that post?") == true) {
    25462548            $.ajax({
    2547                 url : 'admin-ajax.php',
     2549                url : aiPostGenerator.ajaxurl,
    25482550                type: 'post',
    25492551                dataType: 'json',
    25502552                data: {
    2551                 action: 'ai_post_generator_delete_Post', id: post.id
     2553                action: 'ai_post_generator_delete_Post',
     2554                nonce: aiPostGenerator.nonce,
     2555                id: post.id
    25522556                },
    25532557                success: function(data) {
     
    37893793    }
    37903794        $.ajax({
    3791         url : 'admin-ajax.php',
     3795        url : aiPostGenerator.ajaxurl,
    37923796        type: 'post',
    37933797        dataType: 'json',
    37943798        data: {
    3795           action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im
     3799          action: 'ai_post_generator_data_Publish', title: title, text: text, type : "draft", im : im,
     3800          nonce: aiPostGenerator.nonce
    37963801        },
    37973802        success: function(data) {
     
    38283833
    38293834        $.ajax({
    3830         url : 'admin-ajax.php',
     3835        url : aiPostGenerator.ajaxurl,
    38313836        type: 'post',
    38323837        dataType: 'json',
    38333838        data: {
    3834           action: 'ai_post_generator_data_Preview', id: id, text: text
     3839          action: 'ai_post_generator_data_Preview', id: id, text: text,
     3840          nonce: aiPostGenerator.nonce
    38353841        },
    38363842        success: function(data) {
     
    38603866
    38613867    $.ajax({
    3862         url : 'admin-ajax.php',
     3868        url : aiPostGenerator.ajaxurl,
    38633869
    38643870        type: 'post',
     
    38683874        data: {
    38693875
    3870           action: 'ai_post_generator_saveas_Publish', id: id, text: text
     3876          action: 'ai_post_generator_saveas_Publish', id: id, text: text,
     3877          nonce: aiPostGenerator.nonce
    38713878
    38723879        },
Note: See TracChangeset for help on using the changeset viewer.