Skip to content

Commit

Permalink
Added mpdfbutton shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
fkrauthan committed May 25, 2024
1 parent ff533d1 commit 17e758f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Print Wordpress posts as PDF. Optional with Geshi highlighting. It also has supp
## Changelog ##

### 3.9 ###
* Added `mpdfbutton` shortcode to print the PDF button
* Fixed a php warning

### 3.8.3 ###
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Note: You can find the development repository at Github: <https://github.com/fkr
== Changelog ==

= 3.9 =
* Added `mpdfbutton` shortcode to print the PDF button
* Fixed a php warning
= 3.8.3 =
* Fixed deployment of 3.8.2
Expand Down
22 changes: 21 additions & 1 deletion wp-mpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function mpdf_filter( $wp_content = '', $do_pdf = false, $convert = false ) {
$wp_content = str_replace( $d1b, '', $wp_content );

$wp_content = preg_replace( "/$d2a(.*?)$d2b/s", '', $wp_content );

$wp_content = preg_replace( "/\[mpdfbutton[^\]]*\]/s", '', $wp_content );

if ( $convert == true ) {
$wp_content = mb_convert_encoding( $wp_content, "ISO-8859-1", "UTF-8" );
Expand All @@ -337,6 +337,24 @@ function mpdf_mysql2unix( $timestamp ) {
return mktime( $hour, $minute, $second, $month, $day, $year );
}

function mpdf_pdfbutton_shortcode($atts = [], $content = null, $tag = '') {
$atts = array_change_key_case((array) $atts, CASE_LOWER);
$mpdf_atts = shortcode_atts(
array(
'opennewtab' => false,
'buttontext' => '',
'logintext' => '',
'nofollow' => false,
), $atts, $tag
);

return mpdf_pdfbutton($mpdf_atts['opennewtab'], $mpdf_atts['buttontext'], $mpdf_atts['logintext'], false, $mpdf_atts['nofollow']);
}

function mpdf_shortcodes_init() {
add_shortcode( 'mpdfbutton', 'mpdf_pdfbutton_shortcode' );
}

function mpdf_pdfbutton( $opennewtab = false, $buttontext = '', $logintext = 'Login!', $print_button = true, $nofollow = false, $options = array() ) {
$nofollowHtml = '';
if ( $nofollow ) {
Expand Down Expand Up @@ -673,5 +691,7 @@ function mpdf_admin_deletepost( $post_id ) {

add_action( 'save_post', 'mpdf_admin_savepost' );

add_action( 'init', 'mpdf_shortcodes_init' );

register_activation_hook( __FILE__, 'mpdf_install' );
register_deactivation_hook( __FILE__, 'mpdf_deactivate' );

0 comments on commit 17e758f

Please sign in to comment.