eventsmanager

"Pages in Posts" patch to add custom titles + title fix

Apr 18th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.14 KB | None | 0 0
  1. Index: widgets/pages-widget.php
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- widgets/pages-widget.php    (revision 2285717)
  7. +++ widgets/pages-widget.php    (date 1587213595964)
  8. @@ -37,6 +37,9 @@
  9.         if(isset($currentInstance['titleEnable']) == false){
  10.             $currentInstance['titleEnable'] = 'true';
  11.         }
  12. +       if(isset($currentInstance['titleCustom']) == false){
  13. +           $currentInstance['titleCustom'] = '';
  14. +       }
  15.         if(isset($currentInstance['customCssClass']) == false){
  16.             $currentInstance['customCssClass'] = '';
  17.         }
  18. @@ -56,6 +59,7 @@
  19.             $currentInstance['titletype'] = "h2";
  20.         }
  21.         ?>
  22. +       <input type="hidden" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" />
  23.         <p style="font-style: italic;"><small><?php _e( 'Select the page here and then edit the page under the pages tab on the left.', 'pages-in-widgets' ); ?></small></p>
  24.         <p><label for="<?php echo $this->get_field_id('pageID'); ?>"><span style="float:left; width:100%;"><?php _e( 'Page:', 'pages-in-widgets' ); ?></span>
  25.         <select class="large-text" style="width:100%;" id="<?php echo $this->get_field_id('pageID'); ?>" name="<?php echo $this->get_field_name('pageID'); ?>">
  26. @@ -78,6 +82,12 @@
  27.         <label for="<?php echo $this->get_field_id('titleEnable'); ?>-yes"><?php _e( 'Yes:', 'pages-in-widgets' ); ?> <input type="radio" value="true" name="<?php echo $this->get_field_name('titleEnable'); ?>" id="<?php echo $this->get_field_id('titleEnable'); ?>-yes" <?php if($currentInstance['titleEnable'] == 'true'){echo 'checked="checked"';} ?>/></label>
  28.         <label for="<?php echo $this->get_field_id('titleEnable'); ?>-no"><?php _e( 'No:', 'pages-in-widgets' ); ?> <input type="radio" value="false" name="<?php echo $this->get_field_name('titleEnable'); ?>" id="<?php echo $this->get_field_id('titleEnable'); ?>-no" <?php if($currentInstance['titleEnable'] == 'false'){echo 'checked="checked"';} ?>/></label></p>
  29.  
  30. +       <p>
  31. +           <label for="<?php echo $this->get_field_id('titleCustom'); ?>"><?php esc_html_e( 'Custom Title:', 'pages-in-widgets' ); ?></label><br/>
  32. +           <input class="large-text" id="<?php echo $this->get_field_id('titleCustom'); ?>" name="<?php echo $this->get_field_name('titleCustom'); ?>" value="<?php echo esc_html($currentInstance['titleCustom']); ?>">
  33. +           <em><?php esc_html_e('Leave blank for default title.', 'pages-in-widgets'); ?></em>
  34. +       </p>
  35. +      
  36.         <p> <label for="<?php echo $this->get_field_id('titletype'); ?>"><?php _e( 'Title Type:', 'pages-in-widgets' ); ?></label><br/>
  37.         <select class="large-text" id="<?php echo $this->get_field_id('titletype'); ?>" name="<?php echo $this->get_field_name('titletype'); ?>">
  38.             <option value="h1" <?php if($currentInstance['titletype'] == 'h1'){echo 'selected';}?>>H1</option>
  39. @@ -153,6 +163,7 @@
  40.        
  41.         $instance['pageID'] = $new_instance['pageID'];
  42.         $instance['titleEnable'] = $new_instance['titleEnable'];
  43. +       $instance['titleCustom'] = sanitize_text_field($new_instance['titleCustom']);
  44.         $instance['customCssClass'] = $new_instance['customCssClass'];
  45.         $instance['outputtype'] = $new_instance['outputtype'];
  46.         $instance['outputcontent'] = $new_instance['outputcontent'];
  47. @@ -196,7 +207,8 @@
  48.                 echo apply_filters('pagesinwidgets_image',get_the_post_thumbnail($pageID,$imageSize));
  49.             }
  50.             if($titleEnable == 'true'){
  51. -               echo '<'.$titletype . ' class="widget-title widgettitle">' . get_the_title() .'</'.$titletype.'>';
  52. +               $title = !empty($instance['titleCustom']) ? esc_html($instance['titleCustom']) : get_the_title();
  53. +               echo '<'.$titletype . ' class="widget-title widgettitle">' . $title .'</'.$titletype.'>';
  54.             }
  55.             ?>
  56.             <div class="<?php echo (($customCssClass)?$customCssClass:'homepage_section'); ?>">
  57. Index: widgets/posts-widget.php
  58. IDEA additional info:
  59. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  60. <+>UTF-8
  61. ===================================================================
  62. --- widgets/posts-widget.php    (revision 2285717)
  63. +++ widgets/posts-widget.php    (date 1587213569874)
  64. @@ -10,7 +10,7 @@
  65.  }
  66.  
  67.  class pagesinwidgets_post_section extends WP_Widget {
  68. -
  69. +  
  70.     function __construct(){
  71.         parent::__construct(
  72.         'pagesinwidgets_post_section',
  73. @@ -37,6 +37,9 @@
  74.         if(isset($currentInstance['titleEnable']) == false){
  75.             $currentInstance['titleEnable'] = 'true';
  76.         }
  77. +       if(isset($currentInstance['titleCustom']) == false){
  78. +           $currentInstance['titleCustom'] = '';
  79. +       }
  80.         if(isset($currentInstance['customCssClass']) == false){
  81.             $currentInstance['customCssClass'] = '';
  82.         }
  83. @@ -56,8 +59,9 @@
  84.             $currentInstance['titletype'] = "h2";
  85.         }
  86.         ?>
  87. +       <input type="hidden" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" />
  88.         <p style="font-style: italic;"><small><?php _e( 'Select the post here and then edit the post under the posts tab on the left.', 'pages-in-widgets' ); ?></small></p>
  89. -       <p><label for="<?php echo $this->get_field_id('postID'); ?>"><span style="float:left; width:100%;"><?php _e( 'post:', 'pages-in-widgets' ); ?></span>
  90. +       <p><label for="<?php echo $this->get_field_id('postID'); ?>"><span style="float:left; width:100%;"><?php _e( 'Post:', 'pages-in-widgets' ); ?></span><br>
  91.         <select class="large-text" style="width:100%;" id="<?php echo $this->get_field_id('postID'); ?>" name="<?php echo $this->get_field_name('postID'); ?>">
  92.             <?php
  93.                 $args = array( 'post_type' => 'post', 'post_status' => array('publish', 'private'), 'posts_per_post' => -1 );
  94. @@ -78,6 +82,12 @@
  95.         <label for="<?php echo $this->get_field_id('titleEnable'); ?>-yes"><?php _e( 'Yes:', 'pages-in-widgets' ); ?> <input type="radio" value="true" name="<?php echo $this->get_field_name('titleEnable'); ?>" id="<?php echo $this->get_field_id('titleEnable'); ?>-yes" <?php if($currentInstance['titleEnable'] == 'true'){echo 'checked="checked"';} ?>/></label>
  96.         <label for="<?php echo $this->get_field_id('titleEnable'); ?>-no"><?php _e( 'No:', 'pages-in-widgets' ); ?> <input type="radio" value="false" name="<?php echo $this->get_field_name('titleEnable'); ?>" id="<?php echo $this->get_field_id('titleEnable'); ?>-no" <?php if($currentInstance['titleEnable'] == 'false'){echo 'checked="checked"';} ?>/></label></p>
  97.  
  98. +       <p>
  99. +           <label for="<?php echo $this->get_field_id('titleCustom'); ?>"><?php esc_html_e( 'Custom Title:', 'pages-in-widgets' ); ?></label><br/>
  100. +           <input class="large-text" id="<?php echo $this->get_field_id('titleCustom'); ?>" name="<?php echo $this->get_field_name('titleCustom'); ?>" value="<?php echo esc_html($currentInstance['titleCustom']); ?>">
  101. +           <em><?php esc_html_e('Leave blank for default title.', 'pages-in-widgets'); ?></em>
  102. +       </p>
  103. +
  104.         <p> <label for="<?php echo $this->get_field_id('titletype'); ?>"><?php _e( 'Title Type:', 'pages-in-widgets' ); ?></label><br/>
  105.         <select class="large-text" id="<?php echo $this->get_field_id('titletype'); ?>" name="<?php echo $this->get_field_name('titletype'); ?>">
  106.             <option value="h1" <?php if($currentInstance['titletype'] == 'h1'){echo 'selected';}?>>H1</option>
  107. @@ -153,6 +163,7 @@
  108.        
  109.         $instance['postID'] = $new_instance['postID'];
  110.         $instance['titleEnable'] = $new_instance['titleEnable'];
  111. +       $instance['titleCustom'] = sanitize_text_field($new_instance['titleCustom']);
  112.         $instance['customCssClass'] = $new_instance['customCssClass'];
  113.         $instance['outputtype'] = $new_instance['outputtype'];
  114.         $instance['outputcontent'] = $new_instance['outputcontent'];
  115. @@ -198,7 +209,8 @@
  116.                 echo apply_filters('postsinwidgets_image',get_the_post_thumbnail($postID,$imageSize));
  117.             }
  118.             if($titleEnable == 'true'){
  119. -               echo '<'.$titletype . ' class="widget-title widgettitle">' . get_the_title() .'</'.$titletype.'>';
  120. +               $title = !empty($instance['titleCustom']) ? esc_html($instance['titleCustom']) : get_the_title();
  121. +               echo '<'.$titletype . ' class="widget-title widgettitle">' . $title .'</'.$titletype.'>';
  122.             } ?>
  123.             <div class="<?php echo (($customCssClass)?$customCssClass:'homepost_section'); ?>">
  124.                 <?php
Advertisement
Add Comment
Please, Sign In to add comment