*/
class Applyonline_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
// Hook - Applicant Listing - Column Name
add_filter( 'manage_edit-aol_application_columns', array ( $this, 'applicants_list_columns' ) );
// Hook - Applicant Listing - Column Value
add_action( 'manage_aol_application_posts_custom_column', array ( $this, 'applicants_list_columns_value' ), 10, 2 );
//Fix comments on application
add_filter('comment_row_actions', array($this, 'comments_fix'), 10, 2);
add_filter('post_row_actions',array($this, 'aol_post_row_actions'), 10, 2);
//Filter Aplications based on parent.
add_action( 'pre_get_posts', array($this, 'applications_filter') );
// Add Application data to the Application editor.
add_action ( 'edit_form_after_title', array ( $this, 'aol_application_post_editor' ) );
$this->hooks_to_search_in_post_metas();
new Applyonline_MetaBoxes();
new Applyonline_Settings($version);
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Applyonline_Loader as all of the hooks are defined
* in that particular class.
*
* The Applyonline_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/applyonline-admin.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Applyonline_Loader as all of the hooks are defined
* in that particular class.
*
* The Applyonline_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/applyonline-admin.js', array( 'jquery' ), $this->version, false );
}
/**
* Extend WordPress search to include custom fields
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*
* @since 1.6
*/
function hooks_to_search_in_post_metas(){
add_filter('posts_join', array($this, 'cf_search_join' ));
add_filter( 'posts_where', array($this, 'cf_search_where' ));
add_filter( 'posts_distinct', array($this, 'cf_search_distinct' ));
}
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() and is_admin() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
/**
* Modify the search query with posts_where
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
*
* @since 1.6
*/
function cf_search_where( $where ) {
global $wpdb;
if ( is_search() and is_admin() ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}
return $where;
}
/**
* Prevent duplicates
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
*
* @since 1.6
*/
function cf_search_distinct( $where ) {
global $wpdb;
if ( is_search() and is_admin() ) {
return "DISTINCT";
}
return $where;
}
/**
*
*/
public function comments_fix($actions, $comment){
$post_id = $comment->comment_post_ID;
if(get_post_field('post_type', $post_id) == 'aol_application'){
$author = get_user_by('email', $comment->comment_author_email );
if(get_current_user_id() != $author->ID) unset($actions['quickedit']); //if not comment author, dont show the quick edit
unset($actions['unapprove']);
unset($actions['trash']);
unset($actions['edit']);
}
return $actions;
}
/**
* Applicant Listing - Column Name
*
* @param array $columns
* @access public
* @return array
*/
public function applicants_list_columns( $columns ){
$columns = array (
'cb' => '',
'title' => __( 'Ad Title', 'applyonline' ),
'applicant'=> __( 'Applicant', 'applyonline' ),
'taxonomy' => __( 'Categories', 'applyonline' ),
'date' => __( 'Date', 'applyonline' ),
);
return $columns;
}
/**
* Applicant Listing - Column Value
*
* @param array $columns
* @param int $post_id
* @access public
* @return void
*/
//
public function applicants_list_columns_value( $column, $post_id ){
$keys = get_post_custom_keys( $post_id );
switch ( $column ) {
case 'applicant' :
$applicant_name = sprintf( '%s', esc_url( add_query_arg( array ( 'post' => $post_id, 'action' => 'edit' ), 'post.php' ) ), esc_html( get_post_meta( $post_id, $keys[ 0 ], TRUE ) )
);
echo $applicant_name;
break;
case 'taxonomy' :
$parent_id = wp_get_post_parent_id( $post_id ); // get_post_field ( 'post_parent', $post_id );
$terms = get_the_terms( $parent_id, 'aol_ad_category' );
if ( ! empty( $terms ) ) {
$out = array ();
foreach ( $terms as $term ) {
$out[] = sprintf( '%s', esc_url( add_query_arg( array ( 'post_type' => get_post_type( $parent_id ), 'aol_ad_category' => $term->slug ), 'edit.php' ) ), esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'jobpost_category', 'display' ) )
);
}
echo join( ', ', $out );
}/* If no terms were found, output a default message. */ else {
_e( 'No Categories' , 'applyonline');
}
break;
}
}
public function aol_post_row_actions($actions, $post){
if($post->post_type == 'aol_application'){
return null;
}
elseif($post->post_type == 'aol_ad'){
$actions['test'] = 'Applications';
return $actions;
}
}
public function applications_filter( $query ) {
if ( $query->is_main_query() AND is_admin() AND isset($_GET['ad'])) {
$query->set( 'post_parent', $_GET['ad'] );
}
}
/**
* Creates Detail Page for Applicants
*
*
* @access public
* @since 1.0.0
* @return void
*/
public function aol_application_post_editor (){
global $post;
if ( !empty ( $post ) and $post->post_type =='aol_application' ):
$keys = get_post_custom_keys ( $post->ID );
?>
app_field_types = array('text'=>'Text Field', 'email'=>'E Mail', 'text_area'=>'Text Area', 'date'=>'Date', 'checkbox'=>'Check Box', 'dropdown'=>'Drop Down', 'radio'=> 'Radio', 'file'=>'File');
add_action( 'add_meta_boxes_aol_ad', array($this, 'aol_meta_boxes') );
add_action( 'save_post', array( $this, 'save_metas' ) );
add_action('do_meta_boxes', array($this, 'alter_metaboxes_on_application_page'));
}
public function alter_metaboxes_on_application_page(){
remove_meta_box('commentstatusdiv', 'aol_application', 'normal'); //Hide discussion meta box.
}
/**
* Metaboxes for Ads Editor
*
* @since 1.0
*/
function aol_meta_boxes($post) {
add_meta_box(
'aol_ad_metas',
__( 'Ad Features', 'applyonline' ),
array($this, 'ad_features'),
'aol_ad'
);
add_meta_box(
'aol_ad_app_fields',
__( 'Application Form Fields', 'applyonline' ),
array($this, 'application_form_fields'),
'aol_ad'
);
}
function ad_features( $post ) {
// Add a nonce field so we can check for it later.
wp_nonce_field( 'myplugin_adpost_meta_awesome_box', 'adpost_meta_box_nonce' );
/*
* Use get_post_meta() to retrieve an existing value
* from the database and use the value for the form.
*/
?>
';
echo '';
//if(!($val['type']=='text' or $val['type']=='email' or $val['type']=='date' or $val['type']=='text_area' or $val['type']=='file' )):
if(in_array($val['type'], array('checkbox','dropdown','radio',))):
echo '';
else:
echo '';
endif;
echo '
Delete
';
//}
endforeach;
?>
application_fields_generator($this->app_field_types);
}
/**
* Save the meta when the post is saved.
*
* @param int $post_id The ID of the post being saved.
*/
function save_metas( $post_id ) {
/*
* We need to verify this came from our screen and with proper authorization,
* because the save_post action can be triggered at other times.
*/
// Check if our nonce is set.
if ( ! isset( $_POST['adpost_meta_box_nonce'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['adpost_meta_box_nonce'], 'myplugin_adpost_meta_awesome_box' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
/* OK, it's safe for us to save the data now. */
//Delete fields.
$old_keys = get_post_custom_keys($post_id);
$new_keys = array_keys($_POST);
$removed_keys = array_diff($old_keys, $new_keys); //List of removed meta keys.
foreach($removed_keys as $key => $val):
if(substr($val, 0, 4) == '_aol') delete_post_meta($post_id, $val); //Remove meta from the db.
endforeach;
// Add/update new value.
foreach ($_POST as $key => $val):
// Make sure that it is set.
if ( substr($key, 0, 13)=='_aol_feature_' and isset( $val ) ) {
//Sanitize user input.
$my_data = sanitize_text_field( $val );
update_post_meta( $post_id, $key, $my_data); // Add new value.
}
// Make sure that it is set.
elseif ( substr($key, 0, 9) == '_aol_app_' and isset( $val ) ) {
//$my_data = serialize($val);
update_post_meta( $post_id, $key, $val); // Add new value.
}
//Update the meta field in the database.
endforeach;
}
}
/**
* This class contains all nuts and bolts of plugin settings.
*
*
* @since 1.3
* @package Applyonline_settings
* @author Farhan Noor
**/
class Applyonline_Settings extends Applyonline_MetaBoxes{
private $version;
public function __construct($version) {
parent::__construct(); //Acitvating Parent's constructor
$this->version = $version;
//Registering Submenus.
add_action('admin_menu', array($this, 'sub_menus'));
//Registering Settings.
add_action( 'admin_init', array($this, 'registers_settings') );
}
public function sub_menus(){
add_submenu_page( 'edit.php?post_type=aol_ad', 'AOL Settings', 'Settings', 'manage_options', 'settings', array($this, 'settings_page_callback') );
}
public function registers_settings(){
register_setting( 'aol_settings_group', 'aol_recipients_emails' );
register_setting( 'aol_settings_group', 'aol_application_message' );
register_setting( 'aol_settings_group', 'aol_thankyou_page' );
register_setting( 'aol_settings_group', 'aol_slug', 'sanitize_title' );
register_setting( 'aol_settings_group', 'aol_upload_max_size', 'floatval' );
register_setting( 'aol_settings_group', 'aol_upload_folder','sanitize_text_field' );
register_setting( 'aol_settings_group', 'aol_allowed_file_types','sanitize_text_field' );
//On update of aol_slug field, update permalink too.
add_action('update_option_aol_slug', array($this, 'refresh_permalink'));
}
public function refresh_permalink(){
//Re register post type for proper Flush Rules.
$slug = get_option('aol_slug', 'ads');
if(empty($slug)) $slug = 'ads';
/*Register Main Post Type*/
register_post_type('aol_ad', array('has_archive' => true, 'rewrite' => array('slug'=> $slug)));
flush_rewrite_rules();
}
public function settings_page_callback(){
if ( !empty( $_POST['aol_default_app_fields'] ) && check_admin_referer( 'aol_awesome_pretty_nonce','aol_default_app_fields' ) ) {
//Remove unnecessary fields
foreach($_POST as $key => $val){
if(substr($key, 0, 4) != '_aol') unset($_POST[$key]);
}
//Save aol default fields in DB.
update_option('aol_default_fields', $_POST);
}
ob_start();
?>
Apply Online version version; ?>
In your WordPress admin panel, go to "Apply Online" menu and add a new ad listing.
How to show ad listings on the front-end?
1. The url lists all the applications using your theme's default look and feel.
(If above not working, try saving permalinks without any change)
2. Write [aol] shortcode in an existing page or add a new page and write shortcode anywhere in the page editor. Now click on VIEW to see all of your ads on front-end.
Can I show few adds on front-end?
Yes, you can show any number of ads on your website by using shortcode with "ads" attribute. Ad ids must be separated with commas i.e. [aol ads="1,2,3"].
Can I show ads from particular category only?
Yes, you can show ads from any category / categories using "categories" attribute. Categories' ids must be separated with commas i.e. [aol categories="1,2,3"].
Can I show ads without excerpt/summary?
Yes, use shortcode with "excerpt" attribute i.e. [aol excerpt="no"]
What attributes can i use in the shortcode?
Default shortcode with all attributes is [aol categories="1,2,3" ads="1,2,3" excerpt="no"]. Use only required attributes.
How can i get the id of a category or ad?
In admin panel, move your mouse pointer on an item in categories or ads table. Now you can view item ID in the info bar of the browser.
Can i display application form only using shortocode?
Yes, [aol_form id="0"] is the shortcode to display a particular application form in wordpress pages or posts. Use correct form id in the shortocode.