* @license GPL-2.0+ * @link http://tovolt.com * @copyright 2014 ToVolt */ // AnsPress options function ap_opt($key){ $settings = get_option( 'anspress_opt'); if(isset($settings[$key])) return $settings[$key]; return false; } function ap_theme_list(){ $themes = array(); $dirs = array_filter(glob(ANSPRESS_THEME_DIR.'/*'), 'is_dir'); foreach($dirs as $dir) $themes[basename($dir)] = basename($dir); return $themes; } function ap_get_theme(){ $option = ap_opt('theme'); if(!$option) return 'default'; return ap_opt('theme'); } // get the location of the theme function ap_get_theme_location($file){ // checks if the file exists in the theme first, // otherwise serve the file from the plugin if ( $theme_file = locate_template( array( 'anspress/'.$file ) ) ) { $template_path = $theme_file; } else { $template_path = ANSPRESS_THEME_DIR .'/'.ap_get_theme().'/'.$file; } return $template_path; } // get the url theme function ap_get_theme_url($file){ // checks if the file exists in the theme first, // otherwise serve the file from the plugin if ( $theme_file = locate_template( array( 'anspress/'.$file ) ) ) { $template_url = get_template_directory().'/anspress/'.$file; } else { $template_url = ANSPRESS_THEME_URL .'/'.ap_get_theme().'/'.$file; } return $template_url; } function ap_question_tags($list = true){ global $post; if($list) $o = ''; else $o = get_the_term_list( $post->ID, ANSPRESS_TAG_TAX, '', '', '' ); echo $o; } function ap_question_categories($list = true){ global $post; if($list) $o = ''; else $o = get_the_term_list( $post->ID, ANSPRESS_CAT_TAX, '', ', ', '' ); echo $o; } function ap_human_time($time){ return human_time_diff( $time, current_time('timestamp') ); } function ap_please_login(){ $o = '
'; $o .= ''; $o .= __('Please login or register to continue this action.', 'ap'); $o .= '
'; echo apply_filters('ap_please_login', $o); } /* Check if a user can ask a question */ function ap_user_can_ask(){ if(is_user_logged_in()) return true; return false; } /* Check if a user can answer on a question */ function ap_user_can_answer($post_id){ if(is_user_logged_in()){ global $current_user; $user_id = $current_user->ID; if(!ap_opt('multiple_answers') && ap_is_user_answered($post_id, $user_id)) return false; else return true; } return false; } function ap_user_can_edit($post_id = false){ if(is_user_logged_in()){ global $current_user; if($post_id ) $post = get_post($post_id); else global $post; if(is_super_admin()) return true; if($current_user->ID == $post->post_author) return true; } return false; } function ap_comment_btn_html(){ $action = get_post_type(get_the_ID()).'-'.get_the_ID(); $nonce = wp_create_nonce( $action ); echo ''.__('Comment', 'ap').''; } function ap_edit_btn_html(){ $post_id = get_the_ID(); if(ap_user_can_edit($post_id)){ $action = get_post_type($post_id).'-'.$post_id; $nonce = wp_create_nonce( $action ); $edit_link = add_query_arg( 'edit_q', $post_id, get_permalink( ap_opt('edit_page')) ); echo ''.__('Edit', 'ap').''; } return; }