###### ### Setup the Basic WordPress Settings ### ###### ## Remove Query Strings from Static Resources function remove_cssjs_ver( $src ) { if( strpos( $src, '?ver=' ) ) $src = remove_query_arg( 'ver', $src ); return $src; } add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 ); add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 ); ## Remove height & width attributes from inserting media. function remove_width_attribute( $html ) { $html = preg_replace( '/(width|height)="\d*"\s/', "", $html ); return $html; } add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 ); add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 ); ## Remove Dashboard Widgets function remove_dashboard_widgets() { global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); } add_action('wp_dashboard_setup', 'remove_dashboard_widgets' ); ## Remove Admin Footer Text function wpse_edit_footer() { add_filter( 'admin_footer_text', 'wpse_edit_text', 11 ); } function wpse_edit_text($content) { return ""; } add_action( 'admin_init', 'wpse_edit_footer' ); ## Change Admin Menu function restrictAdminMenu() { global $user; $user = $user ? new WP_User( $user ) : wp_get_current_user(); $userRole = $user->roles ? $user->roles[0] : false; ## All Users remove_menu_page( 'edit-comments.php' ); ## Staff Users if( $userRole == 'staff' ) { remove_menu_page( 'edit.php' ); remove_menu_page( 'tools.php' ); remove_menu_page( 'profile.php' ); remove_menu_page( 'wpcf7' ); remove_menu_page( 'admin.php?page=acf-options-theme-settings' ); } #remove_menu_page( 'edit-comments.php' ); } #add_action( 'admin_init', 'restrictAdminMenu', 999); ## Setup custom Email (SMTP) settings for the site -> OFF function send_smtp_email( $phpmailer ) { $phpmailer->isSMTP(); $phpmailer->Host = "smtp.mailgun.org"; $phpmailer->SMTPAuth = true; $phpmailer->Port = "25"; $phpmailer->Username = "postmaster@mg.kanemitchell.co.uk"; ## Add Username from MailGun $phpmailer->Password = "4324bf505ac90db817b531e341935ddc"; ## Add Password from MailGun $phpmailer->SMTPSecure = "tls"; $phpmailer->From = "no-reply@kanemitchell.co.uk"; $phpmailer->FromName = "Kane Mitchell"; } #add_action('phpmailer_init','send_smtp_email'); ## Remove support for comments -> OFF function remove_comment_support() { remove_post_type_support( 'post', 'comments' ); remove_post_type_support( 'page', 'comments' ); } add_action('init', 'remove_comment_support', 100); ?> ###### ### Setup any style settings for the site ### ###### // Set default colour scheme for new users function set_default_admin_color($user_id) { $args = array( 'ID' => $user_id, 'admin_color' => 'midnight' ); wp_update_user( $args ); } add_action('user_register', 'set_default_admin_color'); // Site Custom Stylesheet function site_settings_customStylesheet() { wp_enqueue_style( 'site-settings-custom-style', PLUGIN_SITE_SETUP_URL.'style/css/site-style.css' ); } add_action( 'wp_enqueue_scripts', 'site_settings_customStylesheet' ); // Admin Custom Stylesheet function site_settings_adminStylesheet() { wp_register_style( 'site-settings-admin-style', PLUGIN_SITE_SETUP_URL.'style/css/admin-style.css', false, '1.0.0' ); wp_enqueue_style( 'site-settings-admin-style' ); // wp_register_script( 'site_settings_customJS', PLUGIN_SITE_SETUP_URL.'javascript/min/custom-scripts-min.js', array(), '20130115', true ); // wp_localize_script( 'site_settings_customJS', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php'))); // wp_enqueue_script( 'site_settings_customJS' ); wp_register_script( 'property_site_script', PLUGIN_SITE_SETUP_URL.'javascript/min/property-site-scripts-min.js', array( 'jquery' ) ); wp_localize_script( 'property_site_script', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php'))); wp_enqueue_script( 'property_site_script' ); wp_enqueue_script( 'google-maps-script', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyADcK3NeArY7gv3L0infWsa1kycL_Lve7Q', array( 'jquery' ) ); } add_action( 'admin_enqueue_scripts', 'site_settings_adminStylesheet' ); ## Custom JS function site_settings_addJS() { // wp_register_script( 'site_settings_customJS', PLUGIN_SITE_SETUP_URL.'javascript/min/custom-scripts-min.js', array( 'jquery' ) ); // wp_localize_script( 'site_settings_customJS', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php'))); // wp_enqueue_script( 'site_settings_customJS' ); wp_register_script( 'property_site_script', PLUGIN_SITE_SETUP_URL.'javascript/min/property-site-scripts-min.js', array( 'jquery' ) ); wp_localize_script( 'property_site_script', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php'))); wp_enqueue_script( 'property_site_script' ); wp_enqueue_script( 'google-maps-script', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyADcK3NeArY7gv3L0infWsa1kycL_Lve7Q', array( 'jquery' ) ); } add_action( 'wp_enqueue_scripts', 'site_settings_addJS' ); // Login Stylesheet function siteSettings_login_stylesheet() { wp_register_style( 'custom_login_style', PLUGIN_SITE_SETUP_URL.'style/css/login-style.css' ); wp_enqueue_style( 'custom_login_style' ); wp_enqueue_style( 'custom_login_font', 'https://fonts.googleapis.com/css?family=Droid+Sans', false ); } add_action( 'login_enqueue_scripts', 'siteSettings_login_stylesheet' ); function siteSettings_disable_wp_emojicons() { // all actions related to emojis remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); // filter to remove TinyMCE emojis add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' ); } add_action( 'init', 'siteSettings_disable_wp_emojicons'); function disable_emojicons_tinymce( $plugins ) { if ( is_array( $plugins ) ) { return array_diff( $plugins, array( 'wpemoji' ) ); } else { return array(); } } // Defer jQuery Parsing using the HTML5 defer property function siteSettings_defer_js() { $current_user = wp_get_current_user(); if( !current_user_can('editor') && !current_user_can('administrator') ) { function siteSettings_defer_parsing_of_js ( $url ) { if ( FALSE === strpos( $url, '.js' ) ) return $url; if ( strpos( $url, 'jquery.js' ) ) return $url; // return "$url' defer "; return "$url' defer onload='"; } add_filter( 'clean_url', 'siteSettings_defer_parsing_of_js', 11, 1 ); } } #add_action( 'init', 'siteSettings_defer_js'); ?> ###### ### Useful Shortcodes ### ###### ## Get the Page Title of the current page function shc_showPageTitle( ) { return get_the_title(); } add_shortcode( 'page_title', 'shc_showPageTitle' ); ## Add the current year dynamically. function shc_showYear() { $year = date('Y'); return $year; } add_shortcode('year', 'shc_showYear'); ?> ## Settings for this individual site function custom_register_my_menus() { register_nav_menus( array( 'footer-offer-type-links' => __( 'Footer Offer Type Links' ), 'footer-type-links' => __( 'Footer Type Links' ), ) ); } add_action( 'init', 'custom_register_my_menus' ); // Limit media library access function wpb_show_current_user_attachments( $query ) { $user_id = get_current_user_id(); if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts') ) { $query['author'] = $user_id; } return $query; } add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' ); // Block Agents Accessing WP Dashbard function blockAgentDashboardAccess() { $user_id = get_current_user_id(); $user_info = get_userdata($user_id); $user_roles = implode(', ', $user_info->roles); if (strpos($user_roles, 'agent') !== false && is_admin() && ! wp_doing_ajax() ) { header("Location:/"); die(); } } add_action( 'admin_init', 'blockAgentDashboardAccess' ); #add_filter('show_admin_bar', '__return_false'); add_image_size( 'agent-logo', 300, 125, true ); function remove_menus() { global $user_ID; if ( current_user_can( 'staff' ) ) { remove_menu_page( 'edit.php' ); remove_menu_page( 'edit.php?post_type=notifications' ); remove_menu_page( 'edit-comments.php' ); } } add_action( 'admin_menu', 'remove_menus' ); function my_footer_shh() { remove_filter( 'update_footer', 'core_update_footer' ); } add_action( 'admin_menu', 'my_footer_shh' ); function remove_wp_logo( $wp_admin_bar ) { $wp_admin_bar->remove_node( 'wp-logo' ); $wp_admin_bar->remove_node( 'new-content' ); $wp_admin_bar->remove_node( 'bar-comments' ); } add_action( 'admin_bar_menu', 'remove_wp_logo', 999 ); add_filter( 'bulk_actions-edit-property', 'my_custom_bulk_actions' ); function my_custom_bulk_actions( $actions ){ unset( $actions[ 'edit' ] ); unset( $actions[ 'trash' ] ); return $actions; } function remove_dashboard_meta() { global $user_ID; if ( current_user_can( 'staff' ) ) { remove_meta_box('dashboard_activity', 'dashboard', 'normal'); //Removes the 'Activity' widget (since 3.8) remove_meta_box('dashboard_right_now', 'dashboard', 'normal'); //Removes the 'At a Glance' widget } // remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); //Removes the 'incoming links' widget // remove_meta_box('dashboard_plugins', 'dashboard', 'normal'); //Removes the 'plugins' widget // remove_meta_box('dashboard_primary', 'dashboard', 'normal'); //Removes the 'WordPress News' widget // remove_meta_box('dashboard_secondary', 'dashboard', 'normal'); //Removes the secondary widget // remove_meta_box('dashboard_quick_press', 'dashboard', 'side'); //Removes the 'Quick Draft' widget // remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side'); //Removes the 'Recent Drafts' widget // remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal'); //Removes the 'Activity' widget } add_action('admin_init', 'remove_dashboard_meta'); ?> /*** ## Plugin Name: Custom Page Objects ## Plugin URI: http://www.mitchelldigital.co.uk ## Description: Kane Mitchell - Page Objects. ## Version: 1.0 ## Author: Kane Mitchell ## Author URI: http://www.mitchelldigital.co.uk */ define( 'bbCustom_DIR', plugin_dir_path( __FILE__ ) ); define( 'bbCustom_URL', plugins_url( '/', __FILE__ ) ); function bbCustomModules_bbPlugin() { if ( class_exists( 'FLBuilder' ) ) { require_once 'do-shortcode/do-shortcode.php'; require_once 'latest-properties/latest-properties.php'; } } add_action( 'init', 'bbCustomModules_bbPlugin' ); // Add Post Type -> Properties function register_posttype_properties() { $labels = array( 'name' => _x( 'Properties', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Property', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'Properties', 'text_domain' ), 'name_admin_bar' => __( 'Properties', 'text_domain' ), 'archives' => __( 'Item Archives', 'text_domain' ), 'attributes' => __( 'Item Attributes', 'text_domain' ), 'parent_item_colon' => __( 'Parent Item:', 'text_domain' ), 'all_items' => __( 'All Items', 'text_domain' ), 'add_new_item' => __( 'Add New Item', 'text_domain' ), 'add_new' => __( 'Add New', 'text_domain' ), 'new_item' => __( 'New Item', 'text_domain' ), 'edit_item' => __( 'Edit Item', 'text_domain' ), 'update_item' => __( 'Update Item', 'text_domain' ), 'view_item' => __( 'View Item', 'text_domain' ), 'view_items' => __( 'View Items', 'text_domain' ), 'search_items' => __( 'Search Item', 'text_domain' ), 'not_found' => __( 'Not found', 'text_domain' ), 'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ), 'featured_image' => __( 'Featured Image', 'text_domain' ), 'set_featured_image' => __( 'Set featured image', 'text_domain' ), 'remove_featured_image' => __( 'Remove featured image', 'text_domain' ), 'use_featured_image' => __( 'Use as featured image', 'text_domain' ), 'insert_into_item' => __( 'Insert into item', 'text_domain' ), 'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ), 'items_list' => __( 'Items list', 'text_domain' ), 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ), 'filter_items_list' => __( 'Filter items list', 'text_domain' ), ); $args = array( 'label' => __( 'Property', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'author', 'publicize' ), 'taxonomies' => array(), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_admin_bar' => false, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', ); register_post_type( 'property', $args ); ## Add Property Offer Type -> This is used to say what type of building it is. $labels = array( 'name' => _x( 'Property Offer Types', 'taxonomy general name' ), 'singular_name' => _x( 'Property Offer Type', 'taxonomy singular name' ), 'search_items' => __( 'Search Property Offer Types' ), 'all_items' => __( 'All Property Offer Types' ), 'parent_item' => __( 'Parent Property Offer Type' ), 'parent_item_colon' => __( 'Parent Property Offer Type:' ), 'edit_item' => __( 'Edit Property Offer Type' ), 'update_item' => __( 'Update Property Offer Type' ), 'add_new_item' => __( 'Add New Property Offer Type' ), 'new_item_name' => __( 'New Property Offer Type Name' ), 'menu_name' => __( 'Property Offer Types' ), ); register_taxonomy('property_offer_type','property', array( 'hierarchical' => false, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => false, 'query_var' => true, 'show_in_nav_menus' => false, 'rewrite' => array('slug' => 'properties/property-offer-type', 'with_front' => false), ) ); ## Add Property Type Category -> This is used to say what type of building it is. $labels = array( 'name' => _x( 'Property Types', 'taxonomy general name' ), 'singular_name' => _x( 'Property Type', 'taxonomy singular name' ), 'search_items' => __( 'Search Property Types' ), 'all_items' => __( 'All Property Types' ), 'parent_item' => __( 'Parent Property Type' ), 'parent_item_colon' => __( 'Parent Property Type:' ), 'edit_item' => __( 'Edit Property Type' ), 'update_item' => __( 'Update Property Type' ), 'add_new_item' => __( 'Add New Property Type' ), 'new_item_name' => __( 'New Property Type Name' ), 'menu_name' => __( 'Property Types' ), ); register_taxonomy('property_type','property', array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => false, 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'rewrite' => array('slug' => 'properties/property-type', 'with_front' => false), ) ); ## Add Location State -> States of Nigeria $labels = array( 'name' => _x( 'States', 'taxonomy general name' ), 'singular_name' => _x( 'State', 'taxonomy singular name' ), 'search_items' => __( 'Search States' ), 'all_items' => __( 'All States' ), 'parent_item' => __( 'Parent State' ), 'parent_item_colon' => __( 'Parent State:' ), 'edit_item' => __( 'Edit State' ), 'update_item' => __( 'Update State' ), 'add_new_item' => __( 'Add New State' ), 'new_item_name' => __( 'New State Name' ), 'menu_name' => __( 'States' ), ); register_taxonomy('property_state','property', array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => false, 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'rewrite' => array('slug' => 'properties/property-state', 'with_front' => false), ) ); ## Add Location Cities & Towns -> Cities & Towns of Nigeria $labels = array( 'name' => _x( 'Localitys', 'taxonomy general name' ), 'singular_name' => _x( 'Locality', 'taxonomy singular name' ), 'search_items' => __( 'Search Localitys' ), 'all_items' => __( 'All Localitys' ), 'parent_item' => __( 'Parent Locality' ), 'parent_item_colon' => __( 'Parent Locality:' ), 'edit_item' => __( 'Edit Locality' ), 'update_item' => __( 'Update Locality' ), 'add_new_item' => __( 'Add New Locality' ), 'new_item_name' => __( 'New Locality Name' ), 'menu_name' => __( 'Locality' ), ); register_taxonomy('property_place','property', array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => false, 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'rewrite' => array('slug' => 'properties/property-place', 'with_front' => false), ) ); ## Add Location Area $labels = array( 'name' => _x( 'Areas', 'taxonomy general name' ), 'singular_name' => _x( 'Area', 'taxonomy singular name' ), 'search_items' => __( 'Search Areas' ), 'all_items' => __( 'All Areas' ), 'parent_item' => __( 'Parent Area' ), 'parent_item_colon' => __( 'Parent Area:' ), 'edit_item' => __( 'Edit Area' ), 'update_item' => __( 'Update Area' ), 'add_new_item' => __( 'Add New Area' ), 'new_item_name' => __( 'New Area Name' ), 'menu_name' => __( 'Areas' ), ); register_taxonomy('property_area','property', array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => false, 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'rewrite' => array('slug' => 'properties/property-area', 'with_front' => false), ) ); } add_action( 'init', 'register_posttype_properties', 0 ); ## REMORE META BOXES function remove_PropertyMetaBoxes() { remove_meta_box( 'tagsdiv-property-offer-type', 'property', 'normal' ); remove_meta_box( 'tagsdiv-property_type', 'property', 'normal' ); remove_meta_box( 'tagsdiv-property_state', 'property', 'normal' ); remove_meta_box( 'tagsdiv-property_place', 'property', 'normal' ); } add_action( 'admin_menu' , 'remove_PropertyMetaBoxes' ); // Show the data in the Post List in the admin area. function bs_projects_table_head( $columns ) { $screen = get_current_screen(); #echo $screen; $new = array(); foreach($columns as $key => $title) { if ($key == 'author') { $new['status'] = 'Status'; } $new[$key] = $title; } return $new; } add_filter('manage_property_posts_columns', 'bs_projects_table_head'); function bs_projects_table_content( $column_name, $post_id ) { if( $column_name == 'status' ) { $propertyApproved = get_post_meta( $post_id, 'approved', true ); $propertyRejected = get_post_meta( $post_id, 'rejected', true ); $propertyPublished = get_post_meta( $post_id, 'published', true ); $status = ""; if( $propertyPublished == 0 ) { $status == 'Draft'; } elseif( $propertyPublished == 1 && $propertyApproved == 1 && $propertyRejected == 0 ) { $status = 'Approved'; } elseif( $propertyPublished == 1 && $propertyApproved == 0 && $propertyRejected == 0 ) { $status = 'Awaiting Approval'; } elseif( $propertyPublished == 1 && $propertyRejected == 1 ) { $status = 'Rejected'; } echo $status; } } add_action( 'manage_property_posts_custom_column', 'bs_projects_table_content', 10, 2 ); ?> // Register Custom Post Type function register_posttype_notifications() { $labels = array( 'name' => _x( 'Notifications', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Notification', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'Notifications', 'text_domain' ), 'name_admin_bar' => __( 'Post Type', 'text_domain' ), 'archives' => __( 'Notifications Archives', 'text_domain' ), 'attributes' => __( 'Notification Attributes', 'text_domain' ), 'parent_item_colon' => __( 'Notification Item:', 'text_domain' ), 'all_items' => __( 'All Notifications', 'text_domain' ), 'add_new_item' => __( 'Add New Notifications', 'text_domain' ), 'add_new' => __( 'Add Notification', 'text_domain' ), 'new_item' => __( 'New Notification', 'text_domain' ), 'edit_item' => __( 'Edit Notification', 'text_domain' ), 'update_item' => __( 'Update Notification', 'text_domain' ), 'view_item' => __( 'View Notification', 'text_domain' ), 'view_items' => __( 'View Notifications', 'text_domain' ), 'search_items' => __( 'Search Notification', 'text_domain' ), 'not_found' => __( 'Not found', 'text_domain' ), 'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ), 'featured_image' => __( 'Featured Image', 'text_domain' ), 'set_featured_image' => __( 'Set featured image', 'text_domain' ), 'remove_featured_image' => __( 'Remove featured image', 'text_domain' ), 'use_featured_image' => __( 'Use as featured image', 'text_domain' ), 'insert_into_item' => __( 'Insert into item', 'text_domain' ), 'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ), 'items_list' => __( 'Notifications list', 'text_domain' ), 'items_list_navigation' => __( 'Notifications list navigation', 'text_domain' ), 'filter_items_list' => __( 'Filter Notifications list', 'text_domain' ), ); $args = array( 'label' => __( 'Notification', 'text_domain' ), 'description' => __( 'Post Type Description', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor' ), 'hierarchical' => false, 'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_admin_bar' => false, 'show_in_nav_menus' => true, 'can_export' => false, 'has_archive' => false, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', ); register_post_type( 'notifications', $args ); } add_action( 'init', 'register_posttype_notifications', 0 ); ?> /***** Property Manager -> Shortcodes *****/ ## Add frontend form ## Main Search Form function shc_property_MainSearch() { $termsTypes = get_terms( array('taxonomy' => 'property_type', 'parent' => 0, 'orderby' => 'ID', 'order' => 'ASC', 'hide_empty' => false)); $termsStates = get_terms( array('taxonomy' => 'property_state','hide_empty' => false)); $termsPlaces = get_terms( array('taxonomy' => 'property_place','hide_empty' => false)); $termsAreas = get_terms( array('taxonomy' => 'property_area','hide_empty' => false)); $arrLocations = array(); $arrStates = array(); $arrPlaces = array(); $arrAreas = array(); $typeOptions = ""; foreach ($termsTypes as $type) { $typeOptions .= "