*/
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;
add_action( 'init', array( $this, 'register_aol_post_types' ) );
add_shortcode( 'aol', array($this, 'shortcode_generator') );
//Depricated.
add_shortcode( 'aol_ads', array($this, 'shortcode_generator') );
// 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 );
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' ) );
new Applyonline_MetaBoxes();
new Applyonline_Settings($version);
new Applyonline_AjaxHandler();
}
/**
* 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 );
}
public static function register_aol_post_types(){
/*Register Main Post Type*/
$labels=array(
'add_new' => 'Create Ad',
'add_new_item' => 'New Ad',
'edit_item' => 'Edit Ad',
'all_items' => 'All Ads',
'menu_name' => 'Apply Online'
);
$args=array(
'label' => __( 'All Ads', 'applyonline' ),
'labels'=> $labels,
'public'=> true,
'show_in_nav_menus' => false,
'menu_icon' => 'dashicons-admin-site',
'description' => __( 'Ad Posting' ),
'supports' => array('title', 'editor', 'excerpt'),
'rewrite' => array('slug'=>'ads'),
);
register_post_type('aol_ad',$args);
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Categories', 'taxonomy plural name', 'applyonline' ),
'singular_name' => _x( 'Category','taxonomy singular name', 'applyonline' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'adcat' ),
);
register_taxonomy( 'aol_ad_category', array( 'aol_ad' ), $args );
/*Register Applications Post Type*/
$lables= array(
'edit_item'=>'Application'
);
$args=array(
'label' => __( 'Applications', 'applyonline' ),
'labels' => $lables,
'public' => true,
'show_in_nav_menus' => false,
'exclude_from_search'=> true,
'publicly_queryable' => false,
'map_meta_cap' => true,
'show_in_menu' => 'edit.php?post_type=aol_ad',
'description' => __( 'List of Applications with their resume', 'applyonline' ),
'supports' => array('editor'),
'capabilities' => array(
'create_posts' => false,
)
);
register_post_type('aol_application',$args);
}
/**
* Shortcode Generator
* @param type $atts
* @return type
*/
function shortcode_generator( $atts ) {
$a = shortcode_atts( array(
'categories' => NULL,
'ads' => NULL,
'excerpt' => 'yes',
'per_page' => '-1'
), $atts );
$args=array(
'posts_per_page'=> $a['per_page'],
'post_type' =>'aol_ad',
);
if(isset($a['categories'])) {
$args['tax_query'] = array(
array('taxonomy' => 'aol_ad_category', 'terms' => explode(',',$atts['categories']))
);
}
if(isset($a['ads'])) {
$args['post__in'] = explode(',',$atts['ads']);
}
query_posts( $args );
function custom_excerpt_more( $more ) {
return '....';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );
ob_start();
echo '
app_field_types = array('text'=>'Text Field', 'text_area'=>'Text Area', 'date'=>'Date', 'checkbox'=>'Check Box', 'dropdown'=>'Drop Down', 'radio'=> 'Radio');
add_action( 'add_meta_boxes_aol_ad', array($this, 'aol_meta_boxes') );
add_action( 'save_post', array( $this, 'save_metas' ) );
}
/**
* 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.
*/
?>
';
if(!($val['type']=='text' or $val['type']=='date' or $val['type']=='text_area' )):
echo '';
else:
echo '';
endif;
echo '
Delete
';
//}
endif;
endforeach;
endif;
?>
application_fields_generator();
}
/**
* 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 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($_POST[$key]);
update_post_meta( $post_id, $key, $my_data); // Add new value.
}
//Update the meta field in the database.
endforeach;
}
}
/**
* This class is responsible for plugin Settings.
*
*
* @since 1.3
* @package Applyonline_settings
* @author Farhan Noor
**/
class Applyonline_Settings extends Applyonline_MetaBoxes{
private $version;
public function __construct($version) {
$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_application_template', '_aol_app_Name' );
}
public function settings_page_callback(){
ob_start();
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);
}
?>
Apply Online version version; print_r($this->app_field_types); ?>
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?
Add [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.
1) {
$uploadfiles = $_FILES['applicant_resume'];
if (is_array($uploadfiles)) {
$upload_dir = wp_upload_dir();
$assignment_upload_size = 200;
$time = (!empty($_SERVER['REQUEST_TIME'])) ? $_SERVER['REQUEST_TIME'] : (time() + (get_option('gmt_offset') * 3600)); // Fallback of now
$post_type = 'aol_ad';
$date = explode(" ", date('Y m d H i s', $time));
$timestamp = strtotime(date('Y m d H i s'));
if($post_type){
$upload_dir = array(
'path' => WP_CONTENT_DIR . '/uploads/' . $post_type . '/' . $date[0],
'url' => WP_CONTENT_URL . '/uploads/' . $post_type . '/' . $date[0],
'subdir' => '',
'basedir' => WP_CONTENT_DIR . '/uploads',
'baseurl' => WP_CONTENT_URL . '/uploads',
'error' => false,
);
}
if(!is_dir($upload_dir['path'])) wp_mkdir_p($upload_dir['path']);
$var_cp_assigment_type= 'jpg,jpeg,png,doc,docx,pdf,rtf,odt,txt';
// look only for uploded files
if ($_FILES['applicant_resume']['error'] == 0) {
$filetmp = $_FILES['applicant_resume']['tmp_name'];
$filename = $_FILES['applicant_resume']['name'];
$filesize = $_FILES['applicant_resume']['size'];
$filetype = wp_check_filetype ( $filename );
$file_ext = strtolower($filetype['ext']);
$max_upload_size = $assignment_upload_size*1048576; //Multiply by KBs
if($max_upload_size < $filesize){
$assignment_error[] = 'Maximum upload File size allowed '.$assignment_upload_size.'MB';
$error_assignment = 1;
}
$file_type_match = 0;
$var_cp_assigment_type_array = array();
if($var_cp_assigment_type){
$var_cp_assigment_type_array = explode(',',$var_cp_assigment_type);
}
if(in_array($file_ext, $var_cp_assigment_type_array)){
$file_type_match = 1;
}
/**
* Check File Size
*/
if($file_type_match == 0){
$assignment_error[] = 'Please upload file with one of the extenstions: '.$var_cp_assigment_type;
$error_assignment = 1;
}
// get file info
// @fixme: wp checks the file extension....
$filetype = wp_check_filetype( basename( $filename ), null );
$filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) );
$filename = $filetitle . $timestamp . '.' . $filetype['ext'];
/**
* Check if the filename already exist in the directory and rename the
* file if necessary
*/
$i = 0;
while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) {
$filename = $filetitle . $timestamp . '_' . $i . '.' . $filetype['ext'];
$i++;
}
$filedest = $upload_dir['path'] . '/' . $filename;
/**
* Check write permissions
*/
if ( !is_writeable( $upload_dir['path'] ) ) {
$assignment_error[] = 'Unable to write to directory %s. Is this directory writable by the server?';
$error_assignment = 1;
}
/**
* Save temporary file to uploads dir
*/
if($error_assignment <> 1){
if ( !@move_uploaded_file($filetmp, $filedest) ){
$assignment_error[] = 'Error, the file $filetmp could not moved to : $filedest';
$error_assignment = 1;
}
$newupload = $upload_dir['url'].'/'.$filename;
$uploadpath = $upload_dir['path'].'/'.$filename;
}
}
}
}
if($error_assignment == 1){
$errors = NULL;
foreach($assignment_error as $error_value){
$errors .= esc_html__($error_value, 'applyonline').' ';
}
$response = json_encode( array( 'success' => false, 'error' => $errors )); // generate the response.
// response output
header( "Content-Type: application/json" );
echo $response;
exit;
}
else{
$args= array(
'post_type' =>'aol_application',
'post_content' =>'',
'post_parent' =>$_POST['ad_id'],
'post_title' =>get_the_title($_POST['ad_id']),
'post_status' =>'publish',
);
$pid=wp_insert_post($args);
foreach($_POST as $key => $val):
if(substr($key,0,9) == '_aol_app_') add_post_meta($pid, $key, $val);
if(!empty($newupload)) add_post_meta($pid, 'resume', $newupload);
endforeach;
if($pid>0){
//send email alert.
$post_url = admin_url("post.php?post=$pid&action=edit");
$admin_email = get_option('admin_email');
$emails_raw = get_option('aol_recipients_emails', $admin_email);
$emails = explode("\n", $emails_raw);
$subject = 'Application Alert';
$headers = array('From: '. get_bloginfo('name').' <'.get_bloginfo('admin_email').'>');
$message = "
Hi,
"
. "
You just received an application against an add at ".get_bloginfo('url'). ".