[wp-hackers] Delete Row - Refreshes Page but not DB

Gregory Lancaster greglancaster71 at gmail.com
Mon Oct 21 21:05:15 UTC 2013


Yea :

// enqueue ajax code recommended by JD
function my_enqueue_scripts() {
    wp_localize_script(
        'load_post',
        'wp_ajax',
        array(
            'url' => admin_url( 'admin-ajax.php' ),
        )
    );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );



// ajax post code and nonce recommended by Nikola
add_action('wp_ajax_my_delete_row_action', 'my_delete_row_action');
add_action('wp_ajax_nopriv_my_delete_row_action', 'my_delete_row_action');
function my_delete_row_action() {
global $wpdb;
$id = $_POST['id'];
$file = $_POST['file'];
 if ( ! wp_verify_nonce( $_POST['nonce'], 'delete_' . $id . '_' . $file ) )
{
    exit( 'Cheatin, huh?' ); }

$del_image = wp_delete_attachment( $file, false  );
$qry = $wpdb->prepare("DELETE FROM wp_jo_plugin_options WHERE id = %s",
$id);
$go_qry1 = $wpdb->show_errors(); $wpdb->query($qry);
 $response = array( 'success' => true );
 wp_send_json_success($response);

die();
}





On Mon, Oct 21, 2013 at 1:58 PM, Nikola Nikolov <nikolov.tmw at gmail.com>wrote:

> Ok - so to recap:
>
>  - You are using an AJAX call targeted to /wp-admin/admin-ajax.php with an
> "action" attribute set to your custom key
>  - You are using add_action( 'wp_ajax_*action*', 'action_callback' ); where
> "*action*" is the "action" from above and "action_callback" is your
> callback function
>  - In your action_callback function you are checking whether the input is
> valid and then just call wp_delete_attachment() for the corresponding image
>
> Is that correct?
>
>
> On Mon, Oct 21, 2013 at 11:55 PM, Gregory Lancaster <
> greglancaster71 at gmail.com> wrote:
>
> > Also- I teste other user roles, and only Authors and higher can delete
> the
> > form entries.  But anyone can add new.
> >
> >
> > On Mon, Oct 21, 2013 at 1:53 PM, Gregory Lancaster <
> > greglancaster71 at gmail.com> wrote:
> >
> > > Its JSON that is refurning the failure message.  I checked the error
> log
> > > after clearing it and this is the response:
> > >
> > > [Mon Oct 21 13:49:11 2013] [warn] Init: Session Cache is not configured
> > > [hint: SSLSessionCache]
> > > [Mon Oct 21 13:49:12 2013] [notice] Digest: generating secret for
> digest
> > > authentication ...
> > > [Mon Oct 21 13:49:12 2013] [notice] Digest: done
> > > [Mon Oct 21 13:49:12 2013] [notice] Apache/2.2.14 (Unix) DAV/2
> > > mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
> > > configured -- resuming normal operations
> > >
> > > That relevant?
> > >
> > >
> > > On Sun, Oct 20, 2013 at 10:02 AM, J.D. Grimes <jdg at codesymphony.co>
> > wrote:
> > >
> > >> > $del_image = wp_delete_attachment( $file, true  );
> > >> >
> > >> > I think it would be smarter to convert that to an sql query (maybe
> > >> wordpress
> > >> > wont catch it as a delete post function in sql?)
> > >>
> > >> You want to use wp_delete_attachment(), not a custom query. The
> function
> > >> does a lot more than a single query, it cleans out all of the
> > attachment's
> > >> data from the data base, and delete's the image files if there are
> any.
> > >>
> > >> Are you sure that wp_delete_attachment() is actually being called? Are
> > >> you sure it isn't failing before then somewhere?
> > >> _______________________________________________
> > >> wp-hackers mailing list
> > >> wp-hackers at lists.automattic.com
> > >> http://lists.automattic.com/mailman/listinfo/wp-hackers
> > >>
> > >
> > >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list