WP Document Revisions Shortcodes

Below, you’ll find a detailed guide on how to add the WP Document Revisions Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP Document Revisions Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the WP Document Revisions Plugin and the shortcodes it provides:

Plugin Icon
WP Document Revisions

"WP Document Revisions is a robust tool for managing, tracking, and controlling your WordPress documents. It offers a secure, user-friendly interface for document collaboration and revision history."

★★★☆✩ (22) Active Installs: 3000+ Tested with: 6.1.4 PHP Version: false
Included Shortcodes:
  • [document_revisions]
  • [documents]

WP Document Revisions [document_revisions] Shortcode

The WP-Document-Revisions shortcode is designed to manage and display document revisions. It checks user authorization, verifies document validity, and retrieves revisions. This shortcode can limit the number of revisions shown and control the display of revision summaries. It also has an option to open documents in a new tab. Shortcode: [document_revisions]

Shortcode: [document_revisions]

Parameters

Here is a list of all possible document_revisions shortcode parameters and attributes:

  • id – The unique identifier of the document.
  • number – Specifies the number of document revisions to display.
  • numberposts – Alternative way to limit the number of revisions shown.
  • summary – If set to true, the summary of revisions will be displayed.
  • new_tab – If true, links to revisions open in a new browser tab.

Examples and Usage

Basic example – Displaying document revisions by referencing the document ID

[document_revisions id=5 /]

Advanced examples

Displaying a limited number of document revisions by referencing the document ID and specifying the number of posts.

[document_revisions id=5 numberposts=3 /]

Displaying document revisions with summaries by referencing the document ID and enabling the summary attribute.

[document_revisions id=5 summary=true /]

Opening document revisions in a new tab by referencing the document ID and enabling the new_tab attribute.

[document_revisions id=5 new_tab=true /]

Displaying a limited number of document revisions with summaries in a new tab by referencing the document ID, specifying the number of posts, and enabling both the summary and new_tab attributes.

[document_revisions id=5 numberposts=3 summary=true new_tab=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [document_revisions] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'document_revisions', array( &$this, 'revisions_shortcode' ) );

Shortcode PHP function:

                    function revisions_shortcode( $atts ) {

		// change attribute number into numberposts (for backward compatibility).
		if ( array_key_exists( 'number', $atts ) && ! array_key_exists( 'numberposts', $atts ) ) {
			$atts['numberposts'] = $atts['number'];
			unset( $atts['number'] );
		}

		// normalize args.
		$atts = shortcode_atts( $this->shortcode_defaults, $atts, 'document' );
		foreach ( array_keys( (array) $this->shortcode_defaults ) as $key ) {
			$$key = isset( $atts[ $key ] ) ? (int) $atts[ $key ] : null;
		}

		// do not show output to users that do not have the read_document_revisions capability.
		if ( ! current_user_can( 'read_document_revisions' ) ) {
			return '<p>' . esc_html__( 'You are not authorized to read this data', 'wp-document-revisions' ) . '</p>';
		}

		// Check it is a document.
		global $wpdr;
		if ( ! $wpdr->verify_post_type( $id ) ) {
			return '<p>' . esc_html__( 'This is not a valid document.', 'wp-document-revisions' ) . '</p>';
		}

		// get revisions.
		$revisions = $this->get_revisions( $id );

		// show a limited number of revisions.
		if ( null !== $numberposts ) {
			$revisions = array_slice( $revisions, 0, (int) $numberposts );
		}

		if ( isset( $atts['summary'] ) ) {
			$atts_summary = filter_var( $atts['summary'], FILTER_VALIDATE_BOOLEAN );
		} else {
			$atts_summary = false;
		}

		if ( isset( $atts['new_tab'] ) ) {
			$atts_new_tab = filter_var( $atts['new_tab'], FILTER_VALIDATE_BOOLEAN );
		} else {
			$atts_new_tab = false;
		}

		// buffer output to return rather than echo directly.
		ob_start();
		?>
		<ul class="revisions document-<?php echo esc_attr( $id ); ?>">
		<?php
		// loop through each revision.
		foreach ( $revisions as $revision ) {
			// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
			?>
			<li class="revision revision-<?php echo esc_attr( $revision->ID ); ?>" >
				<?php
				// html - string not to be translated.
				printf( '<a href="%1$s" title="%2$s" id="%3$s" class="timestamp"', esc_url( get_permalink( $revision->ID ) ), esc_attr( $revision->post_modified ), esc_html( strtotime( $revision->post_modified ) ) );
				echo ( $atts_new_tab ? ' target="_blank"' : '' );
				printf( '>%s</a> <span class="agoby">', esc_html( human_time_diff( strtotime( $revision->post_modified_gmt ), time() ) ) );
				esc_html_e( 'ago by', 'wp-document-revisions' );
				printf( '</span> <span class="author">%s</span>', esc_html( get_the_author_meta( 'display_name', $revision->post_author ) ) );
				echo ( $atts_summary ? '<br/>' . esc_html( $revision->post_excerpt ) : '' );
				?>
			</li>
			<?php
			// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
		}
		?>
		</ul>
		<?php
		// grab buffer contents and remove.
		return ob_get_clean();
	}
                    

Code file location:

wp-document-revisions/wp-document-revisions/includes/class-wp-document-revisions-front-end.php

WP Document Revisions [documents] Shortcode

The wp-document-revisions shortcode ‘documents’ is used to adjust document workflow states. It checks if ‘workflow_state’ points to ‘post_status’. If not, it replaces ‘workflow_state’ with ‘post_status’ in the attributes.

Shortcode: [documents]

Parameters

Here is a list of all possible documents shortcode parameters and attributes:

  • workflow_state – It allows to set the post status of a document.
  • post_status – It sets the visibility of the document.

Examples and Usage

Basic example – A shortcode that displays documents without any specific parameters.

[documents /]

Advanced examples

Display documents with a specific workflow state. In this case, the shortcode will only display documents that are in the “published” state.

[documents workflow_state="published" /]

A more complex example would be to display documents with a specific workflow state and post status. Here, the shortcode will display documents that are in the “published” state and have a post status of “public”.

[documents workflow_state="published" post_status="public" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [documents] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'documents', array( &$this, 'documents_shortcode' ) );

Shortcode PHP function:

                    function documents_shortcode( $atts ) {

		// Only need to do something if workflow_state points to post_status.
		if ( 'workflow_state' !== self::$parent->taxonomy_key() ) {
			if ( in_array( 'workflow_state', $atts, true ) ) {
				$atts['post_status'] = $atts['workflow_state'];
				unset( $atts['workflow_state'] );
			}
		}

		return $this->documents_shortcode_int( $atts );
	}
                    

Code file location:

wp-document-revisions/wp-document-revisions/includes/class-wp-document-revisions-front-end.php

Conclusion

Now that you’ve learned how to embed the WP Document Revisions Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *