plugin_name = 'apply-online'; $this->version = '1.9.4'; $this->load_dependencies(); $this->set_locale(); $this->define_admin_hooks(); $this->define_public_hooks(); add_action( 'init', array( $this, 'register_aol_post_types' ), 5 ); add_action( 'init', array($this, 'after_plugin_update')); add_action( 'wp_enqueue_scripts', array($this, 'load_dashicons_front_end') ); add_filter( 'views_edit-aol_application', array($this, 'my_views' )); add_action( 'tgmpa_register', array($this, 'applyonline_register_required_plugins' )); new Applyonline_Shortcodes(); new Applyonline_AjaxHandler(); } /** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - Applyonline_Loader. Orchestrates the hooks of the plugin. * - Applyonline_i18n. Defines internationalization functionality. * - Applyonline_Admin. Defines all hooks for the admin area. * - Applyonline_Public. Defines all hooks for the public side of the site. * * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-applyonline-loader.php'; /** * The class responsible for defining internationalization functionality * of the plugin. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-applyonline-i18n.php'; /** * The class responsible for defining all actions that occur in the admin area. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-applyonline-admin.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-applyonline-public.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'required-plugins/class-tgm-plugin-activation.php'; $this->loader = new Applyonline_Loader(); } /** * Define the locale for this plugin for internationalization. * * Uses the Applyonline_i18n class in order to set the domain and to register the hook * with WordPress. * * @since 1.0.0 * @access private */ private function set_locale() { $plugin_i18n = new Applyonline_i18n(); $plugin_i18n->set_domain( $this->get_plugin_name() ); $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { $plugin_admin = new Applyonline_Admin( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action('aol_schedule_event', $plugin_admin, 'close_ad'); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { $plugin_public = new Applyonline_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles', 1 ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @since 1.0.0 * @return string The name of the plugin. */ public function get_plugin_name() { return $this->plugin_name; } /** * The reference to the class that orchestrates the hooks with the plugin. * * @since 1.0.0 * @return Applyonline_Loader Orchestrates the hooks of the plugin. */ public function get_loader() { return $this->loader; } /** * Retrieve the version number of the plugin. * * @since 1.0 * @return string The version number of the plugin. */ public function get_version() { return $this->version; } function applyonline_register_required_plugins() { /* * Array of plugin arrays. Required keys are name and slug. * If the source is NOT from the .org repo, then source is also required. */ $plugins = array(); $plugins = apply_filters('aol_wp_required_plugins', $plugins); /* * Array of configuration settings. Amend each line as needed. * * TGMPA will start providing localized text strings soon. If you already have translations of our standard * strings available, please help us make TGMPA even better by giving us access to these translations or by * sending in a pull-request with .po file(s) with the translations. * * Only uncomment the strings in the config array if you want to customize the strings. */ $config = array( 'id' => 'apply-online', // Unique ID for hashing notices for multiple instances of TGMPA. 'default_path' => '', // Default absolute path to bundled plugins. 'menu' => 'applyonline-plugins', // Menu slug. 'parent_slug' => 'plugins.php', // Parent menu slug. 'capability' => 'manage_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used. 'has_notices' => true, // Show admin notices or not. 'dismissable' => true, // If false, a user cannot dismiss the nag message. 'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag. 'is_automatic' => TRUE, // Automatically activate plugins after installation or not. 'message' => '', // Message to output right before the plugins table. 'strings' => array( 'menu_title' => __( 'Apply Online Plugins', 'apply-online' ), ) ); tgmpa( $plugins, $config ); } function after_plugin_update(){ require_once plugin_dir_path( __FILE__ ).'class-applyonline-activator.php'; $saved_version = (float)get_option('aol_version', 0); if($saved_version < 1.6) { Applyonline_Activator::bug_fix_before_16(); } if($saved_version < 1.61){ Applyonline_Activator::fix_roles(); update_option('aol_version', $this->get_version(), TRUE); } } function load_dashicons_front_end() { wp_enqueue_style( 'dashicons' ); } function my_views($views){ unset($views['mine']); unset($views['publish']); $statuses = aol_app_statuses(); foreach ($statuses as $key => $status){ (isset($_GET['aol_application_status']) AND $_GET['aol_application_status'] == $key)? $class = 'current' : $class = NULL; $views[$status] = ''.$status.''; } return $views; } public function cpt_generator($cpt, $singular, $plural){ if($singular != NULL){ $labels=array( 'name' => $plural, 'singular_name' => __($singular, 'apply-online' ), 'add_new_item' => __('Add New '.$singular, 'apply-online' ), ); } $args=array( 'labels'=> $labels, 'public'=> true, 'show_in_nav_menus' => false, 'capability_type' => array('ad', 'ads'), 'map_meta_cap' => TRUE, 'has_archive' => true, 'menu_icon' => 'dashicons-admin-site', 'show_in_menu' => 'edit.php?post_type=aol_ad', 'description' => __( 'Ad Posting' ), 'rewrite' => array('slug' => sanitize_key($plural)), 'supports' => array('editor', 'excerpt', 'title', 'thumbnail', 'revisions'), ); register_post_type('aol_'.sanitize_key($cpt),$args); } public function taxonomy_generator($singular, $plural, $hierarchical = TRUE){ // Add new taxonomy, make it hierarchical (like categories) $labels = array( 'name' => __( $plural, 'apply-online' ), 'singular_name' => __( $singular, 'apply-online' ), 'search_items' => sprintf(__( 'Search %s', 'apply-online' ), $plural), 'all_items' => sprintf(__( 'All %s', 'apply-online' ), $plural), 'parent_item' => sprintf(__( 'Parent %s', 'apply-online' ), $singular), 'parent_item_colon' => sprintf(__( 'Parent %s:', 'apply-online' ), $singular), 'edit_item' => sprintf(__( 'Edit %s', 'apply-online' ), $singular), 'update_item' => sprintf(__( 'Update %s', 'apply-online' ), $singular), 'add_new_item' => sprintf(__( 'Add New %s', 'apply-online' ), $singular), 'new_item_name' => sprintf(__( 'New %s Name', 'apply-online' ), $singular), ); $args = array( 'hierarchical' => $hierarchical, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'show_in_menu' => false, 'rewrite' => array( 'slug' => sanitize_key($singular) ), 'capabilities' => array('manage_terms' => 'manage_ad_terms', 'edit_terms' => 'edit_ad_terms', 'delete_terms' => 'delete_ad_terms', 'assign_terms' =>'assign_ad_terms') ); $cpts = get_option('aol_ad_types', array()); $types = array(); if(!is_array($types)) $types = array(); foreach ($cpts as $cpt => $val){ if(isset($val['filters']) AND in_array(sanitize_key($singular), (array)$val['filters'])) $types[] = 'aol_'.$cpt; } register_taxonomy( 'aol_ad_'.sanitize_key($singular), $types, $args ); } /* * @todo make label of the CPT editable from plugin settings so user can show his own title on the archive page */ public function register_aol_post_types(){ $slug = get_option_fixed('aol_slug', 'ads'); /*Register Main Post Type*/ $labels=array( 'add_new' => __('Create Ad', 'apply-online' ), 'add_new_item' => __('New Ad', 'apply-online' ), 'edit_item' => __('Edit Ad', 'apply-online' ), 'all_items' => __('Ads', 'apply-online' ), //'menu_name' => __('Apply Online', 'apply-online' ) ); $args=array( 'label' => __( 'All Ads', 'apply-online' ), 'labels'=> $labels, 'public'=> true, 'show_in_nav_menus' => false, 'capability_type' => array('ad', 'ads'), 'map_meta_cap' => TRUE, 'has_archive' => true, 'menu_icon' => 'dashicons-admin-site', 'description' => __( 'Ad Posting' ), 'supports' => array('editor', 'excerpt', 'title', 'thumbnail', 'revisions'), 'rewrite' => array('slug'=> $slug), 'menu_position' => 30 ); register_post_type('aol_ad',$args); $types = get_option_fixed('aol_ad_types', array()); unset($types['ad']); //Already reigstered couple of lines before. if(!empty($types)){ foreach($types as $cpt => $type){ $this->cpt_generator($cpt, $type['singular'], $type['plural']); } } $filters = aol_ad_filters(); foreach($filters as $key => $val){ $this->taxonomy_generator($key, $val); } /*Register Applications Post Type*/ $lables= array( 'edit_item'=>'Application', 'not_found' => __( 'No applications found.', 'apply-online' ), 'not_found_in_trash' => __( 'No applications found.', 'apply-online' ) ); $args=array( 'label' => __( 'Applications', 'apply-online' ), 'labels' => $lables, 'show_ui' => true, 'public' => true, 'exclude_from_search'=> true, 'capability_type' => array('application', 'applications'), 'description' => __( 'List of Applications', 'apply-online' ), 'supports' => array('comments', 'editor'), 'map_meta_cap' => TRUE, 'show_in_menu' => 'aol-settings', ); register_post_type('aol_application',$args); //Application tags $labels = array( 'name' => _x( 'Application Status', 'apply-online' ), 'singular_name' => 'Status', ); $args = array( 'label' => 'Status', 'hierarchical' => false, 'labels' => $labels, 'show_ui' => false, 'show_admin_column' => false, 'query_var' => true, 'show_in_menu' => false, ); register_taxonomy( 'aol_application_status', 'aol_application', $args ); } } class Applyonline_Shortcodes{ function __construct() { add_shortcode( 'aol', array($this, 'aol') ); //archive of ads. add_shortcode( 'aol_ads', array($this, 'aol') ); //deprecated since 1.1 add_shortcode( 'aol_ad', array($this, 'aol_ad') ); //Single ad with form. add_shortcode( 'aol_form', array($this, 'aol_form') ); //Single ad form only. } /** * Shortcode Generator * @param type $atts * @return type */ function aol( $atts ) { $a = shortcode_atts( array( 'categories' => NULL, //depricated since 1.9 'filter' => NULL, 'ads' => NULL, 'excerpt' => 'yes', 'per_page' => '-1', 'show_filter' => 'yes', 'type' => 'ad' ), $atts ); $args=array( 'posts_per_page'=> $a['per_page'], 'post_type' =>'aol_'.$a['type'], ); /*Start Depricated since 1.9*/ $term = null; if(isset($a['categories'])) { $_POST['aol_ad_category'] = explode(',',$atts['categories']); //$a['show_filter'] = 'no'; /* $args['tax_query'] = array( array('taxonomy' => 'aol_ad_category', 'terms' => explode(',',$atts['categories'])) ); */ } /*End Depricated since 1.9*/ if(isset($a['ads'])) { $args['post__in'] = explode(',',$atts['ads']); $a['show_filter'] = 'no'; } //Get list of taxanomies $taxes = get_object_taxonomies('aol_'.$a['type']); $args['tax_query'] = array(); foreach($taxes as $tax){ $tax = substr($tax, 7); if(isset($_POST[$tax]) AND $_POST[$tax] != NULL) { $args['tax_query'][] = array('taxonomy' => "aol_ad_$tax", 'terms' => array($_POST[$tax])); } } //query_posts( $args ); global $post; $posts = get_posts($args); add_filter( 'excerpt_more', array($this, 'aol_excerpt_more') ); //$show_filter = get_option('aol_show_filter', 1); $filters = aol_ad_cpt_filters($a['type']); $cols = ceil(count($filters)/4); ob_start(); echo '
Hi,
" . 'You have received an application against an add on '.get_bloginfo('name').'.
' . "To view this application, please Click Here
" . '----
This is an automated response from Apply Online plugin on '.site_url().'
'; $message = apply_filters('aol_email_notification', $message, $post_id); //Deprecated. $aol_email = apply_filters('aol_email', array('to' => $emails, 'subject' => $subject, 'message' => $message, 'headers' => $headers, 'attachments' => $attachments), $post_id, $post, $uploads); do_action('aol_email_before', $emails, $subject, $message, $headers, $attachments); add_filter( 'wp_mail_content_type', array($this, 'set_html_content_type') ); wp_mail( $aol_email['to'], $aol_email['subject'], $aol_email['message'], $aol_email['headers'], $aol_email['attachments']); remove_filter( 'wp_mail_content_type', array($this, 'set_html_content_type') ); do_action('aol_email_after', $emails, $subject, $message, $headers, $attachments); return true; } private function sanitize_post_array(&$value,$key){ $value = sanitize_text_field($value); } public function save_setting_template(){ // Check the user's permissions. 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 = "SELECT $wpdb->options WHERE option_name like '_aol_app_%'"; $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, 3) == '_ad') delete_post_meta($post_id, $val); //Remove meta from the db. endforeach; array_walk($_POST[$key], array($this, 'sanitize_post_array')); //Sanitizing each element of the array // 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. update_post_meta( $post_id, sanitize_key($key), sanitize_text_field( $val )); // 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, sanitize_key($key), $my_data); // Add new value. } //Update the meta field in the database. endforeach; } }