Begining to code the Ajax action

This commit is contained in:
Eric van der Vlist 2025-03-27 16:35:50 +01:00
parent 7d8beefebf
commit 338b69d4f1
4 changed files with 125 additions and 2 deletions

22
assets/jquery.ajax.js Normal file
View File

@ -0,0 +1,22 @@
/*
* vim: set ai sw=4 smarttab expandtab: tabstop=8 softtabstop=0
*
*/
jQuery(document).ready( function($){
jQuery('.wpdfh_print_checkbox').on("change", function(){
$.ajax({
url: wpdfh_ajax_object.ajaxurl, // this is the object instantiated in wp_localize_script function
type: 'POST',
data:{
action: 'wpdfh_set_print_metadata', // this is the function in your functions.php that will be triggered
post_id: $(this).data('post_id'),
checked: $(this).prop('checked')
},
success: function( data ){
console.log( data );
}
});
})
});

View File

@ -0,0 +1,8 @@
/*
* vim: set ai sw=4 smarttab expandtab: tabstop=8 softtabstop=0
*
*/
.column-wp-pdf-helper {
width: 50px;
}

View File

@ -0,0 +1,73 @@
/*
* vim: set ai sw=4 smarttab expandtab: tabstop=8 softtabstop=0
*
*/
video,
.attached-videos,
header,
.plyr,
.leaflet-marker-photo,
.leaflet-top,
#wpgpxmaps_downloadfile,
div:empty,
nav,
.wp-block-comments,
.wp-block-query,
footer,
.other-posts,
.no-print,
#wpadminbar,
.skip-link.screen-reader-text
{
display: none !important;
}
html,
main,
#post-content {
padding: 0px !important;
margin: 0px !important;
}
.gallery,
.attached-gpx {
page-break-before: auto; /* 'always,' 'avoid,' 'left,' 'inherit,' or 'right' */
page-break-after: auto; /* 'always,' 'avoid,' 'left,' 'inherit,' or 'right' */
page-break-inside: avoid; /* or 'auto' */
}
#post-grid {
display: flex;
}
#post-grid-column2 {
flex: 70%;
padding-left: 10px;
}
.attached-gpxes {
flex: 30%;
}
.wpgpxmaps_summary {
font-size: var(--wp--preset--font-size--small);
}
.leaflet-control-attribution {
font-size: 8px;
}
.date-prefix {
text-transform: capitalize;
}
.author-line, .author-line > * {
margin-bottom: 0px !important;
margin-top: 5px !important;
font-size: var(--wp--preset--font-size--medium) !important;
}
.entry-content, wp-block-post-excerpt {
text-align: justify;

View File

@ -32,16 +32,36 @@ add_action('manage_media_custom_column', 'manage_custom_columns', 10, 2);
function manage_custom_columns ($column_key, $post_id) { function manage_custom_columns ($column_key, $post_id) {
if ($column_key == 'wp-pdf-helper') { if ($column_key == 'wp-pdf-helper') {
$checked = (get_post_meta($post_id, 'wpdfh.print', true) == '') ? '' : 'checked'; $checked = (get_post_meta($post_id, 'wpdfh.print', true) == '') ? '' : 'checked';
echo "<input type='checkbox' name='Print' value='always' $checked />"; echo "<input type='checkbox' class='wpdfh_print_checkbox' name='Print' data-post_id='$post_id' $checked />";
error_log("PHP: \$column_key: $column_key, \$post_id: $post_id, \$is_printable: $is_printable.", 0); // error_log("PHP: \$column_key: $column_key, \$post_id: $post_id, \$is_printable: $is_printable.", 0);
} }
} }
add_action('admin_enqueue_scripts', 'wpdfh_enqueue_admin_scripts'); add_action('admin_enqueue_scripts', 'wpdfh_enqueue_admin_scripts');
function wpdfh_enqueue_admin_scripts() { function wpdfh_enqueue_admin_scripts() {
wp_enqueue_style( 'wpdfh-admin', plugin_dir_url( __FILE__ ) . 'assets/wp-pdf-helper-admin.css' ); wp_enqueue_style( 'wpdfh-admin', plugin_dir_url( __FILE__ ) . 'assets/wp-pdf-helper-admin.css' );
wp_register_script(
'wpdfh-ajax-admin',
plugins_url('assets/jquery.ajax.js', __FILE__),
array(),
false,
true
);
wp_enqueue_script( 'wpdfh-ajax-admin' );
wp_localize_script(
'wpdfh-ajax-admin',
'wpdfh_ajax_object',
array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) )
);
} }
add_action( "wp_ajax_wpdfh_set_print_metadata", "wpdfh_set_print_metadata" );
function wpdfh_set_print_metadata(){
error_log("PHP: wpdfh_set_print_metadata", 0);
wp_send_json_success();
}
if ( ! array_key_exists('print', $_GET)) { if ( ! array_key_exists('print', $_GET)) {
return; return;
} }