This repository was archived by the owner on Oct 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbulk_action.php
More file actions
84 lines (65 loc) · 2.89 KB
/
bulk_action.php
File metadata and controls
84 lines (65 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
add_filter('bulk_actions-edit-post', 'magazine_render_pdf_bulk_actions');
add_filter('bulk_actions-edit-page', 'magazine_render_pdf_bulk_actions');
function magazine_render_pdf_bulk_actions($bulk_actions) {
$aThemes = magazine_template::_getTemplateNames();
if(is_array($aThemes) && count($aThemes) == 0){ // Create Demo Template if there is none
magazine_template::_createDemoTemplate();
$aThemes = magazine_template::_getTemplateNames();
}
foreach($aThemes as $sTheme){
$bulk_actions['magazine_render_pdf_bulk_action_'. $sTheme] = __( 'Render PDF with ' . $sTheme . ' Theme', 'magazine_render_pdf');
}
return $bulk_actions;
}
add_filter('handle_bulk_actions-edit-post', 'magazine_render_pdf_bulk_handler', 10, 3);
add_filter('handle_bulk_actions-edit-page', 'magazine_render_pdf_bulk_handler', 10, 3);
function magazine_render_pdf_bulk_handler($redirect_to, $doaction, $post_ids) {
if (strpos($doaction, 'magazine_render_pdf_bulk_action_') !== 0) {
return $redirect_to;
}
$sTheme = str_replace('magazine_render_pdf_bulk_action_', '', $doaction);
$aRenderResult = magazine_pdf::_renderPDF($post_ids, $sTheme);
$redirect_to = add_query_arg( 'magazine_pdf_theme', $sTheme, $redirect_to);
$redirect_to = add_query_arg( 'magazine_pdf_post_ids', json_encode($post_ids), $redirect_to);
return $redirect_to;
}
add_action('in_admin_footer', function(){
wp_localize_script(
'wp-api',
'wpApiSettings',
array(
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' )
)
);
wp_enqueue_script('wp-api');
if (!empty($_REQUEST['magazine_pdf_theme']) && !empty($_REQUEST['magazine_pdf_post_ids'])) {
echo '
<script src="' . plugin_dir_url( __DIR__ ). '/magazine/javascript/restrequest.js"></script>
<script>
if(window.jQuery) {
jQuery(document).ready(function($) {
$(window).load(function() {
magazine_post_request(' . $_REQUEST['magazine_pdf_post_ids'] . ', "' . $_REQUEST['magazine_pdf_theme'] . '");
});
});
}
</script>
';
}
}, 1);
// If option to show bulk action on custom post types is on add the filters (add_filter)
if(get_option('magazine_show_action_on_custom_post_types') == 1){
add_action('wp_loaded', function(){
$args = array(
'public' => true,
'_builtin' => false,
);
$post_types = get_post_types( $args );
foreach ( $post_types as $post_type ) {
add_filter('bulk_actions-edit-' . $post_type, 'magazine_render_pdf_bulk_actions');
add_filter('handle_bulk_actions-edit-' . $post_type, 'magazine_render_pdf_bulk_handler', 10, 3);
}
});
}