function form($instance) { // get registered actions $actions = wpsight_listing_title_actions(); //$instance = wp_parse_args( (array) $instance, $defaults ); $title = '[' . __('Listing Title', 'wpsight') . ']'; ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="hidden" value="<?php echo esc_attr($title); ?> " /> <?php foreach ($actions as $action => $v) { ?> <p> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('title_' . $action); ?> " name="<?php echo $this->get_field_name('title_' . $action); ?> " <?php echo isset($instance['title_' . $action]) ? 'checked' : ''; ?> /> <label for="<?php echo $this->get_field_id('title_' . $action); ?> "><?php _e('Display:', 'wpsight'); echo ' ' . ucfirst($action); ?> </label> </p> <?php } }
function wpsight_do_listing_title_actions($args = false, $instance = false) { // Only on single listing page if (!is_listing_single()) { return; } // Don't show when password required if (post_password_required()) { return; } // Get Title Actions $actions = wpsight_listing_title_actions(); // Generate Output $output = '<div class="title-actions">'; // If user is logged in if (isset($_SESSION['feUser'])) { global $wpdb; // Define table name $feUsersTableName = $wpdb->prefix . 'fe_users_favorite'; if (function_exists('icl_object_id')) { global $sitepress; // Get main id of the property for translated post $propMainId = icl_object_id(get_the_id(), 'post', true, $sitepress->get_default_language()); } else { $propMainId = get_the_ID(); } // Check if user has favorited current property $userId = $_SESSION['feUser']['id']; $findUserSql = "select `id` from {$feUsersTableName} where `user_id` = '{$userId}' and `property_id` = '{$propMainId}'"; $arrResult = $wpdb->get_row($findUserSql); $output .= '<div class="title-action title-action-' . $action . '">'; if (!$arrResult->id) { // add custom favorite button $output .= '<a href="#" id="favorite-button" class="btn btn-mini actions-favorites action-link" data-id="' . $propMainId . '">'; // check if icon is available $output .= '<i class="fa fa-star-o"></i>'; $output .= '<span class="favorite-text">' . __('Save', 'wpsight') . '</span>'; $output .= '<span class="un-favorite-text" style="display: none">' . __('Remove', 'wpsight') . '</span>'; $output .= '</a>'; } else { // add un-favorite button $output .= '<a href="#" id="favorite-button" class="favorited btn btn-mini actions-favorites action-link" data-id="' . $propMainId . '">'; // check if icon is available $output .= '<i class="fa fa-star"></i>'; $output .= '<span class="favorite-text" style="display: none">' . __('Save', 'wpsight') . '</span>'; $output .= '<span class="un-favorite-text">' . __('Remove', 'wpsight') . '</span>'; $output .= '</a>'; } $output .= '</div>'; } if (isset($_SESSION['feUser'])) { // Remove default favorite button if fe user if (isset($instance['title_favorites'])) { unset($instance['title_favorites']); } } foreach ($actions as $action => $v) { //if($action == 'print') { // check if option is active if (!isset($instance['title_' . $action])) { continue; } $output .= '<div class="title-action title-action-' . $action . '">'; // check if callback function in use or not if (isset($v['cb']) && is_callable($v['cb'])) { $output .= call_user_func($v['cb'], $v); } else { $output .= '<a href="' . $v['href'] . '" id="' . $v['id'] . '" class="' . $v['class'] . '" target="' . $v['target'] . '" ' . $v['atts'] . '>'; // check if icon is available if ($v['icon']) { $output .= '<i class="' . $v['icon'] . '"></i>'; } $output .= $v['label']; $output .= '</a>'; } $output .= '</div>'; //} } $output .= '</div>'; // echo output echo $output; }