Plugin Directory

Changeset 1870537


Ignore:
Timestamp:
05/08/2018 07:42:49 AM (8 years ago)
Author:
softmixt
Message:
  • Code structure clean.
  • New you can select from related post also his taxonomies as category , tags etc.
Location:
softmixt-relations
Files:
3 added
2 deleted
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • softmixt-relations/trunk/README.txt

    r1728223 r1870537  
    6464        $item_show_content       = $atts[ 'item_show_content' ];
    6565
     66        // Post related taxonomies container element (set on short code)
     67        $item_terms_container       = $atts['item_terms_container'];
     68
     69        // Post related taxonomies container class element (set on short code).
     70        $item_terms_container_class = $atts['item_terms_container_class'];
     71
     72        // Post related taxonomy term item container element (set on short code)
     73        $item_term_container        = $atts['item_term_container'];
     74
     75        // Post related taxonomy term item container class element (set on short code).
     76        $item_term_container_class  = $atts['item_term_container_class'];
     77
    6678        // you can overwrite  post related item view here ...
    6779
     
    8294== Frequently Asked Questions ==
    8395
    84 =  Can i overwrite related items public view ? =
     96=  Can I overwrite related items public view ? =
    8597
    8698Yes, you can overwrite you related items public view by using  'SFT_related_item_content' filter , check Description section.
    8799
    88 = Can i show  one related posts to other post ? =
     100= Can I show  one related posts to other post ? =
    89101
    90102Yes, you can show other post relations by adding an optional "post_id" attribute to your shortcode.
    91103
    92 =Can i easily sort my relations =
     104=Can I easily sort my relations =
    93105
    94106Yes, you can sort your posts related connection by dragging items on "Post Related" section.
     107
     108=Can I select related post taxonomies as categories, terms ? =
     109
     110Yes, you can toggle related post and select taxonomies you want to have in front.
    95111
    96112== Screenshots ==
     
    121137
    122138== Suggestions ==
    123 If someone has a idea or suggestion of a new plugin feature I'm glad to hear it and probably will be implemented in the new versions.
     139If someone has an a idea or suggestion of a new plugin feature I'm glad to hear it and probably will be implemented in the new versions.
  • softmixt-relations/trunk/admin/admin.php

    r1689232 r1870537  
    11<?php
    22// If this file is called directly, abort.
    3 if ( ! defined ( 'WPINC' ) )
     3if ( ! defined( 'WPINC' ) )
    44{
    55    die;
     
    1111 * All plugin  admin logic goes in this file.
    1212 **----------------------------------------------------------------------------**/
    13 if ( ! class_exists ( 'SFT_Relations_Admin' ) )
     13if ( ! class_exists( 'SFT_Relations_Admin' ) )
    1414{
    15     class SFT_Relations_Admin
    16     {
     15    class SFT_Relations_Admin {
    1716
    1817        /**
    1918         * SFT_Relations_Admin constructor.
    2019         */
    21         public function __construct ()
    22         {
     20        public function __construct() {
    2321
    2422            /**
    2523             * Register admin side scripts...
    2624             */
    27             add_action (
    28                 'admin_enqueue_scripts' ,
    29                 array ( $this , '_admin_enqueue_scripts' )
    30             );
     25            add_action( 'admin_enqueue_scripts' , array ( $this , '_admin_enqueue_scripts' ) );
    3126
    3227            /**
    3328             * Register "Post Relations" metabox
    3429             */
    35             add_action (
    36                 'add_meta_boxes' ,
    37                 array ( $this , '_register_metabox' )
    38             );
     30            add_action( 'add_meta_boxes' , array ( $this , '_register_metabox' ) );
    3931
    4032            /**
    4133             * Save post hook
    4234             */
    43             add_action (
    44                 'save_post' ,
    45                 array ( $this , '_save_post' ) ,
    46                 10 ,
    47                 3
    48             );
     35            add_action( 'save_post' , array ( $this , '_save_post' ) , 10 , 3 );
    4936
    5037            /**
    5138             * Register tinymce button
    5239             */
    53             add_action ( 'init' , array ( $this , '_set_tinyMCE_setting' ) );
     40            add_action( 'init' , array ( $this , '_set_tinyMCE_setting' ) );
    5441
    5542        }
     
    6047         * @param $hook
    6148         */
    62         public function _admin_enqueue_scripts ( $hook )
    63         {
     49        public function _admin_enqueue_scripts( $hook ) {
    6450            // Add scripts only in edit and new post
    6551            if ( $hook == 'post-new.php' || $hook == 'post.php' )
    6652            {
    6753                // Styles ...
    68                 wp_enqueue_style ( "softmixt-relations-admin" , plugin_dir_url ( __FILE__ ) . 'assets/css/plugin-admin.css' , array () , '1.0.0' , 'all' );
     54                wp_enqueue_style( "softmixt-relations-admin" , plugin_dir_url( __FILE__ ) . 'assets/css/plugin-admin.css' , array () , '1.0.0' , 'all' );
    6955
    7056                // Scripts ..
    71                 wp_enqueue_script ( "softmixt-relations-admin-js" , plugin_dir_url ( __FILE__ ) . 'assets/js/plugin-admin.min.js' , array ( 'jquery' ) , '1.0.0' , FALSE );
     57                wp_enqueue_script( "softmixt-relations-admin-js" , plugin_dir_url( __FILE__ ) . 'assets/js/plugin-admin.js' , array ( 'jquery' ) , '1.0.0' , FALSE );
    7258
    7359            }
     
    7763         * Register Post Relations metabox
    7864         */
    79         public function _register_metabox ()
    80         {
     65        public function _register_metabox() {
    8166
    8267            // Get global plugin settings
    83             add_meta_box (
    84                 'softmixt-relations-mb-id' ,
    85                 esc_html__ ( 'Post Relations' , SFT_REL_TEXT_DOMAIN ) ,
    86                 array ( $this , '_render_metabox' ) ,
    87                 // Get all post types because we want to have this relation metabox in all
    88                 sft_get_all_post_types () ,
    89                 'advanced' ,
    90                 'core'
    91             );
     68            add_meta_box( 'softmixt-relations-mb-id' , esc_html__( 'Post Relations' , SFT_REL_TEXT_DOMAIN ) , array ( $this , '_render_metabox' ) , sft_get_all_post_types() , 'advanced' , 'core' );
    9269        }
    9370
     
    9774         * @param $post
    9875         */
    99         public function _render_metabox ( $post )
    100         {
     76        public function _render_metabox( $post ) {
    10177            // Add nonce for security and authentication.
    102             wp_nonce_field ( 'custom_nonce_action' , 'custom_nonce' );
    103             $connected_relations = get_post_meta ( $post->ID , 'sftp_relations' , TRUE );
     78            wp_nonce_field( 'custom_nonce_action' , 'custom_nonce' );
     79            $connected_relations            = get_post_meta( $post->ID , 'sftp_relations' , TRUE );
     80            $connected_relations_taxonomies = get_post_meta( $post->ID , 'sftp_relations_taxonomies' , TRUE );
     81
    10482            include_once 'views/softmixt-relations-mb-view.php';
    10583        }
     
    11290         * @param $update
    11391         */
    114         public function _save_post ( $post_id , $post , $update )
    115         {
     92        public function _save_post( $post_id , $post , $update ) {
    11693            // Add nonce for security and authentication.
    11794            $nonce_name   = isset( $_POST[ 'custom_nonce' ] ) ? $_POST[ 'custom_nonce' ] : '';
     
    125102
    126103            // Check if nonce is valid.
    127             if ( ! wp_verify_nonce ( $nonce_name , $nonce_action ) )
     104            if ( ! wp_verify_nonce( $nonce_name , $nonce_action ) )
    128105            {
    129106                return;
     
    131108
    132109            // Check if user has permissions to save data.
    133             if ( ! current_user_can ( 'edit_post' , $post_id ) )
     110            if ( ! current_user_can( 'edit_post' , $post_id ) )
    134111            {
    135112                return;
     
    137114
    138115            // check if there was a multisite switch before
    139             if ( is_multisite () && ms_is_switched () )
     116            if ( is_multisite() && ms_is_switched() )
    140117            {
    141118                return $post_id;
     
    143120
    144121            // Check if not an autosave.
    145             if ( wp_is_post_autosave ( $post_id ) )
     122            if ( wp_is_post_autosave( $post_id ) )
    146123            {
    147124                return;
     
    149126
    150127            // Check if not a revision.
    151             if ( wp_is_post_revision ( $post_id ) )
     128            if ( wp_is_post_revision( $post_id ) )
    152129            {
    153130                return;
     
    156133            if ( isset( $_POST[ 'connected_post' ] ) )
    157134            {
    158                 update_post_meta ( $post_id , 'sftp_relations' , $_POST[ 'connected_post' ] );
     135                update_post_meta( $post_id , 'sftp_relations' , $_POST[ 'connected_post' ] );
     136            } else
     137            {
     138                delete_post_meta( $post_id , 'sftp_relations' );
    159139            }
    160             else
     140
     141            if ( isset( $_POST[ 'connected_post_taxonomies' ] ) )
    161142            {
    162                 delete_post_meta ( $post_id , 'sftp_relations' );
     143                update_post_meta( $post_id , 'sftp_relations_taxonomies' , $_POST[ 'connected_post_taxonomies' ] );
     144            } else
     145            {
     146                delete_post_meta( $post_id , 'sftp_relations_taxonomies' );
    163147            }
    164148
     
    168152         * Register tinymce button and plugin
    169153         */
    170         public function _set_tinyMCE_setting ()
    171         {
    172             add_filter ( 'mce_external_plugins' , array ( $this , '_add_tinyMCE_plugin' ) );
    173             add_filter ( 'mce_buttons' , array ( $this , '_add_tinyMCE_button' ) );
     154        public function _set_tinyMCE_setting() {
     155            add_filter( 'mce_external_plugins' , array ( $this , '_add_tinyMCE_plugin' ) );
     156            add_filter( 'mce_buttons' , array ( $this , '_add_tinyMCE_button' ) );
    174157        }
    175158
    176159
    177         public function _add_tinyMCE_plugin ()
    178         {
    179             $plugin_array[ 'sftrelations' ] = plugin_dir_url ( __FILE__ ) . '/assets/tinymce/plugins/sftrelations/plugin.min.js';
     160        public function _add_tinyMCE_plugin() {
     161            $plugin_array[ 'sftrelations' ] = plugin_dir_url( __FILE__ ) . '/assets/tinymce/plugins/sftrelations/plugin.min.js';
    180162
    181163            return $plugin_array;
    182164        }
    183165
    184         public function _add_tinyMCE_button ( $buttons )
    185         {
    186             array_push ( $buttons , 'sftrelations' );
     166        public function _add_tinyMCE_button( $buttons ) {
     167            array_push( $buttons , 'sftrelations' );
    187168
    188169            return $buttons;
    189170        }
    190 
    191171
    192172    }
  • softmixt-relations/trunk/admin/assets/css/plugin-admin.css

    r1689232 r1870537  
    44    margin: 1%;
    55    width: 47%;
     6}
     7
     8.sft-update-your-post {
     9    display: none;
     10    color: green !important;
     11    padding: 10px;
     12    border-left: 4px solid #ffb900;
     13    box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .1);
     14    margin: 5px 15px 2px;
    615}
    716
     
    3039    height: 220px;
    3140    list-style: outside none none;
    32     overflow-y: scroll;
     41    overflow-y: auto;
     42    border: 1px solid #e5e5e5;
    3343}
    3444
     
    3747    color: black;
    3848    padding: 5px;
    39     margin-right: 25px;
     49    margin: 10px;
    4050    background-color: #f7f7f7;
    4151}
    4252
    43 .sft-rel-connected {
     53.sft-rel-connected, .sft-rel-connected-item {
    4454    cursor: move;
     55}
     56
     57.sft-rel-connected-item {
     58    border: 1px solid #e5e5e5;
     59    color: black;
     60    margin: 10px;
     61    background-color: #f7f7f7;
     62}
     63
     64.sft-rel-section-item-head {
     65    padding: 5px;
     66}
     67
     68.sft-rel-section-item {
     69    padding: 5px;
     70    border-top: 1px solid #e5e5e5;
     71    display: none;
     72}
     73
     74.sft-rel-connected-no-connections {
     75    position: relative;
     76    float: left;
     77    top: 50%;
     78    left: 50%;
     79    transform: translate(-50%, -50%);
     80    color: #c6c5c5;
     81    font-weight: bold;
     82}
     83
     84.sft-rel-post-no-taxonomies {
     85    color: #c6c5c5;
     86    font-weight: bold;
     87    text-align: center;
     88}
     89
     90.sft-rel-toggle-connected-item {
     91    float: right;
     92    display: block;
     93    width: 25px;
     94    cursor: pointer;
    4595}
    4696
  • softmixt-relations/trunk/admin/assets/js/plugin-admin.js

    r1727679 r1870537  
    1 (function ( $ )
    2 {
    3     'use strict';
    4 
    5     $ ( function ()
    6         {
    7             init_sortable ();
    8         } );
    9 
    10     /**
    11      * Insert connection
    12      */
    13     $ ( document ).on ( 'click' , '.js-add-connection' , function ()
    14     {
    15 
    16         // Get parent li
    17         var li_parent = $ ( this ).parent ();
    18 
    19         // Remove All Posts related attributes
    20         $ ( this ).removeClass ( 'js-add-connection dashicons-plus' );
    21         li_parent.removeClass ( 'sft-rel-not-connected js-relations-itm' );
    22 
    23         // Add Posts related related attributes
    24         $ ( this ).addClass ( 'dashicons-trash js-remove-connection sft-rel-remove-connection' );
    25         li_parent.addClass ( 'js-connected-itm sft-rel-connected' );
    26         li_parent.find ( 'input[type="hidden"]' ).attr ( 'name' , 'connected_post[]' );
    27 
    28         // Add li connection to Post Related
    29         $ ( '.js-connected-posts' ).append ( li_parent );
    30 
    31     } );
    32 
    33     /**
    34      * Remove connection
    35      */
    36     $ ( document ).on ( 'click' , '.js-remove-connection' , function ()
    37     {
    38 
    39         // Get parent li
    40         var li_parent = $ ( this ).parent ();
    41 
    42         // Add Posts related related attributes
    43         $ ( this ).removeClass ( 'dashicons-trash js-remove-connection sft-rel-remove-connection' );
    44         li_parent.removeClass ( 'js-connected-itm sft-rel-connected' );
    45         li_parent.find ( 'input[type="hidden"]' ).removeAttr ( 'name' );
    46 
    47         // Remove All Posts related attributes
    48         $ ( this ).addClass ( 'js-add-connection dashicons-plus' );
    49         li_parent.addClass ( 'sft-rel-not-connected js-relations-itm' );
    50 
    51         // Add li connection to Post Related
    52         $ ( '.js-posts-to-connect' ).append ( li_parent );
    53 
    54     } );
    55 
    56     /**
    57      * Filter by Post type
    58      */
    59     $ ( document ).on ( 'change' , '.js-select-post-type' , function ()
    60     {
    61         filter_by_post_type ( this , '.js-relations-itm' , '.js-posts-to-connect' , '.js-search-posts' );
    62     } );
    63 
    64     /**
    65      * Filter by Post Name
    66      */
    67     $ ( document ).on ( 'keyup paste' , '.js-search-posts' , function ()
    68     {
    69         filter_by_post_name ( this , '.js-select-post-type' , '.js-posts-to-connect' , '.js-relations-itm' )
    70     } );
    71 
    72     /**
    73      * Filter by Post Type
    74      */
    75     $ ( document ).on ( 'change' , '.js-select-related-post-type' , function ()
    76     {
    77         filter_by_post_type ( this , '.js-connected-itm' , '.js-connected-posts' , '.js-search-connected-posts' );
    78     } );
    79 
    80     /**
    81      * Filter by Post Name
    82      */
    83     $ ( document ).on ( 'keyup paste' , '.js-search-connected-posts' , function ()
    84     {
    85         filter_by_post_name ( this , '.js-select-related-post-type' , '.js-connected-posts' , '.js-connected-itm' )
    86     } );
    87 
    88     /**
    89      * Initialize Post Related Sortable
    90      */
    91     function init_sortable ()
    92     {
    93         // Enable jquery ui sortable  , now we are able to sort the add-ons.
    94         $ ( ".js-connected-posts" ).sortable ( { revert : true } );
    95     }
    96 
    97     /**
    98      * Filter by post type
    99      * @param $this
    100      * @param posts_items_class
    101      * @param post_to_connect
    102      * @param post_name
    103      */
    104     function filter_by_post_type ( $this , posts_items_class , post_to_connect , post_name )
    105     {
    106         var post_type   = $ ( $this ).val ();
    107         var posts_items = $ ( posts_items_class );
    108         var post_name   = $ ( post_name ).val ();
    109 
    110         if ( post_type === 'all' )
    111         {
    112             if ( post_name )
    113             {
    114                 posts_items.each ( function ()
    115                                    {
    116                                        var data_post_title = $ ( this ).attr ( 'data-post-title' );
    117                                        var check_regex     = new RegExp ( post_name.toLowerCase () );
    118                                        if ( check_regex.test ( data_post_title.toLowerCase () ) )
    119                                        {
    120                                            $ ( this ).show ();
    121                                        }
    122                                        else
    123                                        {
    124                                            $ ( this ).hide ();
    125                                        }
    126                                    } );
    127             }
    128             else
    129             {
    130                 posts_items.show ();
    131             }
    132         }
    133         else
    134         {
    135             posts_items.hide ();
    136 
    137             if ( post_name )
    138             {
    139                 posts_items.each ( function ()
    140                                    {
    141                                        var data_post_type  = $ ( this ).attr ( 'data-post-type' );
    142                                        var data_post_title = $ ( this ).attr ( 'data-post-title' );
    143 
    144                                        var check_regex = new RegExp ( post_name.toLowerCase () );
    145                                        if ( check_regex.test ( data_post_title.toLowerCase () ) && data_post_type === post_type )
    146                                        {
    147                                            $ ( this ).show ();
    148                                        }
    149                                        else
    150                                        {
    151                                            $ ( this ).hide ();
    152                                        }
    153                                    } );
    154 
    155             }
    156             else
    157             {
    158                 $ ( post_to_connect + ' > [data-post-type="' + post_type + '"] ' ).show ();
    159             }
    160 
    161         }
    162     }
    163 
    164     /**
    165      * Filter by post name
    166      * @param $this
    167      * @param post_type_class
    168      * @param posts_to_connect
    169      * @param post_items
    170      */
    171     function filter_by_post_name ( $this , post_type_class , posts_to_connect , post_items )
    172     {
    173         var post_type   = $ ( post_type_class ).val ();
    174         var post_name   = $ ( $this ).val ();
    175         var posts_items = $ ( post_items );
    176 
    177         if ( post_type === 'all' )
    178         {
    179             posts_items.show ();
    180             posts_items.each ( function ()
    181                                {
    182                                    var data_post_title = $ ( this ).attr ( 'data-post-title' );
    183                                    var check_regex     = new RegExp ( post_name.toLowerCase () );
    184 
    185                                    if ( check_regex.test ( data_post_title.toLowerCase () ) )
    186                                    {
    187                                        $ ( this ).show ();
    188                                    }
    189                                    else
    190                                    {
    191                                        $ ( this ).hide ();
    192                                    }
    193                                } );
    194         }
    195         else
    196         {
    197             posts_items.hide ();
    198             $ ( posts_to_connect + ' > [data-post-type="' + post_type + '"] ' ).show ();
    199             posts_items.each ( function ()
    200                                {
    201                                    var data_post_title = $ ( this ).attr ( 'data-post-title' );
    202                                    var check_regex     = new RegExp ( post_name.toLowerCase () );
    203                                    if ( check_regex.test ( data_post_title.toLowerCase () ) )
    204                                    {
    205                                        if ( $ ( this ).attr ( 'data-post-type' ) === post_type )
    206                                        {
    207                                            $ ( this ).show ();
    208                                        }
    209                                        else
    210                                        {
    211                                            $ ( this ).hide ();
    212                                        }
    213                                    }
    214                                    else
    215                                    {
    216                                        $ ( this ).hide ();
    217                                    }
    218                                } );
    219         }
    220     }
     1(function ($) {
     2    'use strict';
     3
     4    $(function () {
     5        init_sortable();
     6    });
     7
     8    /**
     9     * Insert connection
     10     */
     11    $(document).on('click', '.js-add-connection', function () {
     12
     13        // Get parent li
     14
     15        var post_id = $(this).data('post-id');
     16        var post_title = $(this).data('post-title');
     17        var post_type = $(this).data('post-type');
     18
     19        var parent = $('.js-relations-itm[data-post-id="' + post_id + '"]');
     20        var item_container = parent.find('.js-posts-to-connect-tax-data');
     21
     22        var master_li = $('<li>');
     23        master_li.attr('data-post-title', post_title);
     24        master_li.attr('data-post-type', post_type);
     25        master_li.attr('data-post-id', post_id);
     26        master_li.addClass('js-connected-itm');
     27        master_li.addClass('sft-rel-connected-item');
     28
     29        // div1
     30        var div_1 = $('<div>').addClass("sft-rel-section-item-head");
     31
     32        var div_1_span_1 = $("<span>");
     33        div_1_span_1.attr('data-post-id', post_id);
     34        div_1_span_1.addClass('dashicons');
     35        div_1_span_1.addClass('dashicons-trash');
     36        div_1_span_1.addClass('js-remove-connection');
     37        div_1_span_1.addClass('sft-rel-remove-connection');
     38
     39        var div_1_span_2 = $("<span>").text(post_title);
     40
     41        var div_1_span_3 = $("<span>");
     42        div_1_span_3.attr('data-post-id', post_id);
     43        div_1_span_3.addClass('dashicons');
     44        div_1_span_3.addClass('dashicons-arrow-down');
     45        div_1_span_3.addClass('sft-rel-toggle-connected-item');
     46        div_1_span_3.addClass('js-toggle-connected-item');
     47
     48        div_1.append(div_1_span_1).append(div_1_span_2).append(div_1_span_3);
     49
     50        // div1
     51        var div_2 = $('<div>').hide();
     52        div_2.addClass("sft-rel-section-item");
     53        div_2.addClass("js-section-item");
     54
     55        var ul_el = $('<ul>').addClass('categorychecklist');
     56        ul_el.addClass('form-no-clear');
     57
     58        div_2.append(ul_el);
     59
     60        //  hidden input
     61        var hidden_input = $('<input>').val(post_id);
     62        hidden_input.attr('type', 'hidden');
     63        hidden_input.attr('name', "connected_post[]");
     64
     65        master_li.append(div_1).append(div_2).append(hidden_input);
     66
     67        console.log(item_container.length);
     68
     69        if (item_container.length) {
     70            item_container.each(function (index, val) {
     71                var tax_name = $(this).data('taxonomy-name');
     72                var tax_label = $(this).val();
     73
     74                var inpt = $('<input>').val(1);
     75                inpt.attr('type', 'checkbox');
     76                inpt.attr('id', 'in-taxonomy-' + tax_name);
     77                inpt.attr('name', 'connected_post_taxonomies[' + post_id + '][' + tax_name + ']');
     78                inpt.val(tax_name);
     79
     80                var lbl = $('<label>').addClass('selectit').text(tax_label).prepend(inpt);
     81                var li_element = $('<li>').append(lbl);
     82
     83                li_element.attr('id', 'sft-rel-taxonomy-' + tax_name);
     84                li_element.addClass('popular-category');
     85
     86                ul_el.append(li_element);
     87            });
     88        }
     89        else {
     90            var li_no_tax = $('<li>').text($('.js-text-references').data('no-taxonomies')).addClass('sft-rel-post-no-taxonomies');
     91            ul_el.append(li_no_tax);
     92        }
     93
     94        // Add li connection to Post Related
     95        $('.js-connected-posts').append(master_li);
     96        parent.hide();
     97        show_update_alert();
     98
     99        $('.js-connected-no-connections').hide();
     100
     101    });
     102
     103    $(document).on('change', '.js-connected-post-taxonomies-checkbox', function () {
     104        show_update_alert();
     105    });
     106
     107    /**
     108     * Remove connection
     109     */
     110    $(document).on('click', '.js-toggle-connected-item', function () {
     111
     112        var _this_ = this;
     113        var post_id = $(this).data('post-id');
     114        $('[data-post-id="' + post_id + '"]').find('.js-section-item').slideToggle("fast", function () {
     115
     116            if ($(_this_).hasClass('dashicons-arrow-down')) {
     117                $(_this_).removeClass('dashicons-arrow-down').addClass('dashicons-arrow-up');
     118            }
     119            else {
     120                $(_this_).removeClass('dashicons-arrow-up').addClass('dashicons-arrow-down');
     121            }
     122        });
     123    });
     124
     125    /**
     126     * Remove connection
     127     */
     128    $(document).on('click', '.js-remove-connection', function () {
     129
     130        if (confirm($('.js-text-references').data('remove-taxonomy'))) {
     131            var post_id = $(this).data('post-id');
     132            $('.js-connected-itm[data-post-id="' + post_id + '"]').remove();
     133            $('.sft-rel-not-connected[data-post-id="' + post_id + '"]').show();
     134            if ($('.js-connected-itm').length === 0) {
     135                $('.js-connected-no-connections').show();
     136            }
     137            show_update_alert();
     138        }
     139    });
     140
     141    /**
     142     * Filter by Post type
     143     */
     144    $(document).on('change', '.js-select-post-type', function () {
     145        filter_by_post_type(this, '.js-relations-itm', '.js-posts-to-connect', '.js-search-posts');
     146    });
     147
     148    /**
     149     * Filter by Post Name
     150     */
     151    $(document).on('keyup paste', '.js-search-posts', function () {
     152        filter_by_post_name(this, '.js-select-post-type', '.js-posts-to-connect', '.js-relations-itm')
     153    });
     154
     155    /**
     156     * Filter by Post Type
     157     */
     158    $(document).on('change', '.js-select-related-post-type', function () {
     159        filter_by_post_type(this, '.js-connected-itm', '.js-connected-posts', '.js-search-connected-posts');
     160    });
     161
     162    /**
     163     * Filter by Post Name
     164     */
     165    $(document).on('keyup paste', '.js-search-connected-posts', function () {
     166        filter_by_post_name(this, '.js-select-related-post-type', '.js-connected-posts', '.js-connected-itm')
     167    });
     168
     169    /**
     170     * Initialize Post Related Sortable
     171     */
     172    function init_sortable() {
     173        // Enable jquery ui sortable  , now we are able to sort the add-ons.
     174        $(".js-connected-posts").sortable(
     175            {
     176                handle: '.sft-rel-section-item-head',
     177                revert: true,
     178                update: function (ev, ui) {
     179                    show_update_alert();
     180                }
     181            }
     182        );
     183    }
     184
     185    /**
     186     * Filter by post type
     187     * @param $this
     188     * @param posts_items_class
     189     * @param post_to_connect
     190     * @param post_name
     191     */
     192    function filter_by_post_type($this, posts_items_class, post_to_connect, post_name) {
     193        var post_type = $($this).val();
     194        var posts_items = $(posts_items_class);
     195        var post_name = $(post_name).val();
     196
     197        if (post_type === 'all') {
     198            if (post_name) {
     199                posts_items.each(function () {
     200                    var data_post_title = $(this).attr('data-post-title');
     201                    var check_regex = new RegExp(post_name.toLowerCase());
     202                    if (check_regex.test(data_post_title.toLowerCase())) {
     203                        $(this).show();
     204                    }
     205                    else {
     206                        $(this).hide();
     207                    }
     208                });
     209            }
     210            else {
     211                posts_items.show();
     212            }
     213        }
     214        else {
     215            posts_items.hide();
     216
     217            if (post_name) {
     218                posts_items.each(function () {
     219                    var data_post_type = $(this).attr('data-post-type');
     220                    var data_post_title = $(this).attr('data-post-title');
     221
     222                    var check_regex = new RegExp(post_name.toLowerCase());
     223                    if (check_regex.test(data_post_title.toLowerCase()) && data_post_type === post_type) {
     224                        $(this).show();
     225                    }
     226                    else {
     227                        $(this).hide();
     228                    }
     229                });
     230
     231            }
     232            else {
     233                $(post_to_connect + ' > [data-post-type="' + post_type + '"] ').show();
     234            }
     235
     236        }
     237    }
     238
     239    /**
     240     * Filter by post name
     241     * @param $this
     242     * @param post_type_class
     243     * @param posts_to_connect
     244     * @param post_items
     245     */
     246    function filter_by_post_name($this, post_type_class, posts_to_connect, post_items) {
     247        var post_type = $(post_type_class).val();
     248        var post_name = $($this).val();
     249        var posts_items = $(post_items);
     250
     251        if (post_type === 'all') {
     252            posts_items.show();
     253            posts_items.each(function () {
     254                var data_post_title = $(this).attr('data-post-title');
     255                var check_regex = new RegExp(post_name.toLowerCase());
     256
     257                if (check_regex.test(data_post_title.toLowerCase())) {
     258                    $(this).show();
     259                }
     260                else {
     261                    $(this).hide();
     262                }
     263            });
     264        }
     265        else {
     266            posts_items.hide();
     267            $(posts_to_connect + ' > [data-post-type="' + post_type + '"] ').show();
     268            posts_items.each(function () {
     269                var data_post_title = $(this).attr('data-post-title');
     270                var check_regex = new RegExp(post_name.toLowerCase());
     271                if (check_regex.test(data_post_title.toLowerCase())) {
     272                    if ($(this).attr('data-post-type') === post_type) {
     273                        $(this).show();
     274                    }
     275                    else {
     276                        $(this).hide();
     277                    }
     278                }
     279                else {
     280                    $(this).hide();
     281                }
     282            });
     283        }
     284    }
     285
     286    /**
     287     * Show Update Alert
     288     */
     289    function show_update_alert() {
     290        $('.js-update-your-post').show();
     291    }
    221292
    222293})
    223 ( jQuery );
     294(jQuery);
  • softmixt-relations/trunk/admin/assets/js/plugin-admin.min.js

    r1689232 r1870537  
    1 (function(b){b(function(){d()});b(document).on("click",".js-add-connection",function(){var e=b(this).parent();b(this).removeClass("js-add-connection dashicons-plus");e.removeClass("sft-rel-not-connected js-relations-itm");b(this).addClass("dashicons-trash js-remove-connection sft-rel-remove-connection");e.addClass("js-connected-itm sft-rel-connected");e.find('input[type="hidden"]').attr("name","connected_post[]");b(".js-connected-posts").append(e)});b(document).on("click",".js-remove-connection",function(){var e=b(this).parent();b(this).removeClass("dashicons-trash js-remove-connection sft-rel-remove-connection");e.removeClass("js-connected-itm sft-rel-connected");e.find('input[type="hidden"]').removeAttr("name");b(this).addClass("js-add-connection dashicons-plus");e.addClass("sft-rel-not-connected js-relations-itm");b(".js-posts-to-connect").append(e)});b(document).on("change",".js-select-post-type",function(){c(this,".js-relations-itm",".js-posts-to-connect",".js-search-posts")});b(document).on("keyup paste",".js-search-posts",function(){a(this,".js-select-post-type",".js-posts-to-connect",".js-relations-itm")});b(document).on("change",".js-select-related-post-type",function(){c(this,".js-connected-itm",".js-connected-posts",".js-search-connected-posts")});b(document).on("keyup paste",".js-search-connected-posts",function(){a(this,".js-select-related-post-type",".js-connected-posts",".js-connected-itm")});function d(){b(".js-connected-posts").sortable({revert:true})}function c(i,j,h,f){var g=b(i).val();var e=b(j);var f=b(f).val();if(g==="all"){if(f){e.each(function(){var l=b(this).attr("data-post-title");var k=new RegExp(f.toLowerCase());if(k.test(l.toLowerCase())){b(this).show()}else{b(this).hide()}})}else{e.show()}}else{e.hide();if(f){e.each(function(){var l=b(this).attr("data-post-type");var m=b(this).attr("data-post-title");var k=new RegExp(f.toLowerCase());if(k.test(m.toLowerCase())&&l===g){b(this).show()}else{b(this).hide()}})}else{b(h+' > [data-post-type="'+g+'"] ').show()}}}function a(j,h,e,k){var i=b(h).val();var g=b(j).val();var f=b(k);if(i==="all"){f.show();f.each(function(){var m=b(this).attr("data-post-title");var l=new RegExp(g.toLowerCase());if(l.test(m.toLowerCase())){b(this).show()}else{b(this).hide()}})}else{f.hide();b(e+' > [data-post-type="'+i+'"] ').show();f.each(function(){var m=b(this).attr("data-post-title");var l=new RegExp(g.toLowerCase());if(l.test(m.toLowerCase())){if(b(this).attr("data-post-type")===i){b(this).show()}else{b(this).hide()}}else{b(this).hide()}})}}})(jQuery);
     1(function(c){c(function(){e()});c(document).on("click",".js-add-connection",function(){var i=c(this).data("post-id");var g=c(this).data("post-title");var q=c(this).data("post-type");var s=c('.js-relations-itm[data-post-id="'+i+'"]');var h=s.find(".js-posts-to-connect-tax-data");var r=c("<li>");r.attr("data-post-title",g);r.attr("data-post-type",q);r.attr("data-post-id",i);r.addClass("js-connected-itm");r.addClass("sft-rel-connected-item");var m=c("<div>").addClass("sft-rel-section-item-head");var p=c("<span>");p.attr("data-post-id",i);p.addClass("dashicons");p.addClass("dashicons-trash");p.addClass("js-remove-connection");p.addClass("sft-rel-remove-connection");var n=c("<span>").text(g);var l=c("<span>");l.attr("data-post-id",i);l.addClass("dashicons");l.addClass("dashicons-arrow-down");l.addClass("sft-rel-toggle-connected-item");l.addClass("js-toggle-connected-item");m.append(p).append(n).append(l);var k=c("<div>").hide();k.addClass("sft-rel-section-item");k.addClass("js-section-item");var o=c("<ul>").addClass("categorychecklist");o.addClass("form-no-clear");k.append(o);var j=c("<input>").val(i);j.attr("type","hidden");j.attr("name","connected_post[]");r.append(m).append(k).append(j);console.log(h.length);if(h.length){h.each(function(w,z){var v=c(this).data("taxonomy-name");var t=c(this).val();var u=c("<input>").val(1);u.attr("type","checkbox");u.attr("id","in-taxonomy-"+v);u.attr("name","connected_post_taxonomies["+i+"]["+v+"]");u.val(v);var y=c("<label>").addClass("selectit").text(t).prepend(u);var x=c("<li>").append(y);x.attr("id","sft-rel-taxonomy-"+v);x.addClass("popular-category");o.append(x)})}else{var f=c("<li>").text(c(".js-text-references").data("no-taxonomies")).addClass("sft-rel-post-no-taxonomies");o.append(f)}c(".js-connected-posts").append(r);s.hide();a();c(".js-connected-no-connections").hide()});c(document).on("change",".js-connected-post-taxonomies-checkbox",function(){a()});c(document).on("click",".js-toggle-connected-item",function(){var g=this;var f=c(this).data("post-id");c('[data-post-id="'+f+'"]').find(".js-section-item").slideToggle("fast",function(){if(c(g).hasClass("dashicons-arrow-down")){c(g).removeClass("dashicons-arrow-down").addClass("dashicons-arrow-up")}else{c(g).removeClass("dashicons-arrow-up").addClass("dashicons-arrow-down")}})});c(document).on("click",".js-remove-connection",function(){if(confirm(c(".js-text-references").data("remove-taxonomy"))){var f=c(this).data("post-id");c('.js-connected-itm[data-post-id="'+f+'"]').remove();c('.sft-rel-not-connected[data-post-id="'+f+'"]').show();if(c(".js-connected-itm").length===0){c(".js-connected-no-connections").show()}a()}});c(document).on("change",".js-select-post-type",function(){d(this,".js-relations-itm",".js-posts-to-connect",".js-search-posts")});c(document).on("keyup paste",".js-search-posts",function(){b(this,".js-select-post-type",".js-posts-to-connect",".js-relations-itm")});c(document).on("change",".js-select-related-post-type",function(){d(this,".js-connected-itm",".js-connected-posts",".js-search-connected-posts")});c(document).on("keyup paste",".js-search-connected-posts",function(){b(this,".js-select-related-post-type",".js-connected-posts",".js-connected-itm")});function e(){c(".js-connected-posts").sortable({handle:".sft-rel-section-item-head",revert:true,update:function(f,g){a()}})}function d(j,k,i,g){var h=c(j).val();var f=c(k);var g=c(g).val();if(h==="all"){if(g){f.each(function(){var m=c(this).attr("data-post-title");var l=new RegExp(g.toLowerCase());if(l.test(m.toLowerCase())){c(this).show()}else{c(this).hide()}})}else{f.show()}}else{f.hide();if(g){f.each(function(){var m=c(this).attr("data-post-type");var n=c(this).attr("data-post-title");var l=new RegExp(g.toLowerCase());if(l.test(n.toLowerCase())&&m===h){c(this).show()}else{c(this).hide()}})}else{c(i+' > [data-post-type="'+h+'"] ').show()}}}function b(k,i,f,l){var j=c(i).val();var h=c(k).val();var g=c(l);if(j==="all"){g.show();g.each(function(){var n=c(this).attr("data-post-title");var m=new RegExp(h.toLowerCase());if(m.test(n.toLowerCase())){c(this).show()}else{c(this).hide()}})}else{g.hide();c(f+' > [data-post-type="'+j+'"] ').show();g.each(function(){var n=c(this).attr("data-post-title");var m=new RegExp(h.toLowerCase());if(m.test(n.toLowerCase())){if(c(this).attr("data-post-type")===j){c(this).show()}else{c(this).hide()}}else{c(this).hide()}})}}function a(){c(".js-update-your-post").show()}})(jQuery);
  • softmixt-relations/trunk/admin/assets/tinymce/plugins/sftrelations/plugin.js

    r1727691 r1870537  
    1 (function ()
    2 {
    3     tinymce.create ( 'tinymce.plugins.sftrelations' , {
    4         /**
    5          * Initializes the plugin, this will be executed after the plugin has been created.
    6          * This call is done before the editor instance has finished it's initialization so use the onInit event
    7          * of the editor instance to intercept that event.
    8          *
    9          * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
    10          * @param {string} url Absolute URL to where the plugin is located.
    11          */
    12         init : function ( ed , url )
    13         {
    14 
    15 
    16             /**
    17              * Register the button
    18              */
    19             ed.addButton ( 'sftrelations' , {
    20                 title : 'SFT Relations' ,
    21                 cmd : 'sftrelations' ,
    22                 image : url + '/sftrelations.png'
    23             } );
    24 
    25             /**
    26              * Register button callback
    27              */
    28             ed.addCommand ( 'sftrelations' , function ()
    29             {
    30 
    31                 /**
    32                  * Open relations settings popup
    33                  */
    34                 ed.windowManager.open ( {
    35                                             title : 'Add related posts' ,
    36                                             body : [
    37                                                 {
    38                                                     type : 'listbox' ,
    39                                                     name : 'sft_container' ,
    40                                                     label : 'Container element' ,
    41                                                     values : [
    42                                                         { text : 'Div' , value : 'div' } ,
    43                                                         { text : 'Ul' , value : 'ul' } ,
    44                                                         { text : 'Section' , value : 'section' } ,
    45                                                         { text : 'Article' , value : 'article' }
    46                                                     ] ,
    47                                                     minWidth : 350
    48                                                 } ,
    49                                                 {
    50                                                     type : 'textbox' ,
    51                                                     name : 'sft_container_class' ,
    52                                                     label : 'Custom container class' ,
    53                                                     placeholder : 'Custom container class ...' ,
    54                                                     multiline : false ,
    55                                                     minWidth : 700 ,
    56                                                     minHeight : 50
    57                                                 } ,
    58                                                 {
    59                                                     type : 'listbox' ,
    60                                                     name : 'sft_item_container' ,
    61                                                     label : 'Item container element' ,
    62                                                     values : [
    63                                                         { text : 'Div' , value : 'div' } ,
    64                                                         { text : 'Span' , value : 'span' } ,
    65                                                         { text : 'Li' , value : 'li' } ,
    66                                                         { text : 'Section' , value : 'section' } ,
    67                                                         { text : 'Article' , value : 'article' } ,
    68                                                         { text : 'P' , value : 'p' }
    69                                                     ] ,
    70                                                     minWidth : 350
    71                                                 } , {
    72                                                     type : 'listbox' ,
    73                                                     name : 'sft_item_title_element' ,
    74                                                     label : 'Item container title element' ,
    75                                                     values : [
    76                                                         { text : 'None' , value : 'none' } ,
    77                                                         { text : 'H1' , value : 'h1' } ,
    78                                                         { text : 'H2' , value : 'h2' } ,
    79                                                         { text : 'H3' , value : 'h3' } ,
    80                                                         { text : 'H4' , value : 'h4' } ,
    81                                                         { text : 'H5' , value : 'h5' } ,
    82                                                         { text : 'H6' , value : 'h6' } ,
    83                                                         { text : 'Paragraph' , value : 'p' } ,
    84                                                         { text : 'Span' , value : 'span' }
    85                                                     ] ,
    86                                                     minWidth : 350
    87                                                 } ,
    88                                                 {
    89                                                     type : 'textbox' ,
    90                                                     name : 'sft_item_container_class' ,
    91                                                     label : 'Custom item class' ,
    92                                                     placeholder : 'Custom container item class ...' ,
    93                                                     multiline : false ,
    94                                                     minWidth : 700 ,
    95                                                     minHeight : 50
    96                                                 } ,
    97                                                 {
    98                                                     label : 'Show post meta' ,
    99                                                     type : 'checkbox' ,
    100                                                     name : 'sft_item_show_title' ,
    101                                                     text : 'Show post title' ,
    102                                                     checked : true
    103                                                 } ,
    104                                                 {
    105                                                     label : ' ' ,
    106                                                     text : 'Show post date' ,
    107                                                     type : 'checkbox' ,
    108                                                     name : 'sft_item_show_date' ,
    109                                                     checked : true
    110                                                 } ,
    111                                                 {
    112                                                     label : ' ' ,
    113                                                     text : 'Show post author' ,
    114                                                     type : 'checkbox' ,
    115                                                     name : 'sft_item_show_author' ,
    116                                                     checked : false
    117                                                 } ,
    118                                                 {
    119                                                     label : ' ' ,
    120                                                     text : 'Show post feature image' ,
    121                                                     type : 'checkbox' ,
    122                                                     name : 'sft_item_show_feature_image' ,
    123                                                     checked : false
    124                                                 } ,
    125                                                 {
    126                                                     label : ' ' ,
    127                                                     text : 'Show post excerpt' ,
    128                                                     type : 'checkbox' ,
    129                                                     name : 'sft_item_show_excerpt' ,
    130                                                     checked : false
    131                                                 } ,
    132                                                 {
    133                                                     label : ' ' ,
    134                                                     text : 'Show post content' ,
    135                                                     type : 'checkbox' ,
    136                                                     name : 'sft_item_show_content' ,
    137                                                     checked : false
    138                                                 }
    139                                             ] ,
    140                                             onsubmit : function ( e )
    141                                             {
    142                                                 var container_element       = 'container="' + e.data.sft_container + '" ';
    143                                                 var container_class         = e.data.sft_container_class ? 'container_class="' + e.data.sft_container_class + '" ' : '';
    144                                                 var item_container          = 'item_container="' + e.data.sft_item_container + '" ';
    145                                                 var item_title_container    = 'item_title_container="' + e.data.sft_item_title_element + '" ';
    146                                                 var item_container_class    = e.data.sft_item_container_class ? 'item_container_class="' + e.data.sft_item_container_class + '" ' : '';
    147                                                 var item_show_title         = e.data.sft_item_show_title === true ? 'item_show_title="' + e.data.sft_item_show_title + '" ' : '';
    148                                                 var item_show_date          = e.data.sft_item_show_date === true ? 'item_show_date="' + e.data.sft_item_show_date + '" ' : '';
    149                                                 var item_show_author        = e.data.sft_item_show_author === true ? 'item_show_author="' + e.data.sft_item_show_author + '" ' : '';
    150                                                 var item_show_feature_image = e.data.sft_item_show_feature_image === true ? 'item_show_feature_image="' + e.data.sft_item_show_feature_image + '" ' : '';
    151                                                 var item_show_excerpt       = e.data.sft_item_show_excerpt === true ? 'item_show_excerpt="' + e.data.sft_item_show_excerpt + '" ' : '';
    152                                                 var item_show_content       = e.data.sft_item_show_content === true ? 'item_show_content="' + e.data.sft_item_show_content + '" ' : '';
    153 
    154                                                 ed.insertContent ( '[sftrelations ' +
    155                                                                    container_element +
    156                                                                    container_class +
    157                                                                    item_container +
    158                                                                    item_title_container +
    159                                                                    item_container_class +
    160                                                                    item_show_title +
    161                                                                    item_show_date +
    162                                                                    item_show_author +
    163                                                                    item_show_feature_image +
    164                                                                    item_show_excerpt +
    165                                                                    item_show_content +
    166                                                                    '  ]' );
    167 
    168                                             }
    169                                         } );
    170 
    171 
    172             } );
    173 
    174 
    175         } ,
    176 
    177         /**
    178          * Creates control instances based in the incomming name. This method is normally not
    179          * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
    180          * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
    181          * method can be used to create those.
    182          *
    183          * @param {String} n Name of the control to create.
    184          * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
    185          * @return {tinymce.ui.Control} New control instance or null if no control was created.
    186          */
    187         createControl : function ( n , cm )
    188         {
    189             return null;
    190         } ,
    191 
    192         /**
    193          * Returns information about the plugin as a name/value array.
    194          * The current keys are longname, author, authorurl, infourl and version.
    195          *
    196          * @return {Object} Name/value array containing information about the plugin.
    197          */
    198         getInfo : function ()
    199         {
    200             return {
    201                 longname : 'Add related posts.' ,
    202                 author : 'softmixt' ,
    203                 authorurl : 'http://softmixt.com' ,
    204                 infourl : 'http://softmixt.com/wordpress/plugins/softmixt-relations/' ,
    205                 version : "0.1"
    206             };
    207         }
    208     } );
    209 
    210     // Register plugin
    211     tinymce.PluginManager.add ( 'sftrelations' , tinymce.plugins.sftrelations );
    212 }) ();
     1(function () {
     2    tinymce.create('tinymce.plugins.sftrelations', {
     3        /**
     4         * Initializes the plugin, this will be executed after the plugin has been created.
     5         * This call is done before the editor instance has finished it's initialization so use the onInit event
     6         * of the editor instance to intercept that event.
     7         *
     8         * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
     9         * @param {string} url Absolute URL to where the plugin is located.
     10         */
     11        init: function (ed, url) {
     12
     13            /**
     14             * Register the button
     15             */
     16            ed.addButton('sftrelations', {
     17                title: 'SFT Relations',
     18                cmd: 'sftrelations',
     19                image: url + '/sftrelations.png'
     20            });
     21
     22            /**
     23             * Register button callback
     24             */
     25            ed.addCommand('sftrelations', function () {
     26
     27                /**
     28                 * Open relations settings popup
     29                 */
     30                ed.windowManager.open({
     31                    title: 'Add related posts',
     32                    body: [
     33                        {
     34                            type: 'listbox',
     35                            name: 'sft_container',
     36                            label: 'Container element',
     37                            values: [
     38                                {text: 'Div', value: 'div'},
     39                                {text: 'Ul', value: 'ul'},
     40                                {text: 'Section', value: 'section'},
     41                                {text: 'Article', value: 'article'}
     42                            ],
     43                            minWidth: 350
     44                        },
     45                        {
     46                            type: 'textbox',
     47                            name: 'sft_container_class',
     48                            label: 'Custom container class',
     49                            placeholder: 'Custom container class ...',
     50                            multiline: false,
     51                            minWidth: 700,
     52                            minHeight: 30
     53                        },
     54                        {
     55                            type: 'listbox',
     56                            name: 'sft_item_container',
     57                            label: 'Item container element',
     58                            values: [
     59                                {text: 'Div', value: 'div'},
     60                                {text: 'Span', value: 'span'},
     61                                {text: 'Li', value: 'li'},
     62                                {text: 'Section', value: 'section'},
     63                                {text: 'Article', value: 'article'},
     64                                {text: 'P', value: 'p'}
     65                            ],
     66                            minWidth: 350
     67                        }, {
     68                            type: 'listbox',
     69                            name: 'sft_item_title_element',
     70                            label: 'Item container title element',
     71                            values: [
     72                                {text: 'None', value: 'none'},
     73                                {text: 'H1', value: 'h1'},
     74                                {text: 'H2', value: 'h2'},
     75                                {text: 'H3', value: 'h3'},
     76                                {text: 'H4', value: 'h4'},
     77                                {text: 'H5', value: 'h5'},
     78                                {text: 'H6', value: 'h6'},
     79                                {text: 'Paragraph', value: 'p'},
     80                                {text: 'Span', value: 'span'}
     81                            ],
     82                            minWidth: 350
     83                        }, {
     84                            type: 'textbox',
     85                            name: 'sft_item_container_class',
     86                            label: 'Custom item class',
     87                            placeholder: 'Custom container item class ...',
     88                            multiline: false,
     89                            minWidth: 700,
     90                            minHeight: 30
     91                        }, {
     92                            type: 'listbox',
     93                            name: 'sft_item_terms_container',
     94                            label: 'Custom item terms container element',
     95                            values: [
     96                                {text: 'None', value: 'none'},
     97                                {text: 'Div', value: 'div'},
     98                                {text: 'Span', value: 'span'},
     99                                {text: 'Li', value: 'li'},
     100                                {text: 'Section', value: 'section'},
     101                                {text: 'Article', value: 'article'},
     102                                {text: 'P', value: 'p'}
     103                            ],
     104                            minWidth: 350
     105                        },
     106
     107
     108
     109                        {
     110                            type: 'textbox',
     111                            name: 'sft_item_terms_container_class',
     112                            label: 'Custom item terms container class',
     113                            placeholder: 'Custom item terms container class ...',
     114                            multiline: false,
     115                            minWidth: 700,
     116                            minHeight: 30
     117                        },
     118                        {
     119                            type: 'listbox',
     120                            name: 'sft_item_term_container',
     121                            label: 'Custom item term container element',
     122                            values: [
     123                                {text: 'Span', value: 'span'},
     124                                {text: 'Div', value: 'div'},
     125                                {text: 'Li', value: 'li'},
     126                                {text: 'Section', value: 'section'},
     127                                {text: 'Article', value: 'article'},
     128                                {text: 'P', value: 'p'}
     129                            ],
     130                            minWidth: 350
     131                        },
     132                        {
     133                            type: 'textbox',
     134                            name: 'sft_item_term_container_class',
     135                            label: 'Custom item term container class',
     136                            placeholder: 'Custom item term container class ...',
     137                            multiline: false,
     138                            minWidth: 700,
     139                            minHeight: 30
     140                        }, {
     141                            label: 'Show post meta',
     142                            type: 'checkbox',
     143                            name: 'sft_item_show_title',
     144                            text: 'Show post title',
     145                            checked: true
     146                        },
     147                        {
     148                            label: ' ',
     149                            text: 'Show post date',
     150                            type: 'checkbox',
     151                            name: 'sft_item_show_date',
     152                            checked: true
     153                        },
     154                        {
     155                            label: ' ',
     156                            text: 'Show post author',
     157                            type: 'checkbox',
     158                            name: 'sft_item_show_author',
     159                            checked: false
     160                        },
     161                        {
     162                            label: ' ',
     163                            text: 'Show post feature image',
     164                            type: 'checkbox',
     165                            name: 'sft_item_show_feature_image',
     166                            checked: false
     167                        },
     168                        {
     169                            label: ' ',
     170                            text: 'Show post excerpt',
     171                            type: 'checkbox',
     172                            name: 'sft_item_show_excerpt',
     173                            checked: false
     174                        },
     175                        {
     176                            label: ' ',
     177                            text: 'Show post content',
     178                            type: 'checkbox',
     179                            name: 'sft_item_show_content',
     180                            checked: false
     181                        }
     182                    ],
     183                    onsubmit: function (e) {
     184                        var container_element = 'container="' + e.data.sft_container + '" ';
     185                        var container_class = e.data.sft_container_class ? 'container_class="' + e.data.sft_container_class + '" ' : '';
     186                        var item_container = 'item_container="' + e.data.sft_item_container + '" ';
     187                        var item_title_container = 'item_title_container="' + e.data.sft_item_title_element + '" ';
     188                        var item_container_class = e.data.sft_item_container_class ? 'item_container_class="' + e.data.sft_item_container_class + '" ' : '';
     189                        var item_terms_container = 'item_terms_container="' + e.data.sft_item_terms_container + '" ';
     190                        var item_terms_container_class = e.data.sft_item_terms_container_class ? 'item_terms_container_class="' + e.data.sft_item_terms_container_class + '" ' : '';
     191                        var item_term_container = 'item_term_container="' + e.data.sft_item_term_container + '" ';
     192                        var item_term_container_class = e.data.sft_item_term_container_class ? 'item_term_container_class="' + e.data.sft_item_term_container_class + '" ' : '';
     193                        var item_show_title = e.data.sft_item_show_title === true ? 'item_show_title="' + e.data.sft_item_show_title + '" ' : '';
     194                        var item_show_date = e.data.sft_item_show_date === true ? 'item_show_date="' + e.data.sft_item_show_date + '" ' : '';
     195                        var item_show_author = e.data.sft_item_show_author === true ? 'item_show_author="' + e.data.sft_item_show_author + '" ' : '';
     196                        var item_show_feature_image = e.data.sft_item_show_feature_image === true ? 'item_show_feature_image="' + e.data.sft_item_show_feature_image + '" ' : '';
     197                        var item_show_excerpt = e.data.sft_item_show_excerpt === true ? 'item_show_excerpt="' + e.data.sft_item_show_excerpt + '" ' : '';
     198                        var item_show_content = e.data.sft_item_show_content === true ? 'item_show_content="' + e.data.sft_item_show_content + '" ' : '';
     199
     200                        ed.insertContent('[sftrelations ' +
     201                            container_element +
     202                            container_class +
     203                            item_container +
     204                            item_title_container +
     205                            item_container_class +
     206                            item_terms_container +
     207                            item_terms_container_class +
     208                            item_term_container +
     209                            item_term_container_class +
     210                            item_show_title +
     211                            item_show_date +
     212                            item_show_author +
     213                            item_show_feature_image +
     214                            item_show_excerpt +
     215                            item_show_content +
     216                            '  ]');
     217                    }
     218                });
     219
     220            });
     221
     222        },
     223
     224        /**
     225         * Creates control instances based in the incomming name. This method is normally not
     226         * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
     227         * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
     228         * method can be used to create those.
     229         *
     230         * @param {String} n Name of the control to create.
     231         * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
     232         * @return {tinymce.ui.Control} New control instance or null if no control was created.
     233         */
     234        createControl: function (n, cm) {
     235            return null;
     236        },
     237
     238        /**
     239         * Returns information about the plugin as a name/value array.
     240         * The current keys are longname, author, authorurl, infourl and version.
     241         *
     242         * @return {Object} Name/value array containing information about the plugin.
     243         */
     244        getInfo: function () {
     245            return {
     246                longname: 'Add related posts.',
     247                author: 'softmixt',
     248                authorurl: 'http://softmixt.com',
     249                infourl: 'http://softmixt.com/wordpress/plugins/softmixt-relations/',
     250                version: "0.1"
     251            };
     252        }
     253    });
     254
     255    // Register plugin
     256    tinymce.PluginManager.add('sftrelations', tinymce.plugins.sftrelations);
     257})();
  • softmixt-relations/trunk/admin/assets/tinymce/plugins/sftrelations/plugin.min.js

    r1727691 r1870537  
    1 (function(){tinymce.create("tinymce.plugins.sftrelations",{init:function(a,b){a.addButton("sftrelations",{title:"SFT Relations",cmd:"sftrelations",image:b+"/sftrelations.png"});a.addCommand("sftrelations",function(){a.windowManager.open({title:"Add related posts",body:[{type:"listbox",name:"sft_container",label:"Container element",values:[{text:"Div",value:"div"},{text:"Ul",value:"ul"},{text:"Section",value:"section"},{text:"Article",value:"article"}],minWidth:350},{type:"textbox",name:"sft_container_class",label:"Custom container class",placeholder:"Custom container class ...",multiline:false,minWidth:700,minHeight:50},{type:"listbox",name:"sft_item_container",label:"Item container element",values:[{text:"Div",value:"div"},{text:"Span",value:"span"},{text:"Li",value:"li"},{text:"Section",value:"section"},{text:"Article",value:"article"},{text:"P",value:"p"}],minWidth:350},{type:"listbox",name:"sft_item_title_element",label:"Item container title element",values:[{text:"None",value:"none"},{text:"H1",value:"h1"},{text:"H2",value:"h2"},{text:"H3",value:"h3"},{text:"H4",value:"h4"},{text:"H5",value:"h5"},{text:"H6",value:"h6"},{text:"Paragraph",value:"p"},{text:"Span",value:"span"}],minWidth:350},{type:"textbox",name:"sft_item_container_class",label:"Custom item class",placeholder:"Custom container item class ...",multiline:false,minWidth:700,minHeight:50},{label:"Show post meta",type:"checkbox",name:"sft_item_show_title",text:"Show post title",checked:true},{label:" ",text:"Show post date",type:"checkbox",name:"sft_item_show_date",checked:true},{label:" ",text:"Show post author",type:"checkbox",name:"sft_item_show_author",checked:false},{label:" ",text:"Show post feature image",type:"checkbox",name:"sft_item_show_feature_image",checked:false},{label:" ",text:"Show post excerpt",type:"checkbox",name:"sft_item_show_excerpt",checked:false},{label:" ",text:"Show post content",type:"checkbox",name:"sft_item_show_content",checked:false}],onsubmit:function(l){var n='container="'+l.data.sft_container+'" ';var h=l.data.sft_container_class?'container_class="'+l.data.sft_container_class+'" ':"";var d='item_container="'+l.data.sft_item_container+'" ';var f='item_title_container="'+l.data.sft_item_title_element+'" ';var k=l.data.sft_item_container_class?'item_container_class="'+l.data.sft_item_container_class+'" ':"";var i=l.data.sft_item_show_title===true?'item_show_title="'+l.data.sft_item_show_title+'" ':"";var m=l.data.sft_item_show_date===true?'item_show_date="'+l.data.sft_item_show_date+'" ':"";var o=l.data.sft_item_show_author===true?'item_show_author="'+l.data.sft_item_show_author+'" ':"";var c=l.data.sft_item_show_feature_image===true?'item_show_feature_image="'+l.data.sft_item_show_feature_image+'" ':"";var g=l.data.sft_item_show_excerpt===true?'item_show_excerpt="'+l.data.sft_item_show_excerpt+'" ':"";var j=l.data.sft_item_show_content===true?'item_show_content="'+l.data.sft_item_show_content+'" ':"";a.insertContent("[sftrelations "+n+h+d+f+k+i+m+o+c+g+j+"  ]")}})})},createControl:function(b,a){return null},getInfo:function(){return{longname:"Add related posts.",author:"softmixt",authorurl:"http://softmixt.com",infourl:"http://softmixt.com/wordpress/plugins/softmixt-relations/",version:"0.1"}}});tinymce.PluginManager.add("sftrelations",tinymce.plugins.sftrelations)})();
     1(function(){tinymce.create("tinymce.plugins.sftrelations",{init:function(a,b){a.addButton("sftrelations",{title:"SFT Relations",cmd:"sftrelations",image:b+"/sftrelations.png"});a.addCommand("sftrelations",function(){a.windowManager.open({title:"Add related posts",body:[{type:"listbox",name:"sft_container",label:"Container element",values:[{text:"Div",value:"div"},{text:"Ul",value:"ul"},{text:"Section",value:"section"},{text:"Article",value:"article"}],minWidth:350},{type:"textbox",name:"sft_container_class",label:"Custom container class",placeholder:"Custom container class ...",multiline:false,minWidth:700,minHeight:30},{type:"listbox",name:"sft_item_container",label:"Item container element",values:[{text:"Div",value:"div"},{text:"Span",value:"span"},{text:"Li",value:"li"},{text:"Section",value:"section"},{text:"Article",value:"article"},{text:"P",value:"p"}],minWidth:350},{type:"listbox",name:"sft_item_title_element",label:"Item container title element",values:[{text:"None",value:"none"},{text:"H1",value:"h1"},{text:"H2",value:"h2"},{text:"H3",value:"h3"},{text:"H4",value:"h4"},{text:"H5",value:"h5"},{text:"H6",value:"h6"},{text:"Paragraph",value:"p"},{text:"Span",value:"span"}],minWidth:350},{type:"textbox",name:"sft_item_container_class",label:"Custom item class",placeholder:"Custom container item class ...",multiline:false,minWidth:700,minHeight:30},{type:"listbox",name:"sft_item_terms_container",label:"Custom item terms container element",values:[{text:"None",value:"none"},{text:"Div",value:"div"},{text:"Span",value:"span"},{text:"Li",value:"li"},{text:"Section",value:"section"},{text:"Article",value:"article"},{text:"P",value:"p"}],minWidth:350},{type:"textbox",name:"sft_item_terms_container_class",label:"Custom item terms container class",placeholder:"Custom item terms container class ...",multiline:false,minWidth:700,minHeight:30},{type:"listbox",name:"sft_item_term_container",label:"Custom item term container element",values:[{text:"Span",value:"span"},{text:"Div",value:"div"},{text:"Li",value:"li"},{text:"Section",value:"section"},{text:"Article",value:"article"},{text:"P",value:"p"}],minWidth:350},{type:"textbox",name:"sft_item_term_container_class",label:"Custom item term container class",placeholder:"Custom item term container class ...",multiline:false,minWidth:700,minHeight:30},{label:"Show post meta",type:"checkbox",name:"sft_item_show_title",text:"Show post title",checked:true},{label:" ",text:"Show post date",type:"checkbox",name:"sft_item_show_date",checked:true},{label:" ",text:"Show post author",type:"checkbox",name:"sft_item_show_author",checked:false},{label:" ",text:"Show post feature image",type:"checkbox",name:"sft_item_show_feature_image",checked:false},{label:" ",text:"Show post excerpt",type:"checkbox",name:"sft_item_show_excerpt",checked:false},{label:" ",text:"Show post content",type:"checkbox",name:"sft_item_show_content",checked:false}],onsubmit:function(n){var r='container="'+n.data.sft_container+'" ';var i=n.data.sft_container_class?'container_class="'+n.data.sft_container_class+'" ':"";var d='item_container="'+n.data.sft_item_container+'" ';var g='item_title_container="'+n.data.sft_item_title_element+'" ';var m=n.data.sft_item_container_class?'item_container_class="'+n.data.sft_item_container_class+'" ':"";var q='item_terms_container="'+n.data.sft_item_terms_container+'" ';var f=n.data.sft_item_terms_container_class?'item_terms_container_class="'+n.data.sft_item_terms_container_class+'" ':"";var l='item_term_container="'+n.data.sft_item_term_container+'" ';var o=n.data.sft_item_term_container_class?'item_term_container_class="'+n.data.sft_item_term_container_class+'" ':"";var j=n.data.sft_item_show_title===true?'item_show_title="'+n.data.sft_item_show_title+'" ':"";var p=n.data.sft_item_show_date===true?'item_show_date="'+n.data.sft_item_show_date+'" ':"";var s=n.data.sft_item_show_author===true?'item_show_author="'+n.data.sft_item_show_author+'" ':"";var c=n.data.sft_item_show_feature_image===true?'item_show_feature_image="'+n.data.sft_item_show_feature_image+'" ':"";var h=n.data.sft_item_show_excerpt===true?'item_show_excerpt="'+n.data.sft_item_show_excerpt+'" ':"";var k=n.data.sft_item_show_content===true?'item_show_content="'+n.data.sft_item_show_content+'" ':"";a.insertContent("[sftrelations "+r+i+d+g+m+q+f+l+o+j+p+s+c+h+k+"  ]")}})})},createControl:function(b,a){return null},getInfo:function(){return{longname:"Add related posts.",author:"softmixt",authorurl:"http://softmixt.com",infourl:"http://softmixt.com/wordpress/plugins/softmixt-relations/",version:"0.1"}}});tinymce.PluginManager.add("sftrelations",tinymce.plugins.sftrelations)})();
  • softmixt-relations/trunk/admin/views/softmixt-relations-mb-view.php

    r1689232 r1870537  
     1<p class="description js-update-your-post sft-update-your-post"><?php _e( 'Update your post in order to save your new relation changes.' , SFT_REL_TEXT_DOMAIN ); ?></p>
     2
    13<div class="sft-rel-metabox">
    2     <h3><?php _e ( 'All posts' , SFT_REL_TEXT_DOMAIN ); ?></h3>
    3     <select class="js-select-post-type">
    4             <?php foreach ( sft_get_all_post_types () as $pt ) : ?>
    5           <option value="<?php echo $pt; ?>"><?php _e ( ucfirst ( $pt ) , SFT_REL_TEXT_DOMAIN ); ?></option>
     4    <h3><?php _e( 'All posts' , SFT_REL_TEXT_DOMAIN ); ?></h3>
     5    <select class="js-select-post-type">
     6        <?php foreach ( sft_get_all_post_types() as $pt ) : ?>
     7            <option value="<?php echo $pt; ?>"><?php _e( ucfirst( $pt ) , SFT_REL_TEXT_DOMAIN ); ?></option>
     8        <?php endforeach; ?>
     9    </select>
     10    <input type="text" size="50" class="sft-rel-service js-search-posts" placeholder="<?php _e( 'Search...' , SFT_REL_TEXT_DOMAIN ); ?>">
     11    <div class="sft-rel-list-container">
     12        <ul class="js-posts-to-connect sft-rel-relations">
     13            <?php foreach ( sft_get_all_post_types_posts() as $gaptp ) : ?>
     14                <li class="js-relations-itm sft-rel-not-connected" data-post-id="<?php echo $gaptp[ 'id' ]; ?>" <?php echo ! $connected_relations || ! in_array( $gaptp[ 'id' ] , $connected_relations ) ? '' : 'style="display:none;"'; ?> data-post-title="<?php echo $gaptp[ 'post_title' ]; ?>" data-post-type="<?php echo $gaptp[ 'post_type' ]; ?>">
     15                    <span class="dashicons dashicons-plus js-add-connection" data-post-id="<?php echo $gaptp[ 'id' ]; ?>" data-post-title="<?php echo $gaptp[ 'post_title' ]; ?>" data-post-type="<?php echo $gaptp[ 'post_type' ]; ?>"></span> <?php _e( mb_strimwidth( $gaptp[ 'post_title' ] , 0 , 50 , '...' ) , SFT_REL_TEXT_DOMAIN ); ?>
     16                    <?php foreach ( get_object_taxonomies( get_post_type( $gaptp[ 'id' ] ) , 'objects' ) as $taxonomy ) : ?>
     17                        <input class="js-posts-to-connect-tax-data" data-post-id="<?php echo $gaptp[ 'id' ]; ?>" type="hidden" data-taxonomy-name="<?php echo $taxonomy->name; ?>" value="<?php echo $taxonomy->label; ?>">
     18                    <?php endforeach; ?>
     19                </li>
    620            <?php endforeach; ?>
    7     </select>
    8     <input type="text" size="50" class="sft-rel-service js-search-posts" placeholder="<?php _e ( 'Search...' , SFT_REL_TEXT_DOMAIN ); ?>">
    9     <div class="sft-rel-list-container">
    10         <ul class="js-posts-to-connect sft-rel-relations">
    11                     <?php foreach ( sft_get_all_post_types_posts () as $gaptp ) : ?>
    12                         <?php if ( ! $connected_relations || ! in_array ( $gaptp[ 'id' ] , $connected_relations ) ) : ?>
    13                   <li class="js-relations-itm sft-rel-not-connected" data-post-id="<?php echo $gaptp[ 'id' ]; ?>" data-post-title="<?php echo $gaptp[ 'post_title' ]; ?>" data-post-type="<?php echo $gaptp[ 'post_type' ]; ?>">
    14                       <span class="dashicons dashicons-plus js-add-connection"></span> <?php _e ( mb_strimwidth ( $gaptp[ 'post_title' ] , 0, 50 , '...' ) , SFT_REL_TEXT_DOMAIN ); ?>
    15                       <input type="hidden" value="<?php echo $gaptp[ 'id' ]; ?>">
    16                   </li>
    17                         <?php endif; ?>
    18                     <?php endforeach; ?>
    19         </ul>
    20     </div>
     21        </ul>
     22    </div>
    2123</div>
    2224<div class="sft-rel-metabox">
    23     <h3><?php _e ( 'Posts related' , SFT_REL_TEXT_DOMAIN ); ?></h3>
    24     <select class="js-select-related-post-type" id="js-select-post-type" name="js-select-post-type">
    25             <?php foreach ( sft_get_all_post_types () as $pt ) : ?>
    26           <option value="<?php echo $pt; ?>"><?php _e ( ucfirst ( $pt ) , SFT_REL_TEXT_DOMAIN ); ?></option>
    27             <?php endforeach; ?>
    28     </select>
    29     <input type="text" size="50" class="sft-rel-service js-search-connected-posts" placeholder="<?php _e ( 'Search...' , SFT_REL_TEXT_DOMAIN ); ?>">
     25    <h3><?php _e( 'Posts related' , SFT_REL_TEXT_DOMAIN ); ?></h3>
     26    <select class="js-select-related-post-type" id="js-select-post-type" name="js-select-post-type">
     27        <?php foreach ( sft_get_all_post_types() as $pt ) : ?>
     28            <option value="<?php echo $pt; ?>"><?php _e( ucfirst( $pt ) , SFT_REL_TEXT_DOMAIN ); ?></option>
     29        <?php endforeach; ?>
     30    </select>
     31    <input type="text" size="50" class="sft-rel-service js-search-connected-posts" placeholder="<?php _e( 'Search...' , SFT_REL_TEXT_DOMAIN ); ?>">
    3032
    31     <div class="sft-rel-list-container">
    32         <ul class="js-connected-posts sft-rel-relations" id="connected-relations">
    33                     <?php if ( $connected_relations ) : ?>
    34                         <?php foreach ( $connected_relations as $cr ) : ?>
    35                   <li class="js-connected-itm sft-rel-connected" style="cursor: move;" data-post-title="<?php echo get_the_title ( $cr ); ?>" data-post-type="<?php echo get_post_type ( $cr ); ?>" data-post-id="<?php echo $cr; ?>">
    36                       <span class="dashicons dashicons-trash js-remove-connection sft-rel-remove-connection"></span> <?php _e ( mb_strimwidth ( get_the_title ( $cr ) , 0,50 , '...' ) , SFT_REL_TEXT_DOMAIN ); ?>
    37                       <input type="hidden" name="connected_post[]" value="<?php echo $cr; ?>">
    38                   </li>
    39                         <?php endforeach; ?>
    40                     <?php endif; ?>
    41         </ul>
    42     </div>
    43     <p class="description" id="admin-email-description"><?php _e ( 'You can change the order by dragging the items.' , SFT_REL_TEXT_DOMAIN ); ?></p>
     33    <div class="sft-rel-list-container">
     34        <ul class="js-connected-posts sft-rel-relations" id="connected-relations">
     35            <?php if ( $connected_relations ) : ?>
     36                <?php foreach ( $connected_relations as $cr ) : ?>
     37
     38                    <li class="js-connected-itm sft-rel-connected-item" data-post-title="<?php echo get_the_title( $cr ); ?>" data-post-type="<?php echo get_post_type( $cr ); ?>" data-post-id="<?php echo $cr; ?>">
     39
     40                        <div class="sft-rel-section-item-head">
     41                            <span class="dashicons dashicons-trash js-remove-connection sft-rel-remove-connection" data-post-id="<?php echo $cr; ?>"></span> <?php _e( mb_strimwidth( get_the_title( $cr ) , 0 , 50 , '...' ) , SFT_REL_TEXT_DOMAIN ); ?>
     42                            <span class="dashicons dashicons-arrow-down sft-rel-toggle-connected-item js-toggle-connected-item" data-post-id="<?php echo $cr; ?>"></span>
     43                        </div>
     44
     45                        <div class="sft-rel-section-item js-section-item">
     46                            <ul class="categorychecklist form-no-clear">
     47                                <?php $tax = get_object_taxonomies( get_post_type( $cr ) , 'objects' ); ?>
     48
     49                                <?php if ( $tax ) : ?>
     50
     51                                    <?php foreach ( $tax as $taxonomy ): ?>
     52                                        <li id="sft-rel-taxonomy-<?php echo $taxonomy->name; ?>" class="popular-category">
     53                                            <label class=""></label>
     54                                            <label class="selectit">
     55                                                <input class="js-connected-post-taxonomies-checkbox" value="<?php echo $taxonomy->name; ?>" type="checkbox" name="connected_post_taxonomies[<?php echo $cr; ?>][<?php echo $taxonomy->name; ?>]" id="in-taxonomy-<?php echo $taxonomy->name; ?>" <?php checked( isset( $connected_relations_taxonomies[ $cr ][ $taxonomy->name ] ) ); ?>><span> <?php echo $taxonomy->label; ?></span>
     56                                            </label>
     57                                        </li>
     58                                    <?php endforeach; ?>
     59
     60                                <?php else : ?>
     61                                    <li class="sft-rel-post-no-taxonomies"><?php _e( 'No available taxonomies.' , SFT_REL_TEXT_DOMAIN ); ?></li>
     62                                <?php endif; ?>
     63
     64                            </ul>
     65                        </div>
     66                        <input type="hidden" name="connected_post[]" value="<?php echo $cr; ?>">
     67                    </li>
     68
     69                <?php endforeach; ?>
     70            <?php endif; ?>
     71
     72            <li class="sft-rel-connected-no-connections js-connected-no-connections" <?php echo empty( $connected_relations ) ? '' : 'style="display: none;"'; ?>><?php _e( 'Add connections here.' , SFT_REL_TEXT_DOMAIN ); ?></li>
     73
     74        </ul>
     75    </div>
     76    <p class="description" id="admin-email-description"><?php _e( 'You can change the order by dragging the items.' , SFT_REL_TEXT_DOMAIN ); ?></p>
     77    <span style="display: none" class="js-text-references" data-no-taxonomies="<?php _e( 'No available taxonomies.' , SFT_REL_TEXT_DOMAIN ); ?>" data-remove-taxonomy="<?php _e( 'Are you sure you want to remove this Related post ?' , SFT_REL_TEXT_DOMAIN ); ?>"></span>
    4478</div>
  • softmixt-relations/trunk/public/public.php

    r1727679 r1870537  
    11<?php
    22// If this file is called directly, abort.
    3 if ( ! defined ( 'WPINC' ) )
    4 {
     3if ( ! defined( 'WPINC' ) ) {
    54    die;
    65}
    76
    8 /**------------------------------------------------------------------------------
    9  * PUBLIC
    10  **------------------------------------------------------------------------------
    11  * All plugin  public logic goes in this file.
    12  *
    13  * @OBSERVATION : Please change "PluginName_*" into more plugin
    14  *              appropriate name.
    15  *
    16  **----------------------------------------------------------------------------**/
    17 if ( ! class_exists ( 'PluginName_Public' ) )
    18 {
    19     class SFT_Relations_Public
    20     {
     7if ( ! class_exists( 'SFT_Relations_Public' ) ) {
     8    class SFT_Relations_Public {
    219
    22         public function __construct ()
    23         {
    24             add_shortcode ( 'sftrelations' , array ( $this , '_sft_show_related_posts' ) );
     10        public function __construct() {
     11            add_shortcode( 'sftrelations', array( $this, '_sft_show_related_posts' ) );
    2512        }
    2613
     
    3320         * @return string
    3421         */
    35         public function _sft_show_related_posts ( $atts )
    36         {
     22        public function _sft_show_related_posts( $atts ) {
    3723            global $post;
    3824
    3925            $post_id = isset( $post->ID ) ? $post->ID : '';
    40             $atts    = shortcode_atts (
    41                 array (
    42                     'post_id'                 => $post_id ,
    43                     'container'               => 'div' ,
    44                     'container_class'         => 'sft-rlp-container' ,
    45                     'item_container'          => 'div' ,
    46                     'item_title_container'    => 'none' ,
    47                     'item_container_class'    => 'sft-rlp-itm-container' ,
    48                     'item_show_title'         => 'true' ,
    49                     'item_show_date'          => 'true' ,
    50                     'item_show_author'        => 'false' ,
    51                     'item_show_feature_image' => 'false' ,
    52                     'item_show_excerpt'       => 'false' ,
    53                     'item_show_content'       => 'false' ,
    54                 ) ,
    55                 $atts ,
     26            $atts    = shortcode_atts(
     27                array(
     28                    'post_id'                    => $post_id,
     29                    'container'                  => 'div',
     30                    'container_class'            => 'sft-rlp-container',
     31                    'item_container'             => 'div',
     32                    'item_title_container'       => 'none',
     33                    'item_container_class'       => 'sft-rlp-itm-container',
     34                    'item_show_title'            => 'true',
     35                    'item_show_date'             => 'true',
     36                    'item_show_author'           => 'false',
     37                    'item_show_feature_image'    => 'false',
     38                    'item_show_excerpt'          => 'false',
     39                    'item_show_content'          => 'false',
     40                    'item_terms_container'       => 'none',
     41                    'item_terms_container_class' => 'sft-rlp-itm-terms-container',
     42                    'item_term_container'        => 'span',
     43                    'item_term_container_class'  => 'sft-rlp-itm-term-container',
     44                ),
     45                $atts,
    5646                'sftrelations'
    5747            );
    5848
    59             $container               = $atts[ 'container' ];
    60             $container_class         = $atts[ 'container_class' ];
    61             $item_container          = $atts[ 'item_container' ];
    62             $item_title_container    = $atts[ 'item_title_container' ];
    63             $item_container_class    = $atts[ 'item_container_class' ];
    64             $item_show_title         = $atts[ 'item_show_title' ];
    65             $item_show_date          = $atts[ 'item_show_date' ];
    66             $item_show_author        = $atts[ 'item_show_author' ];
    67             $item_show_feature_image = $atts[ 'item_show_feature_image' ];
    68             $item_show_excerpt       = $atts[ 'item_show_excerpt' ];
    69             $item_show_content       = $atts[ 'item_show_content' ];
    70             $connected_relations     = get_post_meta ( $atts[ 'post_id' ] , 'sftp_relations' , TRUE );
     49            $container                  = $atts['container'];
     50            $container_class            = $atts['container_class'];
     51            $item_container             = $atts['item_container'];
     52            $item_title_container       = $atts['item_title_container'];
     53            $item_container_class       = $atts['item_container_class'];
     54            $item_show_title            = $atts['item_show_title'];
     55            $item_show_date             = $atts['item_show_date'];
     56            $item_show_author           = $atts['item_show_author'];
     57            $item_show_feature_image    = $atts['item_show_feature_image'];
     58            $item_show_excerpt          = $atts['item_show_excerpt'];
     59            $item_show_content          = $atts['item_show_content'];
    7160
    72             if ( is_array ( $connected_relations ) && ! empty( $connected_relations ) )
    73             {
     61            $item_terms_container       = $atts['item_terms_container'];
     62            $item_terms_container_class = $atts['item_terms_container_class'];
     63            $item_term_container        = $atts['item_term_container'];
     64            $item_term_container_class  = $atts['item_term_container_class'];
     65            $connected_relations        = get_post_meta( $atts['post_id'], 'sftp_relations', true );
     66
     67            if ( is_array( $connected_relations ) && ! empty( $connected_relations ) ) {
    7468
    7569                $itm_container = "<$container class=\"$container_class\" >";
    76                 foreach ( $connected_relations as $post_related_id )
    77                 {
     70                foreach ( $connected_relations as $post_related_id ) {
     71
     72                    $post_tmp = get_post( $post_related_id );
     73
     74                    // Get taxonomies relations ...
    7875                    $itm_container .= "<$item_container class=\"$item_container_class\" >";
    79                     $post_tmp      = get_post ( $post_related_id );
    8076
    81                     if ( $item_show_title === 'true' )
    82                     {
    83                         $title = get_the_title ( $post_related_id );
    84                         $url   = get_permalink ( $post_related_id );
     77                    if ( $item_show_title === 'true' ) {
     78                        $title = get_the_title( $post_related_id );
     79                        $url   = get_permalink( $post_related_id );
    8580
    86                         if ( $item_title_container == 'none' )
    87                         {
     81                        if ( $item_title_container == 'none' ) {
    8882                            $itm_container .= "<a href=\"$url\">$title</a>";
    89                         }
    90                         else
    91                         {
     83                        } else {
    9284                            $itm_container .= "<$item_title_container class=\"sft-rlp-title\"><a href=\"$url\">$title</a></$item_title_container>";
    9385                        }
    9486                    }
    9587
    96                     if ( $item_show_date === 'true' )
    97                     {
    98                         $date          = get_the_date ( get_option ( 'date_format' ) , $post_related_id );
     88                    if ( $item_show_date === 'true' ) {
     89                        $date          = get_the_date( get_option( 'date_format' ), $post_related_id );
    9990                        $itm_container .= "<p class=\"sft-rlp-date\">$date</p>";
    10091                    }
    10192
    102                     if ( $item_show_author === 'true' )
    103                     {
     93                    if ( $item_show_author === 'true' ) {
    10494                        $author_id       = $post_tmp->post_author;
    105                         $author_nicename = get_the_author_meta ( 'user_nicename' , $author_id );
     95                        $author_nicename = get_the_author_meta( 'user_nicename', $author_id );
    10696                        $itm_container   .= "<p class=\"sft-rlp-author\">by $author_nicename</p>";
    10797                    }
    10898
    109                     if ( $item_show_feature_image === 'true' )
    110                     {
    111                         $feature_image = get_the_post_thumbnail ( $post_related_id , 'large' );
     99                    if ( $item_show_feature_image === 'true' ) {
     100                        $feature_image = get_the_post_thumbnail( $post_related_id, 'large' );
    112101                        $itm_container .= "<div class=\"sft-rlp-feature-image\">$feature_image</div>";
    113102                    }
    114103
    115                     if ( $item_show_excerpt === 'true' )
    116                     {
    117                         if ( has_excerpt ( $post_tmp ) )
    118                         {
    119                             $excerpt       = sft_get_the_excerpt ( $post_tmp );
     104                    if ( $item_show_excerpt === 'true' ) {
     105                        if ( has_excerpt( $post_tmp ) ) {
     106                            $excerpt       = sft_get_the_excerpt( $post_tmp );
    120107                            $itm_container .= "<div class=\"sft-rlp-excerpt\">$excerpt</div>";
    121108                        }
    122109                    }
    123110
    124                     if ( $item_show_content === 'true' )
    125                     {
     111                    if ( $item_show_content === 'true' ) {
    126112                        $content       = $post_tmp->post_content;
    127                         $content       = do_shortcode ( preg_replace ( '/\[sftrelations(.*?)\]/s' , '' , $content ) );
     113                        $content       = do_shortcode( preg_replace( '/\[sftrelations(.*?)\]/s', '', $content ) );
    128114                        $itm_container .= "<div class=\"sft-rlp-content\">$content</div>";
     115                    }
     116
     117                    $connected_relations_taxonomies = get_post_meta( $post_id, 'sftp_relations_taxonomies', true );
     118                    if ( isset( $connected_relations_taxonomies[ $post_related_id ] ) ) {
     119                        foreach ( $connected_relations_taxonomies[ $post_related_id ] as $taxonomy => $taxonomy_label ) {
     120
     121                            $tax_data = wp_get_post_terms( $post_related_id, $taxonomy, array( "fields" => "all" ) );
     122
     123                            $itm_container .= $item_terms_container != 'none' ? "<{$item_terms_container} class=\"{$item_terms_container_class}\">" : '';
     124                            foreach ( $tax_data as $term ) {
     125                                $itm_container .= "<{$item_term_container} class=\"{$item_term_container_class}\">{$term->name}</{$item_term_container}>";
     126                            }
     127                            $itm_container .= $item_terms_container != 'none' ? "</{$item_terms_container}>" : '';
     128                        }
    129129                    }
    130130
     
    133133                $itm_container .= "</$container>";
    134134
    135                 echo apply_filters ( 'SFT_related_item_content' , $itm_container , $connected_relations , $atts );
     135                return apply_filters( 'SFT_related_item_content', $itm_container, $connected_relations, $atts );
    136136
    137137            }
    138 
    139138        }
    140139
  • softmixt-relations/trunk/softmixt-relations.php

    r1727679 r1870537  
    44 * Plugin URI:        https://wordpress.org/plugins/softmixt-relations/
    55 * Description:       Simple way for adding related posts .
    6  * Version:           1.0.1
     6 * Version:           2.0.0
    77 * Author:            Softmixt
    88 * Author URI:        http://softmixt.com/
     
    1414 */
    1515// If this file is called directly, abort.
    16 if ( ! defined ( 'WPINC' ) )
    17 {
     16if ( ! defined( 'WPINC' ) ) {
    1817    die;
    1918}
    2019
    21 /**---------------------------------------------------------------------------------------------------------------------------------
    22  * PLUGIN ROOT FILE PATH
    23  **---------------------------------------------------------------------------------------------------------------------------------
    24  * This variable it should not be changed because this will give you a global
    25  * way to read your plugin root file path and there are files depending on it
    26  * check config.php
    27  **----------------------------------------------------------------------------**/
    28 $__ROOT_FILE__ = __FILE__;
     20// Get plugin text domain all over the plugin
     21define( 'SFT_REL_TEXT_DOMAIN', 'softmixt-relations' );
    2922
    3023
    31 /**---------------------------------------------------------------------------------------------------------------------------------
    32  * PLUGIN CONFIG
    33  **---------------------------------------------------------------------------------------------------------------------------------
    34  * This file should only store configuration variables / globals, to make your
    35  * life easier now it store plugin root file configuration like . "Plugin Name",
    36  * "Version" , "Description", "Author", "Author URI", "Licence", "Licence URI",
    37  * "Text Domain", "Domain Path"
    38  *
    39  * @OBSERVATION : Please change "$plugin_name_settings" into more plugin
    40  *              appropriate name.
    41  **----------------------------------------------------------------------------**/
    42 require_once ( dirname ( __FILE__ ) . '/config.php' );
     24// Include Default Widget
     25require_once( dirname( __FILE__ ) . '/widgets/default/SFT_DefaultWidget.php' );
    4326
    4427
    45 /**---------------------------------------------------------------------------------------------------------------------------------
    46  * PLUGIN FUNCTIONS
    47  **---------------------------------------------------------------------------------------------------------------------------------
    48  * Here where we store entire plugin function  , the recommended functions can be
    49  * helper functions , database functions  mostly functions that will be used in
    50  * your public , admin classes .
    51  **----------------------------------------------------------------------------**/
    52 require_once ( dirname ( __FILE__ ) . '/includes/functions.php' );
     28// Load the plugin ...
     29add_action( 'plugins_loaded',
     30    function () {
    5331
    54 /**---------------------------------------------------------------------------------------------------------------------------------
    55  * ACTIVATOR / DEACTIVATOR
    56  **---------------------------------------------------------------------------------------------------------------------------------
    57  * This is where we define Plugin Activation / Deactivation hooks.
    58  *
    59  *
    60  **----------------------------------------------------------------------------**/
    61 require_once ( dirname ( __FILE__ ) . '/includes/activator.php' );
     32        // Load languages
     33        load_plugin_textdomain( SFT_REL_TEXT_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
    6234
    63 /**---------------------------------------------------------------------------------------------------------------------------------
    64  * ADMIN / PUBLIC
    65  **---------------------------------------------------------------------------------------------------------------------------------
    66  * Load Admin / Public classes, those classes are the ones where almost all of
    67  * your plugin logic code must be try to keep  them minimalistic ,clean and nice
    68  * commented.
    69  **----------------------------------------------------------------------------**/
    70 if ( is_admin () )
    71 {
    72     // Admin hooks / functions
    73     require_once ( dirname ( __FILE__ ) . '/admin/admin.php' );
    74 }
     35        // General functions, functions from this file are available for public and admin
     36        require_once( dirname( __FILE__ ) . '/includes/functions.php' );
    7537
    76 // Public hooks / functions
    77 require_once ( dirname ( __FILE__ ) . '/public/public.php' );
    78 
    79 // Include Default Widget
    80 require ( dirname ( __FILE__ ) . '/widgets/default/SFT_DefaultWidget.php' );
    81 
    82 /**---------------------------------------------------------------------------------------------------------------------------------
    83  * RUN PLUGIN
    84  **---------------------------------------------------------------------------------------------------------------------------------
    85  * We are going to initialize Admin / Public classes when plugin loaded hook triggered
    86  * which means  here is where
    87  * all our magic starts.
    88  *
    89  * @plugins_loaded :    This hook is called once any activated plugins have been loaded.
    90  *                      Is generally used for immediate filter setup, or plugin overrides.
    91  *                      The plugins_loaded action hook fires early, and precedes the
    92  *                      setup_theme, after_setup_theme, init and wp_loaded action hooks.
    93  *
    94  * @DOCUMENTATION  : https://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded
    95  *
    96  *
    97  *
    98  **--------------------------------------------------------------------------------------------------------------------------------**/
    99 add_action (
    100     'plugins_loaded' ,
    101     function ()
    102     {
    103         /**
    104          * Loads the plugin's translated strings.
    105          *
    106          * If the path is not given then it will be the root of the plugin directory.
    107          * The .mo file should be named based on the domain followed by a dash, and then the locale exactly.
    108          * For example, the locale for German is 'de_DE', and the locale for Danish is 'da_DK'.
    109          * If your plugin's text domain is "my-plugin" the Danish .mo and.po files should be named "my-plugin-da_DK.mo" and "my-plugin-da_DK.po"
    110          * Call this function in your plugin as early as the init action.
    111          *
    112          * If you call load_plugin_textdomain multiple times for the same domain, the translations will be merged.
    113          * If both sets have the same string, the translation from the original value will be taken.
    114          *
    115          * @DOCUMENTATION : https://codex.wordpress.org/Function_Reference/load_plugin_textdomain
    116          * @get_file_data : Searches for metadata in the first 8kiB of a file, such as a plugin or theme. Each piece of metadata must be on its own line.
    117          * Fields can not span multiple lines, the value will get cut at the end of the first line.
    118          * If the file data is not within that first 8kiB, then the author should correct their plugin file and move the data headers to the top.
    119          *
    120          * @DOCUMENTATION : https://developer.wordpress.org/reference/functions/get_file_data/
    121          */
    122         load_plugin_textdomain ( get_file_data ( __FILE__ , array ( 'text_domain' => 'Text Domain' ) )[ 'text_domain' ] , FALSE , dirname ( plugin_basename ( __FILE__ ) ) . '/languages/' );
    123 
    124         // Is Admin ...
    125         if ( is_admin () )
    126         {
     38        if ( is_admin() ) {
    12739            // Initialize Admin hooks
     40            require_once( dirname( __FILE__ ) . '/admin/admin.php' );
    12841            new SFT_Relations_Admin();
     42        } else {
     43            // Initialize Public hooks
     44            require_once( dirname( __FILE__ ) . '/public/public.php' );
     45            new SFT_Relations_Public();
    12946        }
    13047
    131         // Initialize Public hooks
    132         new SFT_Relations_Public();
    133     }
    134 );
     48    } );
    13549
    13650// HAPPY CODDING !!
  • softmixt-relations/trunk/widgets/default/SFT_DefaultWidget.php

    r1727679 r1870537  
    11<?php
    22
    3 class SFT_DefaultWidget extends WP_Widget
    4 {
    5 
     3class SFT_DefaultWidget extends WP_Widget {
    64
    75    /**
    86     * Register widget with WordPress.
    97     */
    10     function __construct ()
    11     {
    12         parent::__construct (
    13             'SFT_DefaultWidget' , // Base ID
    14             esc_html__ ( 'SFT Relations' , SFT_REL_TEXT_DOMAIN ) , // Name
    15             array ( 'description' => esc_html__ ( 'Show post/page related items' , SFT_REL_TEXT_DOMAIN ) , ) // Args
     8    function __construct() {
     9        parent::__construct(
     10            'SFT_DefaultWidget', // Base ID
     11            esc_html__( 'SFT Relations', SFT_REL_TEXT_DOMAIN ), // Name
     12            array( 'description' => esc_html__( 'Show post/page related items', SFT_REL_TEXT_DOMAIN ), ) // Args
    1613        );
    1714    }
     
    2219     * @see WP_Widget::widget()
    2320     *
    24      * @param array $args     Widget arguments.
     21     * @param array $args Widget arguments.
    2522     * @param array $instance Saved values from database.
    2623     */
    27     public function widget ( $args , $instance )
    28     {
     24    public function widget( $args, $instance ) {
    2925        global $post;
    3026
    31         echo $args[ 'before_widget' ];
    32         if ( ! empty( $instance[ 'sft_title' ] ) )
    33         {
    34             echo $args[ 'before_title' ] . apply_filters ( 'widget_title' , $instance[ 'sft_title' ] ) . $args[ 'after_title' ];
     27        echo $args['before_widget'];
     28        if ( ! empty( $instance['sft_title'] ) ) {
     29            echo $args['before_title'] . apply_filters( 'widget_title', $instance['sft_title'] ) . $args['after_title'];
    3530        }
    36         $sft_container_element       = ! empty( $instance[ 'sft_container_element' ] ) ? $instance[ 'sft_container_element' ] : 'div';
    37         $sft_container_class         = ! empty( $instance[ 'sft_container_class' ] ) ? $instance[ 'sft_container_class' ] : '';
    38         $sft_item_container_element  = ! empty( $instance[ 'sft_item_container_element' ] ) ? $instance[ 'sft_item_container_element' ] : 'div';
    39         $sft_item_title_element      = ! empty( $instance[ 'sft_item_title_element' ] ) ? $instance[ 'sft_item_title_element' ] : 'none';
    40         $sft_custom_item_class       = ! empty( $instance[ 'sft_custom_item_class' ] ) ? $instance[ 'sft_custom_item_class' ] : '';
    41         $sft_show_post_title         = isset( $instance[ 'sft_show_post_title' ] ) ? $instance[ 'sft_show_post_title' ] : 0;
    42         $sft_show_post_date          = isset( $instance[ 'sft_show_post_date' ] ) ? $instance[ 'sft_show_post_date' ] : 0;
    43         $sft_show_post_author        = isset( $instance[ 'sft_show_post_author' ] ) ? $instance[ 'sft_show_post_author' ] : 0;
    44         $sft_show_post_feature_image = isset( $instance[ 'sft_show_post_feature_image' ] ) ? $instance[ 'sft_show_post_feature_image' ] : 0;
    45         $sft_show_post_excerpt       = isset( $instance[ 'sft_show_post_excerpt' ] ) ? $instance[ 'sft_show_post_excerpt' ] : 0;
    46         $sft_show_post_content       = isset( $instance[ 'sft_show_post_content' ] ) ? $instance[ 'sft_show_post_content' ] : 0;
    47 
    48         do_shortcode (
     31        $sft_container_element            = ! empty( $instance['sft_container_element'] ) ? $instance['sft_container_element'] : 'div';
     32        $sft_container_class              = ! empty( $instance['sft_container_class'] ) ? $instance['sft_container_class'] : '';
     33        $sft_item_container_element       = ! empty( $instance['sft_item_container_element'] ) ? $instance['sft_item_container_element'] : 'div';
     34        $sft_item_title_element           = ! empty( $instance['sft_item_title_element'] ) ? $instance['sft_item_title_element'] : 'none';
     35        $sft_custom_item_class            = ! empty( $instance['sft_custom_item_class'] ) ? $instance['sft_custom_item_class'] : '';
     36        $sft_show_post_title              = isset( $instance['sft_show_post_title'] ) ? $instance['sft_show_post_title'] : 0;
     37        $sft_show_post_date               = isset( $instance['sft_show_post_date'] ) ? $instance['sft_show_post_date'] : 0;
     38        $sft_show_post_author             = isset( $instance['sft_show_post_author'] ) ? $instance['sft_show_post_author'] : 0;
     39        $sft_show_post_feature_image      = isset( $instance['sft_show_post_feature_image'] ) ? $instance['sft_show_post_feature_image'] : 0;
     40        $sft_show_post_excerpt            = isset( $instance['sft_show_post_excerpt'] ) ? $instance['sft_show_post_excerpt'] : 0;
     41        $sft_show_post_content            = isset( $instance['sft_show_post_content'] ) ? $instance['sft_show_post_content'] : 0;
     42        $sft_item_terms_container_element = ! empty( $instance['sft_item_terms_container_element'] ) ? $instance['sft_item_terms_container_element'] : '';
     43        $sft_item_terms_container_class   = ! empty( $instance['sft_item_terms_container_class'] ) ? $instance['sft_item_terms_container_class'] : '';
     44        $sft_item_term_container_element      = ! empty( $instance['sft_item_term_container_element'] ) ? $instance['sft_item_term_container_element'] : 'span';
     45        $sft_item_term_container_class = ! empty( $instance['sft_item_term_container_class'] ) ? $instance['sft_item_term_container_class'] : '';
     46
     47        echo do_shortcode(
    4948            '[sftrelations post_id="' .
    5049            $post->ID .
     
    6564            '" item_container_class="' .
    6665            $sft_custom_item_class .
     66            '" item_terms_container="' .
     67            $sft_item_terms_container_element .
     68            '" item_terms_container_class="' .
     69            $sft_item_terms_container_class .
     70            '" item_terms_container="' .
     71            $sft_item_term_container_element .
     72            '" item_term_container_class="' .
     73            $sft_item_term_container_class .
    6774            '" item_show_feature_image="' .
    6875            ( $sft_show_post_feature_image ? 'true' : 'false' ) .
     
    7481        );
    7582
    76         echo $args[ 'after_widget' ];
     83        echo $args['after_widget'];
    7784    }
    7885
     
    8491     * @param array $instance
    8592     */
    86     public function form ( $instance )
    87     {
    88         $sft_title                   = ! empty( $instance[ 'sft_title' ] ) ? $instance[ 'sft_title' ] : esc_html__ ( 'Related Posts' , SFT_REL_TEXT_DOMAIN );
    89         $sft_container_element       = ! empty( $instance[ 'sft_container_element' ] ) ? $instance[ 'sft_container_element' ] : 'div';
    90         $sft_container_class         = ! empty( $instance[ 'sft_container_class' ] ) ? $instance[ 'sft_container_class' ] : '';
    91         $sft_item_container_element  = ! empty( $instance[ 'sft_item_container_element' ] ) ? $instance[ 'sft_item_container_element' ] : 'div';
    92         $sft_item_title_element      = ! empty( $instance[ 'sft_item_title_element' ] ) ? $instance[ 'sft_item_title_element' ] : 'none';
    93         $sft_custom_item_class       = ! empty( $instance[ 'sft_custom_item_class' ] ) ? $instance[ 'sft_custom_item_class' ] : '';
    94         $sft_show_post_title         = isset( $instance[ 'sft_show_post_title' ] ) ? $instance[ 'sft_show_post_title' ] : 0;
    95         $sft_show_post_date          = isset( $instance[ 'sft_show_post_date' ] ) ? $instance[ 'sft_show_post_date' ] : 0;
    96         $sft_show_post_author        = isset( $instance[ 'sft_show_post_author' ] ) ? $instance[ 'sft_show_post_author' ] : 0;
    97         $sft_show_post_feature_image = isset( $instance[ 'sft_show_post_feature_image' ] ) ? $instance[ 'sft_show_post_feature_image' ] : 0;
    98         $sft_show_post_excerpt       = isset( $instance[ 'sft_show_post_excerpt' ] ) ? $instance[ 'sft_show_post_excerpt' ] : 0;
    99         $sft_show_post_content       = isset( $instance[ 'sft_show_post_content' ] ) ? $instance[ 'sft_show_post_content' ] : 0;
    100         $html_elements               = [
    101             'div'     => 'Div' ,
    102             'ul'      => 'Ul' ,
    103             'li'      => 'Li' ,
    104             'section' => 'Section' ,
    105             'article' => 'Article' ,
     93    public function form( $instance ) {
     94        $sft_title                        = ! empty( $instance['sft_title'] ) ? $instance['sft_title'] : esc_html__( 'Related Posts', SFT_REL_TEXT_DOMAIN );
     95        $sft_container_element            = ! empty( $instance['sft_container_element'] ) ? $instance['sft_container_element'] : 'div';
     96        $sft_container_class              = ! empty( $instance['sft_container_class'] ) ? $instance['sft_container_class'] : '';
     97        $sft_item_container_element       = ! empty( $instance['sft_item_container_element'] ) ? $instance['sft_item_container_element'] : 'div';
     98        $sft_item_title_element           = ! empty( $instance['sft_item_title_element'] ) ? $instance['sft_item_title_element'] : 'none';
     99        $sft_custom_item_class            = ! empty( $instance['sft_custom_item_class'] ) ? $instance['sft_custom_item_class'] : '';
     100        $sft_show_post_title              = isset( $instance['sft_show_post_title'] ) ? $instance['sft_show_post_title'] : 0;
     101        $sft_show_post_date               = isset( $instance['sft_show_post_date'] ) ? $instance['sft_show_post_date'] : 0;
     102        $sft_show_post_author             = isset( $instance['sft_show_post_author'] ) ? $instance['sft_show_post_author'] : 0;
     103        $sft_show_post_feature_image      = isset( $instance['sft_show_post_feature_image'] ) ? $instance['sft_show_post_feature_image'] : 0;
     104        $sft_show_post_excerpt            = isset( $instance['sft_show_post_excerpt'] ) ? $instance['sft_show_post_excerpt'] : 0;
     105        $sft_show_post_content            = isset( $instance['sft_show_post_content'] ) ? $instance['sft_show_post_content'] : 0;
     106        $sft_item_terms_container_element = ! empty( $instance['sft_item_terms_container_element'] ) ? $instance['sft_item_terms_container_element'] : '';
     107        $sft_item_terms_container_class   = ! empty( $instance['sft_item_terms_container_class'] ) ? $instance['sft_item_terms_container_class'] : '';
     108        $sft_item_term_container_element      = ! empty( $instance['sft_item_term_container_element'] ) ? $instance['sft_item_term_container_element'] : 'span';
     109        $sft_item_term_container_class = ! empty( $instance['sft_item_term_container_class'] ) ? $instance['sft_item_term_container_class'] : '';
     110
     111        $html_elements = [
     112            'span'    => 'Span',
     113            'div'     => 'Div',
     114            'ul'      => 'Ul',
     115            'li'      => 'Li',
     116            'section' => 'Section',
     117            'article' => 'Article',
    106118        ];
    107119
    108120        $html_title_elements = [
    109             'none' => 'None' ,
    110             'h1'   => 'H1' ,
    111             'h2'   => 'H2' ,
    112             'h3'   => 'H3' ,
    113             'h4'   => 'H4' ,
    114             'h5'   => 'H5' ,
    115             'h6'   => 'H6' ,
    116             'p'    => 'Paragraph' ,
    117             'span' => 'Span' ,
     121            'none' => 'None',
     122            'h1'   => 'H1',
     123            'h2'   => 'H2',
     124            'h3'   => 'H3',
     125            'h4'   => 'H4',
     126            'h5'   => 'H5',
     127            'h6'   => 'H6',
     128            'p'    => 'Paragraph',
     129            'span' => 'Span',
    118130        ];
    119131
    120132        ?>
    121         <p>
    122             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_title' ) ); ?>"><?php esc_attr_e ( 'Title:' , SFT_REL_TEXT_DOMAIN ); ?></label>
    123             <input class="widefat" id="<?php echo esc_attr ( $this->get_field_id ( 'sft_title' ) ); ?>" name="<?php echo esc_attr ( $this->get_field_name ( 'sft_title' ) ); ?>" type="text" value="<?php echo esc_attr ( $sft_title ); ?>">
    124         </p>
    125         <p>
    126             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_container_element' ) ); ?>"><?php esc_attr_e ( 'Container element:' , SFT_REL_TEXT_DOMAIN ); ?></label>
    127             <select id="<?php echo $this->get_field_id ( 'sft_container_element' ); ?>" name="<?php echo $this->get_field_name ( 'sft_container_element' ); ?>" class="widefat" style="width:100%;">
     133        <p>
     134            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_title' ) ); ?>"><?php esc_attr_e( 'Title:', SFT_REL_TEXT_DOMAIN ); ?></label>
     135            <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'sft_title' ) ); ?>"
     136                   name="<?php echo esc_attr( $this->get_field_name( 'sft_title' ) ); ?>" type="text"
     137                   value="<?php echo esc_attr( $sft_title ); ?>">
     138        </p>
     139        <p>
     140            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_container_element' ) ); ?>"><?php esc_attr_e( 'Container element:', SFT_REL_TEXT_DOMAIN ); ?></label>
     141            <select id="<?php echo $this->get_field_id( 'sft_container_element' ); ?>"
     142                    name="<?php echo $this->get_field_name( 'sft_container_element' ); ?>" class="widefat"
     143                    style="width:100%;">
    128144                <?php foreach ( $html_elements as $elm => $elm_name ) : ?>
    129                     <option <?php selected ( $sft_container_element , $elm ); ?> value="<?php echo $elm; ?>"><?php echo $elm_name; ?></option>
    130                 <?php endforeach; ?>
    131             </select>
    132         </p>
    133         <p>
    134             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_container_class' ) ); ?>"><?php esc_attr_e ( 'Custom container class:' , SFT_REL_TEXT_DOMAIN ); ?></label>
    135             <input class="widefat" id="<?php echo esc_attr ( $this->get_field_id ( 'sft_container_class' ) ); ?>" name="<?php echo esc_attr ( $this->get_field_name ( 'sft_container_class' ) ); ?>" type="text" value="<?php echo esc_attr ( $sft_container_class ); ?>">
    136         </p>
    137         <p>
    138             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_item_title_element' ) ); ?>"><?php esc_attr_e ( 'Custom container item title element:' , SFT_REL_TEXT_DOMAIN ); ?></label>
    139             <select id="<?php echo $this->get_field_id ( 'sft_item_title_element' ); ?>" name="<?php echo $this->get_field_name ( 'sft_item_title_element' ); ?>" class="widefat" style="width:100%;">
     145                    <option <?php selected( $sft_container_element, $elm ); ?>
     146                            value="<?php echo $elm; ?>"><?php echo $elm_name; ?></option>
     147                <?php endforeach; ?>
     148            </select>
     149        </p>
     150        <p>
     151            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_container_class' ) ); ?>"><?php esc_attr_e( 'Custom container class:', SFT_REL_TEXT_DOMAIN ); ?></label>
     152            <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'sft_container_class' ) ); ?>"
     153                   name="<?php echo esc_attr( $this->get_field_name( 'sft_container_class' ) ); ?>" type="text"
     154                   value="<?php echo esc_attr( $sft_container_class ); ?>">
     155        </p>
     156        <p>
     157            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_item_title_element' ) ); ?>"><?php esc_attr_e( 'Custom container item title element:', SFT_REL_TEXT_DOMAIN ); ?></label>
     158            <select id="<?php echo $this->get_field_id( 'sft_item_title_element' ); ?>"
     159                    name="<?php echo $this->get_field_name( 'sft_item_title_element' ); ?>" class="widefat"
     160                    style="width:100%;">
    140161                <?php foreach ( $html_title_elements as $elm => $elm_name ) : ?>
    141                     <option <?php selected ( $sft_item_title_element , $elm ); ?> value="<?php echo $elm; ?>"><?php echo $elm_name; ?></option>
    142                 <?php endforeach; ?>
    143             </select>
    144         </p>
    145         <p>
    146             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_item_container_element' ) ); ?>"><?php esc_attr_e ( 'Item container element:' , SFT_REL_TEXT_DOMAIN ); ?></label>
    147             <select id="<?php echo $this->get_field_id ( 'sft_item_container_element' ); ?>" name="<?php echo $this->get_field_name ( 'sft_item_container_element' ); ?>" class="widefat" style="width:100%;">
     162                    <option <?php selected( $sft_item_title_element, $elm ); ?>
     163                            value="<?php echo $elm; ?>"><?php echo $elm_name; ?></option>
     164                <?php endforeach; ?>
     165            </select>
     166        </p>
     167        <p>
     168            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_item_container_element' ) ); ?>"><?php esc_attr_e( 'Item container element:', SFT_REL_TEXT_DOMAIN ); ?></label>
     169            <select id="<?php echo $this->get_field_id( 'sft_item_container_element' ); ?>"
     170                    name="<?php echo $this->get_field_name( 'sft_item_container_element' ); ?>" class="widefat"
     171                    style="width:100%;">
    148172                <?php foreach ( $html_elements as $elm => $elm_name ) : ?>
    149                     <option <?php selected ( $sft_item_container_element , $elm ); ?> value="<?php echo $elm; ?>"><?php echo $elm_name; ?></option>
    150                 <?php endforeach; ?>
    151             </select>
    152         </p>
    153         <p>
    154             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_custom_item_class' ) ); ?>"><?php esc_attr_e ( 'Custom item class:' , SFT_REL_TEXT_DOMAIN ); ?></label>
    155             <input class="widefat" id="<?php echo esc_attr ( $this->get_field_id ( 'sft_custom_item_class' ) ); ?>" name="<?php echo esc_attr ( $this->get_field_name ( 'sft_custom_item_class' ) ); ?>" type="text" value="<?php echo esc_attr ( $sft_custom_item_class ); ?>">
    156         </p>
    157         <span><?php esc_attr_e ( 'Show post meta:' , SFT_REL_TEXT_DOMAIN ); ?></span>
    158         <p>
    159             <input class="checkbox" type="checkbox" <?php checked ( $sft_show_post_title ); ?> id="<?php echo $this->get_field_id ( 'sft_show_post_title' ); ?>" name="<?php echo $this->get_field_name ( 'sft_show_post_title' ); ?>"/>
    160             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_show_post_title' ) ); ?>"><?php esc_attr_e ( 'Show post title' , SFT_REL_TEXT_DOMAIN ); ?></label>
    161         </p>
    162         <p>
    163             <input class="checkbox" type="checkbox" <?php checked ( $sft_show_post_date ); ?> id="<?php echo $this->get_field_id ( 'sft_show_post_date' ); ?>" name="<?php echo $this->get_field_name ( 'sft_show_post_date' ); ?>"/>
    164             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_show_post_date' ) ); ?>"><?php esc_attr_e ( 'Show post date' , SFT_REL_TEXT_DOMAIN ); ?></label>
    165         </p>
    166         <p>
    167             <input class="checkbox" type="checkbox" <?php checked ( $sft_show_post_author ); ?> id="<?php echo $this->get_field_id ( 'sft_show_post_author' ); ?>" name="<?php echo $this->get_field_name ( 'sft_show_post_author' ); ?>"/>
    168             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_show_post_author' ) ); ?>"><?php esc_attr_e ( 'Show post author' , SFT_REL_TEXT_DOMAIN ); ?></label>
    169         </p>
    170         <p>
    171             <input class="checkbox" type="checkbox" <?php checked ( $sft_show_post_feature_image ); ?> id="<?php echo $this->get_field_id ( 'sft_show_post_feature_image' ); ?>" name="<?php echo $this->get_field_name ( 'sft_show_post_feature_image' ); ?>"/>
    172             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_show_post_feature_image' ) ); ?>"><?php esc_attr_e ( 'Show post feature image' , SFT_REL_TEXT_DOMAIN ); ?></label>
    173         </p>
    174         <p>
    175             <input class="checkbox" type="checkbox" <?php checked ( $sft_show_post_excerpt ); ?> id="<?php echo $this->get_field_id ( 'sft_show_post_excerpt' ); ?>" name="<?php echo $this->get_field_name ( 'sft_show_post_excerpt' ); ?>"/>
    176             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_show_post_excerpt' ) ); ?>"><?php esc_attr_e ( 'Show post excerpt' , SFT_REL_TEXT_DOMAIN ); ?></label>
    177         </p>
    178         <p>
    179             <input class="checkbox" type="checkbox" <?php checked ( $sft_show_post_content ); ?> id="<?php echo $this->get_field_id ( 'sft_show_post_content' ); ?>" name="<?php echo $this->get_field_name ( 'sft_show_post_content' ); ?>"/>
    180             <label for="<?php echo esc_attr ( $this->get_field_id ( 'sft_show_post_content' ) ); ?>"><?php esc_attr_e ( 'Show post content' , SFT_REL_TEXT_DOMAIN ); ?></label>
    181         </p>
     173                    <option <?php selected( $sft_item_container_element, $elm ); ?>
     174                            value="<?php echo $elm; ?>"><?php echo $elm_name; ?></option>
     175                <?php endforeach; ?>
     176            </select>
     177        </p>
     178        <p>
     179            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_custom_item_class' ) ); ?>"><?php esc_attr_e( 'Custom item class:', SFT_REL_TEXT_DOMAIN ); ?></label>
     180            <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'sft_custom_item_class' ) ); ?>"
     181                   name="<?php echo esc_attr( $this->get_field_name( 'sft_custom_item_class' ) ); ?>" type="text"
     182                   value="<?php echo esc_attr( $sft_custom_item_class ); ?>">
     183        </p>
     184        <span><?php esc_attr_e( 'Show post meta:', SFT_REL_TEXT_DOMAIN ); ?></span>
     185        <p>
     186            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_item_terms_container_element' ) ); ?>"><?php esc_attr_e( 'Item terms container element:', SFT_REL_TEXT_DOMAIN ); ?></label>
     187            <select id="<?php echo $this->get_field_id( 'sft_item_terms_container_element' ); ?>"
     188                    name="<?php echo $this->get_field_name( 'sft_item_terms_container_element' ); ?>" class="widefat"
     189                    style="width:100%;">
     190                <?php foreach ( $html_elements as $elm => $elm_name ) : ?>
     191                    <option <?php selected( $sft_item_terms_container_element, $elm ); ?>
     192                            value="<?php echo $elm; ?>"><?php echo $elm_name; ?></option>
     193                <?php endforeach; ?>
     194            </select>
     195        </p>
     196        <p>
     197            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_item_terms_container_class' ) ); ?>"><?php esc_attr_e( 'Custom item terms container class:', SFT_REL_TEXT_DOMAIN ); ?></label>
     198            <input class="widefat"
     199                   id="<?php echo esc_attr( $this->get_field_id( 'sft_item_terms_container_class' ) ); ?>"
     200                   name="<?php echo esc_attr( $this->get_field_name( 'sft_item_terms_container_class' ) ); ?>"
     201                   type="text"
     202                   value="<?php echo esc_attr( $sft_item_terms_container_class ); ?>">
     203        </p>
     204        <p>
     205            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_item_term_container_element' ) ); ?>"><?php esc_attr_e( 'Item term container element:', SFT_REL_TEXT_DOMAIN ); ?></label>
     206            <select id="<?php echo $this->get_field_id( 'sft_item_term_container_element' ); ?>"
     207                    name="<?php echo $this->get_field_name( 'sft_item_term_container_element' ); ?>" class="widefat"
     208                    style="width:100%;">
     209                <?php foreach ( $html_elements as $elm => $elm_name ) : ?>
     210                    <option <?php selected( $sft_item_term_container_element, $elm ); ?>
     211                            value="<?php echo $elm; ?>"><?php echo $elm_name; ?></option>
     212                <?php endforeach; ?>
     213            </select>
     214        </p>
     215        <p>
     216            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_item_term_container_class' ) ); ?>"><?php esc_attr_e( 'Custom item term container class:', SFT_REL_TEXT_DOMAIN ); ?></label>
     217            <input class="widefat"
     218                   id="<?php echo esc_attr( $this->get_field_id( 'sft_item_term_container_class' ) ); ?>"
     219                   name="<?php echo esc_attr( $this->get_field_name( 'sft_item_term_container_class' ) ); ?>"
     220                   type="text"
     221                   value="<?php echo esc_attr( $sft_item_term_container_class ); ?>">
     222        </p>
     223        <p>
     224            <input class="checkbox" type="checkbox" <?php checked( $sft_show_post_title ); ?>
     225                   id="<?php echo $this->get_field_id( 'sft_show_post_title' ); ?>"
     226                   name="<?php echo $this->get_field_name( 'sft_show_post_title' ); ?>"/>
     227            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_show_post_title' ) ); ?>"><?php esc_attr_e( 'Show post title', SFT_REL_TEXT_DOMAIN ); ?></label>
     228        </p>
     229        <p>
     230            <input class="checkbox" type="checkbox" <?php checked( $sft_show_post_date ); ?>
     231                   id="<?php echo $this->get_field_id( 'sft_show_post_date' ); ?>"
     232                   name="<?php echo $this->get_field_name( 'sft_show_post_date' ); ?>"/>
     233            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_show_post_date' ) ); ?>"><?php esc_attr_e( 'Show post date', SFT_REL_TEXT_DOMAIN ); ?></label>
     234        </p>
     235        <p>
     236            <input class="checkbox" type="checkbox" <?php checked( $sft_show_post_author ); ?>
     237                   id="<?php echo $this->get_field_id( 'sft_show_post_author' ); ?>"
     238                   name="<?php echo $this->get_field_name( 'sft_show_post_author' ); ?>"/>
     239            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_show_post_author' ) ); ?>"><?php esc_attr_e( 'Show post author', SFT_REL_TEXT_DOMAIN ); ?></label>
     240        </p>
     241        <p>
     242            <input class="checkbox" type="checkbox" <?php checked( $sft_show_post_feature_image ); ?>
     243                   id="<?php echo $this->get_field_id( 'sft_show_post_feature_image' ); ?>"
     244                   name="<?php echo $this->get_field_name( 'sft_show_post_feature_image' ); ?>"/>
     245            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_show_post_feature_image' ) ); ?>"><?php esc_attr_e( 'Show post feature image', SFT_REL_TEXT_DOMAIN ); ?></label>
     246        </p>
     247        <p>
     248            <input class="checkbox" type="checkbox" <?php checked( $sft_show_post_excerpt ); ?>
     249                   id="<?php echo $this->get_field_id( 'sft_show_post_excerpt' ); ?>"
     250                   name="<?php echo $this->get_field_name( 'sft_show_post_excerpt' ); ?>"/>
     251            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_show_post_excerpt' ) ); ?>"><?php esc_attr_e( 'Show post excerpt', SFT_REL_TEXT_DOMAIN ); ?></label>
     252        </p>
     253        <p>
     254            <input class="checkbox" type="checkbox" <?php checked( $sft_show_post_content ); ?>
     255                   id="<?php echo $this->get_field_id( 'sft_show_post_content' ); ?>"
     256                   name="<?php echo $this->get_field_name( 'sft_show_post_content' ); ?>"/>
     257            <label for="<?php echo esc_attr( $this->get_field_id( 'sft_show_post_content' ) ); ?>"><?php esc_attr_e( 'Show post content', SFT_REL_TEXT_DOMAIN ); ?></label>
     258        </p>
    182259
    183260        <?php
     
    195272     * @return array Updated safe values to be saved.
    196273     */
    197     public function update ( $new_instance , $old_instance )
    198     {
    199         $instance                                  = array ();
    200         $instance[ 'sft_title' ]                   = ( ! empty( $new_instance[ 'sft_title' ] ) ) ? strip_tags ( $new_instance[ 'sft_title' ] ) : '';
    201         $instance[ 'sft_container_element' ]       = ( ! empty( $new_instance[ 'sft_container_element' ] ) ) ? strip_tags ( $new_instance[ 'sft_container_element' ] ) : '';
    202         $instance[ 'sft_container_class' ]         = ( ! empty( $new_instance[ 'sft_container_class' ] ) ) ? strip_tags ( $new_instance[ 'sft_container_class' ] ) : '';
    203         $instance[ 'sft_item_container_element' ]  = ( ! empty( $new_instance[ 'sft_item_container_element' ] ) ) ? strip_tags ( $new_instance[ 'sft_item_container_element' ] ) : '';
    204         $instance[ 'sft_item_title_element' ]      = ( ! empty( $new_instance[ 'sft_item_title_element' ] ) ) ? strip_tags ( $new_instance[ 'sft_item_title_element' ] ) : 'none';
    205         $instance[ 'sft_custom_item_class' ]       = ( ! empty( $new_instance[ 'sft_custom_item_class' ] ) ) ? strip_tags ( $new_instance[ 'sft_custom_item_class' ] ) : '';
    206         $instance[ 'sft_show_post_title' ]         = isset( $new_instance[ 'sft_show_post_title' ] ) ? 1 : 0;
    207         $instance[ 'sft_show_post_date' ]          = isset( $new_instance[ 'sft_show_post_date' ] ) ? 1 : 0;
    208         $instance[ 'sft_show_post_author' ]        = isset( $new_instance[ 'sft_show_post_author' ] ) ? 1 : 0;
    209         $instance[ 'sft_show_post_feature_image' ] = isset( $new_instance[ 'sft_show_post_feature_image' ] ) ? 1 : 0;
    210         $instance[ 'sft_show_post_excerpt' ]       = isset( $new_instance[ 'sft_show_post_excerpt' ] ) ? 1 : 0;
    211         $instance[ 'sft_show_post_content' ]       = isset( $new_instance[ 'sft_show_post_content' ] ) ? 1 : 0;
     274    public function update( $new_instance, $old_instance ) {
     275        $instance                                         = array();
     276        $instance['sft_title']                            = ( ! empty( $new_instance['sft_title'] ) ) ? strip_tags( $new_instance['sft_title'] ) : '';
     277        $instance['sft_container_element']                = ( ! empty( $new_instance['sft_container_element'] ) ) ? strip_tags( $new_instance['sft_container_element'] ) : '';
     278        $instance['sft_container_class']                  = ( ! empty( $new_instance['sft_container_class'] ) ) ? strip_tags( $new_instance['sft_container_class'] ) : '';
     279        $instance['sft_item_container_element']           = ( ! empty( $new_instance['sft_item_container_element'] ) ) ? strip_tags( $new_instance['sft_item_container_element'] ) : '';
     280        $instance['sft_item_title_element']               = ( ! empty( $new_instance['sft_item_title_element'] ) ) ? strip_tags( $new_instance['sft_item_title_element'] ) : 'none';
     281        $instance['sft_custom_item_class']                = ( ! empty( $new_instance['sft_custom_item_class'] ) ) ? strip_tags( $new_instance['sft_custom_item_class'] ) : '';
     282        $instance['sft_show_post_title']                  = isset( $new_instance['sft_show_post_title'] ) ? 1 : 0;
     283        $instance['sft_show_post_date']                   = isset( $new_instance['sft_show_post_date'] ) ? 1 : 0;
     284        $instance['sft_show_post_author']                 = isset( $new_instance['sft_show_post_author'] ) ? 1 : 0;
     285        $instance['sft_show_post_feature_image']          = isset( $new_instance['sft_show_post_feature_image'] ) ? 1 : 0;
     286        $instance['sft_show_post_excerpt']                = isset( $new_instance['sft_show_post_excerpt'] ) ? 1 : 0;
     287        $instance['sft_show_post_content']                = isset( $new_instance['sft_show_post_content'] ) ? 1 : 0;
     288        $instance['sft_item_terms_container_element']     = ( ! empty( $new_instance['sft_item_terms_container_element'] ) ) ? strip_tags( $new_instance['sft_item_terms_container_element'] ) : '';
     289        $instance['sft_item_terms_container_class']       = ( ! empty( $new_instance['sft_item_terms_container_class'] ) ) ? strip_tags( $new_instance['sft_item_terms_container_class'] ) : '';
     290        $instance['sft_item_term_container_element']      = ( ! empty( $new_instance['sft_item_term_container_element'] ) ) ? strip_tags( $new_instance['sft_item_term_container_element'] ) : '';
     291        $instance['sft_item_term_container_class']        = ( ! empty( $new_instance['sft_item_term_container_class'] ) ) ? strip_tags( $new_instance['sft_item_term_container_class'] ) : '';
    212292
    213293        return $instance;
     
    216296}
    217297
    218 add_action (
    219     'widgets_init' ,
    220     function ()
    221     {
    222         register_widget ( 'SFT_DefaultWidget' );
     298add_action(
     299    'widgets_init',
     300    function () {
     301        register_widget( 'SFT_DefaultWidget' );
    223302    }
    224303);
Note: See TracChangeset for help on using the changeset viewer.