Skip to content

Commit

Permalink
Merge pull request #7 from scoredetect/feature/timestamps-shortcode-1…
Browse files Browse the repository at this point in the history
…714025409

Add [timestamps] Shortcode
  • Loading branch information
michael-sumner authored Apr 25, 2024
2 parents c13130a + ca05f99 commit 3953fc6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions includes/classes/Feature/Timestamp/Timestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function setup_init() {
add_action( 'edit_post', array( $this, 'save_post_meta' ), 10, 2 );
add_action( 'rest_insert_post', array( $this, 'save_post_meta_rest' ), 10, 2 );
add_filter( 'is_protected_meta', array( $this, 'is_protected_meta' ), 10, 3 );
add_shortcode( 'timestamps', array( $this, 'shortcode' ) );
}

/**
Expand Down Expand Up @@ -170,6 +171,31 @@ public function enqueue_block_editor_assets() {
);
}

/**
* Outputs the shortcode for the feature.
*
* @see includes/blocks/timestamp-post/markup.php for the original code.
*
* @return string The shortcode output.
*/
public function shortcode(): string {
ob_start();

$sdcom_previous_certificate_id = get_post_meta( get_the_ID(), 'sdcom_previous_certificate_id', true );

// Bail early if there is no embed_code.
if ( empty( $sdcom_previous_certificate_id ) ) {
return '';
}

printf(
'<div class="sdcom-timestamps" data-id="%s"></div>',
esc_attr( $sdcom_previous_certificate_id )
);

return ob_get_clean();
}

/**
* Outputs the checkbox field.
*
Expand Down

0 comments on commit 3953fc6

Please # to comment.