Advertisement
duskopro

functions.php new

Mar 25th, 2024
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 30.39 KB | Source Code | 0 0
  1. <?php
  2. /**
  3.  * Piha functions and definitions
  4.  *
  5.  * @package WordPress
  6.  * @subpackage Piha
  7.  */
  8.  
  9. /*-----------------------------------------------------------------------------------*/
  10. /* Make theme available for translation
  11. /* Translations can be filed in the /languages/ directory
  12. /*-----------------------------------------------------------------------------------*/
  13.  
  14. load_theme_textdomain( 'piha', TEMPLATEPATH . '/languages' );
  15.  
  16. $locale = get_locale();
  17. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  18.     if ( is_readable( $locale_file ) )
  19.         require_once( $locale_file );
  20.  
  21. /*-----------------------------------------------------------------------------------*/
  22. /* Set the content width based on the theme's design and stylesheet.
  23. /*-----------------------------------------------------------------------------------*/
  24.  
  25. if ( ! isset( $content_width ) )
  26.     $content_width = 680;
  27.  
  28. /*-----------------------------------------------------------------------------------*/
  29. /* Tell WordPress to run piha() when the 'after_setup_theme' hook is run.
  30. /*-----------------------------------------------------------------------------------*/
  31.  
  32. add_action( 'after_setup_theme', 'piha' );
  33.  
  34. if ( ! function_exists( 'piha' ) ):
  35.  
  36. /*-----------------------------------------------------------------------------------*/
  37. /* Create the Piha Theme Options Page
  38. /*-----------------------------------------------------------------------------------*/
  39.  
  40. require_once ( get_template_directory() . '/includes/theme-options.php' );
  41.  
  42. /*-----------------------------------------------------------------------------------*/
  43. /* Call JavaScript Scripts for Piha (Fitvids for Elasic Videos and Custom)
  44. /*-----------------------------------------------------------------------------------*/
  45.  
  46. add_action('wp_enqueue_scripts','piha_scripts_function');
  47.     function piha_scripts_function() {
  48.         wp_enqueue_script( 'fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', false, '1.0');
  49.         wp_enqueue_script( 'respond', get_template_directory_uri() . '/js/respond.min.js', false, '1.0.1');
  50.         wp_enqueue_script( 'custom', get_template_directory_uri() . '/js/custom.js', false, '1.0.1');
  51. }
  52.  
  53. /*-----------------------------------------------------------------------------------*/
  54. /* Sets up theme defaults and registers support for WordPress features.
  55. /*-----------------------------------------------------------------------------------*/
  56.  
  57. function piha() {
  58.  
  59.     // This theme styles the visual editor with editor-style.css to match the theme style.
  60.     add_editor_style();
  61.  
  62.     // This theme uses post thumbnails
  63.     add_theme_support( 'post-thumbnails' );
  64.  
  65.     // Add default posts and comments RSS feed links to head
  66.     add_theme_support( 'automatic-feed-links' );
  67.  
  68.     // This theme uses wp_nav_menu() in one location.
  69.     register_nav_menus( array(
  70.         'primary' => __( 'Primary Navigation', 'piha' ),
  71.         'top' => __( 'Optional Top Navigation (no sub menus supported)', 'piha' ),
  72.         'footer' => __( 'Optional Footer Navigation (no sub menus supported)', 'piha' )
  73.     ) );
  74.    
  75.     // Add support for Post Formats
  76.     add_theme_support( 'post-formats', array( 'aside', 'status', 'link', 'quote', 'chat', 'image', 'gallery', 'video', 'audio' ) );
  77.  
  78.     // This theme allows users to set a custom background
  79.     add_custom_background();
  80.    
  81.     // The default header text color
  82.     define( 'HEADER_TEXTCOLOR', '222' );
  83.    
  84.     // By leaving empty, we allow for random image rotation.
  85.     define( 'HEADER_IMAGE', '' );
  86.  
  87.     // The height and width of your custom header. You can hook into the theme's own filters to change these values.
  88.     // Add a filter to piha_header_image_width and piha_header_image_height to change these values.
  89.     define( 'HEADER_IMAGE_WIDTH', apply_filters( 'piha_header_image_width', 750 ) );
  90.     define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'piha_header_image_height', 200 ) );
  91.  
  92.     // Don't support text inside the header image.
  93.     define( 'NO_HEADER_TEXT', true );
  94.  
  95.     // Add a way for the custom header to be styled in the admin panel that controls
  96.     // custom headers. See piha_admin_header_style(), below.
  97.     add_custom_image_header( '', 'piha_admin_header_style' );
  98.  
  99.     // ... and thus ends the changeable header business.
  100.  
  101.     // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
  102.     register_default_headers( array(
  103.             'numbers' => array(
  104.                 'url' => '%s/images/headers/headerimage.jpg',
  105.                 'thumbnail_url' => '%s/images/headers/headerimage-thumbnail.jpg',
  106.                 /* translators: header image description */
  107.                 'description' => __( 'Numbers', 'piha' )
  108.             ),
  109.             'mosaik' => array(
  110.                 'url' => '%s/images/headers/headerimage02.jpg',
  111.                 'thumbnail_url' => '%s/images/headers/headerimage02-thumbnail.jpg',
  112.                 /* translators: header image description */
  113.                 'description' => __( 'Mosaik', 'piha' )
  114.         )
  115.     ) );
  116. }
  117. endif;
  118.  
  119. if ( ! function_exists( 'piha_admin_header_style' ) ) :
  120.  
  121. /*-----------------------------------------------------------------------------------*/
  122. /* Styles the header image displayed on the Appearance > Header admin panel.
  123. /* Referenced via add_custom_image_header() in piha_setup().
  124. /*-----------------------------------------------------------------------------------*/
  125.  
  126. function piha_admin_header_style() {
  127. ?>
  128. <style type="text/css">
  129. /* Shows the same border as on front end */
  130. #heading {
  131.     border-bottom: 1px solid #000;
  132.     border-top: 4px solid #000;
  133. }
  134. /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
  135.     #headimg #name { }
  136.     #headimg #desc { }
  137. */
  138. </style>
  139. <?php
  140. }
  141. endif;
  142.  
  143. /*-----------------------------------------------------------------------------------*/
  144. /* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  145. /*-----------------------------------------------------------------------------------*/
  146.  
  147. function piha_page_menu_args( $args ) {
  148.     $args['show_home'] = true;
  149.     return $args;
  150. }
  151. add_filter( 'wp_page_menu_args', 'piha_page_menu_args' );
  152.  
  153. /*-----------------------------------------------------------------------------------*/
  154. /* Sets the post excerpt length to 40 characters.
  155. /*-----------------------------------------------------------------------------------*/
  156.  
  157. function piha_excerpt_length( $length ) {
  158.     return 40;
  159. }
  160. add_filter( 'excerpt_length', 'piha_excerpt_length' );
  161.  
  162. /*-----------------------------------------------------------------------------------*/
  163. /* Returns a "Continue Reading" link for excerpts
  164. /*-----------------------------------------------------------------------------------*/
  165.  
  166. function piha_continue_reading_link() {
  167.     return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'piha' ) . '</a>';
  168. }
  169.  
  170. /*-----------------------------------------------------------------------------------*/
  171. /* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and piha_continue_reading_link().
  172. /*
  173. /* To override this in a child theme, remove the filter and add your own
  174. /* function tied to the excerpt_more filter hook.
  175. /*-----------------------------------------------------------------------------------*/
  176.  
  177. function piha_auto_excerpt_more( $more ) {
  178.     return ' &hellip;' . piha_continue_reading_link();
  179. }
  180. add_filter( 'excerpt_more', 'piha_auto_excerpt_more' );
  181.  
  182. /*-----------------------------------------------------------------------------------*/
  183. /* Adds a pretty "Continue Reading" link to custom post excerpts.
  184. /*
  185. /* To override this link in a child theme, remove the filter and add your own
  186. /* function tied to the get_the_excerpt filter hook.
  187. /*-----------------------------------------------------------------------------------*/
  188.  
  189. function piha_custom_excerpt_more( $output ) {
  190.     if ( has_excerpt() && ! is_attachment() ) {
  191.         $output .= piha_continue_reading_link();
  192.     }
  193.     return $output;
  194. }
  195. add_filter( 'get_the_excerpt', 'piha_custom_excerpt_more' );
  196.  
  197. /*-----------------------------------------------------------------------------------*/
  198. /* Remove inline styles printed when the gallery shortcode is used.
  199. /*-----------------------------------------------------------------------------------*/
  200.  
  201. function piha_remove_gallery_css( $css ) {
  202.     return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  203. }
  204. add_filter( 'gallery_style', 'piha_remove_gallery_css' );
  205.  
  206.  
  207.  
  208. if ( ! function_exists( 'piha_comment' ) ) :
  209.  
  210. /*-----------------------------------------------------------------------------------*/
  211. /* Comments template piha_comment
  212. /*-----------------------------------------------------------------------------------*/
  213.  
  214. function piha_comment( $comment, $args, $depth ) {
  215.     $GLOBALS['comment'] = $comment;
  216.     switch ( $comment->comment_type ) :
  217.         case '' :
  218.     ?>
  219.  
  220.     <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  221.         <article id="comment-<?php comment_ID(); ?>" class="comment">
  222.                        
  223.             <div class="comment-header">
  224.                 <?php echo get_avatar( $comment, 40 ); ?>
  225.                 <?php printf( __( '%s', 'piha' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  226.                 <p><a class="comment-time" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  227.                 <?php
  228.                     /* translators: 1: date, 2: time */
  229.                     printf( __( '%1$s &#64; %2$s', 'piha' ),
  230.                     get_comment_date('d/m/Y'),
  231.                     get_comment_time() );
  232.                 ?></a></p>
  233.                
  234.                 <p><?php edit_comment_link( __( 'Edit comment &raquo;', 'piha' ), ' ' );?></p>
  235.             </div><!-- end .comment-header --> 
  236.        
  237.             <div class="comment-content">
  238.                 <?php comment_text(); ?>   
  239.                 <?php if ( $comment->comment_approved == '0' ) : ?>
  240.                     <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'piha' ); ?></p>
  241.                 <?php endif; ?>
  242.             <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'piha' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  243.             </div><!-- end .comment-content -->
  244.         </article><!-- end .comment -->
  245.  
  246.     <?php
  247.             break;
  248.         case 'pingback'  :
  249.         case 'trackback' :
  250.     ?>
  251.     <li class="post pingback">
  252.         <p><?php _e( 'Pingback:', 'piha' ); ?> <?php comment_author_link(); ?></p>
  253.         <p><?php edit_comment_link( __('Edit pingback &raquo;', 'piha'), ' ' ); ?></p>
  254.     <?php
  255.             break;
  256.     endswitch;
  257. }
  258. endif;
  259.  
  260. /*-----------------------------------------------------------------------------------*/
  261. /* Register widgetized area and update sidebar with default widgets
  262. /*-----------------------------------------------------------------------------------*/
  263.  
  264. function piha_widgets_init() {
  265.  
  266.     register_sidebar( array (
  267.         'name' => __( 'Main Sidebar', 'piha' ),
  268.         'id' => 'sidebar-1',
  269.         'description' => __( 'Add your sidebar widgets here.', 'piha' ),
  270.         'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  271.         'after_widget' => "</aside>",
  272.         'before_title' => '<h3 class="widget-title">',
  273.         'after_title' => '</h3>',
  274.     ) );
  275.  
  276. }
  277. add_action( 'init', 'piha_widgets_init' );
  278.  
  279. /*-----------------------------------------------------------------------------------*/
  280. /* Customized Piha search form
  281. /*-----------------------------------------------------------------------------------*/
  282.  
  283. function piha_search_form( $form ) {
  284.  
  285.     $form = '   <form method="get" class="searchform" action="'.get_bloginfo('url').'">
  286.             <input type="text" class="field s" name="s" placeholder="'. esc_attr__('Search', 'piha') .'" />
  287.             <input type="submit" class="searchsubmit" name="submit" value="'. esc_attr__('Search', 'piha') .'" />
  288.     </form>';
  289.  
  290.     return $form;
  291. }
  292. add_filter( 'get_search_form', 'piha_search_form' );
  293.  
  294. /**
  295.  * Removes the default CSS style from the WP image gallery
  296.  */
  297. add_filter('gallery_style', function($a) {
  298.     return "<div class='gallery'>";
  299. });
  300.  
  301.  
  302. /*-----------------------------------------------------------------------------------*/
  303. /* Piha Shortcodes
  304. /*-----------------------------------------------------------------------------------*/
  305.  
  306. // Enable shortcodes in widget areas
  307. add_filter( 'widget_text', 'do_shortcode' );
  308.  
  309. // Replace WP autop formatting
  310. if (!function_exists( "piha_remove_wpautop")) {
  311.     function piha_remove_wpautop($content) {
  312.         $content = do_shortcode( shortcode_unautop( $content ) );
  313.         $content = preg_replace( '#^<\/p>|^<br \/>|<p>$#', '', $content);
  314.         return $content;
  315.     }
  316. }
  317.  
  318. /*-----------------------------------------------------------------------------------*/
  319. /* Multi Columns Shortcodes
  320. /* Don't forget to add "_last" behind the shortcode if it is the last column.
  321. /*-----------------------------------------------------------------------------------*/
  322.  
  323. // Two Columns
  324. function piha_shortcode_two_columns_one( $atts, $content = null ) {
  325.    return '<div class="two-columns-one">' . piha_remove_wpautop($content) . '</div>';
  326. }
  327. add_shortcode( 'two_columns_one', 'piha_shortcode_two_columns_one' );
  328.  
  329. function piha_shortcode_two_columns_one_last( $atts, $content = null ) {
  330.    return '<div class="two-columns-one last">' . piha_remove_wpautop($content) . '</div>';
  331. }
  332. add_shortcode( 'two_columns_one_last', 'piha_shortcode_two_columns_one_last' );
  333.  
  334. // Three Columns
  335. function piha_shortcode_three_columns_one($atts, $content = null) {
  336.    return '<div class="three-columns-one">' . piha_remove_wpautop($content) . '</div>';
  337. }
  338. add_shortcode( 'three_columns_one', 'piha_shortcode_three_columns_one' );
  339.  
  340. function piha_shortcode_three_columns_one_last($atts, $content = null) {
  341.    return '<div class="three-columns-one last">' . piha_remove_wpautop($content) . '</div>';
  342. }
  343. add_shortcode( 'three_columns_one_last', 'piha_shortcode_three_columns_one_last' );
  344.  
  345. function piha_shortcode_three_columns_two($atts, $content = null) {
  346.    return '<div class="three-columns-two">' . piha_remove_wpautop($content) . '</div>';
  347. }
  348. add_shortcode( 'three_columns_two', 'piha_shortcode_three_columns' );
  349.  
  350. function piha_shortcode_three_columns_two_last($atts, $content = null) {
  351.    return '<div class="three-columns-two last">' . piha_remove_wpautop($content) . '</div>';
  352. }
  353. add_shortcode( 'three_columns_two_last', 'piha_shortcode_three_columns_two_last' );
  354.  
  355. // Four Columns
  356. function piha_shortcode_four_columns_one($atts, $content = null) {
  357.    return '<div class="four-columns-one">' . piha_remove_wpautop($content) . '</div>';
  358. }
  359. add_shortcode( 'four_columns_one', 'piha_shortcode_four_columns_one' );
  360.  
  361. function piha_shortcode_four_columns_one_last($atts, $content = null) {
  362.    return '<div class="four-columns-one last">' . piha_remove_wpautop($content) . '</div>';
  363. }
  364. add_shortcode( 'four_columns_one_last', 'piha_shortcode_four_columns_one_last' );
  365.  
  366. function piha_shortcode_four_columns_two($atts, $content = null) {
  367.    return '<div class="four-columns-two">' . piha_remove_wpautop($content) . '</div>';
  368. }
  369. add_shortcode( 'four_columns_two', 'piha_shortcode_four_columns_two' );
  370.  
  371. function piha_shortcode_four_columns_two_last($atts, $content = null) {
  372.    return '<div class="four-columns-two last">' . piha_remove_wpautop($content) . '</div>';
  373. }
  374. add_shortcode( 'four_columns_two_last', 'piha_shortcode_four_columns_two_last' );
  375.  
  376. function piha_shortcode_four_columns_three($atts, $content = null) {
  377.    return '<div class="four-columns-three">' . piha_remove_wpautop($content) . '</div>';
  378. }
  379. add_shortcode( 'four_columns_three', 'piha_shortcode_four_columns_three' );
  380.  
  381. function piha_shortcode_four_columns_three_last($atts, $content = null) {
  382.    return '<div class="four-columns-three last">' . piha_remove_wpautop($content) . '</div>';
  383. }
  384. add_shortcode( 'four_columns_three_last', 'piha_shortcode_four_columns_three_last' );
  385.  
  386. // Divide Text Shortcode
  387. function piha_shortcode_divider($atts, $content = null) {
  388.    return '<div class="divider"></div>';
  389. }
  390. add_shortcode( 'divider', 'piha_shortcode_divider' );
  391.  
  392. /*-----------------------------------------------------------------------------------*/
  393. /* Text Highlight and Info Boxes Shortcodes
  394. /*-----------------------------------------------------------------------------------*/
  395.  
  396. function piha_shortcode_white_box($atts, $content = null) {
  397.    return '<div class="white-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
  398. }
  399. add_shortcode( 'white_box', 'piha_shortcode_white_box' );
  400.  
  401. function piha_shortcode_yellow_box($atts, $content = null) {
  402.    return '<div class="yellow-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
  403. }
  404. add_shortcode( 'yellow_box', 'piha_shortcode_yellow_box' );
  405.  
  406. function piha_shortcode_red_box($atts, $content = null) {
  407.    return '<div class="red-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
  408. }
  409. add_shortcode( 'red_box', 'piha_shortcode_red_box' );
  410.  
  411. function piha_shortcode_blue_box($atts, $content = null) {
  412.    return '<div class="blue-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
  413. }
  414. add_shortcode( 'blue_box', 'piha_shortcode_blue_box' );
  415.  
  416. function piha_shortcode_green_box($atts, $content = null) {
  417.    return '<div class="green-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
  418. }
  419. add_shortcode( 'green_box', 'piha_shortcode_green_box' );
  420.  
  421. function piha_shortcode_lightgrey_box($atts, $content = null) {
  422.    return '<div class="lightgrey-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
  423. }
  424. add_shortcode( 'lightgrey_box', 'piha_shortcode_lightgrey_box' );
  425.  
  426. function piha_shortcode_grey_box($atts, $content = null) {
  427.    return '<div class="grey-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
  428. }
  429. add_shortcode( 'grey_box', 'piha_shortcode_grey_box' );
  430.  
  431. function piha_shortcode_darkgrey_box($atts, $content = null) {
  432.    return '<div class="darkgrey-box">' . do_shortcode( piha_remove_wpautop($content) ) . '</div>';
  433. }
  434. add_shortcode( 'darkgrey_box', 'piha_shortcode_darkgrey_box' );
  435.  
  436. /*-----------------------------------------------------------------------------------*/
  437. /* General Buttons Shortcodes
  438. /*-----------------------------------------------------------------------------------*/
  439.  
  440. function piha_button( $atts, $content = null ) {
  441.     extract(shortcode_atts(array(
  442.     'link'  => '#',
  443.     'target'    => '',
  444.     'color' => '',
  445.     'size'  => '',
  446.     'form'  => '',
  447.     'style' => '',
  448.     ), $atts));
  449.  
  450.     $color = ($color) ? ' '.$color. '-btn' : '';
  451.     $size = ($size) ? ' '.$size. '-btn' : '';
  452.     $form = ($form) ? ' '.$form. '-btn' : '';
  453.     $target = ($target == 'blank') ? ' target="_blank"' : '';
  454.  
  455.     $out = '<a' .$target. ' class="standard-btn' .$color.$size.$form. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
  456.  
  457.     return $out;
  458. }
  459. add_shortcode('button', 'piha_button');
  460.  
  461. /*-----------------------------------------------------------------------------------*/
  462. /* PDF, Info and Add Buttons Shortcodes
  463. /*-----------------------------------------------------------------------------------*/
  464.  
  465. function piha_icons_button( $atts, $content = null ) {
  466.     extract(shortcode_atts(array(
  467.     'link'  => '#',
  468.     'target'    => '',
  469.     'color' => '',
  470.     'style' => '',
  471.     'form'  => '',
  472.     ), $atts));
  473.  
  474.     $color = ($color) ? ' '.$color. '-btn' : '';
  475.     $style = ($style) ? ' '.$style. '-btn' : '';
  476.     $form = ($form) ? ' '.$form. '-btn' : '';
  477.     $target = ($target == 'blank') ? ' target="_blank"' : '';
  478.  
  479.     $out = '<a' .$target. ' class="icons-btn' .$color.$style.$form. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
  480.  
  481.     return $out;
  482. }
  483. add_shortcode('icons_button', 'piha_icons_button');
  484.  
  485. /*-----------------------------------------------------------------------------------*/
  486. /* Simple PDF, Info and Add Buttons Shortcodes
  487. /*-----------------------------------------------------------------------------------*/
  488.  
  489. function piha_simple_icons_button( $atts, $content = null ) {
  490.     extract(shortcode_atts(array(
  491.         'link'  => '#',
  492.         'target'    => '',
  493.         'style' => '',
  494.     ), $atts));
  495.  
  496.     $style = ($style) ? ' '.$style. '-btn' : '';
  497.     $target = ($target == 'blank') ? ' target="_blank"' : '';
  498.  
  499.     $out = '<a' .$target. ' class="simple-icons-btn' .$style. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
  500.  
  501.     return $out;
  502. }
  503. add_shortcode('simple_icons_button', 'piha_simple_icons_button');
  504.  
  505. /*-----------------------------------------------------------------------------------*/
  506. /* Link Post Format Button Shortcode
  507. /*-----------------------------------------------------------------------------------*/
  508.  
  509. function piha_link_format( $atts, $content = null ) {
  510.     extract(shortcode_atts(array(
  511.     'link'  => '#',
  512.     'target'    => '',
  513.      'style'    => '',
  514.     ), $atts));
  515.  
  516.     $target = ($target == 'blank') ? ' target="_blank"' : '';
  517.  
  518.     $out = '<a' .$target. ' class="link-format-btn' .$style. '" href="' .$link. '"><span>' .do_shortcode($content). '</span></a>';
  519.  
  520.     return $out;
  521. }
  522. add_shortcode('link_format', 'piha_link_format');
  523.  
  524.  
  525. /*-----------------------------------------------------------------------------------*/
  526. /* Deactives the default CSS styles for the Smart Archives Reloaded plugin
  527. /*-----------------------------------------------------------------------------------*/
  528.  
  529. add_filter('smart_archives_load_default_styles', '__return_false');
  530.  
  531. /*-----------------------------------------------------------------------------------*/
  532. /* Include a custom Flickr Widget
  533. /*-----------------------------------------------------------------------------------*/
  534.  
  535. class Piha_Flickr extends WP_Widget {
  536.  
  537.     public function __construct() {
  538.         $widget_ops = array('description' => 'Show preview images from a flickr account or group.' , 'piha');
  539.  
  540.         parent::__construct('piha_flickr', __('Flickr Widget', 'piha'), $widget_ops);
  541.     }
  542.  
  543.     public function widget($args, $instance) {  
  544.         extract($args);
  545.         $title = $instance['title'];
  546.         $id = $instance['id'];
  547.         $linktext = $instance['linktext'];
  548.         $linkurl = $instance['linkurl'];
  549.         $number = $instance['number'];
  550.         $type = $instance['type'];
  551.         $sorting = $instance['sorting'];
  552.        
  553.         echo $before_widget; ?>
  554.         <?php if ($title != '') {
  555.             echo '<h3 class="widget-title">' . $title . '</h3>';
  556.         } ?>
  557.            
  558.         <div class="flickr_badge_wrapper"><script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count=<?php echo $number; ?>&amp;display=<?php echo $sorting; ?>&amp;&amp;source=<?php echo $type; ?>&amp;<?php echo $type; ?>=<?php echo $id; ?>&amp;size=m"></script><div class="clear"></div>
  559.         <?php if ($linktext == '') {
  560.             echo '';
  561.         } else {
  562.             echo '<div class="flickr-bottom"><a href="'.$linkurl.'" class="flickr-home" target="_blank">'.$linktext.'</a></div>';
  563.         }?>
  564.         </div><!-- end .flickr_badge_wrapper -->
  565.    
  566.        <?php           
  567.        echo $after_widget;
  568.    }
  569.  
  570.    public function update($new_instance, $old_instance) {                
  571.        return $new_instance;
  572.    }
  573.  
  574.    public function form($instance) {
  575.         $title = esc_attr($instance['title']);
  576.         $id = esc_attr($instance['id']);
  577.         $linktext = esc_attr($instance['linktext']);
  578.         $linkurl = esc_attr($instance['linkurl']);
  579.         $number = esc_attr($instance['number']);
  580.         $type = esc_attr($instance['type']);
  581.         $sorting = esc_attr($instance['sorting']);
  582.         ?>
  583.        
  584.          <p>
  585.             <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','piha'); ?></label>
  586.             <input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />
  587.         </p>
  588.  
  589.         <p>
  590.             <label for="<?php echo $this->get_field_id('id'); ?>"><?php _e('Flickr ID (<a href="http://www.idgettr.com" target="_blank">idGettr</a>):','piha'); ?></label>
  591.             <input type="text" name="<?php echo $this->get_field_name('id'); ?>" value="<?php echo $id; ?>" class="widefat" id="<?php echo $this->get_field_id('id'); ?>" />
  592.         </p>
  593.  
  594.         <p>
  595.             <label for="<?php echo $this->get_field_id('linktext'); ?>"><?php _e('Flickr Profile Link Text:','piha'); ?></label>
  596.             <input type="text" name="<?php echo $this->get_field_name('linktext'); ?>" value="<?php echo $linktext; ?>" class="widefat" id="<?php echo $this->get_field_id('linktext'); ?>" />
  597.         </p>
  598.        
  599.         <p>
  600.             <label for="<?php echo $this->get_field_id('linkurl'); ?>"><?php _e('Flickr Profile URL:','piha'); ?></label>
  601.             <input type="text" name="<?php echo $this->get_field_name('linkurl'); ?>" value="<?php echo $linkurl; ?>" class="widefat" id="<?php echo $this->get_field_id('linkurl'); ?>" />
  602.         </p>
  603.  
  604.         <p>
  605.             <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of photos:','piha'); ?></label>
  606.             <select name="<?php echo $this->get_field_name('number'); ?>" class="widefat" id="<?php echo $this->get_field_id('number'); ?>">
  607.                 <?php for ($i = 1; $i <= 10; $i += 1) { ?>
  608.                 <option value="<?php echo $i; ?>" <?php if ($number == $i) { echo "selected='selected'";} ?>><?php echo $i; ?></option>
  609.                 <?php } ?>
  610.             </select>
  611.         </p>
  612.  
  613.         <p>
  614.             <label for="<?php echo $this->get_field_id('type'); ?>"><?php _e('Choose user or group:','piha'); ?></label>
  615.             <select name="<?php echo $this->get_field_name('type'); ?>" class="widefat" id="<?php echo $this->get_field_id('type'); ?>">
  616.                 <option value="user" <?php if ($type == "user") { echo "selected='selected'";} ?>><?php _e('User', 'piha'); ?></option>
  617.                 <option value="group" <?php if ($type == "group") { echo "selected='selected'";} ?>><?php _e('Group', 'piha'); ?></option>            
  618.             </select>
  619.         </p>
  620.         <p>
  621.             <label for="<?php echo $this->get_field_id('sorting'); ?>"><?php _e('Show latest or random pictures:','piha'); ?></label>
  622.             <select name="<?php echo $this->get_field_name('sorting'); ?>" class="widefat" id="<?php echo $this->get_field_id('sorting'); ?>">
  623.                 <option value="latest" <?php if ($sorting == "latest") { echo "selected='selected'";} ?>><?php _e('Latest', 'piha'); ?></option>
  624.                 <option value="random" <?php if ($sorting == "random") { echo "selected='selected'";} ?>><?php _e('Random', 'piha'); ?></option>            
  625.             </select>
  626.         </p>
  627.         <?php
  628.     }
  629. }
  630.  
  631. // Register the widget using the class name
  632. add_action('widgets_init', function(){
  633.     register_widget('Piha_Flickr');
  634. });
  635.  
  636. /*-----------------------------------------------------------------------------------*/
  637. /* Include a custom Video Widget
  638. /*-----------------------------------------------------------------------------------*/
  639.  
  640. class Piha_Video extends WP_Widget {
  641.  
  642.     public function __construct() {
  643.             $widget_ops = array('description' => 'Show a custom featured video.', 'piha');
  644.  
  645.             parent::__construct('piha_video', __('Video Widget', 'piha'), $widget_ops);
  646.     }
  647.  
  648.     public function widget($args, $instance) {
  649.             extract($args);
  650.             $title = $instance['title'];
  651.             $embedcode = $instance['embedcode'];
  652.  
  653.             echo $before_widget; ?>
  654.             <?php if ($title != '') {
  655.                     echo '<h3 class="widget-title">' . $title . '</h3>';
  656.             } ?>
  657.  
  658.             <div class="video_widget">
  659.                     <div class="featured-video"><?php echo $embedcode; ?></div>
  660.             </div><!-- end .video_widget -->
  661.  
  662.             <?php
  663.             echo $after_widget;
  664.     }
  665.  
  666.     public function update($new_instance, $old_instance) {
  667.             return $new_instance;
  668.     }
  669.  
  670.     public function form($instance) {
  671.             $title = esc_attr($instance['title']);
  672.             $embedcode = esc_attr($instance['embedcode']);
  673.             ?>
  674.  
  675.             <p>
  676.                     <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'piha'); ?></label>
  677.                     <input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />
  678.             </p>
  679.  
  680.             <p>
  681.                     <label for="<?php echo $this->get_field_id('embedcode'); ?>"><?php _e('Video embed code:', 'piha'); ?></label>
  682.                     <textarea name="<?php echo $this->get_field_name('embedcode'); ?>" class="widefat" rows="6" id="<?php echo $this->get_field_id('embedcode'); ?>"><?php echo ($embedcode); ?></textarea>
  683.             </p>
  684.  
  685.             <?php
  686.     }
  687. }
  688.  
  689. // Register the widget using the class name
  690. add_action('widgets_init', function () {
  691.     register_widget('Piha_Video');
  692. });
  693.  
  694. /*-----------------------------------------------------------------------------------*/
  695. /* Including a custom Social Media Widget
  696. /*-----------------------------------------------------------------------------------*/
  697.  
  698. class Piha_SocialLinks extends WP_Widget {
  699.     public function __construct() {
  700.             $widget_ops = array('description' => 'Link to your social profiles.');
  701.  
  702.             parent::__construct('piha_sociallinks', __('Social Links Widget', 'piha'), $widget_ops);
  703.     }
  704.  
  705.     public function widget($args, $instance) {
  706.             $title = !empty($instance['title']) ? $instance['title'] : '';
  707.             $target = !empty($instance['target']) ? 'target="_blank"' : '';
  708.  
  709.             echo $args['before_widget'];
  710.  
  711.             if (!empty($title)) {
  712.                     echo $args['before_title'] . $title . $args['after_title'];
  713.             }
  714.  
  715.             ?>
  716.             <ul class="sociallinks">
  717.                     <?php
  718.                     $social_links = array(
  719.                             'twitter' => 'Twitter',
  720.                             'facebook' => 'Facebook',
  721.                             // Add more social links as needed
  722.                     );
  723.  
  724.                     foreach ($social_links as $key => $label) {
  725.                             $url = !empty($instance[$key]) ? esc_url($instance[$key]) : '';
  726.                             if (!empty($url)) {
  727.                                     echo '<li><a href="' . $url . '" class="' . $key . '" title="' . $label . '" ' . $target . '>' . $label . '</a></li>';
  728.                             }
  729.                     }
  730.                     ?>
  731.             </ul><!-- end .sociallinks -->
  732.             <?php
  733.  
  734.             echo $args['after_widget'];
  735.     }
  736.  
  737.     public function update($new_instance, $old_instance) {
  738.             $instance = $old_instance;
  739.             $instance['title'] = sanitize_text_field($new_instance['title']);
  740.             $instance['target'] = isset($new_instance['target']) ? true : false;
  741.             // Update other fields as needed
  742.  
  743.             return $instance;
  744.     }
  745.  
  746.     public function form($instance) {
  747.             $title = !empty($instance['title']) ? esc_attr($instance['title']) : '';
  748.             $target = !empty($instance['target']) ? 'checked="checked"' : '';
  749.  
  750.             ?>
  751.             <p>
  752.                     <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  753.                     <input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />
  754.             </p>
  755.  
  756.             <p>
  757.                     <input class="checkbox" type="checkbox" <?php echo $target; ?> id="<?php echo $this->get_field_id('target'); ?>" name="<?php echo $this->get_field_name('target'); ?>" />
  758.                     <label for="<?php echo $this->get_field_id('target'); ?>"><?php _e('Open all links in a new browser tab'); ?></label>
  759.             </p>
  760.             <?php
  761.     }
  762. }
  763.  
  764. function register_piha_sociallinks_widget() {
  765.     register_widget('Piha_SocialLinks');
  766. }
  767. add_action('widgets_init', 'register_piha_sociallinks_widget');
  768.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement