67 lines
2.2 KiB
PHP
67 lines
2.2 KiB
PHP
<?php
|
|
/*
|
|
* vim: set ai sw=4 smarttab expandtab: tabstop=8 softtabstop=0
|
|
*
|
|
* Plugin Name: WP PDF Helper
|
|
* Description: Helps to print pages and posts as PDF
|
|
*/
|
|
|
|
// If this file is called directly, abort.
|
|
if ( ! defined( 'WPINC' ) ) {
|
|
die;
|
|
}
|
|
|
|
|
|
add_filter('manage_media_columns', 'add_media_column', 50, 2);
|
|
function add_media_column($columns, $detached) {
|
|
# error_log('PHP: $columns: '.print_r($columns, true), 0);
|
|
$keys = array_keys($columns);
|
|
$columns_updated = [];
|
|
foreach ($keys as $key) {
|
|
$columns_updated[$key] = $columns[$key];
|
|
if ($key == 'parent') {
|
|
$columns_updated['wp-pdf-helper'] = 'Print';
|
|
}
|
|
}
|
|
# $actions['download'] = '<a href="' . wp_get_attachment_url($post->ID) . '">Download</a>';
|
|
return $columns_updated;
|
|
}
|
|
|
|
add_action('manage_media_custom_column', 'manage_custom_columns', 10, 2);
|
|
|
|
function manage_custom_columns ($column_key, $post_id) {
|
|
if ($column_key == 'wp-pdf-helper') {
|
|
$checked = (get_post_meta($post_id, 'wpdfh.print', true) == '') ? '' : 'checked';
|
|
echo "<input type='checkbox' name='Print' value='always' $checked />";
|
|
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');
|
|
function wpdfh_enqueue_admin_scripts() {
|
|
wp_enqueue_style( 'wpdfh-admin', plugin_dir_url( __FILE__ ) . 'assets/wp-pdf-helper-admin.css' );
|
|
}
|
|
|
|
if ( ! array_key_exists('print', $_GET)) {
|
|
return;
|
|
}
|
|
|
|
add_action('wp_enqueue_scripts', 'wpdfh_enqueue_print_scripts');
|
|
function wpdfh_enqueue_print_scripts() {
|
|
wp_enqueue_style( 'wpdfh-print', plugin_dir_url( __FILE__ ) . 'assets/wp-pdf-helper-print.css' );
|
|
}
|
|
|
|
#error_log("PHP: parse_url($url, PHP_URL_QUERY): ".print_r(parse_url($url, PHP_URL_QUERY), true), 0);
|
|
#error_log('PHP: $_GET: '.print_r($_GET, true), 0);
|
|
|
|
add_filter( 'wpagpx_shortcode_parameters', 'filter_shortcode_parameters' );
|
|
|
|
function filter_shortcode_parameters($parameters) {
|
|
$parameters['mheight'] = '200px';
|
|
$parameters['gheight'] = '150px';
|
|
$parameters['download'] = 'false';
|
|
$parameters['attachments'] = 'false';
|
|
return $parameters;
|
|
}
|
|
|