Advertisement
fauzanjeg

Create Custom Functions to Render Bookmark Button

Jun 15th, 2021
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. /* Create Custom Functions to Render Bookmark Button */
  2. function custom_bookmark_button( $post_id ) {
  3.     /* need to flag if this can render login form */
  4.     add_filter( 'jnews_can_render_account_popup', '__return_true' );
  5.  
  6.     if ( is_plugin_active( 'jnews-bookmark/jnews-bookmark.php' ) ) {
  7.         wp_enqueue_style( 'jnews-bookmark', JNEWS_BOOKMARK_URL . '/assets/css/plugin.css', array(), JNEWS_BOOKMARK_VERSION, 'all' );
  8.         wp_enqueue_script( 'jnews-bookmark', JNEWS_BOOKMARK_URL . '/assets/js/plugin.js', array( 'jquery' ), JNEWS_BOOKMARK_VERSION, true );
  9.  
  10.         $bookmark_status = get_user_meta( get_current_user_id(), 'jnews_bookmark_article', true );
  11.         $bookmark_status = '' !== $bookmark_status ? $bookmark_status : array();
  12.         $class           = 'fa fa-bookmark-o';
  13.         $status          = false;
  14.  
  15.         if ( array_key_exists( $post_id, (array) $bookmark_status ) && $bookmark_status[ $post_id ]['status'] === true ) {
  16.             $class  = 'fa fa-bookmark';
  17.             $status = true;
  18.         }
  19.  
  20.         $output = '<div class="jeg_meta_bookmark">
  21.                         <a href="#" data-id="' . $post_id . '" data-added="' . $status . '" data-message><i class="' . $class . '"></i></a>
  22.                     </div>';
  23.  
  24.         echo jnews_sanitize_by_pass( $output );
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement