Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.0.1 #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.DS_Store
1 change: 1 addition & 0 deletions admin/assets/css/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
1 change: 1 addition & 0 deletions admin/assets/js/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
56 changes: 56 additions & 0 deletions admin/class-idea-factory-admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
class Idea_Factory_Admin {

/**
* Instance of this class.
*
* @since 0.0.1
*
* @var object
*/
protected static $instance = null;

/**
* Slug of the plugin screen.
*
* @since 0.0.1
*
* @var string
*/
protected $plugin_screen_hook_suffix = null;

/**
* Initialize the plugin by loading admin scripts & styles and adding a
* settings page and menu.
*
* @since 0.0.1
*/
private function __construct() {

$plugin = Idea_Factory::get_instance();
$this->plugin_slug = $plugin->get_plugin_slug();

require_once(IDEA_FACTORY_DIR.'/admin/includes/class.settings.php');
require_once(IDEA_FACTORY_DIR.'/admin/includes/class.meta.php');
require_once(IDEA_FACTORY_DIR.'/admin/includes/class.column-mods.php');


}

/**
* Return an instance of this class.
*
* @since 0.0.1
*
* @return object A single instance of this class.
*/
public static function get_instance() {

// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}

return self::$instance;
}
}
73 changes: 73 additions & 0 deletions admin/includes/class.column-mods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
*
* Class responsible for adding columns into the edit posts screen in the ideas post type
* used for showing admins the status of an idea
* @since 1.1
*/
class ideaFactoryColumnMods {

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);

}
}

/**
*
* Log the columns
*
* @since 1.1
*/
function col_head( $item ) {

unset(
$item['title'],
$item['date'],
$item['author'],
$item['comments']
);

$item['title'] = __('Title','idea-factory');
$item['author'] = __('Author','idea-factory');
$item['idea_status'] = __('Idea Status','idea-factory');
$item['date'] = __('Date Published','idea-factory');

return $item;
}

/**
* Callback for col_head
* Show the status of an idea
*
* @since 1.1
*/
function col_content( $column_name, $post_ID ) {

if ( 'idea_status' == $column_name ) {

$status = get_post_meta( $post_ID,'_idea_status', true );

if ( 'approved' == $status ) {
$color = '#5cb85c';
} elseif ('declined' == $status ) {
$color = '#d9534f';
} else {
$status = __('open', 'idea_factory');
$color = '#5bc0de';
}

echo '<strong style="color:'.esc_attr( $color ).';">'.esc_html( ucfirst( $status ) ).'</strong>';

}
}

}
new ideaFactoryColumnMods;
84 changes: 84 additions & 0 deletions admin/includes/class.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/**
*
* Class responsible for adding a status metabox to single ideas so that admins can manulaly chnage the status
*
* @since 1.1
*
*/
class ideaFactoryMeta {

function __construct(){

add_action( 'add_meta_boxes', array($this,'add_status_box') );
add_action( 'save_post', array($this,'save_status_box'), 10, 3 );
}

/**
*
*
* 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');
}

}

/**
* Render status metabox
*
* @param WP_Post $post The post object.
* @since 1.1
*
*/
function render_status_box( $post ){

wp_nonce_field( 'idea_factory_meta', 'idea_factory_nonce' );

$status = get_post_meta( $post->ID, '_idea_status', true );

?>
<select name="idea_status">
<option value="approved" <?php selected( $status, 'approved' ); ?>><?php _e('Approved','idea-factory');?></option>
<option value="declined" <?php selected( $status, 'declined' ); ?>><?php _e('Declined','idea-factory');?></option>
<option value="open" <?php selected( $status, 'open' ); ?>><?php _e('Open','idea-factory');?></option>
</select>
<?php
}

/**
*
* Save the status
*
* @param int $post_id The ID of the post being saved.
* @param post $post the post
* @since 1.1
*
*/
function save_status_box( $post_id, $post, $update ) {

if ( ! isset( $_POST['idea_factory_nonce'] ) )
return $post_id;

$nonce = $_POST['idea_factory_nonce'];

if ( !wp_verify_nonce( $nonce, 'idea_factory_meta' ) || defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || 'ideas' != $post->post_type )
return $post_id;

$status = isset( $_POST['idea_status'] ) ? $_POST['idea_status'] : false;

update_post_meta( $post_id, '_idea_status', sanitize_text_field( trim( $status ) ) );


}
}
new ideaFactoryMeta;
Loading