__('Ask Me', 'askme-plugin'),
'singular_name' => __('Ask Me', 'askme-plugin'),
'add_new' => __('New Ask Me', 'askme-plugin'),
'add_new_item' => __('Add new Ask Me', 'askme-plugin'),
'edit_item' => __('Edit Ask Me', 'askme-plugin'),
'new_item' => __('New Ask Me', 'askme-plugin'),
'view_item' => __('View Ask Me', 'askme-plugin'),
'search_items' => __('Search Ask Me s', 'askme-plugin'),
'not_found' => __('No Ask Me found', 'askme-plugin'),
'not_found_in_trash' => __('No Ask Me found in Trash', 'askme-plugin'),
'parent_item_colon' => '',
);
$args = array(
'label' => __('Ask me', 'askme-plugin'),
'labels' => $labels,
'public' => false,
'can_export' => true,
'show_ui' => true,
'menu_position' => 32,
'_builtin' => false,
'capability_type' => 'post',
'menu_icon' => plugin_dir_url(__FILE__).'images/icon.png',
'hierarchical' => false,
'rewrite' => array( "slug" => "askme" ),
'supports'=> array('title', 'editor', 'comments'),
'show_in_nav_menus' => true
);
register_post_type( 'askme', $args);
}
add_action( 'init', 'create_askme_postype' );
function askme_title_placeholder( $title ){
$screen = get_current_screen();
if ( 'askme' == $screen->post_type ){
$title = __('your question here', 'askme-plugin');
}
return $title;
}
add_filter( 'enter_title_here', 'askme_title_placeholder' );
function show_asks( ) {
$isCaptcha = get_option('askme_setting_captcha');
if($isCaptcha)
{
require_once(dirname(__FILE__).'/captcha/captcha.php');
$publickey = get_option( 'askme_setting_captcha_publickey' );
$privatekey = get_option( 'askme_setting_captcha_privatekey' );
$resp = null;
$error = null;
}
ob_start();
wp_enqueue_style( 'askme', plugins_url('askme.css',__FILE__) );
if( 'POST' == $_SERVER['REQUEST_METHOD']
&& !empty( $_POST['action'] )
&& $_POST['post_type'] == 'askme' && $_POST['question'] != "")
{
if ($isCaptcha && $_POST["recaptcha_response_field"])
{
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
$title = $_POST['question'];
$post = array(
'post_title' => $title,
'post_status' => 'draft',
'post_type' => 'askme'
);
$id = wp_insert_post($post);
echo "
".__('Success! Ask Me is now ready for approval.')."
";
if(isset($_POST['username']))
{
add_post_meta($id, 'askme_username', $_POST['username']);
}
if(isset($_POST['email']))
{
add_post_meta($id, 'askme_email', $_POST['email']);
}
if(get_option('askme_setting_email') == true)
{
$mailtext = __('New Ask Me Received', 'askme-plugin');
$admin_email = get_option('admin_email');
wp_mail( $admin_email, $mailtext, "Ask Me: ".$title);
}
}
else
{
$error = $resp->error;
echo "".__('Error! The Captcha was wrong.')."
";
}
}
else if(!$isCaptcha)
{
$title = $_POST['question'];
$post = array(
'post_title' => $title,
'post_status' => 'draft',
'post_type' => 'askme'
);
$id = wp_insert_post($post);
echo "".__('Success! Ask Me is now ready for approval.')."
";
if(isset($_POST['username']))
{
add_post_meta($id, 'askme_username', $_POST['username']);
}
if(isset($_POST['email']))
{
add_post_meta($id, 'askme_email', $_POST['email']);
}
if(get_option('askme_setting_email') == true)
{
$mailtext = __('New Ask Me Received', 'askme-plugin');
$admin_email = get_option('admin_email');
wp_mail( $admin_email, $mailtext, "Ask Me: ".$title);
}
}
else
{
echo "".__('Error! You have to fill out the Captcha.')."
";
}
}
else if('POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['question'] == "")
{
echo "".__('Error! You have to fill out the Question.')."
";
}
?>
'askme',
'post_status' => 'publish',
'paged' => $paged,
'orderby' => 'date',
'posts_per_page' => 5
);
query_posts($args);
while ( have_posts() ) : the_post(); ?>
max_num_pages); ?>
';
$new_columns['date'] = __('Date', 'askme-plugin');
$new_columns['title'] = __('Ask Me', 'askme-plugin');
$new_columns['answer'] = __('Answer', 'askme-plugin');
$new_columns['username'] = __('Username', 'askme-plugin');
$new_columns['email'] = __('Email', 'askme-plugin');
return $new_columns;
}
add_filter('manage_edit-askme_columns', 'add_askme_columns');
add_action('manage_askme_posts_custom_column', 'manage_askme_columns', 10, 2);
function manage_askme_columns($column_name, $id) {
$customs = get_post_custom($id);
switch ($column_name) {
case 'id':
echo $id;
break;
case 'username':
if(isset($customs['askme_username']))
{
foreach( $customs['askme_username'] as $key => $value)
echo $value;
}
break;
case 'email':
if(isset($customs['askme_email']))
{
foreach( $customs['askme_email'] as $key => $value)
echo $value;
}
break;
case 'answer':
echo get_the_content($id);
break;
default:
break;
}
}
function askme_pagination($pages = '', $range = 5)
{
$showitems = ($range * 2)+1;
global $paged;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
?>
Ask Me - Overview
$type,
'post_status' => 'publish',
'posts_per_page' => -1);
$my_query = query_posts( $args );
?>
$type,
'post_status' => 'draft',
'posts_per_page' => -1);
$my_query = query_posts( $args );
?>
'.__("Configure your Asks", "askme-plugin").'';
}
function askme_setting_callback() {
echo ' ';
}
function askme_captcha_callback() {
echo ' ';
}
function askme_setting_user_response_callback() {
echo ' ' . __('Would you like to display User Fields, like E-Mail and Username? This would give your users the possibility to receive a Notification if an Answer is answered.', 'askme-plugin');
}
function askme_captcha_prk_callback() {
echo '
' . __('Get a key from https://www.google.com/recaptcha/admin/create ', 'askme-plugin') . "
";
}
function askme_captcha_puk_callback() {
echo '
' . __('Get a key from https://www.google.com/recaptcha/admin/create ', 'askme-plugin') . "
";
}
add_action( 'admin_menu', 'add_user_menu_bubble' );
function add_user_menu_bubble() {
global $menu;
foreach ( $menu as $key => $value ) {
if ( $menu[$key][2] == 'edit.php?post_type=askme' ) {
$type = 'askme';
$args = array(
'post_type' => $type,
'post_status' => 'draft',
'posts_per_page' => -1);
$my_query = query_posts( $args );
if(count($my_query) > 0)
{
$menu[$key][0] .= ' ' . count($my_query) . ' ';
}
wp_reset_query();
return;
}
}
}
function publish_askme_hook($id)
{
$customs = get_post_custom($id);
if(isset($customs['askme_email']))
wp_mail( $customs['askme_email'], get_bloginfo('name').__(' - Ask Me - Answer Received', 'askme-plugin'), __('Your Ask Me has been Answered!', 'askme-plugin'));
}
add_action( 'publish_askme', 'publish_askme_hook' );
?>