GochiSiyan

functions.php

Oct 29th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.40 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////
  2. //JNews Custom Drawer Code | START |
  3. ////////////////////////////////////////////////////////////
  4.  
  5. add_action('init', function (){
  6. remove_action( 'jnews_mobile_menu_cotent', 'jnews_render_mobile_menu_content' );
  7.  
  8. add_action( 'jnews_mobile_menu_cotent', 'drawer_builder' );
  9.  
  10. function drawer_builder() {
  11. $post_id = 94425;
  12. get_template_part('fragment/header/element/mobile/logo');
  13. ?>
  14. <div class="jeg_header">
  15. <div class="container">
  16. <div id="icon-x">
  17. <svg>
  18. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 308.3 308.3">
  19. <path d="M188.8 154.1l119.1-119L273.2.4 154.1 119.5 35.3.6.2 34.9l119.3 119.2L.4 273.2l34.7 34.7 119.2-119.2 118.9 119.2 34.9-34.5z"></path>
  20. </svg>
  21. </svg>
  22. </div>
  23. </div>
  24. </div>
  25. <hr>
  26. <style>
  27. .jeg_mobile_wrapper .jeg_header {
  28. display:block;
  29. }
  30. #icon-x {
  31. position: relative;
  32. }
  33. #icon-x>svg {
  34. width: 25px;
  35. height: 25px;
  36. position: absolute;
  37. top: -43px;
  38. left: 0;
  39. cursor: pointer;
  40. }
  41. div.jeg_header + hr {
  42. margin-top:15px !important;
  43. }
  44. .jeg_mobile_wrapper {
  45. width: 100vw;
  46. }
  47. .item_main {
  48. max-width: 500px;
  49. margin: auto;
  50. }
  51. .jeg_mobile_wrapper .jeg_mobile_logo img {
  52. margin: auto;
  53. margin-top: 25px;
  54. }
  55. @media (max-width: 1024px) {
  56. #icon-x>svg {
  57. top: -28px;
  58. }
  59. }
  60. </style>
  61. <script>
  62. (function (){
  63. document.getElementById('icon-x').addEventListener('click', function (e) {
  64. document.querySelector('.jeg_menu_close').click();
  65. });
  66. })();
  67. </script>
  68. <?php
  69.  
  70.  
  71. $document = \Elementor\Plugin::$instance->documents->get_doc_for_frontend( $post_id );
  72. $data = $document->get_elements_data();
  73. $css_file = \Elementor\Core\Files\CSS\Post::create( $post_id );
  74. ob_start();
  75. $css_file->print_css();
  76. $document->print_elements_with_wrapper( $data );
  77. echo ob_get_clean();
  78. }
  79. });
  80.  
  81. ////////////////////////////////////////////////////////////
  82. //JNews Custom Drawer Code | END |
  83. ////////////////////////////////////////////////////////////
  84.  
  85. ////////////////////////////////////////////////////////////
  86. //JNews Author Tooltip | START |
  87. ////////////////////////////////////////////////////////////
  88.  
  89. add_action( 'wp_head', function () {
  90. ?>
  91. <style>
  92. .jeg_mobile_wrapper {
  93. transition: none;
  94. }
  95.  
  96. .jeg_mobile_wrapper img.jeg_logo_img {
  97. margin-top: 15px !important;
  98. height: 60px;
  99. max-height: unset;
  100. }
  101.  
  102. .jeg_header_wrapper .jeg_bottombar .jeg_nav_row {
  103. display: grid;
  104. grid-auto-flow: column;
  105. grid-template-columns: 1fr 1fr 1fr;
  106. }
  107.  
  108. .jeg_navbar_mobile_wrapper .jeg_mobile_midbar.jeg_mobile_bottombar .jeg_nav_row {
  109. display: grid;
  110. grid-auto-flow: column;
  111. grid-template-columns: 1fr 3fr 1fr;
  112. }
  113. .author-tooltip-container {
  114. position: relative;
  115. }
  116. .author-tooltip-container strong {
  117. font-weight: 700;
  118. }
  119. .author-tooltip-container .fa::before {
  120. /* display: none; */
  121. }
  122. .author-tooltip {
  123. color: #212121;
  124. position: absolute;
  125. top: calc(100% + 10px);
  126. left: 0;
  127. z-index: 99;
  128. background: white;
  129. border: solid #D3D3D3 1px;
  130. display: grid;
  131. grid-template-areas:
  132. "a b"
  133. "a c"
  134. "d d"
  135. "e e";
  136. grid-template-columns: 80px max(200px);
  137. grid-template-rows: min-content min-content auto;
  138. grid-gap: 10px;
  139. padding: 10px;
  140. visibility: hidden;
  141. }
  142. .author-tooltip.right {
  143. left: unset;
  144. right: 0;
  145. }
  146. .author-tooltip-container:hover>.author-tooltip {
  147. visibility: visible;
  148. }
  149. .author-tooltip-container.show>.author-tooltip {
  150. visibility: visible;
  151. }
  152. .author-tooltip a {
  153. color: #0d57cf;
  154. text-decoration: underline;
  155. }
  156. .author-tooltip>img {
  157. width: unset !important;
  158. border-radius: unset !important;
  159. grid-area: a;
  160. }
  161. .author-tooltip>.jeg_author_name {
  162. grid-area: b;
  163. align-self: end;
  164. }
  165. .author-tooltip>.jeg_author_socials a {
  166. margin: 11px 10px 6px 0;
  167. }
  168. .author-tooltip>.jeg_author_socials {
  169. grid-area: c;
  170. }
  171. .author-tooltip>.jeg_author_description {
  172. grid-area: d;
  173. }
  174. .author-tooltip>.jeg_author_footer {
  175. grid-area: e;
  176. padding-top: 10px;
  177. border-top: 1px solid #EEE;
  178. }
  179. .author-tooltip::before {
  180. content: "";
  181. position:absolute;
  182. width: 10px;
  183. height: 10px;
  184. background: white;
  185. transform: translate(10px,-6px) rotate(45deg);
  186. border: #D3D3D3 solid 1px;
  187. border-bottom: unset;
  188. border-right: unset;
  189. }
  190. .author-tooltip.right::before {
  191. transform: translate(-10px,-6px) rotate(45deg);
  192. right: 0;
  193. }
  194. .author-tooltip .jeg_author_socials>a {
  195. text-decoration:none;
  196. }
  197. .author-tooltip-container .fa {
  198. background:black;
  199. color: white !important;
  200. display:flex;
  201. align-items: center;
  202. justify-content: center;
  203. border-radius: 50%
  204. }
  205. .author-tooltip-container .jeg_author_socials>a {
  206. margin: 0 .3125rem 0 0;
  207. }
  208. @media (max-width: 768px) {
  209. .author-tooltip, .author-tooltip.right {
  210. position: absolute;
  211. top: 25px;
  212. transform: translate(-50%, 0%);
  213. right: unset;
  214. }
  215. .author-tooltip::before {
  216. display: none;
  217. }
  218. }
  219. @media (max-width: 1024px) {
  220. .jeg_mobile_wrapper .jeg_mobile_logo .jeg_logo_img {
  221. height: 30px;
  222. }
  223. }
  224. </style>
  225. <?php
  226. }, 99999);
  227.  
  228. add_action( 'wp_footer', function () {
  229. ?>
  230. <script>
  231. (function(){
  232. document.querySelectorAll(".author-tooltip-container").forEach(function (value) {
  233. let timeout;
  234. ["mouseover", "mouseleave"].forEach(function(event) {
  235. value.addEventListener(event, function() {
  236. this.classList.add("show");
  237. clearTimeout(timeout) || (timeout = setTimeout(function() {
  238. this.classList.remove("show");
  239. }.bind(this),1000));
  240. });
  241. });
  242. })
  243. })();
  244. (function() {
  245. let authors = document.querySelectorAll('.author-tooltip '),
  246. resonsive = function() {
  247. let width = window.outerWidth;
  248.  
  249. if(width > 768) {
  250. authors.forEach(function(author) {
  251. author.style.left = '';
  252. });
  253. } else {
  254. authors.forEach(function(author) {
  255. author.style.left = `${(width / 2 - author.parentElement.getBoundingClientRect().left)}px`;
  256. });
  257. }
  258. };
  259. window.addEventListener('resize', resonsive);
  260. resonsive();
  261. })();
  262. </script>
  263. <?php
  264. } );
  265.  
  266. // if ( ! function_exists( 'jnews_the_author_link' ) && false ) {
  267. if ( ! function_exists( 'jnews_the_author_link' ) ) {function jnews_the_author_link( $author = null, $print = true, $review = false ) {
  268. ob_start();
  269. get_template_part( 'fragment/post/author-social' );
  270. $social = ob_get_clean();
  271.  
  272. $footer = 'Learn about our <a href="#">editorial process</a>.';
  273. $prefix = '';
  274. $suffix = '';
  275. $right = '';
  276. if ( $review ) {
  277. $right = 'right';
  278. $post_id = get_the_ID();
  279. if ( $review_footer = vp_metabox( 'jnews_custom_review.footer', false, $post_id ) ) $footer = $review_footer;
  280. if ( $review_prefix = vp_metabox( 'jnews_custom_review.prefix', false, $post_id ) ) $prefix = $review_prefix;
  281. if ( $review_suffix = vp_metabox( 'jnews_custom_review.suffix', false, $post_id ) ) $suffix = $review_suffix;
  282. }
  283.  
  284. $ret = sprintf(
  285. '
  286. <span class="author-tooltip-container">
  287. <a href="%1$s">%2$s</a>
  288. <div class="author-tooltip %7$s">
  289. ' . get_avatar( get_the_author_meta( 'ID', $author ), 80, null, get_the_author_meta( 'display_name', $author ) ) . '
  290. <div class="jeg_author_name">
  291. <strong>%5$s</strong> <a href="%1$s">%2$s</a> <span>%6$s</span>
  292. </div>
  293. <div class="jeg_author_socials">
  294. %3$s
  295. </div>
  296. <div class="jeg_author_description">' . get_the_author_meta( 'description', $author ) . '</div>
  297. <div class="jeg_author_footer">
  298. <span>%4$s</span>
  299. </div>
  300. </div>
  301. </span>
  302. ',
  303. esc_url( get_author_posts_url( get_the_author_meta( 'ID', $author ) ) ),
  304. '<strong>' . get_the_author_meta( 'display_name', $author ) . '</strong>',
  305. $social,
  306. $footer,
  307. $prefix,
  308. $suffix,
  309. $right
  310. );
  311. if ( ! $print ) return $ret;
  312. echo $ret;
  313. }
  314. }
  315.  
  316. ////////////////////////////////////////////////////////////
  317. //JNews Author Tooltip | END |
  318. ////////////////////////////////////////////////////////////
  319.  
  320. ////////////////////////////////////////////////////////////
  321. //JNews Reviewer | START |
  322. ////////////////////////////////////////////////////////////
  323. add_action('after_setup_theme', 'review_check_metabox');
  324.  
  325. function review_check_metabox () {
  326. if( class_exists('VP_Metabox') ) {
  327. new VP_Metabox( [
  328. 'id' => 'jnews_custom_review',
  329. 'types' => [ 'post' ],
  330. 'title' => 'JNews : Fact Checker',
  331. 'priority' => 'high',
  332. 'template' => [
  333. [
  334. 'type' => 'toggle',
  335. 'name' => 'reviewed',
  336. 'label' => esc_html__( 'Reviewed?', 'jnews-custom' ),
  337. 'description' => esc_html__( 'enable this option if this article has been reviewed', 'jnews-custom' ),
  338. 'default' => false,
  339. ],
  340. [
  341. 'type' => 'textbox',
  342. 'name' => 'prefix',
  343. 'label' => esc_html__( 'Prefix', 'jnews-custom' ),
  344. 'description' => esc_html__( 'please insert the review prefix', 'jnews-custom' ),
  345. 'default' => 'reviewed by',
  346. 'active_callback' => [
  347. [
  348. 'field' => 'reviewed',
  349. 'operator' => '==',
  350. 'value' => true,
  351. ]
  352. ]
  353. ],
  354. [
  355. 'type' => 'select',
  356. 'name' => 'reviewer',
  357. 'label' => esc_html__( 'The Reviewer', 'jnews-custom' ),
  358. 'description' => esc_html__( 'Assign user that has reviewd this article', 'jnews-custom' ),
  359. 'default' => '',
  360. 'items' => call_user_func( function () {
  361. $users = [];
  362.  
  363. foreach ( get_users() as $user ) {
  364. $users[] = [
  365. 'value' => $user->ID,
  366. 'label' => $user->display_name,
  367. ];
  368. }
  369.  
  370. return $users;
  371. } ),
  372. 'active_callback' => [
  373. [
  374. 'field' => 'reviewed',
  375. 'operator' => '==',
  376. 'value' => true,
  377. ]
  378. ]
  379. ],
  380. [
  381. 'type' => 'textbox',
  382. 'name' => 'suffix',
  383. 'label' => esc_html__( 'Suffix', 'jnews-custom' ),
  384. 'description' => esc_html__( 'please insert the review suffix', 'jnews-custom' ),
  385. 'default' => '',
  386. 'active_callback' => [
  387. [
  388. 'field' => 'reviewed',
  389. 'operator' => '==',
  390. 'value' => true,
  391. ]
  392. ]
  393. ],
  394. [
  395. 'type' => 'textbox',
  396. 'name' => 'footer',
  397. 'label' => esc_html__( 'Footer', 'jnews-custom' ),
  398. 'description' => esc_html__( 'please insert the review footer', 'jnews-custom' ),
  399. 'default' => '',
  400. 'active_callback' => [
  401. [
  402. 'field' => 'reviewed',
  403. 'operator' => '==',
  404. 'value' => true,
  405. ]
  406. ]
  407. ],
  408. ],
  409. ] );
  410. }
  411. }
  412.  
  413. add_action( 'jnews_render_after_meta_left', function () {
  414. global $post;
  415. if ( vp_metabox( 'jnews_custom_review.reviewed', false, $post->ID ) ) {
  416. if ( ! is_numeric( $author = vp_metabox( 'jnews_custom_review.reviewer', '', $post->ID ) ) ) return;
  417. ?>
  418. <div class="jeg_meta_reviewed">
  419. <svg class="reviewer-icon" width="14px" height="14px">
  420. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
  421. <path fill="#FF3300" fill-rule="evenodd" d="M9.15254 3.72881c-3.93152 0-7.11864 3.18713-7.11864 7.11869 0 3.9315 3.18712 7.1186 7.11864 7.1186 3.93156 0 7.11866-3.1871 7.11866-7.1186 0-1.22169-.3069-2.36863-.847-3.37101l1.3082-1.85999.4824.89528c.6958 1.29151 1.0903 2.76904 1.0903 4.33572 0 5.0548-4.0977 9.1525-9.15256 9.1525C4.09773 20 0 15.9023 0 10.8475c0-5.05485 4.09773-9.15258 9.15254-9.15258.96176 0 1.89076.14869 2.76416.42508l.9696.30683-1.5833 1.63229c-.6772-.21431-1.39931-.33031-2.15046-.33031z" clip-rule="evenodd"></path>
  422. <path fill="#00040B" d="M8.61503 10.6461c.27188-.4746.52111-.96029.81564-1.41285.58743-.94516 1.22653-1.85894 1.91443-2.73741.891-1.0994 1.844-2.14963 2.8548-3.14581.9773-.96997 2.0642-1.82904 3.2399-2.560805.5756-.347472 1.202-.607978 1.8578-.7726565.1426-.02209132.2879-.02209132.4305 0h.2718l-.0113.2538725-.1359.154531c-.0886.100988-.1831.196816-.2832.286987C17.2471 2.73398 15.2093 5.04622 13.5088 7.5886c-1.4535 2.26724-2.6355 4.6893-3.52305 7.2188-.65703 1.7992-1.88049 1.9537-3.06996.3863-1.12443-1.5455-2.03121-3.2309-2.69613-5.0112-.22375-.51301-.38349-1.05036-.47578-1.60049-.14727-1.24728.8043-1.76607 1.85783-1.99786 1.05353-.2318 1.2801.51878 1.59729 1.30247.12461.30907.98556 3.00228 1.28009 2.85888.04602-.0324.08461-.0738.11329-.1215l.02265.0221z"></path>
  423. </svg>
  424. </svg>
  425. <span><?php echo vp_metabox( 'jnews_custom_review.prefix', '', $post->ID ) ?></span>
  426. <?php jnews_the_author_link( $author, true, true ) ?>
  427. </div>
  428. <?php
  429. }
  430. }, 999 );
  431. ////////////////////////////////////////////////////////////
  432. //JNews Reviewer | END |
  433. ////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment