Esempio n. 1
0
 function fix_permalink($url, $post)
 {
     if (is_sp_post_type(get_post_type($post)) && 1 !== get_current_blog_id()) {
         return str_replace(get_site_url() . '/blog', get_site_url(), $url);
     }
     return $url;
 }
 function post_row_action($actions, $post)
 {
     if ($this->allowed($post->post_type) && is_sp_post_type($post->post_type)) {
         $actions = array_slice($actions, 0, 2, true) + array('duplicate' => '<a href="' . $this->link($post) . '" title="' . esc_attr__('Duplicate this item', 'sportspress') . '">' . __('Duplicate', 'sportspress') . '</a>') + array_slice($actions, 2, NULL, true);
     }
     return $actions;
 }
 /**
  * Change messages when a post type is updated.
  *
  * @param  array $messages
  * @return array
  */
 public function post_updated_messages($messages)
 {
     global $typenow, $post;
     if (is_sp_config_type($typenow)) {
         $obj = get_post_type_object($typenow);
         for ($i = 0; $i <= 10; $i++) {
             $messages['post'][$i] = __('Settings saved.', 'sportspress') . ' <a href="' . esc_url(admin_url('edit.php?post_type=' . $typenow)) . '">' . __('View All', 'sportspress') . '</a>';
         }
     } elseif (is_sp_post_type($typenow)) {
         $obj = get_post_type_object($typenow);
         $messages['post'][1] = __('Changes saved.', 'sportspress') . ' <a href="' . esc_url(get_permalink($post->ID)) . '">' . $obj->labels->view_item . '</a>';
         $messages['post'][4] = __('Changes saved.', 'sportspress');
         $messages['post'][6] = __('Success!', 'sportspress') . ' <a href="' . esc_url(get_permalink($post->ID)) . '">' . $obj->labels->view_item . '</a>';
         $messages['post'][7] = __('Changes saved.', 'sportspress');
         $messages['post'][8] = __('Success!', 'sportspress') . ' <a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($post->ID))) . '">' . sprintf(__('Preview %s', 'sportspress'), $obj->labels->singular_name) . '</a>';
         $messages['post'][9] = sprintf(__('Scheduled for: <b>%1$s</b>.', 'sportspress'), date_i18n(__('M j, Y @ G:i', 'sportspress'), strtotime($post->post_date)), esc_url(get_permalink($post->ID))) . ' <a target="_blank" href="' . esc_url(get_permalink($post->ID)) . '">' . sprintf(__('Preview %s', 'sportspress'), $obj->labels->singular_name) . '</a>';
         $messages['post'][10] = __('Success!', 'sportspress') . ' <a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($post->ID))) . '">' . sprintf(__('Preview %s', 'sportspress'), $obj->labels->singular_name) . '</a>';
     }
     return $messages;
 }
 /**
  * Load a template.
  *
  * Handles template usage so that we can use our own templates instead of the themes.
  *
  * Templates are in the 'templates' folder. sportspress looks for theme
  * overrides in /theme/sportspress/ by default
  *
  * For beginners, it also looks for a sportspress.php template last. If the user adds
  * this to the theme (containing a sportspress() inside) this will be used as a
  * fallback for all sportspress templates.
  *
  * @param mixed $template
  * @return string
  */
 public function template_loader($template)
 {
     $find = array();
     $file = '';
     if (is_single()) {
         $post_type = get_post_type();
         if (is_sp_post_type($post_type)) {
             $file = 'single-' . str_replace('sp_', '', $post_type) . '.php';
             $find[] = $file;
             $find[] = SP_TEMPLATE_PATH . $file;
         }
     } elseif (is_tax()) {
         $term = get_queried_object();
         switch ($term->taxonomy) {
             case 'sp_venue':
                 $file = 'taxonomy-venue.php';
                 $find[] = 'taxonomy-venue-' . $term->slug . '.php';
                 $find[] = SP_TEMPLATE_PATH . 'taxonomy-venue-' . $term->slug . '.php';
                 $find[] = $file;
                 $find[] = SP_TEMPLATE_PATH . $file;
         }
     }
     $find[] = 'sportspress.php';
     if ($file) {
         $located = locate_template($find);
         if ($located) {
             $template = $located;
         }
     }
     return $template;
 }
function sportspress_remove_page_parent_class($classes, $item)
{
    if ((is_sp_post_type(get_post_type()) && ($key = array_search('current_page_parent', $classes))) !== false) {
        unset($classes[$key]);
    }
    return $classes;
}
Esempio n. 6
0
function prosports_pre_get_posts($query)
{
    $post_type = sp_array_value($query->query, 'post_type', null);
    if (is_sp_post_type($post_type)) {
        $query->set('suppress_filters', 0);
    }
    if (is_admin()) {
        if (isset($query->query['orderby']) || isset($query->query['order'])) {
            return $query;
        }
        if (is_sp_config_type($post_type)) {
            $query->set('orderby', 'menu_order');
            $query->set('order', 'ASC');
        }
    } else {
        if (isset($query->query['sp_venue'])) {
            $GLOBALS['wp_post_statuses']['future']->public = true;
        }
    }
    return $query;
}
 /**
  * Check if we're saving, then trigger an action based on the post type
  *
  * @param  int $post_id
  * @param  object $post
  */
 public function save_meta_boxes($post_id, $post)
 {
     if (empty($post_id) || empty($post)) {
         return;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     if (is_int(wp_is_post_revision($post))) {
         return;
     }
     if (is_int(wp_is_post_autosave($post))) {
         return;
     }
     if (empty($_POST['sportspress_meta_nonce']) || !wp_verify_nonce($_POST['sportspress_meta_nonce'], 'sportspress_save_data')) {
         return;
     }
     if (!apply_filters('sportspress_user_can', current_user_can('edit_post', $post_id), $post_id)) {
         return;
     }
     if (!is_sp_post_type($post->post_type) && !is_sp_config_type($post->post_type)) {
         return;
     }
     do_action('sportspress_process_' . $post->post_type . '_meta', $post_id, $post);
 }
 /**
  * Load page template.
  */
 public function template_loader($template)
 {
     if (is_single()) {
         $post_type = get_post_type();
         if (is_sp_post_type($post_type)) {
             $option = get_option('sportspress_' . str_replace('sp_', '', $post_type) . '_page_template', 'default');
             if ('default' !== $option) {
                 $new_template = locate_template(array($option));
                 if ('' != $new_template) {
                     return $new_template;
                 }
             }
         }
     }
     return $template;
 }
 public static function can_localize($post, $id = null)
 {
     return function_exists('icl_object_id') && is_sp_post_type(get_post_type($post));
 }
 /**
  * Filter admin access by team.
  *
  * @param mixed $query
  */
 public function filter($query)
 {
     // Return if not admin
     if (!is_admin()) {
         return $query;
     }
     // Return if not SportsPress post type
     if (!is_sp_post_type()) {
         return $query;
     }
     // Return if limit doesn't apply to user and post type
     global $current_user;
     $post_type = sp_array_value($query->query_vars, 'post_type', 'post');
     $roles = $current_user->roles;
     $role = array_shift($roles);
     if (!$this->role_is_limited($role) || !$this->limit_applies($post_type)) {
         return $query;
     }
     // Get current user team setting and return if not set
     $user = wp_get_current_user();
     $teams = get_user_meta($user->ID, 'sp_team', false);
     if (!$teams || !is_array($teams)) {
         return $query;
     }
     $query = $this->query($query, $teams, $post_type);
     return $query;
 }