示例#1
0
 /**
  *
  *
  *	Add a status metabox if teh user has opted in for the threshold settings
  *
  *	@since 1.1
  */
 function add_status_box()
 {
     // get threashold
     $threshold = idea_factory_get_option('if_threshold', 'if_settings_main');
     if ($threshold) {
         add_meta_box('idea_factory_status', __('Idea Status', 'idea-factory'), array($this, 'render_status_box'), 'ideas', 'side', 'core');
     }
 }
示例#2
0
 /**
  * Creates a post type
  *
  * @since    1.0.0
  */
 function do_type()
 {
     $disable_archive = idea_factory_get_option('if_disable_archive', 'if_settings_advanced');
     $domain = 'on' == $disable_archive ? false : idea_factory_get_option('if_domain', 'if_settings_main', 'ideas');
     $labels = array('name' => _x('Ideas', 'idea-factory'), 'singular_name' => _x('Idea', 'idea-factory'), 'menu_name' => __('Ideas', 'idea-factory'), 'parent_item_colon' => __('Parent Idea:', 'idea-factory'), 'all_items' => __('All Ideas', 'idea-factory'), 'view_item' => __('View Idea', 'idea-factory'), 'add_new_item' => __('Add New Idea', 'idea-factory'), 'add_new' => __('New Idea', 'idea-factory'), 'edit_item' => __('Edit Idea', 'idea-factory'), 'update_item' => __('Update Idea', 'idea-factory'), 'search_items' => __('Search Ideas', 'idea-factory'), 'not_found' => __('No Ideas found', 'idea-factory'), 'not_found_in_trash' => __('No Ideas found in Trash', 'idea-factory'));
     $args = array('label' => __('Ideas', 'idea-factory'), 'description' => __('Create votes', 'idea-factory'), 'labels' => $labels, 'supports' => array('editor', 'title', 'comments', 'author'), 'public' => false, 'menu_icon' => 'dashicons-lightbulb', 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'can_export' => true, 'has_archive' => $domain, 'capability_type' => 'post');
     register_post_type('ideas', apply_filters('idea_factory_type_args', $args));
 }
 function __construct()
 {
     $threshold = idea_factory_get_option('if_threshold', 'if_settings_main');
     if ($threshold) {
         add_filter('manage_ideas_posts_columns', array($this, 'col_head'));
         add_action('manage_ideas_posts_custom_column', array($this, 'col_content'), 10, 2);
     }
 }
 /**
  *
  * @since version 1.0
  * @param $template - return based on view
  * @return page template based on view regardless if the post type doesnt even exist yet due to no posts
  */
 function template_loader($template)
 {
     $disable_archive = idea_factory_get_option('if_disable_archive', 'if_settings_advanced');
     if (idea_factory_is_archive() && 'on' !== $disable_archive) {
         if ($overridden_template = locate_template('template-ideas.php', true)) {
             $template = load_template($overridden_template);
         } else {
             $template = IDEA_FACTORY_DIR . 'templates/template-ideas.php';
         }
     }
     return $template;
 }
 /**
  *
  *	Send email to the admin notifying of a status change on an idea
  *
  *	@param $status string approved | declined
  *	@param $postid int postid object
  *
  */
 function mail_status($status, $postid)
 {
     $admin_email = get_bloginfo('admin_email');
     $entry = get_post($postid);
     $mail_disabled = idea_factory_get_option('if_disable_mail', 'if_settings_advanced');
     $message = "The status of " . $entry->post_title . " has been updated to:\n";
     $message .= "" . $status . "\n\n";
     $message .= "Manage ideas at link below\n";
     $message .= "" . wp_login_url() . "\n\n";
     if (!$mail_disabled) {
         wp_mail($admin_email, 'Idea ' . $postid . ' Approved ', $message);
     }
 }
示例#6
0
 function scripts()
 {
     global $wp_query, $post;
     $disable_css = idea_factory_get_option('if_disable_css', 'if_settings_advanced');
     $max = $wp_query->max_num_pages;
     $paged = get_query_var('paged') > 1 ? get_query_var('paged') : 1;
     if (idea_factory_is_archive() || has_shortcode(isset($post->post_content) ? $post->post_content : null, 'idea_factory')) {
         if ('on' !== $disable_css) {
             wp_enqueue_style('dashicons');
             wp_enqueue_style('idea-factory-css', IDEA_FACTORY_URL . '/public/assets/css/idea-factory.css', IDEA_FACTORY_VERSION, true);
         }
         wp_enqueue_script('idea-factory-script', IDEA_FACTORY_URL . '/public/assets/js/idea-factory.js', array('jquery'), IDEA_FACTORY_VERSION, true);
         wp_localize_script('idea-factory-script', 'idea_factory', idea_factory_localized_args($max, $paged));
     }
 }
 /**
  *
  *	Send email to the admin notifying of a new submission
  *
  *	@param $entry_id int postid object
  *	@param $userid int userid object
  *
  */
 function send_mail($entry_id, $userid)
 {
     $user = get_userdata($userid);
     $admin_email = get_bloginfo('admin_email');
     $entry = get_post($entry_id);
     $mail_disabled = idea_factory_get_option('if_disable_mail', 'if_settings_advanced');
     $message = sprintf(__("Submitted by: %s", 'idea-factory'), $user->display_name) . ".\n\n";
     $message .= __("Title:", 'idea-factory') . "\n";
     $message .= $entry->post_title . "\n\n";
     $message .= __("Description:", 'idea-factory') . "\n";
     $message .= $entry->post_content . "\n\n";
     $message .= __("Manage all ideas at", 'idea-factory') . "\n";
     $message .= admin_url('edit.php?post_type=ideas');
     if (!isset($mail_disabled) || $mail_disabled == 'off') {
         wp_mail($admin_email, sprintf(__('New Idea Submission - %s', 'idea-factory'), $entry_id), $message);
     }
 }
 /**
  *
  *	Process the form submission
  *
  */
 function process_vote_down()
 {
     check_ajax_referer('idea_factory', 'nonce');
     if (isset($_POST['post_id'])) {
         $postid = $_POST['post_id'];
         // get vote statuses
         $has_public_voted = idea_factory_has_public_voted($postid);
         $has_private_voted = idea_factory_has_private_voted($postid);
         // get votes
         $votes = get_post_meta($postid, '_idea_votes', true);
         $total_votes = get_post_meta($postid, '_idea_total_votes', true);
         // public voting enabled
         $public_can_vote = idea_factory_get_option('if_public_voting', 'if_settings_main');
         if (is_user_logged_in()) {
             $userid = get_current_user_ID();
         } elseif (!is_user_logged_in() && $public_can_vote) {
             $userid = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 0;
         }
         // if the public can vote and the user has already voted or they are logged in and have already voted then bail out
         if ($public_can_vote && $has_public_voted || $has_private_voted) {
             echo 'already-voted';
             die;
         }
         // increase votes
         update_post_meta($postid, '_idea_votes', intval($votes) - 1);
         update_post_meta($postid, '_idea_total_votes', intval($total_votes) + 1);
         // update user meta so they can't vote on this again
         if (!is_user_logged_in() && $public_can_vote) {
             $args = array('postid' => $postid);
             idea_factory_add_public_vote($args);
         } elseif (is_user_logged_in()) {
             // update user meta so they can't vote on this again
             update_user_meta($userid, '_idea' . $postid . '_has_voted', true);
         }
         do_action('idea_factory_vote_down', $postid, $userid);
         echo 'success';
     }
     die;
 }
 function get_settings_fields()
 {
     $domain = idea_factory_get_option('if_domain', 'if_settings_main', 'ideas');
     $settings_fields = array('if_settings_main' => array(array('name' => 'if_domain', 'label' => __('Naming Convention', 'idea-factory'), 'desc' => '<a href="' . get_post_type_archive_link($domain) . '">' . __('Link to ideas page', 'idea-factory') . '</a> - ' . __('By default its called Ideas. You can rename this here.', 'idea-factory'), 'type' => 'text', 'default' => __('ideas', 'idea-factory'), 'sanitize_callback' => 'sanitize_text_field'), array('name' => 'if_welcome', 'label' => __('Welcome Message', 'idea-factory'), 'desc' => __('Enter a message to display to users to vote. Some HTML ok.', 'idea-factory'), 'type' => 'textarea', 'default' => __('Submit and vote for new features!', 'idea-factory'), 'sanitize_callback' => 'idea_factory_media_filter'), array('name' => 'if_approve_ideas', 'label' => __('Require Idea Approval', 'idea-factory'), 'desc' => __('Check this box to enable newly submitted ideas to be put into a pending status instead of automatically publishing.', 'idea-factory'), 'type' => 'checkbox', 'default' => '', 'sanitize_callback' => 'idea_factory_sanitize_checkbox'), array('name' => 'if_public_voting', 'label' => __('Enable Public Voting', 'idea-factory'), 'desc' => __('Enable the public (non logged in users) to submit and vote on new ideas.', 'idea-factory'), 'type' => 'checkbox', 'default' => '', 'sanitize_callback' => 'idea_factory_sanitize_checkbox'), array('name' => 'if_threshold', 'label' => __('Voting Threshold', 'idea-factory'), 'desc' => __('Specify an optional number of votes that each idea must reach in order for its status to be automatically updated to "approved" , "declined", or "open."', 'idea-factory'), 'type' => 'text', 'default' => '', 'sanitize_callback' => 'idea_factory_sanitize_int')), 'if_settings_advanced' => array(array('name' => 'if_disable_css', 'label' => __('Disable Core CSS', 'idea-factory'), 'desc' => __('Disable the core css file from loading.', 'idea-factory'), 'type' => 'checkbox', 'default' => '', 'sanitize_callback' => 'idea_factory_sanitize_checkbox'), array('name' => 'if_disable_mail', 'label' => __('Disable Emails', 'idea-factory'), 'desc' => __('Disable the admin email notification of new submissions.', 'idea-factory'), 'type' => 'checkbox', 'default' => '', 'sanitize_callback' => 'idea_factory_sanitize_checkbox'), array('name' => 'if_disable_archive', 'label' => __('Disable Archive', 'idea-factory'), 'desc' => __('Disable the automatic archive. This assumes you will be using the shortcode instead to show the ideas on a page that you specify.', 'idea-factory'), 'type' => 'checkbox', 'default' => '', 'sanitize_callback' => 'idea_factory_sanitize_checkbox')));
     return $settings_fields;
 }
示例#10
0
    /**
     *	Show teh votes and vote form within a shortcode
     * 	@since version 1.1
     */
    function idea_factory_sc($atts, $content = null)
    {
        $defaults = array('hide_submit' => 'off', 'hide_voting' => 'off', 'hide_votes' => 'off');
        $atts = shortcode_atts($defaults, $atts);
        $postid = get_the_ID();
        $show_submit = 'on' !== $atts['hide_submit'];
        $show_voting = 'on' !== $atts['hide_voting'];
        $show_votes = 'on' !== $atts['hide_votes'];
        ob_start();
        do_action('idea_factory_sc_layout_before', $postid);
        ?>
<div class="idea-factory--wrap"><?php 
        do_action('idea_factory_sc_layout_before_entries', $postid);
        if ($show_submit) {
            echo idea_factory_submit_header();
        }
        ?>

			<section class="idea-factory--layout-main">
				<?php 
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $args = array('post_type' => 'ideas', 'meta_key' => '_idea_votes', 'orderby' => 'meta_value_num', 'paged' => $paged);
        $q = new WP_Query(apply_filters('idea_factory_query_args', $args));
        $max = $q->max_num_pages;
        wp_localize_script('idea-factory-script', 'idea_factory', idea_factory_localized_args($max, $paged));
        if ($q->have_posts()) {
            while ($q->have_posts()) {
                $q->the_post();
                // setup some vars
                $id = get_the_ID();
                if (is_user_logged_in()) {
                    $has_voted = get_user_meta(get_current_user_ID(), '_idea' . $id . '_has_voted', true);
                } elseif ($public_can_vote) {
                    $has_voted = idea_factory_has_public_voted($id);
                } else {
                    $has_voted = false;
                }
                $total_votes = idea_factory_get_votes($id);
                $status = idea_factory_get_status($id);
                $status_class = $status ? sprintf('idea-factory--entry__%s', $status) : false;
                $public_can_vote = idea_factory_get_option('if_public_voting', 'if_settings_main');
                ?>
						<section class="idea-factory--entry-wrap <?php 
                echo sanitize_html_class($status_class);
                ?>
 <?php 
                echo $has_voted ? 'idea-factory--hasvoted' : false;
                ?>
">

							<?php 
                do_action('idea_factory_sc_entry_wrap_top', $postid);
                ?>

							<div class="idea-factory--controls">

								<?php 
                if (idea_factory_is_voting_active($id) && $show_voting) {
                    echo idea_factory_vote_controls($id);
                }
                if ($total_votes && $show_votes) {
                    ?>
									<div class="idea-factory--totals">
										<?php 
                    if (1 == $total_votes) {
                        printf('<span class="idea-factory--totals_label">' . apply_filters('idea_factory_vote', __('%s vote', 'idea-factory')) . '</span>', '<span class="idea-factory--totals_num">1</span>');
                    } elseif (!empty($total_votes)) {
                        printf('<span class="idea-factory--totals_label">' . apply_filters('idea_factory_votes', __('%s votes', 'idea-factory')) . '</span>', '<span class="idea-factory--totals_num">' . (int) $total_votes . '</span>');
                    }
                    ?>
									</div>
								<?php 
                }
                echo idea_factory_vote_status($id);
                ?>

							</div>

							<div class="idea-factory--entry">

								<?php 
                the_title('<h2>', '</h2>');
                the_content();
                ?>

							</div>

							<?php 
                do_action('idea_factory_sc_entry_wrap_bottom', $postid);
                ?>

						</section>

						<?php 
            }
        } else {
            apply_filters('idea_factory_no_ideas', _e('No ideas found. Why not submit one?', 'idea-factory'));
        }
        wp_reset_query();
        ?>
			</section>

			<?php 
        do_action('idea_factory_sc_layout_after_entries', $postid);
        ?>

		</div>

		<?php 
        if ($show_submit) {
            echo idea_factory_submit_modal();
        }
        do_action('idea_factory_sc_layout_after', $postid);
        return ob_get_clean();
    }
示例#11
0
<?php

get_header();
$public_can_vote = idea_factory_get_option('if_public_voting', 'if_settings_main');
do_action('idea_factory_layout_before');
?>

	<div class="idea-factory--wrap">

		<?php 
echo idea_factory_submit_header();
do_action('idea_factory_before_entries');
?>

		<section class="idea-factory--layout-main">
			<?php 
if (have_posts()) {
    while (have_posts()) {
        the_post();
        // setup some vars
        $id = get_the_ID();
        if (is_user_logged_in()) {
            $has_voted = get_user_meta(get_current_user_ID(), '_idea' . $id . '_has_voted', true);
        } elseif ($public_can_vote) {
            $has_voted = idea_factory_has_public_voted($id);
        }
        $total_votes = idea_factory_get_votes($id);
        $status = idea_factory_get_status($id);
        $status_class = $status ? sprintf('idea-factory--entry__%s', $status) : false;
        ?>
					<section class="idea-factory--entry-wrap <?php 
示例#12
0
    function idea_factory_vote_status($postid = '')
    {
        $status = idea_factory_get_status($postid);
        $threshold = idea_factory_get_option('if_threshold', 'if_settings_main');
        if ('open' !== $status && false !== $status && !empty($threshold)) {
            ?>
			<div class="idea-factory--status">
				<?php 
            echo '<span class="idea-factory--status_' . sanitize_html_class($status) . '">' . esc_attr($status) . '</span>';
            ?>
			</div>
		<?php 
        }
    }