Guest User

Untitled

a guest
Aug 19th, 2019
209
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Author Porfile Widgets
  2. =====================
  3. php
  4. ====
  5. <?php
  6.  
  7. class prefix_Author_Widget extends WP_Widget
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct(
  12. 'author-widget',
  13. __( 'TM: Author Widget', 'web-log' ),
  14. array( 'description' => __( 'Best displayed in Sidebar.', 'web-log' ) )
  15. );
  16. }
  17.  
  18. public function widget( $args, $instance )
  19. {
  20. extract( $args );
  21. if(!empty($instance))
  22. {
  23.  
  24. $facebook =$instance['facebook'];
  25. $twitter =$instance['twitter'];
  26. $instagram =$instance['instagram'];
  27. $linkedin =$instance['linkedin'];
  28. $youtube =$instance['youtube'];
  29. $image =$instance['image_uri'];
  30. $title = apply_filters( 'widget_title', !empty( $instance['title'] ) ? $instance['title'] : '', $instance, $this->id_base );
  31.  
  32. if( !empty($image))
  33. {
  34. ?>
  35. <div class="widget">
  36. <?php echo $args['before_title'] . $title . $args['after_title']; ?>
  37. <div class="shape2"></div>
  38. <div class="about-me text-center">
  39. <img src="<?php echo esc_url( $instance['image_uri'] );?>" alt="about me">
  40. <p><?php echo wp_kses_post( $instance['description'] );?></p>
  41. <ul class="social-icons list-inline">
  42.  
  43. <?php
  44. if ( !empty( $facebook ) ) { ?>
  45. <li>
  46. <a class="img-circle" href="<?php echo esc_url( $facebook ); ?>" data-title="Facebook" target="_blank"><i class="fa fa-facebook"></i></a>
  47. </li>
  48. <?php }
  49. if ( !empty( $twitter ) ) { ?>
  50. <li>
  51. <a class="img-circle" href="<?php echo esc_url( $twitter ); ?>" data-title="Twitter" target="_blank"><i class="fa fa-twitter"></i></a>
  52. </li>
  53. <?php }
  54. if ( !empty( $linkedin ) ) {
  55. ?>
  56. <li>
  57. <a class="img-circle" href="<?php echo esc_url( $linkedin ); ?>" data-title="Linkedin" target="_blank"><i class="fa fa-linkedin"></i></a>
  58. </li>
  59. <?php
  60. }
  61. if ( !empty( $instagram) ) {
  62. ?>
  63. <li>
  64. <a class="img-circle" href="<?php echo esc_url( $instagram); ?>" data-title="Instagram" target="_blank"><i class="fa fa-instagram"></i></a>
  65. </li>
  66. <?php
  67. }
  68. if ( !empty( $youtube ) ) { ?>
  69. <li>
  70. <a class="img-circle" href="<?php echo esc_url( $youtube ); ?>" data-title="Youtube" target="_blank"><i class="fa fa-youtube"></i></a>
  71. </li>
  72. <?php
  73. }
  74.  
  75. ?>
  76. </ul>
  77. </div><!-- .about-me -->
  78. </div><!-- .widget -->
  79.  
  80. <?php
  81. }
  82. }
  83. }
  84.  
  85. public function update( $new_instance, $old_instance ){
  86. $instance = $old_instance;
  87. $instance['title'] = sanitize_text_field( $new_instance['title'] );
  88. $instance['description'] = wp_kses_post( $new_instance['description'] );
  89. $instance['image_uri'] = esc_url_raw( $new_instance['image_uri'] );
  90. $instance['facebook'] = esc_url_raw( $new_instance['facebook'] );
  91. $instance['twitter'] = esc_url_raw( $new_instance['twitter'] );
  92. $instance['googleplus'] = esc_url_raw( $new_instance['googleplus'] );
  93. $instance['instagram'] = esc_url_raw( $new_instance['instagram'] );
  94. $instance['linkedin'] = esc_url_raw( $new_instance['linkedin'] );
  95. $instance['youtube'] = esc_url_raw( $new_instance['youtube'] );
  96. return $instance;
  97. }
  98.  
  99. public function form($instance ){
  100. ?>
  101. <p>
  102. <label for="<?php echo $this->get_field_id('image_uri'); ?>">
  103. <?php _e( 'Image', 'web-log' ); ?>
  104. </label>
  105. <br />
  106. <?php
  107. if (isset($instance['image_uri']) && $instance['image_uri'] != '' ) :
  108. echo '<img class="custom_media_image" src="' . esc_url( $instance['image_uri'] ) . '" style="margin:0;padding:0;max-width:100px;float:left;display:inline-block" /><br />';
  109. endif;
  110. ?>
  111.  
  112. <input type="text" class="widefat custom_media_url" name="<?php echo $this->get_field_name('image_uri'); ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php
  113. if (isset($instance['image_uri']) && $instance['image_uri'] != '' ) :
  114. echo esc_url( $instance['image_uri'] );
  115. endif;
  116. ?>" style="margin-top:5px;">
  117. <input type="button" id="custom_media_button" value="<?php esc_attr_e( 'Upload Image', 'web-log' ); ?>" class="button media-image-upload" data-title="<?php esc_attr_e( 'Select Image','web-log'); ?>" data-button="<?php esc_attr_e( 'Select Image','web-log'); ?>"/>
  118. <input type="button" id="remove_media_button" value="<?php esc_attr_e( 'Remove Image', 'web-log' ); ?>" class="button media-image-remove" />
  119. </p>
  120. <p>
  121. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title', 'web-log' ); ?></label><br />
  122. <input type="text" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" value="<?php
  123. if (isset($instance['title']) && $instance['title'] != '' ) :
  124. echo esc_attr($instance['title']);
  125. endif;
  126.  
  127. ?>" class="widefat" />
  128. </p>
  129.  
  130. <p>
  131. <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e( 'Description', 'web-log' ); ?></label><br />
  132. <textarea rows="8" name="<?php echo $this->get_field_name('description'); ?>" id="<?php echo $this->get_field_id('description'); ?>" class="widefat" ><?php
  133.  
  134. if (isset($instance['description']) && $instance['description'] != '' ) :
  135. echo esc_textarea( $instance['description'] );
  136. endif;
  137. ?></textarea>
  138. </p>
  139.  
  140. <p>
  141. <label for="<?php echo esc_attr( $this->get_field_id('facebook') ); ?>"><?php _e( 'Facebook', 'web-log' ); ?></label><br />
  142. <input type="text" name="<?php echo esc_attr( $this->get_field_name('facebook') ); ?>" id="<?php echo esc_attr( $this->get_field_id('facebook')); ?>" value="<?php
  143. if (isset($instance['facebook']) && $instance['facebook'] != '' ) :
  144. echo esc_attr($instance['facebook']);
  145. endif;
  146.  
  147. ?>" class="widefat" />
  148. </p>
  149.  
  150. <p>
  151. <label for="<?php echo esc_attr( $this->get_field_id('twitter') ); ?>"><?php _e( 'Twitter', 'web-log' ); ?></label><br />
  152. <input type="text" name="<?php echo esc_attr( $this->get_field_name('twitter') ); ?>" id="<?php echo esc_attr( $this->get_field_id('twitter')); ?>" value="<?php
  153. if (isset($instance['twitter']) && $instance['twitter'] != '' ) :
  154. echo esc_attr($instance['twitter']);
  155. endif;
  156.  
  157. ?>" class="widefat" />
  158. </p>
  159.  
  160.  
  161. <p>
  162. <label for="<?php echo esc_attr( $this->get_field_id('instagram') ); ?>"><?php _e( 'Instagram', 'web-log' ); ?></label><br />
  163. <input type="text" name="<?php echo esc_attr( $this->get_field_name('instagram') ); ?>" id="<?php echo esc_attr( $this->get_field_id('instagram')); ?>" value="<?php
  164. if (isset($instance['instagram']) && $instance['instagram'] != '' ) :
  165. echo esc_attr($instance['instagram']);
  166. endif;
  167.  
  168. ?>" class="widefat" />
  169. </p>
  170.  
  171. <p>
  172. <label for="<?php echo esc_attr( $this->get_field_id('linkedin') ); ?>"><?php _e( 'Linkedin', 'web-log' ); ?></label><br />
  173. <input type="text" name="<?php echo esc_attr( $this->get_field_name('linkedin') ); ?>" id="<?php echo esc_attr( $this->get_field_id('linkedin')); ?>" value="<?php
  174. if (isset($instance['linkedin']) && $instance['linkedin'] != '' ) :
  175. echo esc_attr($instance['linkedin']);
  176. endif;
  177.  
  178. ?>" class="widefat" />
  179. </p>
  180. <p>
  181. <label for="<?php echo esc_attr( $this->get_field_id('youtube') ); ?>"><?php _e( 'Youtube', 'web-log' ); ?></label><br />
  182. <input type="text" name="<?php echo esc_attr( $this->get_field_name('youtube') ); ?>" id="<?php echo esc_attr( $this->get_field_id('youtube')); ?>" value="<?php
  183. if (isset($instance['youtube']) && $instance['youtube'] != '' ) :
  184. echo esc_attr($instance['youtube']);
  185. endif;
  186.  
  187. ?>" class="widefat" />
  188. </p>
  189. <?php
  190. }
  191. }
  192.  
  193.  
  194. add_action( 'widgets_init', 'prefix_author_widget' );
  195. function prefix_author_widget(){
  196. register_widget( 'prefix_Author_Widget' );
  197.  
  198. }
  199.  
  200. ==========
  201. javascript code
  202. ============
  203. var at_document = $(document);
  204.  
  205. at_document.on('click','.media-image-upload', function(e){
  206.  
  207. // Prevents the default action from occuring.
  208. e.preventDefault();
  209. var media_image_upload = $(this);
  210. var media_title = $(this).data('title');
  211. var media_button = $(this).data('button');
  212. var media_input_val = $(this).prev();
  213. var media_image_url_value = $(this).prev().prev().children('img');
  214. var media_image_url = $(this).siblings('.img-preview-wrap');
  215.  
  216. var meta_image_frame = wp.media.frames.meta_image_frame = wp.media({
  217. title: media_title,
  218. button: { text: media_button },
  219. library: { type: 'image' }
  220. });
  221. // Opens the media library frame.
  222. meta_image_frame.open();
  223. // Runs when an image is selected.
  224. meta_image_frame.on('select', function(){
  225.  
  226. // Grabs the attachment selection and creates a JSON representation of the model.
  227. var media_attachment = meta_image_frame.state().get('selection').first().toJSON();
  228.  
  229. // Sends the attachment URL to our custom image input field.
  230. media_input_val.val(media_attachment.url);
  231. if( media_image_url_value !== null ){
  232. media_image_url_value.attr( 'src', media_attachment.url );
  233. media_image_url.show();
  234. LATESTVALUE(media_image_upload.closest("p"));
  235. }
  236. });
  237. });
  238.  
  239. // Runs when the image button is clicked.
  240. jQuery('body').on('click','.media-image-remove', function(e){
  241. $(this).siblings('.img-preview-wrap').hide();
  242. $(this).prev().prev().val('');
  243. });
  244.  
  245. var LATESTVALUE = function (wrapObject) {
  246. wrapObject.find('[name]').each(function(){
  247. $(this).trigger('change');
  248. });
  249. };
  250. ======
  251. Call hooks and only script call desgbord
  252. ======
  253.  
  254. if (!function_exists('prifix_widgets_backend_enqueue')) :
  255. function prifix_widgets_backend_enqueue($hook)
  256. {
  257. if ('widgets.php' != $hook)
  258. {
  259. return;
  260. }
  261.  
  262. wp_register_script('prifix-custom-widgets', get_template_directory_uri() . '/assets/js/widget.js', array('jquery'), true);
  263. wp_enqueue_media();
  264. wp_enqueue_script('prifix-custom-widgets');
  265. }
  266.  
  267. add_action('admin_enqueue_scripts', 'prifix_widgets_backend_enqueue');
  268. endif;
  269. ====================================== End Author Widget =========================================
  270.  
  271. ====================================== Start Sidebar post widget =========================================
  272. <?php
  273.  
  274. /**
  275. * Displays latest or category wised posts list.
  276. *
  277. */
  278.  
  279. class prefix_Sidebar_Posts extends WP_Widget {
  280.  
  281. /* Register Widget with WordPress*/
  282. function __construct() {
  283. parent::__construct(
  284. 'sidebar_posts', // Base ID
  285. esc_html__( 'prefix: Sidebar Posts', 'prefix' ), // Name
  286. array( 'description' => esc_html__( 'Displays latest posts or posts from a choosen category.Use this widget in the main sidebars.', 'prefix' ), ) // Args
  287. );
  288. }
  289.  
  290. /**
  291. * Back-end widget form.
  292. *
  293. * @see WP_Widget::form()
  294. *
  295. * @param array $instance Previously saved values from database.
  296. */
  297.  
  298. public function form( $instance ) {
  299. $defaults = array(
  300. 'title' => esc_html__( 'Latest Posts', 'prefix' ),
  301. 'category' => 'all',
  302. 'number_posts' => 5,
  303. 'sticky_posts' => true,
  304. );
  305. $instance = wp_parse_args( (array) $instance, $defaults );
  306.  
  307. ?>
  308.  
  309. <p>
  310. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'prefix' ); ?></label>
  311. <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>"/>
  312. </p>
  313. <p>
  314. <label><?php esc_html_e( 'Select a post category', 'prefix' ); ?></label>
  315. <?php wp_dropdown_categories( array( 'name' => $this->get_field_name('category'), 'selected' => $instance['category'], 'show_option_all' => 'Show all posts' ) ); ?>
  316. </p>
  317. <p>
  318. <label for="<?php echo $this->get_field_id( 'number_posts' ); ?>"><?php esc_html_e( 'Number of posts:', 'prefix' ); ?></label>
  319. <input type="number" id="<?php echo $this->get_field_id( 'number_posts' ); ?>" name="<?php echo $this->get_field_name( 'number_posts' );?>" value="<?php echo absint( $instance['number_posts'] ) ?>" size="3"/>
  320. </p>
  321. <p>
  322. <input type="checkbox" <?php checked( $instance['sticky_posts'], true ) ?> class="checkbox" id="<?php echo $this->get_field_id('sticky_posts'); ?>" name="<?php echo $this->get_field_name('sticky_posts'); ?>" />
  323. <label for="<?php echo $this->get_field_id('sticky_posts'); ?>"><?php esc_html_e( 'Ignore sticky posts.', 'prefix' ); ?></label>
  324. </p>
  325.  
  326. <?php
  327.  
  328. }
  329.  
  330. /**
  331. * Sanitize widget form values as they are saved.
  332. *
  333. * @see WP_Widget::update()
  334. *
  335. * @param array $new_instance Values just sent to be saved.
  336. * @param array $old_instance Previously saved values from database.
  337. *
  338. * @return array Updated safe values to be saved.
  339. */
  340.  
  341. public function update( $new_instance, $old_instance ) {
  342. $instance = $old_instance;
  343. $instance[ 'title' ] = sanitize_text_field( $new_instance[ 'title' ] );
  344. $instance[ 'category' ] = absint( $new_instance[ 'category' ] );
  345. $instance[ 'number_posts' ] = (int)$new_instance[ 'number_posts' ];
  346. $instance[ 'sticky_posts' ] = (bool)$new_instance[ 'sticky_posts' ];
  347. return $instance;
  348. }
  349.  
  350.  
  351. /**
  352. * Front-end display of widget.
  353. *
  354. * @see WP_Widget::widget()
  355. *
  356. * @param array $args Widget arguments.
  357. * @param array $instance Saved values from database.
  358. */
  359.  
  360. public function widget( $args, $instance ) {
  361. extract($args);
  362.  
  363. $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : '';
  364. $title = apply_filters( 'widget_title', $title , $instance, $this->id_base );
  365. $category = ( ! empty( $instance['category'] ) ) ? absint( $instance['category'] ) : 0;
  366. $number_posts = ( ! empty( $instance['number_posts'] ) ) ? absint( $instance['number_posts'] ) : 5;
  367. $sticky_posts = ( isset( $instance['sticky_posts'] ) ) ? $instance['sticky_posts'] : false;
  368.  
  369. // Latest Posts
  370. $latest_posts = new WP_Query(
  371. array(
  372. 'cat' => $category,
  373. 'posts_per_page' => $number_posts,
  374. 'ignore_sticky_posts' => $sticky_posts
  375. )
  376. );
  377.  
  378. echo $before_widget; ?>
  379. <div class="prefix-category-posts">
  380. <?php
  381. if ( $title ) {
  382. echo $before_title . $title . $after_title;
  383. }
  384. ?>
  385.  
  386.  
  387. <?php if( $latest_posts -> have_posts() ) : ?>
  388. <?php while ( $latest_posts -> have_posts() ) : $latest_posts -> the_post(); ?>
  389. <div class="bms-post clearfix">
  390. <?php if ( has_post_thumbnail() ) { ?>
  391. <div class="bms-thumb">
  392. <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
  393. <?php the_post_thumbnail( 'prefix-small' ); ?>
  394. </a>
  395. </div>
  396. <?php } ?>
  397. <div class="bms-details">
  398. <?php the_title( sprintf( '<h3 class="bms-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h3>' ); ?>
  399. <div class="entry-meta"><?php prefix_posted_on(); ?></div>
  400. </div>
  401. </div><!-- .bms-post -->
  402. <?php endwhile; ?>
  403. <?php wp_reset_postdata(); ?>
  404. <?php endif; ?>
  405.  
  406. </div><!-- .prefix-category-posts -->
  407.  
  408.  
  409. <?php
  410. echo $after_widget;
  411. }
  412.  
  413. }
  414.  
  415. // Register single category posts widget
  416. function prefix_register_sidebar_posts() {
  417. register_widget( 'prefix_Sidebar_Posts' );
  418. }
  419. add_action( 'widgets_init', 'prefix_register_sidebar_posts' );
  420. ====================================== End Sidebar post widget =========================================
RAW Paste Data