diff --git a/.gitignore b/.gitignore index 7bde6cd..c538b8f 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,5 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +vendor/* diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b3b6744 --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "stevegrunwell/wp-enforcer": "^0.5.0" + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..14623b4 --- /dev/null +++ b/composer.lock @@ -0,0 +1,153 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "81ff4fd6aed1d08f491e16f206291a67", + "packages": [], + "packages-dev": [ + { + "name": "squizlabs/php_codesniffer", + "version": "3.3.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "http://www.squizlabs.com/php-codesniffer", + "keywords": [ + "phpcs", + "standards" + ], + "time": "2018-09-23T23:08:17+00:00" + }, + { + "name": "stevegrunwell/wp-enforcer", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/stevegrunwell/wp-enforcer.git", + "reference": "6d583588d06346982b5819066f14675ddc8004d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stevegrunwell/wp-enforcer/zipball/6d583588d06346982b5819066f14675ddc8004d7", + "reference": "6d583588d06346982b5819066f14675ddc8004d7", + "shasum": "" + }, + "require": { + "wp-coding-standards/wpcs": "*" + }, + "bin": [ + "bin/wp-enforcer" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Steve Grunwell", + "email": "steve@stevegrunwell.com", + "homepage": "https://stevegrunwell.com" + } + ], + "description": "Git hooks to encourage well-written WordPress.", + "keywords": [ + "PHP_CodeSniffer", + "coding standards", + "git hooks", + "wordpress" + ], + "time": "2017-05-28T18:44:13+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git", + "reference": "7aa217ab38156c5cb4eae0f04ae376027c407a9b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress-Coding-Standards/WordPress-Coding-Standards/zipball/7aa217ab38156c5cb4eae0f04ae376027c407a9b", + "reference": "7aa217ab38156c5cb4eae0f04ae376027c407a9b", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2" + }, + "require-dev": { + "phpcompatibility/php-compatibility": "^9.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "wordpress" + ], + "time": "2018-11-12T10:13:12+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/includes/class-agent-import.php b/includes/class-agent-import.php index d3c57a4..3bca667 100755 --- a/includes/class-agent-import.php +++ b/includes/class-agent-import.php @@ -4,7 +4,9 @@ * to import agent data */ -if ( ! defined( 'ABSPATH' ) ) exit; +if ( ! defined( 'ABSPATH' ) ) { + exit; +} class IMPress_Agents_Import { public $_idx; @@ -12,10 +14,12 @@ class IMPress_Agents_Import { public function __construct() { } - public static function in_array($needle, $haystack, $strict = false) { - if(!$haystack) return false; - foreach ($haystack as $item) { - if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && self::in_array($needle, $item, $strict))) { + public static function in_array( $needle, $haystack, $strict = false ) { + if ( ! $haystack ) { + return false; + } + foreach ( $haystack as $item ) { + if ( ( $strict ? $item === $needle : $item == $needle ) || ( is_array( $item ) && self::in_array( $needle, $item, $strict ) ) ) { return true; } } @@ -24,182 +28,196 @@ public static function in_array($needle, $haystack, $strict = false) { /** * Creates a post of employee type using post data from options page + * * @param array $agentIDs agentID of the property * @return [type] $featured [description] */ - public static function impress_agents_idx_create_post($agentIDs) { - if(class_exists( 'IDX_Broker_Plugin')) { + public static function impress_agents_idx_create_post( $agentIDs ) { + if ( class_exists( 'IDX_Broker_Plugin' ) ) { // Load IDX Broker API Class and retrieve agents - $_idx_api = new \IDX\Idx_Api(); - $agents = $_idx_api->idx_api( + $_idx_api = new \IDX\Idx_Api(); + $agents = $_idx_api->idx_api( 'agents', - $apiversion = '1.2.2', - $level = 'clients', - $params = array(), - $expiration = 7200, - $request_type = 'GET', + $apiversion = '1.2.2', + $level = 'clients', + $params = array(), + $expiration = 7200, + $request_type = 'GET', $json_decode_type = true ); // Load WP options - $idx_agent_wp_options = get_option('impress_agents_idx_agent_wp_options'); - $impa_options = get_option('plugin_impress_agents_settings'); + $idx_agent_wp_options = get_option( 'impress_agents_idx_agent_wp_options' ); + $impa_options = get_option( 'plugin_impress_agents_settings' ); - foreach($agents as $agent) { + foreach ( $agents as $agent ) { - foreach($agent as $a) { + foreach ( $agent as $a ) { - if(!in_array($a['agentID'], $agentIDs)) { - $idx_agent_wp_options[$a['agentID']]['agentID'] = $a['agentID']; - $idx_agent_wp_options[$a['agentID']]['status'] = ''; + if ( ! in_array( $a['agentID'], $agentIDs ) ) { + $idx_agent_wp_options[ $a['agentID'] ]['agentID'] = $a['agentID']; + $idx_agent_wp_options[ $a['agentID'] ]['status'] = ''; } - if(isset($idx_agent_wp_options[$a['agentID']]['post_id']) && !get_post($idx_agent_wp_options[$a['agentID']]['post_id'])) { - unset($idx_agent_wp_options[$a['agentID']]['post_id']); - unset($idx_agent_wp_options[$a['agentID']]['status']); - } + if ( isset( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ) && ! get_post( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ) ) { + unset( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ); + unset( $idx_agent_wp_options[ $a['agentID'] ]['status'] ); + } - if(in_array($a['agentID'], $agentIDs) && !isset($idx_agent_wp_options[$a['agentID']]['post_id'])) { + if ( in_array( $a['agentID'], $agentIDs ) && ! isset( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ) ) { - $opts = array( + $opts = array( 'post_content' => $a['bioDetails'], - 'post_title' => $a['agentDisplayName'], - 'post_status' => 'publish', - 'post_type' => 'employee' + 'post_title' => $a['agentDisplayName'], + 'post_status' => 'publish', + 'post_type' => 'employee', ); - $add_post = wp_insert_post($opts, true); - if (is_wp_error($add_post)) { + $add_post = wp_insert_post( $opts, true ); + if ( is_wp_error( $add_post ) ) { $error_string = $add_post->get_error_message(); - add_settings_error('impress_agents_idx_agent_settings_group', 'insert_post_failed', 'WordPress failed to insert the post. Error ' . $error_string, 'error'); + add_settings_error( 'impress_agents_idx_agent_settings_group', 'insert_post_failed', 'WordPress failed to insert the post. Error ' . $error_string, 'error' ); return; - } elseif($add_post) { - $idx_agent_wp_options[$a['agentID']]['post_id'] = $add_post; - $idx_agent_wp_options[$a['agentID']]['status'] = 'publish'; - self::impress_agents_idx_insert_post_meta($add_post, $a); + } elseif ( $add_post ) { + $idx_agent_wp_options[ $a['agentID'] ]['post_id'] = $add_post; + $idx_agent_wp_options[ $a['agentID'] ]['status'] = 'publish'; + self::impress_agents_idx_insert_post_meta( $add_post, $a ); } - } - elseif( in_array($a['agentID'], $agentIDs) && $idx_agent_wp_options[$a['agentID']]['status'] != 'publish' ) { - self::impress_agents_idx_change_post_status($idx_agent_wp_options[$a['agentID']]['post_id'], 'publish'); - $idx_agent_wp_options[$a['agentID']]['status'] = 'publish'; - } - elseif( !in_array($a['agentID'], $agentIDs) && $idx_agent_wp_options[$a['agentID']]['status'] == 'publish' ) { + } elseif ( in_array( $a['agentID'], $agentIDs ) && $idx_agent_wp_options[ $a['agentID'] ]['status'] != 'publish' ) { + self::impress_agents_idx_change_post_status( $idx_agent_wp_options[ $a['agentID'] ]['post_id'], 'publish' ); + $idx_agent_wp_options[ $a['agentID'] ]['status'] = 'publish'; + } elseif ( ! in_array( $a['agentID'], $agentIDs ) && $idx_agent_wp_options[ $a['agentID'] ]['status'] == 'publish' ) { // change to draft or delete agent if the post exists but is not in the agent array based on settings - if(isset($impa_options['impress_agents_idx_remove']) && $impa_options['impress_agents_idx_remove'] == 'remove-draft') { + if ( isset( $impa_options['impress_agents_idx_remove'] ) && $impa_options['impress_agents_idx_remove'] == 'remove-draft' ) { // Change to draft - self::impress_agents_idx_change_post_status($idx_agent_wp_options[$a['agentID']]['post_id'], 'draft'); - $idx_agent_wp_options[$a['agentID']]['status'] = 'draft'; - } elseif(isset($impa_options['impress_agents_idx_remove']) && $impa_options['impress_agents_idx_remove'] == 'remove-delete') { + self::impress_agents_idx_change_post_status( $idx_agent_wp_options[ $a['agentID'] ]['post_id'], 'draft' ); + $idx_agent_wp_options[ $a['agentID'] ]['status'] = 'draft'; + } elseif ( isset( $impa_options['impress_agents_idx_remove'] ) && $impa_options['impress_agents_idx_remove'] == 'remove-delete' ) { - $idx_agent_wp_options[$a['agentID']]['status'] = 'deleted'; + $idx_agent_wp_options[ $a['agentID'] ]['status'] = 'deleted'; // Delete featured image - $post_featured_image_id = get_post_thumbnail_id( $idx_agent_wp_options[$a['agentID']]['post_id'] ); + $post_featured_image_id = get_post_thumbnail_id( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ); wp_delete_attachment( $post_featured_image_id ); - //Delete post - wp_delete_post( $idx_agent_wp_options[$a['agentID']]['post_id'] ); + // Delete post + wp_delete_post( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ); } } } } - update_option('impress_agents_idx_agent_wp_options', $idx_agent_wp_options); + update_option( 'impress_agents_idx_agent_wp_options', $idx_agent_wp_options ); return $idx_agent_wp_options; } } /** * Update existing post + * * @return true if success */ public static function impress_agents_update_post() { // Load IDX Broker API Class and retrieve agents - $_idx_api = new \IDX\Idx_Api(); - $agents = $_idx_api->idx_api( + $_idx_api = new \IDX\Idx_Api(); + $agents = $_idx_api->idx_api( 'agents', - $apiversion = '1.2.2', - $level = 'clients', - $params = array(), - $expiration = 7200, - $request_type = 'GET', + $apiversion = '1.2.2', + $level = 'clients', + $params = array(), + $expiration = 7200, + $request_type = 'GET', $json_decode_type = true ); // Load WP options - $idx_agent_wp_options = get_option('impress_agents_idx_agent_wp_options'); - $impa_options = get_option('plugin_impress_agents_settings'); + $idx_agent_wp_options = get_option( 'impress_agents_idx_agent_wp_options' ); + $impa_options = get_option( 'plugin_impress_agents_settings' ); foreach ( $agents as $agent ) { - foreach($agent as $a) { + foreach ( $agent as $a ) { - if( isset($idx_agent_wp_options[$a['agentID']]['post_id']) ) { + if ( isset( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ) ) { // Update agent data - if(!isset($impa_options['impress_agents_idx_update']) || isset($impa_options['impress_agents_idx_update']) && $impa_options['impress_agents_idx_update'] != 'update-none') - self::impress_agents_idx_insert_post_meta($idx_agent_wp_options[$a['agentID']]['post_id'], $a, true, false ); - $idx_agent_wp_options[$a['agentID']]['updated'] = date("m/d/Y h:i:sa"); + if ( ! isset( $impa_options['impress_agents_idx_update'] ) || isset( $impa_options['impress_agents_idx_update'] ) && $impa_options['impress_agents_idx_update'] != 'update-none' ) { + self::impress_agents_idx_insert_post_meta( $idx_agent_wp_options[ $a['agentID'] ]['post_id'], $a, true, false ); + } + $idx_agent_wp_options[ $a['agentID'] ]['updated'] = date( 'm/d/Y h:i:sa' ); } } - } - update_option('impress_agents_idx_agent_wp_options', $idx_agent_wp_options); + update_option( 'impress_agents_idx_agent_wp_options', $idx_agent_wp_options ); } /** * Change post status + * * @param [type] $post_id [description] * @param [type] $status [description] * @return [type] [description] */ - public static function impress_agents_idx_change_post_status($post_id, $status){ - $current_post = get_post( $post_id, 'ARRAY_A' ); - $current_post['post_status'] = $status; - wp_update_post($current_post); + public static function impress_agents_idx_change_post_status( $post_id, $status ) { + $current_post = get_post( $post_id, 'ARRAY_A' ); + $current_post['post_status'] = $status; + wp_update_post( $current_post ); } /** * Inserts post meta based on property data * API fields are mapped to post meta fields * prefixed with _employee_ and lowercased + * * @param [type] $id [description] * @return [type] [description] */ - public static function impress_agents_idx_insert_post_meta($id, $idx_agent_data, $update = false, $update_image = true) { + public static function impress_agents_idx_insert_post_meta( $id, $idx_agent_data, $update = false, $update_image = true ) { // Add or reset taxonomies terms for job-types = agentTitle - wp_set_object_terms($id, $idx_agent_data['agentTitle'], 'job-types'); + wp_set_object_terms( $id, $idx_agent_data['agentTitle'], 'job-types' ); // Add post meta for existing fields - if(get_post_meta($id, '_employee_title') == false) { update_post_meta($id, '_employee_title', $idx_agent_data['agentTitle']); } - if(get_post_meta($id, '_employee_first_name') == false) { update_post_meta($id, '_employee_first_name', $idx_agent_data['agentFirstName']); } - if(get_post_meta($id, '_employee_last_name') == false) { update_post_meta($id, '_employee_last_name', $idx_agent_data['agentLastName']); } - if(get_post_meta($id, '_employee_agent_id') == false) { update_post_meta($id, '_employee_agent_id', $idx_agent_data['agentID']); } - if(get_post_meta($id, '_employee_phone') == false) { update_post_meta($id, '_employee_phone', $idx_agent_data['agentContactPhone']); } - if(get_post_meta($id, '_employee_mobile') == false) { update_post_meta($id, '_employee_mobile', $idx_agent_data['agentCellPhone']); } - if(get_post_meta($id, '_employee_email') == false) { update_post_meta($id, '_employee_email', $idx_agent_data['agentEmail']); } - if(get_post_meta($id, '_employee_website') == false) { update_post_meta($id, '_employee_website', $idx_agent_data['agentURL']); } - if(get_post_meta($id, '_employee_address') == false) { update_post_meta($id, '_employee_address', $idx_agent_data['address']); } - if(get_post_meta($id, '_employee_city') == false) { update_post_meta($id, '_employee_city', $idx_agent_data['city']); } - if(get_post_meta($id, '_employee_state') == false) { update_post_meta($id, '_employee_state', $idx_agent_data['stateProvince']); } - if(get_post_meta($id, '_employee_zip') == false) { update_post_meta($id, '_employee_zip', $idx_agent_data['zipCode']); } - - foreach ($idx_agent_data as $metakey => $metavalue) { - if(isset($metavalue) && !is_array($metavalue) && $metavalue != '') { - if(get_post_meta($id, '_employee_' . strtolower($metakey)) == false) { - update_post_meta($id, '_employee_' . strtolower($metakey), $metavalue); + if ( get_post_meta( $id, '_employee_title' ) == false ) { + update_post_meta( $id, '_employee_title', $idx_agent_data['agentTitle'] ); } + if ( get_post_meta( $id, '_employee_first_name' ) == false ) { + update_post_meta( $id, '_employee_first_name', $idx_agent_data['agentFirstName'] ); } + if ( get_post_meta( $id, '_employee_last_name' ) == false ) { + update_post_meta( $id, '_employee_last_name', $idx_agent_data['agentLastName'] ); } + if ( get_post_meta( $id, '_employee_agent_id' ) == false ) { + update_post_meta( $id, '_employee_agent_id', $idx_agent_data['agentID'] ); } + if ( get_post_meta( $id, '_employee_phone' ) == false ) { + update_post_meta( $id, '_employee_phone', $idx_agent_data['agentContactPhone'] ); } + if ( get_post_meta( $id, '_employee_mobile' ) == false ) { + update_post_meta( $id, '_employee_mobile', $idx_agent_data['agentCellPhone'] ); } + if ( get_post_meta( $id, '_employee_email' ) == false ) { + update_post_meta( $id, '_employee_email', $idx_agent_data['agentEmail'] ); } + if ( get_post_meta( $id, '_employee_website' ) == false ) { + update_post_meta( $id, '_employee_website', $idx_agent_data['agentURL'] ); } + if ( get_post_meta( $id, '_employee_address' ) == false ) { + update_post_meta( $id, '_employee_address', $idx_agent_data['address'] ); } + if ( get_post_meta( $id, '_employee_city' ) == false ) { + update_post_meta( $id, '_employee_city', $idx_agent_data['city'] ); } + if ( get_post_meta( $id, '_employee_state' ) == false ) { + update_post_meta( $id, '_employee_state', $idx_agent_data['stateProvince'] ); } + if ( get_post_meta( $id, '_employee_zip' ) == false ) { + update_post_meta( $id, '_employee_zip', $idx_agent_data['zipCode'] ); } + + foreach ( $idx_agent_data as $metakey => $metavalue ) { + if ( isset( $metavalue ) && ! is_array( $metavalue ) && $metavalue != '' ) { + if ( get_post_meta( $id, '_employee_' . strtolower( $metakey ) ) == false ) { + update_post_meta( $id, '_employee_' . strtolower( $metakey ), $metavalue ); } - } elseif(isset( $metavalue ) && is_array( $metavalue )) { - foreach ($metavalue as $key => $value) { - if(get_post_meta($id, '_employee_' . strtolower($metakey))) { - $oldvalue = get_post_meta($id, '_employee_' . strtolower($metakey), true); + } elseif ( isset( $metavalue ) && is_array( $metavalue ) ) { + foreach ( $metavalue as $key => $value ) { + if ( get_post_meta( $id, '_employee_' . strtolower( $metakey ) ) ) { + $oldvalue = get_post_meta( $id, '_employee_' . strtolower( $metakey ), true ); $newvalue = $value . ', ' . $oldvalue; - update_post_meta($id, '_employee_' . strtolower($metakey), $newvalue); + update_post_meta( $id, '_employee_' . strtolower( $metakey ), $newvalue ); } else { - update_post_meta($id, '_employee_' . strtolower($metakey), $value); + update_post_meta( $id, '_employee_' . strtolower( $metakey ), $value ); } } } @@ -210,8 +228,8 @@ public static function impress_agents_idx_insert_post_meta($id, $idx_agent_data, */ $featured_image = $idx_agent_data['agentPhotoURL']; - if(isset($featured_image) && $featured_image != null) { - if($update == false || $update_image == true) { + if ( isset( $featured_image ) && $featured_image != null ) { + if ( $update == false || $update_image == true ) { // Delete previously attached image $post_featured_image_id = get_post_thumbnail_id( $id ); wp_delete_attachment( $post_featured_image_id ); @@ -219,19 +237,20 @@ public static function impress_agents_idx_insert_post_meta($id, $idx_agent_data, // Add Featured Image to Post $image_url = $featured_image; // Define the image URL here $upload_dir = wp_upload_dir(); // Set upload folder - $image_data = file_get_contents($image_url); // Get image data - $filename = basename(sanitize_file_name(strtolower( $idx_agent_data['agentDisplayName'] )) . '.jpg'); // Create image file name + $image_data = file_get_contents( $image_url ); // Get image data + $filename = basename( sanitize_file_name( strtolower( $idx_agent_data['agentDisplayName'] ) ) . '.jpg' ); // Create image file name // Check folder permission and define file location - if( wp_mkdir_p( $upload_dir['path'] ) ) { + if ( wp_mkdir_p( $upload_dir['path'] ) ) { $file = $upload_dir['path'] . '/' . $filename; } else { $file = $upload_dir['basedir'] . '/' . $filename; } // Create the image file on the server - if(!file_exists($file)) + if ( ! file_exists( $file ) ) { file_put_contents( $file, $image_data ); + } // Check image file type $wp_filetype = wp_check_filetype( $filename, null ); @@ -241,14 +260,14 @@ public static function impress_agents_idx_insert_post_meta($id, $idx_agent_data, 'post_mime_type' => $wp_filetype['type'], 'post_title' => $idx_agent_data['agentDisplayName'] . ' - ' . $idx_agent_data['agentID'], 'post_content' => '', - 'post_status' => 'inherit' + 'post_status' => 'inherit', ); // Create the attachment $attach_id = wp_insert_attachment( $attachment, $file, $id ); // Include image.php - require_once(ABSPATH . 'wp-admin/includes/image.php'); + require_once ABSPATH . 'wp-admin/includes/image.php'; // Define attachment metadata $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); @@ -272,21 +291,22 @@ public static function impress_agents_idx_insert_post_meta($id, $idx_agent_data, * Enqueues scripts for display * Deletes post and post thumbnail via ajax */ -add_action( 'admin_menu', 'impress_agents_idx_agent_register_menu_page'); +add_action( 'admin_menu', 'impress_agents_idx_agent_register_menu_page' ); function impress_agents_idx_agent_register_menu_page() { add_submenu_page( 'edit.php?post_type=employee', __( 'Import Agents', 'impress_agents' ), __( 'Import Agents', 'impress_agents' ), 'manage_options', 'impa-idx-agent', 'impress_agents_idx_agent_setting_page' ); add_action( 'admin_init', 'impress_agents_idx_agent_register_settings' ); } function impress_agents_idx_agent_register_settings() { - register_setting('impress_agents_idx_agent_settings_group', 'impress_agents_idx_agent_options', array('IMPress_Agents_Import', 'impress_agents_idx_create_post')); + register_setting( 'impress_agents_idx_agent_settings_group', 'impress_agents_idx_agent_options', array( 'IMPress_Agents_Import', 'impress_agents_idx_create_post' ) ); } add_action( 'admin_enqueue_scripts', 'impress_agents_idx_agent_scripts' ); function impress_agents_idx_agent_scripts() { $screen = get_current_screen(); - if($screen->id != 'employee_page_impa-idx-agent') + if ( $screen->id != 'employee_page_impa-idx-agent' ) { return; + } wp_enqueue_script( 'impress_agents_idx_agent_delete_script', IMPRESS_AGENTS_URL . 'includes/js/admin-agent-import.js', array( 'jquery' ), true ); wp_enqueue_script( 'jquery-masonry' ); @@ -295,18 +315,17 @@ function impress_agents_idx_agent_scripts() { wp_enqueue_style( 'impress_agents_idx_agent_style', IMPRESS_AGENTS_URL . 'includes/css/impress-agents-import.css' ); } add_action( 'wp_ajax_impa_idx_agent_delete', 'impa_idx_agent_delete' ); -function impa_idx_agent_delete(){ +function impa_idx_agent_delete() { $permission = check_ajax_referer( 'impa_idx_agent_delete_nonce', 'nonce', false ); - if( $permission == false ) { + if ( $permission == false ) { echo 'error'; - } - else { + } else { // Delete featured image $post_featured_image_id = get_post_thumbnail_id( $_REQUEST['id'] ); wp_delete_attachment( $post_featured_image_id ); - //Delete post + // Delete post wp_delete_post( $_REQUEST['id'] ); echo 'success'; } @@ -319,23 +338,22 @@ function impress_agents_idx_agent_setting_page() {

Select the agents to import.

- + - //
- // Sign up for IDX now! - //
'; - + // + //
+ // Sign up for IDX now! + //
'; return; } - settings_errors('impress_agents_idx_agent_settings_group'); + settings_errors( 'impress_agents_idx_agent_settings_group' ); ?>
    @@ -346,80 +364,81 @@ function impress_agents_idx_agent_setting_page() { $plugin_data = get_plugins(); // Get agents from IDX Broker plugin - if (class_exists( 'IDX_Broker_Plugin' )) { + if ( class_exists( 'IDX_Broker_Plugin' ) ) { // bail if IDX plugin version is not at least 2.0 - if($plugin_data['idx-broker-platinum/idx-broker-platinum.php']['Version'] < 2.0 ) { - add_settings_error('impress_agents_idx_agent_settings_group', 'idx_agent_update', 'You must update to IMPress for IDX Broker version 2.0.0 or higher to import listings.', 'error'); - settings_errors('impress_agents_idx_agent_settings_group'); + if ( $plugin_data['idx-broker-platinum/idx-broker-platinum.php']['Version'] < 2.0 ) { + add_settings_error( 'impress_agents_idx_agent_settings_group', 'idx_agent_update', 'You must update to IMPress for IDX Broker version 2.0.0 or higher to import listings.', 'error' ); + settings_errors( 'impress_agents_idx_agent_settings_group' ); return; } - $_idx_api = new \IDX\Idx_Api(); - $agents = $_idx_api->idx_api( + $_idx_api = new \IDX\Idx_Api(); + $agents = $_idx_api->idx_api( 'agents', - $apiversion = '1.2.2', - $level = 'clients', - $params = array(), - $expiration = 7200, - $request_type = 'GET', + $apiversion = '1.2.2', + $level = 'clients', + $params = array(), + $expiration = 7200, + $request_type = 'GET', $json_decode_type = true ); - //$agents = $_idx_api->idx_api('agents'); + // $agents = $_idx_api->idx_api('agents'); } else { return; } - $idx_agent_wp_options = get_option('impress_agents_idx_agent_options'); + $idx_agent_wp_options = get_option( 'impress_agents_idx_agent_options' ); settings_fields( 'impress_agents_idx_agent_settings_group' ); do_settings_sections( 'impress_agents_idx_agent_settings_group' ); // No agents found - if(!$agents) { + if ( ! $agents ) { echo 'No agents found.'; return; } // Loop through agents - foreach ($agents as $agent) { - foreach ($agent as $a) { + foreach ( $agents as $agent ) { + foreach ( $agent as $a ) { - if(!isset($idx_agent_wp_options[$a['agentID']]['post_id']) || !get_post($idx_agent_wp_options[$a['agentID']]['post_id']) ) { - $idx_agent_wp_options[$a['agentID']] = array( - 'agentID' => $a['agentID'] - ); + if ( ! isset( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ) || ! get_post( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ) ) { + $idx_agent_wp_options[ $a['agentID'] ] = array( + 'agentID' => $a['agentID'], + ); } - if(isset($idx_agent_wp_options[$a['agentID']]['post_id']) && get_post($idx_agent_wp_options[$a['agentID']]['post_id']) ) { - $pid = $idx_agent_wp_options[$a['agentID']]['post_id']; - $nonce = wp_create_nonce('impa_idx_agent_delete_nonce'); - $delete_agent = sprintf('Delete', - admin_url( 'admin-ajax.php?action=impa_idx_agent_delete&id=' . $pid . '&nonce=' . $nonce), - $pid, - $nonce - ); + if ( isset( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ) && get_post( $idx_agent_wp_options[ $a['agentID'] ]['post_id'] ) ) { + $pid = $idx_agent_wp_options[ $a['agentID'] ]['post_id']; + $nonce = wp_create_nonce( 'impa_idx_agent_delete_nonce' ); + $delete_agent = sprintf( + 'Delete', + admin_url( 'admin-ajax.php?action=impa_idx_agent_delete&id=' . $pid . '&nonce=' . $nonce ), + $pid, + $nonce + ); } - printf('
    ', + printf( + '
    ', $a['agentID'], - isset($idx_agent_wp_options[$a['agentID']]['status']) ? ($idx_agent_wp_options[$a['agentID']]['status'] == 'publish' ? "imported" : '') : '', - isset($a['agentPhotoURL']) && $a['agentPhotoURL'] != '' ? $a['agentPhotoURL'] : IMPRESS_AGENTS_URL . 'images/impress-agents-nophoto.png', + isset( $idx_agent_wp_options[ $a['agentID'] ]['status'] ) ? ( $idx_agent_wp_options[ $a['agentID'] ]['status'] == 'publish' ? 'imported' : '' ) : '', + isset( $a['agentPhotoURL'] ) && $a['agentPhotoURL'] != '' ? $a['agentPhotoURL'] : IMPRESS_AGENTS_URL . 'images/impress-agents-nophoto.png', $a['agentID'], $a['agentID'], - isset($idx_agent_wp_options[$a['agentID']]['status']) ? ($idx_agent_wp_options[$a['agentID']]['status'] == 'publish' ? "checked" : '') : '', + isset( $idx_agent_wp_options[ $a['agentID'] ]['status'] ) ? ( $idx_agent_wp_options[ $a['agentID'] ]['status'] == 'publish' ? 'checked' : '' ) : '', $a['agentDisplayName'], $a['agentTitle'], - isset($a['agentContactPhone']) ? $a['agentContactPhone'] : '', + isset( $a['agentContactPhone'] ) ? $a['agentContactPhone'] : '', $a['agentID'], - isset($idx_agent_wp_options[$a['agentID']]['status']) ? ($idx_agent_wp_options[$a['agentID']]['status'] == 'publish' ? "Imported" : '') : '', - isset($idx_agent_wp_options[$a['agentID']]['status']) ? ($idx_agent_wp_options[$a['agentID']]['status'] == 'publish' ? $delete_agent : '') : '' - ); + isset( $idx_agent_wp_options[ $a['agentID'] ]['status'] ) ? ( $idx_agent_wp_options[ $a['agentID'] ]['status'] == 'publish' ? "Imported" : '' ) : '', + isset( $idx_agent_wp_options[ $a['agentID'] ]['status'] ) ? ( $idx_agent_wp_options[ $a['agentID'] ]['status'] == 'publish' ? $delete_agent : '' ) : '' + ); } - } echo '
'; - submit_button('Import Agents'); + submit_button( 'Import Agents' ); ?>
options = get_option('plugin_impress_agents_settings'); - - $this->employee_details = apply_filters( 'impress_agents_employee_details', array( - 'col1' => array( - __( 'First Name:', 'impress_agents' ) => '_employee_first_name', - __( 'Last Name:', 'impress_agents' ) => '_employee_last_name', - __( 'Title:', 'impress_agents' ) => '_employee_title', - __( 'Email:', 'impress_agents' ) => '_employee_email', - __( 'Website:', 'impress_agents' ) => '_employee_website', - __( 'Phone:', 'impress_agents' ) => '_employee_phone', - __( 'Mobile:', 'impress_agents' ) => '_employee_mobile' - ), - 'col2' => array( - __( 'License #:', 'impress_agents' ) => '_employee_license', - __( 'Agent ID:', 'impress_agents' ) => '_employee_agent_id', - __( 'Designations:', 'impress_agents' ) => '_employee_designations', - __( 'Address:', 'impress_agents' ) => '_employee_address', - __( 'City:', 'impress_agents' ) => '_employee_city', - __( 'State:', 'impress_agents' ) => '_employee_state', - __( 'Zip:', 'impress_agents' ) => '_employee_zip' - ), - ) ); - - $this->employee_social = apply_filters( 'impress_agents_employee_social', array( - __( 'Facebook URL:', 'impress_agents' ) => '_employee_facebook', - __( 'Twitter URL:', 'impress_agents' ) => '_employee_twitter', - __( 'LinkedIn URL:', 'impress_agents' ) => '_employee_linkedin', - __( 'Google+ URL:', 'impress_agents' ) => '_employee_googleplus', - __( 'Pinterest URL:', 'impress_agents' ) => '_employee_pinterest', - __( 'YouTube URL:', 'impress_agents' ) => '_employee_youtube', - __( 'Instagram URL:', 'impress_agents' ) => '_employee_instagram' + $this->options = get_option( 'plugin_impress_agents_settings' ); + + $this->employee_details = apply_filters( + 'impress_agents_employee_details', + array( + 'col1' => array( + __( 'First Name:', 'impress_agents' ) => '_employee_first_name', + __( 'Last Name:', 'impress_agents' ) => '_employee_last_name', + __( 'Title:', 'impress_agents' ) => '_employee_title', + __( 'Email:', 'impress_agents' ) => '_employee_email', + __( 'Website:', 'impress_agents' ) => '_employee_website', + __( 'Phone:', 'impress_agents' ) => '_employee_phone', + __( 'Mobile:', 'impress_agents' ) => '_employee_mobile', + ), + 'col2' => array( + __( 'License #:', 'impress_agents' ) => '_employee_license', + __( 'Agent ID:', 'impress_agents' ) => '_employee_agent_id', + __( 'Designations:', 'impress_agents' ) => '_employee_designations', + __( 'Address:', 'impress_agents' ) => '_employee_address', + __( 'City:', 'impress_agents' ) => '_employee_city', + __( 'State:', 'impress_agents' ) => '_employee_state', + __( 'Zip:', 'impress_agents' ) => '_employee_zip', + ), + ) + ); + + $this->employee_social = apply_filters( + 'impress_agents_employee_social', + array( + __( 'Facebook URL:', 'impress_agents' ) => '_employee_facebook', + __( 'Twitter URL:', 'impress_agents' ) => '_employee_twitter', + __( 'LinkedIn URL:', 'impress_agents' ) => '_employee_linkedin', + __( 'Google+ URL:', 'impress_agents' ) => '_employee_googleplus', + __( 'Pinterest URL:', 'impress_agents' ) => '_employee_pinterest', + __( 'YouTube URL:', 'impress_agents' ) => '_employee_youtube', + __( 'Instagram URL:', 'impress_agents' ) => '_employee_instagram', ) ); @@ -90,10 +96,10 @@ function add_options() { $new_options = array( 'impress_agents_archive_posts_num' => 9, - 'impress_agents_slug' => 'employees' + 'impress_agents_slug' => 'employees', ); - if ( empty($this->options['impress_agents_slug']) && empty($this->options['impress_agents_archive_posts_num']) ) { + if ( empty( $this->options['impress_agents_slug'] ) && empty( $this->options['impress_agents_archive_posts_num'] ) ) { add_option( 'plugin_impress_agents_settings', $new_options ); } @@ -110,7 +116,7 @@ function settings_init() { * Creates display of settings page along with form fields */ function settings_page() { - include( dirname( __FILE__ ) . '/views/impress-agents-settings.php' ); + include dirname( __FILE__ ) . '/views/impress-agents-settings.php'; } /** @@ -118,35 +124,40 @@ function settings_page() { */ function create_post_type() { - $args = apply_filters( 'impress_agents_post_type_args', + $args = apply_filters( + 'impress_agents_post_type_args', array( - 'labels' => array( - 'name' => __( 'Employees', 'impress_agents' ), - 'singular_name' => __( 'Employee', 'impress_agents' ), - 'add_new' => __( 'Add New', 'impress_agents' ), - 'add_new_item' => __( 'Add New Employee', 'impress_agents' ), - 'edit' => __( 'Edit', 'impress_agents' ), - 'edit_item' => __( 'Edit Employee', 'impress_agents' ), - 'new_item' => __( 'New Employee', 'impress_agents' ), - 'view' => __( 'View Employee', 'impress_agents' ), - 'view_item' => __( 'View Employee', 'impress_agents' ), - 'search_items' => __( 'Search Employees', 'impress_agents' ), - 'not_found' => __( 'No employees found', 'impress_agents' ), - 'not_found_in_trash' => __( 'No employees found in Trash', 'impress_agents' ), + 'labels' => array( + 'name' => __( 'Employees', 'impress_agents' ), + 'singular_name' => __( 'Employee', 'impress_agents' ), + 'add_new' => __( 'Add New', 'impress_agents' ), + 'add_new_item' => __( 'Add New Employee', 'impress_agents' ), + 'edit' => __( 'Edit', 'impress_agents' ), + 'edit_item' => __( 'Edit Employee', 'impress_agents' ), + 'new_item' => __( 'New Employee', 'impress_agents' ), + 'view' => __( 'View Employee', 'impress_agents' ), + 'view_item' => __( 'View Employee', 'impress_agents' ), + 'search_items' => __( 'Search Employees', 'impress_agents' ), + 'not_found' => __( 'No employees found', 'impress_agents' ), + 'not_found_in_trash' => __( 'No employees found in Trash', 'impress_agents' ), 'filter_items_list' => __( 'Filter Employees', 'impress_agents' ), 'items_list_navigation' => __( 'Employees navigation', 'impress_agents' ), - 'items_list' => __( 'Employees list', 'impress_agents' ) + 'items_list' => __( 'Employees list', 'impress_agents' ), ), - 'public' => true, - 'query_var' => true, - 'show_in_rest' => true, - 'rest_base' => 'employee', + 'public' => true, + 'query_var' => true, + 'show_in_rest' => true, + 'rest_base' => 'employee', 'rest_controller_class' => 'WP_REST_Posts_Controller', - 'menu_position' => 5, - 'menu_icon' => 'dashicons-groups', - 'has_archive' => true, - 'supports' => array( 'title', 'editor', 'author', 'comments', 'excerpt', 'thumbnail', 'revisions', 'equity-layouts', 'equity-cpt-archives-settings', 'genesis-seo', 'genesis-layouts', 'genesis-simple-sidebars', 'genesis-cpt-archives-settings', 'publicize', 'wpcom-markdown'), - 'rewrite' => array( 'slug' => $this->options['impress_agents_slug'], 'feeds' => true, 'with_front' => false ), + 'menu_position' => 5, + 'menu_icon' => 'dashicons-groups', + 'has_archive' => true, + 'supports' => array( 'title', 'editor', 'author', 'comments', 'excerpt', 'thumbnail', 'revisions', 'equity-layouts', 'equity-cpt-archives-settings', 'genesis-seo', 'genesis-layouts', 'genesis-simple-sidebars', 'genesis-cpt-archives-settings', 'publicize', 'wpcom-markdown' ), + 'rewrite' => array( + 'slug' => $this->options['impress_agents_slug'], + 'feeds' => true, + 'with_front' => false, + ), ) ); @@ -159,62 +170,70 @@ function register_meta_boxes() { } function employee_details_metabox() { - include( dirname( __FILE__ ) . '/views/employee-details-metabox.php' ); + include dirname( __FILE__ ) . '/views/employee-details-metabox.php'; } function metabox_save( $post_id, $post ) { /** Run only on employees post type save */ - if ( 'employee' != $post->post_type ) + if ( 'employee' != $post->post_type ) { return; + } - if ( !isset( $_POST['impress_agents_metabox_nonce'] ) || !wp_verify_nonce( $_POST['impress_agents_metabox_nonce'], 'impress_agents_metabox_save' ) ) - return $post_id; - - /** Don't try to save the data under autosave, ajax, or future post */ - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return; - if ( defined( 'DOING_CRON' ) && DOING_CRON ) return; + if ( ! isset( $_POST['impress_agents_metabox_nonce'] ) || ! wp_verify_nonce( $_POST['impress_agents_metabox_nonce'], 'impress_agents_metabox_save' ) ) { + return $post_id; + } - /** Check permissions */ - if ( ! current_user_can( 'edit_post', $post_id ) ) - return; + /** Don't try to save the data under autosave, ajax, or future post */ + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + return; + } + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { + return; + } + if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + return; + } - $employee_details = $_POST['impress_agents']; + /** Check permissions */ + if ( ! current_user_can( 'edit_post', $post_id ) ) { + return; + } - /** Store the employee details custom fields */ - foreach ( (array) $employee_details as $key => $value ) { + $employee_details = $_POST['impress_agents']; - $key = sanitize_key($key); + /** Store the employee details custom fields */ + foreach ( (array) $employee_details as $key => $value ) { - if($key == '_employee_email') { - $value = sanitize_email($value); - } else { - $value = sanitize_text_field($value); - } + $key = sanitize_key( $key ); - /** Save/Update/Delete */ - if ( $value ) { - update_post_meta($post->ID, $key, $value); - } else { - delete_post_meta($post->ID, $key); - } + if ( $key == '_employee_email' ) { + $value = sanitize_email( $value ); + } else { + $value = sanitize_text_field( $value ); + } - } + /** Save/Update/Delete */ + if ( $value ) { + update_post_meta( $post->ID, $key, $value ); + } else { + delete_post_meta( $post->ID, $key ); + } + } } /** * Filter the columns in the "Employees" screen, define our own. */ - function columns_filter ( $columns ) { + function columns_filter( $columns ) { $columns = array( - 'cb' => '', - 'employee_thumbnail' => __( 'Thumbnail', 'impress_agents' ), - 'title' => __( 'Employee Name', 'impress_agents' ), - 'employee_details' => __( 'Details', 'impress_agents' ), - 'employee_tags' => __( 'Categories', 'impress_agents' ) + 'cb' => '', + 'employee_thumbnail' => __( 'Thumbnail', 'impress_agents' ), + 'title' => __( 'Employee Name', 'impress_agents' ), + 'employee_details' => __( 'Details', 'impress_agents' ), + 'employee_tags' => __( 'Categories', 'impress_agents' ), ); return $columns; @@ -230,27 +249,28 @@ function columns_data( $column ) { $image_size = 'style="max-width: 115px;"'; - apply_filters( 'impress_agents_admin_employee_details', $admin_details = $this->employee_details['col1']); + apply_filters( 'impress_agents_admin_employee_details', $admin_details = $this->employee_details['col1'] ); - if (isset($_GET["mode"]) && trim($_GET["mode"]) == 'excerpt' ) { - apply_filters( 'impress_agents_admin_extended_details', $admin_details = $this->employee_details['col1'] + $this->employee_details['col2']); + if ( isset( $_GET['mode'] ) && trim( $_GET['mode'] ) == 'excerpt' ) { + apply_filters( 'impress_agents_admin_extended_details', $admin_details = $this->employee_details['col1'] + $this->employee_details['col2'] ); $image_size = 'style="max-width: 150px;"'; } - $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail'); + $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' ); - switch( $column ) { - case "employee_thumbnail": + switch ( $column ) { + case 'employee_thumbnail': echo '

employee-thumbnail

'; break; - case "employee_details": + case 'employee_details': foreach ( (array) $admin_details as $label => $key ) { - printf( '%s %s
', esc_html( $label ), esc_html( get_post_meta($post->ID, $key, true) ) ); + printf( '%s %s
', esc_html( $label ), esc_html( get_post_meta( $post->ID, $key, true ) ) ); } break; - case "employee_tags": - _e('Job Type: ' . get_the_term_list( $post->ID, 'job-types', '', ', ', '' ) . '
', 'impress_agents'); - _e('Office: ' . get_the_term_list( $post->ID, 'offices', '', ', ', '' ) . '
', 'impress_agents'); break; + case 'employee_tags': + _e( 'Job Type: ' . get_the_term_list( $post->ID, 'job-types', '', ', ', '' ) . '
', 'impress_agents' ); + _e( 'Office: ' . get_the_term_list( $post->ID, 'offices', '', ', ', '' ) . '
', 'impress_agents' ); + break; } } diff --git a/includes/class-employee-widget.php b/includes/class-employee-widget.php index bb8846a..6400ef0 100755 --- a/includes/class-employee-widget.php +++ b/includes/class-employee-widget.php @@ -1,5 +1,7 @@ 'featured-employee', 'description' => __( 'Display a featured employee or employees contact info.', 'impress_agents' ), 'customize_selective_refresh' => true ); - $control_ops = array( 'width' => 300, 'height' => 350 ); + $widget_ops = array( + 'classname' => 'featured-employee', + 'description' => __( 'Display a featured employee or employees contact info.', 'impress_agents' ), + 'customize_selective_refresh' => true, + ); + $control_ops = array( + 'width' => 300, + 'height' => 350, + ); parent::__construct( 'featured-employee', __( 'IMPress Agents', 'impress_agents' ), $widget_ops, $control_ops ); } @@ -19,60 +28,80 @@ function widget( $args, $instance ) { global $post; /** defaults */ - $instance = wp_parse_args( $instance, array( - 'post_id' => '', - 'title' => '', - 'show_agent' => 0, - 'show_number' => 1, - 'orderby' => '', - 'order' => '' - ) ); + $instance = wp_parse_args( + $instance, + array( + 'post_id' => '', + 'title' => '', + 'show_agent' => 0, + 'show_number' => 1, + 'orderby' => '', + 'order' => '', + ) + ); extract( $args ); - $post_id = $instance['post_id']; - $title = $instance['title']; - $orderby = $instance['orderby']; - $order = $instance['order']; - $show_agent = $instance['show_agent']; - $show_number = (!empty($instance['show_number'])) ? absint($instance['show_number']) : 1; + $post_id = $instance['post_id']; + $title = $instance['title']; + $orderby = $instance['orderby']; + $order = $instance['order']; + $show_agent = $instance['show_agent']; + $show_number = ( ! empty( $instance['show_number'] ) ) ? absint( $instance['show_number'] ) : 1; echo $before_widget; - if ($show_agent == 'show_all') { - echo $before_title . apply_filters('widget_title', $title, $instance, $this->id_base) . $after_title; - $query_args = array('post_type' => 'employee', 'posts_per_page' => - 1, 'orderby' => $orderby, 'order' => $order); - - } elseif ($show_agent == 'show_random') { - echo $before_title . apply_filters('widget_title', $title, $instance, $this->id_base) . $after_title; - $query_args = array('post_type' => 'employee', 'posts_per_page' => $show_number, 'orderby' => 'rand', 'order' => $order); - - } elseif (!empty($instance['post_id'])) { - $post_id = explode(',', $instance['post_id']); - echo $before_title . apply_filters('widget_title', $title, $instance, $this->id_base) . $after_title; - $query_args = array('post_type' => 'employee', 'p' => $post_id[0], 'posts_per_page' => 1, 'orderby' => $orderby, 'order' => $order); - - } + if ( $show_agent == 'show_all' ) { + echo $before_title . apply_filters( 'widget_title', $title, $instance, $this->id_base ) . $after_title; + $query_args = array( + 'post_type' => 'employee', + 'posts_per_page' => - 1, + 'orderby' => $orderby, + 'order' => $order, + ); + + } elseif ( $show_agent == 'show_random' ) { + echo $before_title . apply_filters( 'widget_title', $title, $instance, $this->id_base ) . $after_title; + $query_args = array( + 'post_type' => 'employee', + 'posts_per_page' => $show_number, + 'orderby' => 'rand', + 'order' => $order, + ); + + } elseif ( ! empty( $instance['post_id'] ) ) { + $post_id = explode( ',', $instance['post_id'] ); + echo $before_title . apply_filters( 'widget_title', $title, $instance, $this->id_base ) . $after_title; + $query_args = array( + 'post_type' => 'employee', + 'p' => $post_id[0], + 'posts_per_page' => 1, + 'orderby' => $orderby, + 'order' => $order, + ); + + } query_posts( $query_args ); - if ( have_posts() ) : while ( have_posts() ) : the_post(); + if ( have_posts() ) : + while ( have_posts() ) : + the_post(); - echo '
'; + echo '
'; echo '', get_the_post_thumbnail( $post->ID, 'employee-thumbnail' ), ''; - printf('
%s', get_permalink(), get_the_title() ); + printf( '
%s', get_permalink(), get_the_title() ); echo impa_employee_archive_details(); - if (function_exists('_p2p_init') && function_exists('agentpress_listings_init') || function_exists('_p2p_init') && function_exists('wp_listings_init')) { + if ( function_exists( '_p2p_init' ) && function_exists( 'agentpress_listings_init' ) || function_exists( '_p2p_init' ) && function_exists( 'wp_listings_init' ) ) { $has_listings = impa_has_listings( $post->ID ); - if (!empty($has_listings)) { - echo '

View My Listings

'; + if ( ! empty( $has_listings ) ) { + echo '

View My Listings

'; } } echo '
'; - //echo impa_employee_social(); - + // echo impa_employee_social(); echo '
'; endwhile; @@ -84,23 +113,26 @@ function widget( $args, $instance ) { } function update( $new_instance, $old_instance ) { - $instance = array(); - $instance['title'] = strip_tags( $new_instance['title'] ); - $instance['show_number'] = (int)$new_instance['show_number']; + $instance = array(); + $instance['title'] = strip_tags( $new_instance['title'] ); + $instance['show_number'] = (int) $new_instance['show_number']; return $new_instance; } function form( $instance ) { - $instance = wp_parse_args( $instance, array( - 'post_id' => '', - 'title' => 'Featured Employees', - 'show_agent' => 'show_selected', - 'show_number' => 1, - 'orderby' => 'menu_order', - 'order' => 'ASC' - ) ); + $instance = wp_parse_args( + $instance, + array( + 'post_id' => '', + 'title' => 'Featured Employees', + 'show_agent' => 'show_selected', + 'show_number' => 1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ) + ); ?>

@@ -113,10 +145,14 @@ function form( $instance ) { echo ''; echo ''; echo '

'; @@ -124,40 +160,40 @@ function form( $instance ) { ?>

- - + + +


-

+

- - + +


-

+

- - + + + + +

- - + +

'aeprofiles', - 'nopaging' => true + */ +class IMPress_Agents_Migrate { + + public function __construct() { + $post_info = get_posts( + array( + 'post_type' => 'aeprofiles', + 'nopaging' => true, ) ); - if (empty($post_info)) { + if ( empty( $post_info ) ) { return; } - $this->update_post_type($post_info); + $this->update_post_type( $post_info ); } - public function update_post_type($post_info) - { + public function update_post_type( $post_info ) { $meta_keys = array( - '_agent_title' => '_employee_title', - '_agent_license' => '_employee_license', + '_agent_title' => '_employee_title', + '_agent_license' => '_employee_license', '_agent_designations' => '_employee_designations', - '_agent_phone' => '_employee_phone', - '_agent_mobile' => '_employee_mobile', - '_agent_email' => '_employee_email', - '_agent_website' => '_employee_website', - '_agent_address' => '_employee_address', - '_agent_city' => '_employee_city', - '_agent_state' => '_employee_state', - '_agent_zip' => '_employee_zip', - '_agent_facebook' => '_employee_facebook', - '_agent_twitter' => '_employee_twitter', - '_agent_linkedin' => '_employee_linkedin', + '_agent_phone' => '_employee_phone', + '_agent_mobile' => '_employee_mobile', + '_agent_email' => '_employee_email', + '_agent_website' => '_employee_website', + '_agent_address' => '_employee_address', + '_agent_city' => '_employee_city', + '_agent_state' => '_employee_state', + '_agent_zip' => '_employee_zip', + '_agent_facebook' => '_employee_facebook', + '_agent_twitter' => '_employee_twitter', + '_agent_linkedin' => '_employee_linkedin', '_agent_googleplus' => '_employee_googleplus', - '_agent_pinterest' => '_employee_pinterest', - '_agent_youtube' => '_employee_youtube', - '_agent_instagram' => '_employee_instagram' - ); + '_agent_pinterest' => '_employee_pinterest', + '_agent_youtube' => '_employee_youtube', + '_agent_instagram' => '_employee_instagram', + ); - foreach($post_info as $post) { - foreach($meta_keys as $old_key => $new_key) { - $old_value = get_post_meta($post->ID, $old_key, true); - update_post_meta($post->ID, $new_key, $old_value); + foreach ( $post_info as $post ) { + foreach ( $meta_keys as $old_key => $new_key ) { + $old_value = get_post_meta( $post->ID, $old_key, true ); + update_post_meta( $post->ID, $new_key, $old_value ); } - set_post_type($post->ID, 'employee'); + set_post_type( $post->ID, 'employee' ); } } } diff --git a/includes/class-taxonomies.php b/includes/class-taxonomies.php index e8112d8..d2d0da9 100644 --- a/includes/class-taxonomies.php +++ b/includes/class-taxonomies.php @@ -1,5 +1,7 @@ get_taxonomies() as $slug => $data ) { - add_action( "{$slug}_add_form_fields", array( $this, 'impress_agents_new_term_image_field') ); - add_action( "{$slug}_edit_form_fields", array( $this, 'impress_agents_edit_term_image_field') ); - add_action( "create_{$slug}", array( $this, 'impress_agents_save_term_image') ); - add_action( "edit_{$slug}", array( $this, 'impress_agents_save_term_image') ); + foreach ( (array) $this->get_taxonomies() as $slug => $data ) { + add_action( "{$slug}_add_form_fields", array( $this, 'impress_agents_new_term_image_field' ) ); + add_action( "{$slug}_edit_form_fields", array( $this, 'impress_agents_edit_term_image_field' ) ); + add_action( "create_{$slug}", array( $this, 'impress_agents_save_term_image' ) ); + add_action( "edit_{$slug}", array( $this, 'impress_agents_save_term_image' ) ); add_filter( "manage_edit-{$slug}_columns", array( $this, 'impress_agents_edit_term_columns' ) ); add_action( "manage_{$slug}_custom_column", array( $this, 'impress_agents_manage_term_custom_column' ), 10, 3 ); } } - add_action('restrict_manage_posts', array($this, 'impress_agents_filter_post_type_by_taxonomy') ); - add_filter('parse_query', array($this, 'impress_agents_convert_id_to_term_in_query') ); + add_action( 'restrict_manage_posts', array( $this, 'impress_agents_filter_post_type_by_taxonomy' ) ); + add_filter( 'parse_query', array( $this, 'impress_agents_convert_id_to_term_in_query' ) ); } @@ -83,12 +84,11 @@ function admin() { echo '
'; - if ( isset( $_REQUEST['view'] ) && 'edit' == $_REQUEST['view'] ) { - require( dirname( __FILE__ ) . '/views/edit-tax.php' ); - } - else { - require( dirname( __FILE__ ) . '/views/create-tax.php' ); - } + if ( isset( $_REQUEST['view'] ) && 'edit' == $_REQUEST['view'] ) { + require dirname( __FILE__ ) . '/views/edit-tax.php'; + } else { + require dirname( __FILE__ ) . '/views/create-tax.php'; + } echo '
'; @@ -96,39 +96,45 @@ function admin() { function create_taxonomy( $args = array() ) { - /**** VERIFY THE NONCE ****/ + /**** VERIFY THE NONCE */ /** No empty fields */ - if ( ! isset( $args['id'] ) || empty( $args['id'] ) ) + if ( ! isset( $args['id'] ) || empty( $args['id'] ) ) { wp_die( __( 'Please complete all required fields.', 'impress_agents' ) ); - if ( ! isset( $args['name'] ) || empty( $args['name'] ) ) + } + if ( ! isset( $args['name'] ) || empty( $args['name'] ) ) { wp_die( __( 'Please complete all required fields.', 'impress_agents' ) ); - if ( ! isset( $args['singular_name'] ) || empty( $args['singular_name'] ) ) + } + if ( ! isset( $args['singular_name'] ) || empty( $args['singular_name'] ) ) { wp_die( __( 'Please complete all required fields.', 'impress_agents' ) ); + } extract( $args ); $labels = array( - 'name' => strip_tags( $name ), - 'singular_name' => strip_tags( $singular_name ), - 'menu_name' => strip_tags( $name ), - - 'search_items' => sprintf( __( 'Search %s', 'impress_agents' ), strip_tags( $name ) ), - 'popular_items' => sprintf( __( 'Popular %s', 'impress_agents' ), strip_tags( $name ) ), - 'all_items' => sprintf( __( 'All %s', 'impress_agents' ), strip_tags( $name ) ), - 'edit_item' => sprintf( __( 'Edit %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'update_item' => sprintf( __( 'Update %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'add_new_item' => sprintf( __( 'Add New %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'new_item_name' => sprintf( __( 'New %s Name', 'impress_agents' ), strip_tags( $singular_name ) ), - 'add_or_remove_items' => sprintf( __( 'Add or Remove %s', 'impress_agents' ), strip_tags( $name ) ), - 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'impress_agents' ), strip_tags( $name ) ) + 'name' => strip_tags( $name ), + 'singular_name' => strip_tags( $singular_name ), + 'menu_name' => strip_tags( $name ), + + 'search_items' => sprintf( __( 'Search %s', 'impress_agents' ), strip_tags( $name ) ), + 'popular_items' => sprintf( __( 'Popular %s', 'impress_agents' ), strip_tags( $name ) ), + 'all_items' => sprintf( __( 'All %s', 'impress_agents' ), strip_tags( $name ) ), + 'edit_item' => sprintf( __( 'Edit %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'update_item' => sprintf( __( 'Update %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'add_new_item' => sprintf( __( 'Add New %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'new_item_name' => sprintf( __( 'New %s Name', 'impress_agents' ), strip_tags( $singular_name ) ), + 'add_or_remove_items' => sprintf( __( 'Add or Remove %s', 'impress_agents' ), strip_tags( $name ) ), + 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'impress_agents' ), strip_tags( $name ) ), ); $args = array( - 'labels' => $labels, - 'hierarchical' => true, - 'rewrite' => array( 'slug' => $id, 'with_front' => false ), - 'editable' => 1 + 'labels' => $labels, + 'hierarchical' => true, + 'rewrite' => array( + 'slug' => $id, + 'with_front' => false, + ), + 'editable' => 1, ); $tax = array( $id => $args ); @@ -146,17 +152,18 @@ function create_taxonomy( $args = array() ) { function delete_taxonomy( $id = '' ) { - /**** VERIFY THE NONCE ****/ + /**** VERIFY THE NONCE */ /** No empty ID */ - if ( ! isset( $id ) || empty( $id ) ) + if ( ! isset( $id ) || empty( $id ) ) { wp_die( __( "Nice try, partner. But that taxonomy doesn't exist. Click back and try again.", 'impress_agents' ) ); + } $options = get_option( $this->settings_field ); /** Look for the ID, delete if it exists */ if ( array_key_exists( $id, (array) $options ) ) { - unset( $options[$id] ); + unset( $options[ $id ] ); } else { wp_die( __( "Nice try, partner. But that taxonomy doesn't exist. Click back and try again.", 'impress_agents' ) ); } @@ -168,39 +175,45 @@ function delete_taxonomy( $id = '' ) { function edit_taxonomy( $args = array() ) { - /**** VERIFY THE NONCE ****/ + /**** VERIFY THE NONCE */ /** No empty fields */ - if ( ! isset( $args['id'] ) || empty( $args['id'] ) ) + if ( ! isset( $args['id'] ) || empty( $args['id'] ) ) { wp_die( __( 'Please complete all required fields.', 'impress_agents' ) ); - if ( ! isset( $args['name'] ) || empty( $args['name'] ) ) + } + if ( ! isset( $args['name'] ) || empty( $args['name'] ) ) { wp_die( __( 'Please complete all required fields.', 'impress_agents' ) ); - if ( ! isset( $args['singular_name'] ) || empty( $args['singular_name'] ) ) + } + if ( ! isset( $args['singular_name'] ) || empty( $args['singular_name'] ) ) { wp_die( __( 'Please complete all required fields.', 'impress_agents' ) ); + } extract( $args ); $labels = array( - 'name' => strip_tags( $name ), - 'singular_name' => strip_tags( $singular_name ), - 'menu_name' => strip_tags( $name ), - - 'search_items' => sprintf( __( 'Search %s', 'impress_agents' ), strip_tags( $name ) ), - 'popular_items' => sprintf( __( 'Popular %s', 'impress_agents' ), strip_tags( $name ) ), - 'all_items' => sprintf( __( 'All %s', 'impress_agents' ), strip_tags( $name ) ), - 'edit_item' => sprintf( __( 'Edit %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'update_item' => sprintf( __( 'Update %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'add_new_item' => sprintf( __( 'Add New %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'new_item_name' => sprintf( __( 'New %s Name', 'impress_agents' ), strip_tags( $singular_name ) ), - 'add_or_remove_items' => sprintf( __( 'Add or Remove %s', 'impress_agents' ), strip_tags( $name ) ), - 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'impress_agents' ), strip_tags( $name ) ) + 'name' => strip_tags( $name ), + 'singular_name' => strip_tags( $singular_name ), + 'menu_name' => strip_tags( $name ), + + 'search_items' => sprintf( __( 'Search %s', 'impress_agents' ), strip_tags( $name ) ), + 'popular_items' => sprintf( __( 'Popular %s', 'impress_agents' ), strip_tags( $name ) ), + 'all_items' => sprintf( __( 'All %s', 'impress_agents' ), strip_tags( $name ) ), + 'edit_item' => sprintf( __( 'Edit %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'update_item' => sprintf( __( 'Update %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'add_new_item' => sprintf( __( 'Add New %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'new_item_name' => sprintf( __( 'New %s Name', 'impress_agents' ), strip_tags( $singular_name ) ), + 'add_or_remove_items' => sprintf( __( 'Add or Remove %s', 'impress_agents' ), strip_tags( $name ) ), + 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'impress_agents' ), strip_tags( $name ) ), ); $args = array( - 'labels' => $labels, - 'hierarchical' => true, - 'rewrite' => array( 'slug' => $id, 'with_front' => false ), - 'editable' => 1 + 'labels' => $labels, + 'hierarchical' => true, + 'rewrite' => array( + 'slug' => $id, + 'with_front' => false, + ), + 'editable' => 1, ); $tax = array( $id => $args ); @@ -220,17 +233,17 @@ function notices() { $format = '

%s

'; if ( isset( $_REQUEST['created'] ) && 'true' == $_REQUEST['created'] ) { - printf( $format, __('New taxonomy successfully created!', 'impress_agents') ); + printf( $format, __( 'New taxonomy successfully created!', 'impress_agents' ) ); return; } if ( isset( $_REQUEST['edited'] ) && 'true' == $_REQUEST['edited'] ) { - printf( $format, __('Taxonomy successfully edited!', 'impress_agents') ); + printf( $format, __( 'Taxonomy successfully edited!', 'impress_agents' ) ); return; } if ( isset( $_REQUEST['deleted'] ) && 'true' == $_REQUEST['deleted'] ) { - printf( $format, __('Taxonomy successfully deleted.', 'impress_agents') ); + printf( $format, __( 'Taxonomy successfully deleted.', 'impress_agents' ) ); return; } @@ -243,33 +256,36 @@ function notices() { */ function employee_job_type_taxonomy() { - $name = __( 'Job Types', 'impress_agents' ); + $name = __( 'Job Types', 'impress_agents' ); $singular_name = __( 'Job Type', 'impress_agents' ); return array( 'job-types' => array( - 'labels' => array( - 'name' => strip_tags( $name ), - 'singular_name' => strip_tags( $singular_name ), - 'menu_name' => strip_tags( $name ), - - 'search_items' => sprintf( __( 'Search %s', 'impress_agents' ), strip_tags( $name ) ), - 'popular_items' => sprintf( __( 'Popular %s', 'impress_agents' ), strip_tags( $name ) ), - 'all_items' => sprintf( __( 'All %s', 'impress_agents' ), strip_tags( $name ) ), - 'edit_item' => sprintf( __( 'Edit %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'update_item' => sprintf( __( 'Update %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'add_new_item' => sprintf( __( 'Add New %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'new_item_name' => sprintf( __( 'New %s Name', 'impress_agents' ), strip_tags( $singular_name ) ), - 'add_or_remove_items' => sprintf( __( 'Add or Remove %s', 'impress_agents' ), strip_tags( $name ) ), - 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'impress_agents' ), strip_tags( $name ) ) + 'labels' => array( + 'name' => strip_tags( $name ), + 'singular_name' => strip_tags( $singular_name ), + 'menu_name' => strip_tags( $name ), + + 'search_items' => sprintf( __( 'Search %s', 'impress_agents' ), strip_tags( $name ) ), + 'popular_items' => sprintf( __( 'Popular %s', 'impress_agents' ), strip_tags( $name ) ), + 'all_items' => sprintf( __( 'All %s', 'impress_agents' ), strip_tags( $name ) ), + 'edit_item' => sprintf( __( 'Edit %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'update_item' => sprintf( __( 'Update %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'add_new_item' => sprintf( __( 'Add New %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'new_item_name' => sprintf( __( 'New %s Name', 'impress_agents' ), strip_tags( $singular_name ) ), + 'add_or_remove_items' => sprintf( __( 'Add or Remove %s', 'impress_agents' ), strip_tags( $name ) ), + 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'impress_agents' ), strip_tags( $name ) ), + ), + 'hierarchical' => true, + 'rewrite' => array( + __( 'job-types', 'impress_agents' ), + 'with_front' => false, ), - 'hierarchical' => true, - 'rewrite' => array( __( 'job-types', 'impress_agents' ), 'with_front' => false ), - 'editable' => 0, - 'show_in_rest' => true, - 'rest_base' => 'job-types', - 'rest_controller_class' => 'WP_REST_Terms_Controller' - ) + 'editable' => 0, + 'show_in_rest' => true, + 'rest_base' => 'job-types', + 'rest_controller_class' => 'WP_REST_Terms_Controller', + ), ); } @@ -279,33 +295,36 @@ function employee_job_type_taxonomy() { */ function employee_offices_taxonomy() { - $name = __( 'Offices', 'impress_agents' ); + $name = __( 'Offices', 'impress_agents' ); $singular_name = __( 'Office', 'impress_agents' ); return array( 'offices' => array( - 'labels' => array( - 'name' => strip_tags( $name ), - 'singular_name' => strip_tags( $singular_name ), - 'menu_name' => strip_tags( $name ), - - 'search_items' => sprintf( __( 'Search %s', 'impress_agents' ), strip_tags( $name ) ), - 'popular_items' => sprintf( __( 'Popular %s', 'impress_agents' ), strip_tags( $name ) ), - 'all_items' => sprintf( __( 'All %s', 'impress_agents' ), strip_tags( $name ) ), - 'edit_item' => sprintf( __( 'Edit %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'update_item' => sprintf( __( 'Update %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'add_new_item' => sprintf( __( 'Add New %s', 'impress_agents' ), strip_tags( $singular_name ) ), - 'new_item_name' => sprintf( __( 'New %s Name', 'impress_agents' ), strip_tags( $singular_name ) ), - 'add_or_remove_items' => sprintf( __( 'Add or Remove %s', 'impress_agents' ), strip_tags( $name ) ), - 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'impress_agents' ), strip_tags( $name ) ) + 'labels' => array( + 'name' => strip_tags( $name ), + 'singular_name' => strip_tags( $singular_name ), + 'menu_name' => strip_tags( $name ), + + 'search_items' => sprintf( __( 'Search %s', 'impress_agents' ), strip_tags( $name ) ), + 'popular_items' => sprintf( __( 'Popular %s', 'impress_agents' ), strip_tags( $name ) ), + 'all_items' => sprintf( __( 'All %s', 'impress_agents' ), strip_tags( $name ) ), + 'edit_item' => sprintf( __( 'Edit %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'update_item' => sprintf( __( 'Update %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'add_new_item' => sprintf( __( 'Add New %s', 'impress_agents' ), strip_tags( $singular_name ) ), + 'new_item_name' => sprintf( __( 'New %s Name', 'impress_agents' ), strip_tags( $singular_name ) ), + 'add_or_remove_items' => sprintf( __( 'Add or Remove %s', 'impress_agents' ), strip_tags( $name ) ), + 'choose_from_most_used' => sprintf( __( 'Choose from the most used %s', 'impress_agents' ), strip_tags( $name ) ), + ), + 'hierarchical' => true, + 'rewrite' => array( + __( 'offices', 'impress_agents' ), + 'with_front' => false, ), - 'hierarchical' => true, - 'rewrite' => array( __( 'offices', 'impress_agents' ), 'with_front' => false ), - 'editable' => 0, - 'show_in_rest' => true, - 'rest_base' => 'offices', - 'rest_controller_class' => 'WP_REST_Terms_Controller' - ) + 'editable' => 0, + 'show_in_rest' => true, + 'rest_base' => 'offices', + 'rest_controller_class' => 'WP_REST_Terms_Controller', + ), ); } @@ -315,7 +334,7 @@ function employee_offices_taxonomy() { */ function register_taxonomies() { - foreach( (array) $this->get_taxonomies() as $id => $data ) { + foreach ( (array) $this->get_taxonomies() as $id => $data ) { register_taxonomy( $id, array( 'employee' ), $data ); } @@ -332,6 +351,7 @@ function get_taxonomies() { /** * Register term meta for a featured image + * * @return [type] [description] */ function register_term_meta() { @@ -340,6 +360,7 @@ function register_term_meta() { /** * Callback to retrieve the term image + * * @return [type] [description] */ function impress_agents_sanitize_term_image( $impa_term_image ) { @@ -348,6 +369,7 @@ function impress_agents_sanitize_term_image( $impa_term_image ) { /** * Get the term featured image id + * * @param $html bool whether to use html wrapper * @uses wp_get_attachment_image to return image id wrapped in markup */ @@ -358,23 +380,26 @@ function impress_agents_get_term_image( $term_id, $html = true ) { /** * Save the image uploaded + * * @param string $term_id term slug */ function impress_agents_save_term_image( $term_id ) { - if ( ! isset( $_POST['impa_term_image_nonce'] ) || ! wp_verify_nonce( $_POST['impa_term_image_nonce'], basename( __FILE__ ) ) ) - return; + if ( ! isset( $_POST['impa_term_image_nonce'] ) || ! wp_verify_nonce( $_POST['impa_term_image_nonce'], basename( __FILE__ ) ) ) { + return; + } - $old_image = $this->impress_agents_get_term_image( $term_id ); - $new_image = isset( $_POST['impa-term-image'] ) ? $_POST['impa-term-image'] : ''; + $old_image = $this->impress_agents_get_term_image( $term_id ); + $new_image = isset( $_POST['impa-term-image'] ) ? $_POST['impa-term-image'] : ''; - if ( $old_image && '' === $new_image ) - delete_term_meta( $term_id, 'impa_term_image' ); + if ( $old_image && '' === $new_image ) { + delete_term_meta( $term_id, 'impa_term_image' ); - else if ( $old_image !== $new_image ) - update_term_meta( $term_id, 'impa_term_image', $new_image ); + } elseif ( $old_image !== $new_image ) { + update_term_meta( $term_id, 'impa_term_image', $new_image ); + } - return $term_id; + return $term_id; } @@ -384,9 +409,9 @@ function impress_agents_save_term_image( $term_id ) { function impress_agents_edit_term_columns( $columns ) { - $columns['impa_term_image'] = __( 'Image', 'impress_agents' ); + $columns['impa_term_image'] = __( 'Image', 'impress_agents' ); - return $columns; + return $columns; } /** @@ -394,19 +419,20 @@ function impress_agents_edit_term_columns( $columns ) { */ function impress_agents_manage_term_custom_column( $out, $column, $term_id ) { - if ( 'impa_term_image' === $column ) { + if ( 'impa_term_image' === $column ) { - $image_id = $this->impress_agents_get_term_image( $term_id, false ); + $image_id = $this->impress_agents_get_term_image( $term_id, false ); - if (!$image_id) - return $out; + if ( ! $image_id ) { + return $out; + } - $image_markup = wp_get_attachment_image( $image_id, 'thumbnail', true, array('class' => 'impa-term-image')); + $image_markup = wp_get_attachment_image( $image_id, 'thumbnail', true, array( 'class' => 'impa-term-image' ) ); - $out = $image_markup; - } + $out = $image_markup; + } - return $out; + return $out; } /** @@ -414,21 +440,23 @@ function impress_agents_manage_term_custom_column( $out, $column, $term_id ) { */ function impress_agents_filter_post_type_by_taxonomy() { global $typenow; - $post_type = 'employee'; - $taxonomies = array('job-types', 'offices'); - foreach($taxonomies as $taxonomy) { - if ($typenow == $post_type) { - $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; - $info_taxonomy = get_taxonomy($taxonomy); - wp_dropdown_categories(array( - 'show_option_all' => __("Show All {$info_taxonomy->label}"), - 'taxonomy' => $taxonomy, - 'name' => $taxonomy, - 'orderby' => 'name', - 'selected' => $selected, - 'show_count' => true, - 'hide_empty' => true, - )); + $post_type = 'employee'; + $taxonomies = array( 'job-types', 'offices' ); + foreach ( $taxonomies as $taxonomy ) { + if ( $typenow == $post_type ) { + $selected = isset( $_GET[ $taxonomy ] ) ? $_GET[ $taxonomy ] : ''; + $info_taxonomy = get_taxonomy( $taxonomy ); + wp_dropdown_categories( + array( + 'show_option_all' => __( "Show All {$info_taxonomy->label}" ), + 'taxonomy' => $taxonomy, + 'name' => $taxonomy, + 'orderby' => 'name', + 'selected' => $selected, + 'show_count' => true, + 'hide_empty' => true, + ) + ); }; } } @@ -436,15 +464,15 @@ function impress_agents_filter_post_type_by_taxonomy() { /** * Filter posts by taxonomy in admin */ - function impress_agents_convert_id_to_term_in_query($query) { + function impress_agents_convert_id_to_term_in_query( $query ) { global $pagenow; - $post_type = 'employee'; - $taxonomies = array('job-types', 'offices'); - $q_vars = &$query->query_vars; - foreach($taxonomies as $taxonomy) { - if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) { - $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); - $q_vars[$taxonomy] = $term->slug; + $post_type = 'employee'; + $taxonomies = array( 'job-types', 'offices' ); + $q_vars = &$query->query_vars; + foreach ( $taxonomies as $taxonomy ) { + if ( $pagenow == 'edit.php' && isset( $q_vars['post_type'] ) && $q_vars['post_type'] == $post_type && isset( $q_vars[ $taxonomy ] ) && is_numeric( $q_vars[ $taxonomy ] ) && $q_vars[ $taxonomy ] != 0 ) { + $term = get_term_by( 'id', $q_vars[ $taxonomy ], $taxonomy ); + $q_vars[ $taxonomy ] = $term->slug; } } } @@ -454,13 +482,13 @@ function impress_agents_convert_id_to_term_in_query($query) { */ function impress_agents_new_term_image_field( $term ) { - $image_id = ''; + $image_id = ''; - wp_nonce_field( basename( __FILE__ ), 'impa_term_image_nonce' ); ?> + wp_nonce_field( basename( __FILE__ ), 'impa_term_image_nonce' ); ?> -
- - +
+ +

@@ -468,25 +496,28 @@ function impress_agents_new_term_image_field( $term ) {

-
- + impress_agents_get_term_image( $term->term_id, false ); - $image_url = wp_get_attachment_url($image_id); + $image_id = $this->impress_agents_get_term_image( $term->term_id, false ); + $image_url = wp_get_attachment_url( $image_id ); - if ( ! $image_url ) - $image_url = ''; ?> + if ( ! $image_url ) { + $image_url = ''; + } + ?> - - - - - + + + + +

@@ -494,8 +525,9 @@ function impress_agents_edit_term_image_field( $term ) {

- - - + + 'agents_to_listings', - 'from' => 'employee', - 'to' => 'listing', - 'sortable' => 'any' - ) ); + p2p_register_connection_type( + array( + 'name' => 'agents_to_listings', + 'from' => 'employee', + 'to' => 'listing', + 'sortable' => 'any', + ) + ); } add_image_size( 'employee-thumbnail', 150, 200, true ); @@ -48,17 +51,17 @@ function impress_agents_template_include( $template ) { $post_type = 'employee'; if ( $wp_query->is_search && get_post_type() == 'employee' ) { - if ( file_exists(get_stylesheet_directory() . '/search-' . $post_type . '.php') ) { + if ( file_exists( get_stylesheet_directory() . '/search-' . $post_type . '.php' ) ) { $template = get_stylesheet_directory() . '/search-' . $post_type . '.php'; return $template; } else { return dirname( __FILE__ ) . '/views/archive-' . $post_type . '.php'; } } - if ( impress_agents_is_taxonomy_of($post_type) ) { - if ( file_exists(get_stylesheet_directory() . '/taxonomy-' . $post_type . '.php' ) ) { + if ( impress_agents_is_taxonomy_of( $post_type ) ) { + if ( file_exists( get_stylesheet_directory() . '/taxonomy-' . $post_type . '.php' ) ) { return get_stylesheet_directory() . '/taxonomy-' . $post_type . '.php'; - } elseif ( file_exists(get_stylesheet_directory() . '/archive-' . $post_type . '.php' ) ) { + } elseif ( file_exists( get_stylesheet_directory() . '/archive-' . $post_type . '.php' ) ) { return get_stylesheet_directory() . '/archive-' . $post_type . '.php'; } else { return dirname( __FILE__ ) . '/views/archive-' . $post_type . '.php'; @@ -66,7 +69,7 @@ function impress_agents_template_include( $template ) { } if ( is_post_type_archive( $post_type ) ) { - if ( file_exists(get_stylesheet_directory() . '/archive-' . $post_type . '.php') ) { + if ( file_exists( get_stylesheet_directory() . '/archive-' . $post_type . '.php' ) ) { $template = get_stylesheet_directory() . '/archive-' . $post_type . '.php'; return $template; } else { @@ -75,10 +78,11 @@ function impress_agents_template_include( $template ) { } if ( is_single() && $post_type == get_post_type() ) { - if( file_exists(get_stylesheet_directory() . '/single-' . $post_type . '.php') ) + if ( file_exists( get_stylesheet_directory() . '/single-' . $post_type . '.php' ) ) { return $template; - else + } else { return dirname( __FILE__ ) . '/views/single-' . $post_type . '.php'; + } } return $template; @@ -89,55 +93,60 @@ function impa_employee_details() { $output = ''; - if (get_post_meta($post->ID, '_employee_title', true) != '') - $output .= sprintf('

%s

', get_post_meta($post->ID, '_employee_title', true) ); + if ( get_post_meta( $post->ID, '_employee_title', true ) != '' ) { + $output .= sprintf( '

%s

', get_post_meta( $post->ID, '_employee_title', true ) ); + } - if (get_post_meta($post->ID, '_employee_license', true) != '') - $output .= sprintf('

%s

', get_post_meta($post->ID, '_employee_license', true) ); + if ( get_post_meta( $post->ID, '_employee_license', true ) != '' ) { + $output .= sprintf( '

%s

', get_post_meta( $post->ID, '_employee_license', true ) ); + } - if (get_post_meta($post->ID, '_employee_designations', true) != '') - $output .= sprintf('

%s

', get_post_meta($post->ID, '_employee_designations', true) ); + if ( get_post_meta( $post->ID, '_employee_designations', true ) != '' ) { + $output .= sprintf( '

%s

', get_post_meta( $post->ID, '_employee_designations', true ) ); + } - if (get_post_meta($post->ID, '_employee_phone', true) != '') - $output .= sprintf('

Office: %s

', get_post_meta($post->ID, '_employee_phone', true) ); + if ( get_post_meta( $post->ID, '_employee_phone', true ) != '' ) { + $output .= sprintf( '

Office: %s

', get_post_meta( $post->ID, '_employee_phone', true ) ); + } - if (get_post_meta($post->ID, '_employee_mobile', true) != '') - $output .= sprintf('

Cell: %s

', get_post_meta($post->ID, '_employee_mobile', true) ); + if ( get_post_meta( $post->ID, '_employee_mobile', true ) != '' ) { + $output .= sprintf( '

Cell: %s

', get_post_meta( $post->ID, '_employee_mobile', true ) ); + } - if (get_post_meta($post->ID, '_employee_email', true) != '') { - $email = get_post_meta($post->ID, '_employee_email', true); - $output .= sprintf('

', antispambot($email), antispambot($email) ); + if ( get_post_meta( $post->ID, '_employee_email', true ) != '' ) { + $email = get_post_meta( $post->ID, '_employee_email', true ); + $output .= sprintf( '

', antispambot( $email ), antispambot( $email ) ); } - if (get_post_meta($post->ID, '_employee_website', true) != '') { - $website = get_post_meta($post->ID, '_employee_website', true); - $website_no_http = preg_replace('#^https?://#', '', rtrim($website,'/')); - $output .= sprintf('

', $website, $website_no_http ); + if ( get_post_meta( $post->ID, '_employee_website', true ) != '' ) { + $website = get_post_meta( $post->ID, '_employee_website', true ); + $website_no_http = preg_replace( '#^https?://#', '', rtrim( $website, '/' ) ); + $output .= sprintf( '

', $website, $website_no_http ); } - if (get_post_meta($post->ID, '_employee_city', true) != '' || get_post_meta($post->ID, '_employee_address', true) != '' || get_post_meta($post->ID, '_employee_state', true) != '' || get_post_meta($post->ID, '_employee_zip', true) != '' ) { + if ( get_post_meta( $post->ID, '_employee_city', true ) != '' || get_post_meta( $post->ID, '_employee_address', true ) != '' || get_post_meta( $post->ID, '_employee_state', true ) != '' || get_post_meta( $post->ID, '_employee_zip', true ) != '' ) { $address = '

'; - if (get_post_meta($post->ID, '_employee_address', true) != '') { - $address .= '' . get_post_meta($post->ID, '_employee_address', true) . '
'; + if ( get_post_meta( $post->ID, '_employee_address', true ) != '' ) { + $address .= '' . get_post_meta( $post->ID, '_employee_address', true ) . '
'; } - if (get_post_meta($post->ID, '_employee_city', true) != '') { - $address .= '' . get_post_meta($post->ID, '_employee_city', true) . ', '; + if ( get_post_meta( $post->ID, '_employee_city', true ) != '' ) { + $address .= '' . get_post_meta( $post->ID, '_employee_city', true ) . ', '; } - if (get_post_meta($post->ID, '_employee_state', true) != '') { - $address .= '' . get_post_meta($post->ID, '_employee_state', true) . ' '; + if ( get_post_meta( $post->ID, '_employee_state', true ) != '' ) { + $address .= '' . get_post_meta( $post->ID, '_employee_state', true ) . ' '; } - if (get_post_meta($post->ID, '_employee_zip', true) != '') { - $address .= '' . get_post_meta($post->ID, '_employee_zip', true) . ''; + if ( get_post_meta( $post->ID, '_employee_zip', true ) != '' ) { + $address .= '' . get_post_meta( $post->ID, '_employee_zip', true ) . ''; } $address .= '

'; - if (get_post_meta($post->ID, '_employee_address', true) != '' || get_post_meta($post->ID, '_employee_city', true) != '' || get_post_meta($post->ID, '_employee_state', true) != '' || get_post_meta($post->ID, '_employee_zip', true) != '' ) { + if ( get_post_meta( $post->ID, '_employee_address', true ) != '' || get_post_meta( $post->ID, '_employee_city', true ) != '' || get_post_meta( $post->ID, '_employee_state', true ) != '' || get_post_meta( $post->ID, '_employee_zip', true ) != '' ) { $output .= $address; } } @@ -150,20 +159,22 @@ function impa_employee_archive_details() { $output = ''; - if (get_post_meta($post->ID, '_employee_title', true) != '') - $output .= sprintf('

%s

', get_post_meta($post->ID, '_employee_title', true) ); + if ( get_post_meta( $post->ID, '_employee_title', true ) != '' ) { + $output .= sprintf( '

%s

', get_post_meta( $post->ID, '_employee_title', true ) ); + } - if (get_post_meta($post->ID, '_employee_phone', true) != '') - $output .= sprintf('

Office: %s

', get_post_meta($post->ID, '_employee_phone', true) ); + if ( get_post_meta( $post->ID, '_employee_phone', true ) != '' ) { + $output .= sprintf( '

Office: %s

', get_post_meta( $post->ID, '_employee_phone', true ) ); + } - if (get_post_meta($post->ID, '_employee_email', true) != '') { - $email = get_post_meta($post->ID, '_employee_email', true); - $output .= sprintf('

', antispambot($email), antispambot($email) ); + if ( get_post_meta( $post->ID, '_employee_email', true ) != '' ) { + $email = get_post_meta( $post->ID, '_employee_email', true ); + $output .= sprintf( '

', antispambot( $email ), antispambot( $email ) ); } - if (function_exists('_p2p_init') && function_exists('agentpress_listings_init') || function_exists('_p2p_init') && function_exists('wp_listings_init')) { - $listings = impa_get_connected_posts_of_type('agents_to_listings'); - if ( !empty($listings) ) { + if ( function_exists( '_p2p_init' ) && function_exists( 'agentpress_listings_init' ) || function_exists( '_p2p_init' ) && function_exists( 'wp_listings_init' ) ) { + $listings = impa_get_connected_posts_of_type( 'agents_to_listings' ); + if ( ! empty( $listings ) ) { echo '

View My Listings

'; } } @@ -174,36 +185,36 @@ function impa_employee_archive_details() { function impa_employee_social() { global $post; - if (get_post_meta($post->ID, '_employee_facebook', true) != '' || get_post_meta($post->ID, '_employee_twitter', true) != '' || get_post_meta($post->ID, '_employee_linkedin', true) != '' || get_post_meta($post->ID, '_employee_googleplus', true) != '' || get_post_meta($post->ID, '_employee_pinterest', true) != '' || get_post_meta($post->ID, '_employee_youtube', true) != '' || get_post_meta($post->ID, '_employee_instagram', true) != '') { + if ( get_post_meta( $post->ID, '_employee_facebook', true ) != '' || get_post_meta( $post->ID, '_employee_twitter', true ) != '' || get_post_meta( $post->ID, '_employee_linkedin', true ) != '' || get_post_meta( $post->ID, '_employee_googleplus', true ) != '' || get_post_meta( $post->ID, '_employee_pinterest', true ) != '' || get_post_meta( $post->ID, '_employee_youtube', true ) != '' || get_post_meta( $post->ID, '_employee_instagram', true ) != '' ) { $output = '
'; - if (get_post_meta($post->ID, '_employee_facebook', true) != '') { - $output .= sprintf('', get_post_meta($post->ID, '_employee_facebook', true)); + if ( get_post_meta( $post->ID, '_employee_facebook', true ) != '' ) { + $output .= sprintf( '', get_post_meta( $post->ID, '_employee_facebook', true ) ); } - if (get_post_meta($post->ID, '_employee_twitter', true) != '') { - $output .= sprintf('', get_post_meta($post->ID, '_employee_twitter', true)); + if ( get_post_meta( $post->ID, '_employee_twitter', true ) != '' ) { + $output .= sprintf( '', get_post_meta( $post->ID, '_employee_twitter', true ) ); } - if (get_post_meta($post->ID, '_employee_linkedin', true) != '') { - $output .= sprintf('', get_post_meta($post->ID, '_employee_linkedin', true)); + if ( get_post_meta( $post->ID, '_employee_linkedin', true ) != '' ) { + $output .= sprintf( '', get_post_meta( $post->ID, '_employee_linkedin', true ) ); } - if (get_post_meta($post->ID, '_employee_googleplus', true) != '') { - $output .= sprintf('', get_post_meta($post->ID, '_employee_googleplus', true)); + if ( get_post_meta( $post->ID, '_employee_googleplus', true ) != '' ) { + $output .= sprintf( '', get_post_meta( $post->ID, '_employee_googleplus', true ) ); } - if (get_post_meta($post->ID, '_employee_pinterest', true) != '') { - $output .= sprintf('', get_post_meta($post->ID, '_employee_pinterest', true)); + if ( get_post_meta( $post->ID, '_employee_pinterest', true ) != '' ) { + $output .= sprintf( '', get_post_meta( $post->ID, '_employee_pinterest', true ) ); } - if (get_post_meta($post->ID, '_employee_youtube', true) != '') { - $output .= sprintf('', get_post_meta($post->ID, '_employee_youtube', true)); + if ( get_post_meta( $post->ID, '_employee_youtube', true ) != '' ) { + $output .= sprintf( '', get_post_meta( $post->ID, '_employee_youtube', true ) ); } - if (get_post_meta($post->ID, '_employee_instagram', true) != '') { - $output .= sprintf('', get_post_meta($post->ID, '_employee_instagram', true)); + if ( get_post_meta( $post->ID, '_employee_instagram', true ) != '' ) { + $output .= sprintf( '', get_post_meta( $post->ID, '_employee_instagram', true ) ); } $output .= '
'; @@ -215,20 +226,20 @@ function impa_employee_social() { /** * Displays the job type of a employee */ -function impress_agents_get_job_types($post_id = null) { +function impress_agents_get_job_types( $post_id = null ) { if ( null == $post_id ) { global $post; $post_id = $post->ID; } - $employee_job_types = wp_get_object_terms($post_id, 'job-types'); + $employee_job_types = wp_get_object_terms( $post_id, 'job-types' ); - if ( empty($employee_job_types) || is_wp_error($employee_job_types) ) { + if ( empty( $employee_job_types ) || is_wp_error( $employee_job_types ) ) { return; } - foreach($employee_job_types as $type) { + foreach ( $employee_job_types as $type ) { return $type->name; } } @@ -236,35 +247,35 @@ function impress_agents_get_job_types($post_id = null) { /** * Displays the office of a employee */ -function impress_agents_get_offices($post_id = null) { +function impress_agents_get_offices( $post_id = null ) { if ( null == $post_id ) { global $post; $post_id = $post->ID; } - $employee_occifcs = wp_get_object_terms($post_id, 'occifcs'); + $employee_occifcs = wp_get_object_terms( $post_id, 'occifcs' ); - if ( empty($employee_occifcs) || is_wp_error($employee_occifcs) ) { + if ( empty( $employee_occifcs ) || is_wp_error( $employee_occifcs ) ) { return; } - foreach($employee_occifcs as $office) { + foreach ( $employee_occifcs as $office ) { return $office->name; } } function impress_agents_post_number( $query ) { - if ( !$query->is_main_query() || is_admin() || !is_post_type_archive('employee') ) { + if ( ! $query->is_main_query() || is_admin() || ! is_post_type_archive( 'employee' ) ) { return; } - $options = get_option('plugin_impress_agents_settings'); + $options = get_option( 'plugin_impress_agents_settings' ); $archive_posts_num = $options['impress_agents_archive_posts_num']; - if ( empty($archive_posts_num) ) { + if ( empty( $archive_posts_num ) ) { $archive_posts_num = '9'; } @@ -281,13 +292,15 @@ function impress_agents_glance_items( $items = array() ) { $post_types = array( 'employee' ); - foreach( $post_types as $type ) { + foreach ( $post_types as $type ) { - if( ! post_type_exists( $type ) ) continue; + if ( ! post_type_exists( $type ) ) { + continue; + } $num_posts = wp_count_posts( $type ); - if( $num_posts ) { + if ( $num_posts ) { $published = intval( $num_posts->publish ); $post_type = get_post_type_object( $type ); @@ -324,11 +337,12 @@ function impress_agents_jetpack_sitemap() { /** * Function to return term image for use on front end - * @param num $term_id the id of the term + * + * @param num $term_id the id of the term * @param boolean $html use html wrapper with wp_get_attachment_image * @return mixed the image with html markup or the image id */ function impress_agents_term_image( $term_id, $html = true, $size = 'full' ) { $image_id = get_term_meta( $term_id, 'impa_term_image', true ); - return $image_id && $html ? wp_get_attachment_image( $image_id, $size, false, array('class' => 'impress-agents-term-image') ) : $image_id; + return $image_id && $html ? wp_get_attachment_image( $image_id, $size, false, array( 'class' => 'impress-agents-term-image' ) ) : $image_id; } diff --git a/includes/helpers.php b/includes/helpers.php index 66f0761..9c16647 100755 --- a/includes/helpers.php +++ b/includes/helpers.php @@ -1,22 +1,25 @@ 0) { - foreach ($terms as $term) { - $i++; - $term_list .= '
  • ' . $term->name . ' (' . $term->count . ')
  • '; - } +function impress_agents_list_terms( $taxonomy ) { + $the_tax_object = get_taxonomy( $taxonomy ); + $terms = get_terms( $taxonomy ); + $term_list = ''; + + $count = count( $terms ); + $i = 0; + if ( $count > 0 ) { + foreach ( $terms as $term ) { + $i++; + $term_list .= '
  • ' . $term->name . ' (' . $term->count . ')
  • '; + } echo '
    '; echo '

    ' . $the_tax_object->label . '

    '; echo "
      {$term_list}
    "; @@ -28,11 +31,11 @@ function impress_agents_list_terms($taxonomy) { /** * Returns true if the queried taxonomy is a taxonomy of the given post type */ -function impress_agents_is_taxonomy_of($post_type) { - $taxonomies = get_object_taxonomies($post_type); - $queried_tax = get_query_var('taxonomy'); +function impress_agents_is_taxonomy_of( $post_type ) { + $taxonomies = get_object_taxonomies( $post_type ); + $queried_tax = get_query_var( 'taxonomy' ); - if ( in_array($queried_tax, $taxonomies) ) { + if ( in_array( $queried_tax, $taxonomies ) ) { return true; } @@ -98,27 +101,29 @@ function impress_agents_paging_nav() { $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%'; // Set up paginated links. - $links = paginate_links( array( - 'base' => $pagenum_link, - 'format' => $format, - 'total' => $GLOBALS['wp_query']->max_num_pages, - 'current' => $paged, - 'mid_size' => 1, - 'add_args' => array_map( 'urlencode', $query_args ), - 'prev_text' => __( '← Previous', 'impress_agents' ), - 'next_text' => __( 'Next →', 'impress_agents' ), - ) ); + $links = paginate_links( + array( + 'base' => $pagenum_link, + 'format' => $format, + 'total' => $GLOBALS['wp_query']->max_num_pages, + 'current' => $paged, + 'mid_size' => 1, + 'add_args' => array_map( 'urlencode', $query_args ), + 'prev_text' => __( '← Previous', 'impress_agents' ), + 'next_text' => __( 'Next →', 'impress_agents' ), + ) + ); if ( $links ) : - ?> + ?> - $type, - 'connected_items' => get_queried_object(), - 'nopaging' => true - ) ); + $connected = get_posts( + array( + 'connected_type' => $type, + 'connected_items' => get_queried_object(), + 'nopaging' => true, + ) + ); - if ( empty($connected) ) { - return false; - } + if ( empty( $connected ) ) { + return false; + } - return $connected; + return $connected; } /** @@ -171,22 +179,24 @@ function impa_get_connected_posts_of_type($type) { * instead of get_queried_object() * * @param string $type the connected_type - * @param int $post the post id + * @param int $post the post id * @return array|bool array of posts if any else false */ -function impa_get_connected_posts_of_type_archive($type, $post) { +function impa_get_connected_posts_of_type_archive( $type, $post ) { - $connected = get_posts( array( - 'connected_type' => $type, - 'connected_items' => $post, - 'nopaging' => true - ) ); + $connected = get_posts( + array( + 'connected_type' => $type, + 'connected_items' => $post, + 'nopaging' => true, + ) + ); - if ( empty($connected) ) { - return false; - } + if ( empty( $connected ) ) { + return false; + } - return $connected; + return $connected; } /** @@ -196,24 +206,24 @@ function impa_connected_listings_markup() { $count = 0; - $listings = impa_get_connected_posts_of_type('agents_to_listings'); + $listings = impa_get_connected_posts_of_type( 'agents_to_listings' ); - if ( empty($listings) ) { + if ( empty( $listings ) ) { return; } - echo apply_filters('impa_connected_listing_heading', $heading = '

    My Listings

    '); + echo apply_filters( 'impa_connected_listing_heading', $heading = '

    My Listings

    ' ); global $post; - foreach ($listings as $listing) { + foreach ( $listings as $listing ) { - setup_postdata($listing); + setup_postdata( $listing ); $post = $listing; - $thumb_id = get_post_thumbnail_id(); - $thumb_url = wp_get_attachment_image_src($thumb_id, 'medium', true); + $thumb_id = get_post_thumbnail_id(); + $thumb_url = wp_get_attachment_image_src( $thumb_id, 'medium', true ); $count++; @@ -221,14 +231,14 @@ function impa_connected_listings_markup() { $count = 1; } - $class = ($count == 1) ? ' first' : ''; + $class = ( $count == 1 ) ? ' first' : ''; echo ' '; } @@ -241,11 +251,11 @@ function impa_connected_listings_markup() { /** * Check if the agent post id has connected listings */ -function impa_has_listings($post) { +function impa_has_listings( $post ) { - $listings = impa_get_connected_posts_of_type_archive('agents_to_listings', $post); + $listings = impa_get_connected_posts_of_type_archive( 'agents_to_listings', $post ); - if ( empty($listings) ) { + if ( empty( $listings ) ) { return false; } return true; @@ -256,28 +266,28 @@ function impa_has_listings($post) { */ function impa_connected_agents_markup() { - $profiles = impa_get_connected_posts_of_type('agents_to_listings'); + $profiles = impa_get_connected_posts_of_type( 'agents_to_listings' ); - if ( empty($profiles) ) { + if ( empty( $profiles ) ) { return; } - echo apply_filters('impa_connected_agent_heading', $heading = '

    Listing Presented by:

    '); + echo apply_filters( 'impa_connected_agent_heading', $heading = '

    Listing Presented by:

    ' ); global $post; - foreach ($profiles as $profile) { + foreach ( $profiles as $profile ) { - setup_postdata($profile); + setup_postdata( $profile ); - $post = $profile; - $thumb_id = get_post_thumbnail_id(); - $thumb_url = wp_get_attachment_image_src($thumb_id, 'agent-profile-photo', true); + $post = $profile; + $thumb_id = get_post_thumbnail_id(); + $thumb_url = wp_get_attachment_image_src( $thumb_id, 'agent-profile-photo', true ); echo ' -
    -
    ', get_the_title(), ' photo
    -
    ', get_the_title($profile->ID), '
    '; +
    +
    ', get_the_title(), ' photo
    +
    ', get_the_title( $profile->ID ), '
    '; echo impa_employee_details(); echo impa_employee_social(); echo '
    '; diff --git a/includes/shortcodes.php b/includes/shortcodes.php index 59275ce..931df01 100644 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -1,64 +1,72 @@ '', - 'orderby' => 'menu_order', - 'order' => 'ASC' - ), $atts ) ); +function impa_profile_shortcode( $atts, $content = null ) { + extract( + shortcode_atts( + array( + 'id' => '', + 'orderby' => 'menu_order', + 'order' => 'ASC', + ), + $atts + ) + ); - if ($id == '') { - $query_args = array( - 'post_type' => 'employee', - 'posts_per_page' => -1, - 'orderby' => $orderby, - 'order' => $order + if ( $id == '' ) { + $query_args = array( + 'post_type' => 'employee', + 'posts_per_page' => -1, + 'orderby' => $orderby, + 'order' => $order, - ); - } else { - $query_args = array( - 'post_type' => 'employee', - 'post__in' => explode(',', $id), - 'posts_per_page' => -1, - 'orderby' => $orderby, - 'order' => $order + ); + } else { + $query_args = array( + 'post_type' => 'employee', + 'post__in' => explode( ',', $id ), + 'posts_per_page' => -1, + 'orderby' => $orderby, + 'order' => $order, - ); - } + ); + } - global $post; + global $post; - $profiles_array = get_posts( $query_args ); + $profiles_array = get_posts( $query_args ); - $output = ''; + $output = ''; - foreach ( $profiles_array as $post ) : setup_postdata( $post ); + foreach ( $profiles_array as $post ) : + setup_postdata( $post ); - $output .= '
    '; - $output .= '' . get_the_post_thumbnail( $post->ID, 'employee-thumbnail' ) . ''; - $output .= '
    ' . get_the_title() . ''; - $output .= impa_employee_details(); - if (function_exists('_p2p_init') && function_exists('agentpress_listings_init') || function_exists('_p2p_init') && function_exists('wp_listings_init')) { + $output .= '
    '; + $output .= '' . get_the_post_thumbnail( $post->ID, 'employee-thumbnail' ) . ''; + $output .= '
    ' . get_the_title() . ''; + $output .= impa_employee_details(); + if ( function_exists( '_p2p_init' ) && function_exists( 'agentpress_listings_init' ) || function_exists( '_p2p_init' ) && function_exists( 'wp_listings_init' ) ) { $has_listings = impa_has_listings( $post->ID ); - if (!empty($has_listings)) { - echo '

    View My Listings

    '; + if ( ! empty( $has_listings ) ) { + echo '

    View My Listings

    '; } } - $output .= '
    '; - $output .= impa_employee_social(); + $output .= '
    '; + $output .= impa_employee_social(); - $output .= '
    '; + $output .= '
    '; - endforeach; - wp_reset_postdata(); + endforeach; + wp_reset_postdata(); - return $output; + return $output; } diff --git a/includes/views/archive-employee.php b/includes/views/archive-employee.php index 3fb0cd1..49341dc 100644 --- a/includes/views/archive-employee.php +++ b/includes/views/archive-employee.php @@ -8,83 +8,86 @@ * @since 0.9.0 */ -$options = get_option('plugin_impress_agents_settings'); +$options = get_option( 'plugin_impress_agents_settings' ); -add_action('wp_enqueue_scripts', 'enqueue_single_employee_scripts'); +add_action( 'wp_enqueue_scripts', 'enqueue_single_employee_scripts' ); function enqueue_single_employee_scripts() { wp_enqueue_style( 'font-awesome-4.7.0' ); } -add_filter('body_class', 'add_body_class'); +add_filter( 'body_class', 'add_body_class' ); -function add_body_class($classes) { - $classes[] = 'archive-employee'; - return $classes; +function add_body_class( $classes ) { + $classes[] = 'archive-employee'; + return $classes; } function archive_employee_loop() { $class = ''; - $i = 4; + $i = 4; - if ( have_posts() ) : while ( have_posts() ) : the_post(); + if ( have_posts() ) : + while ( have_posts() ) : + the_post(); - // starting at 4 - if ($i == 4) { - $class = 'first one-fourth agent-wrap'; - $i = 0; - } - else { - $class = 'one-fourth agent-wrap'; - } + // starting at 4 + if ( $i == 4 ) { + $class = 'first one-fourth agent-wrap'; + $i = 0; + } else { + $class = 'one-fourth agent-wrap'; + } - //increase count by 1 - $i++; + // increase count by 1 + $i++; - $post_id = get_the_id(); - $thumb_id = get_post_thumbnail_id(); - $thumb_url = wp_get_attachment_image_src($thumb_id, 'employee-thumbnail', true); + $post_id = get_the_id(); + $thumb_id = get_post_thumbnail_id(); + $thumb_url = wp_get_attachment_image_src( $thumb_id, 'employee-thumbnail', true ); - ?> + ?> -
    itemscope itemtype="http://schema.org/Person"> - ' . get_the_title() . ' photo'; ?> +
    itemscope itemtype="http://schema.org/Person"> + ' . get_the_title() . ' photo'; ?>
    - %s

    ', get_permalink(), get_the_title() ); + printf( '

    %s

    ', get_permalink(), get_the_title() ); - echo impa_employee_archive_details(); - if (function_exists('_p2p_init') && function_exists('agentpress_listings_init') || function_exists('_p2p_init') && function_exists('wp_listings_init')) { + echo impa_employee_archive_details(); + if ( function_exists( '_p2p_init' ) && function_exists( 'agentpress_listings_init' ) || function_exists( '_p2p_init' ) && function_exists( 'wp_listings_init' ) ) { - $has_listings = impa_has_listings( $post_id ); - if (!empty($has_listings)) { - echo '

    View My Listings

    '; + $has_listings = impa_has_listings( $post_id ); + if ( ! empty( $has_listings ) ) { + echo '

    View My Listings

    '; + } } - } - - //echo impa_employee_social(); - ?> + // echo impa_employee_social(); + ?>
    - + else : + ?> -

    -

    + + get_header(); + if ( $options['impress_agents_custom_wrapper'] && $options['impress_agents_start_wrapper'] ) { + echo $options['impress_agents_start_wrapper']; + } else { + echo '
    '; -} - if ( have_posts() ) : ?> + } + if ( have_posts() ) : + ?>
    label) ) { + if ( ! isset( $object->label ) ) { $title = '

    ' . $object->name . '

    '; } else { - $title = '

    ' . get_bloginfo('name') . ' Employees

    '; + $title = '

    ' . get_bloginfo( 'name' ) . ' Employees

    '; } - echo $title; ?> + echo $title; + ?> - ','

    '); } ?>
    + + ', '

    ' ); } + ?> +
    - + if ( $options['impress_agents_custom_wrapper'] && $options['impress_agents_end_wrapper'] ) { + echo $options['impress_agents_end_wrapper']; + } else { + echo '
    '; -} -get_sidebar(); -get_footer(); + } + get_sidebar(); + get_footer(); } diff --git a/includes/views/create-tax.php b/includes/views/create-tax.php index 89fa242..1b65133 100755 --- a/includes/views/create-tax.php +++ b/includes/views/create-tax.php @@ -1,5 +1,7 @@

    @@ -21,8 +23,8 @@ - - + + @@ -34,9 +36,17 @@ $employee_taxonomies = array_merge( $this->employee_job_type_taxonomy(), $this->employee_offices_taxonomy(), get_option( $this->settings_field ) ); foreach ( (array) $employee_taxonomies as $id => $data ) : - ?> - - > + ?> + + + > @@ -53,8 +63,8 @@ - - + + diff --git a/includes/views/edit-tax.php b/includes/views/edit-tax.php index 8b93478..c322e8f 100755 --- a/includes/views/edit-tax.php +++ b/includes/views/edit-tax.php @@ -2,7 +2,7 @@ $options = get_option( $this->settings_field ); if ( array_key_exists( $_REQUEST['id'], (array) $options ) ) { - $taxonomy = stripslashes_deep( $options[$_REQUEST['id']] ); + $taxonomy = stripslashes_deep( $options[ $_REQUEST['id'] ] ); } else { wp_die( __( "Nice try, partner. But that taxonomy doesn't exist or can't be edited. Click back and try again.", 'impress_agents' ) ); } diff --git a/includes/views/employee-details-metabox.php b/includes/views/employee-details-metabox.php index 11682fb..46d3c4e 100644 --- a/includes/views/employee-details-metabox.php +++ b/includes/views/employee-details-metabox.php @@ -1,5 +1,7 @@ '; - foreach ( (array) $this->employee_details['col1'] as $label => $key ) { - printf( $pattern, esc_html( $label ), $key, esc_attr( get_post_meta( $post->ID, $key, true ) ) ); - } +foreach ( (array) $this->employee_details['col1'] as $label => $key ) { + printf( $pattern, esc_html( $label ), $key, esc_attr( get_post_meta( $post->ID, $key, true ) ) ); +} echo '
    '; echo '
    '; - foreach ( (array) $this->employee_details['col2'] as $label => $key ) { - printf( $pattern, esc_html( $label ), $key, esc_attr( get_post_meta( $post->ID, $key, true ) ) ); - } +foreach ( (array) $this->employee_details['col2'] as $label => $key ) { + printf( $pattern, esc_html( $label ), $key, esc_attr( get_post_meta( $post->ID, $key, true ) ) ); +} echo '
    '; $pattern = '

    '; -echo '

    ' . __('Social info:', 'impress_agents') . '


    '; +echo '

    ' . __( 'Social info:', 'impress_agents' ) . '


    '; - foreach ( (array) $this->employee_social as $label => $key ) { - printf( $pattern, esc_html( $label ), $key, esc_attr( get_post_meta( $post->ID, $key, true ) ) ); - } +foreach ( (array) $this->employee_social as $label => $key ) { + printf( $pattern, esc_html( $label ), $key, esc_attr( get_post_meta( $post->ID, $key, true ) ) ); +} echo '
    '; diff --git a/includes/views/impress-agents-settings.php b/includes/views/impress-agents-settings.php index 999a892..0209827 100644 --- a/includes/views/impress-agents-settings.php +++ b/includes/views/impress-agents-settings.php @@ -1,71 +1,75 @@ -
    -

    -
    - +
    +

    +
    +
    -

    +


    - +
    -
    -
    +
    +
    - 0, - 'impress_agents_archive_posts_num' => 9, - 'impress_agents_slug' => 'employees', - 'impress_agents_custom_wrapper' => 0, - 'impress_agents_start_wrapper' => '', - 'impress_agents_end_wrapper' => '' - ); + $defaults = array( + 'impress_agents_stylesheet_load' => 0, + 'impress_agents_archive_posts_num' => 9, + 'impress_agents_slug' => 'employees', + 'impress_agents_custom_wrapper' => 0, + 'impress_agents_start_wrapper' => '', + 'impress_agents_end_wrapper' => '', + ); - foreach($defaults as $name => $value) { - if ( !isset($options[$name]) ) { - $options[$name] = $value; + foreach ( $defaults as $name => $value ) { + if ( ! isset( $options[ $name ] ) ) { + $options[ $name ] = $value; } - } + } - if ($options['impress_agents_stylesheet_load'] == 1) + if ( $options['impress_agents_stylesheet_load'] == 1 ) { echo '

    The plugin\'s main stylesheet (impress-agents.css) has been deregistered

    '; + } ?>

    Include CSS?', 'impress_agents'); - _e('

    Here you can deregister the IMPress Agents CSS files and move to your theme\'s css file for ease of customization

    ', 'impress_agents'); - _e('

    Deregister IMPress Agents main CSS (impress-agents.css)?

    ', 'impress-agents' ); + _e( '

    Include CSS?

    ', 'impress_agents' ); + _e( '

    Here you can deregister the IMPress Agents CSS files and move to your theme\'s css file for ease of customization

    ', 'impress_agents' ); + _e( '

    Deregister IMPress Agents main CSS (impress-agents.css)?

    ', 'impress-agents' ); - _e("

    Default Number of Posts

    The default number of posts displayed on a employee archive page is 9. Here you can set a custom number. Enter -1 to display all employee posts.
    If you have more than 20-30 posts, it's not recommended to show all or your page will load slow.

    ", 'impress_agents' ); - _e('

    Number of posts on employee archive page:


    ', 'impress-agents' ); + _e( "

    Default Number of Posts

    The default number of posts displayed on a employee archive page is 9. Here you can set a custom number. Enter -1 to display all employee posts.
    If you have more than 20-30 posts, it's not recommended to show all or your page will load slow.

    ", 'impress_agents' ); + _e( '

    Number of posts on employee archive page:


    ', 'impress-agents' ); - _e("

    Custom Wrapper

    If your theme's content HTML ID's and Classes are different than the included template, you can enter the HTML of your content wrapper beginning and end:

    ", 'impress_agents' ); - _e('

    ', 'impress-agents' ); - _e('

    ', 'impress-agents' ); - _e('


    ', 'impress-agents' ); + _e( "

    Custom Wrapper

    If your theme's content HTML ID's and Classes are different than the included template, you can enter the HTML of your content wrapper beginning and end:

    ", 'impress_agents' ); + _e( '

    ', 'impress-agents' ); + _e( '

    ', 'impress-agents' ); + _e( '


    ', 'impress-agents' ); - _e('

    Directory slug

    Optionally change the slug of the employee post type

    ', 'impress-agents' ); - _e("Don't forget to reset your permalinks if you change the slug!

    ", 'impress-agents' ); + _e( '

    Directory slug

    Optionally change the slug of the employee post type

    ', 'impress-agents' ); + _e( "Don't forget to reset your permalinks if you change the slug!

    ", 'impress-agents' ); ?> - +
    -
    -
    -
    +
    +
    +
    diff --git a/includes/views/single-employee.php b/includes/views/single-employee.php index 8d474c2..8e5b493 100644 --- a/includes/views/single-employee.php +++ b/includes/views/single-employee.php @@ -6,7 +6,7 @@ * @since 0.9.0 */ -add_action('wp_enqueue_scripts', 'enqueue_single_employee_scripts'); +add_action( 'wp_enqueue_scripts', 'enqueue_single_employee_scripts' ); function enqueue_single_employee_scripts() { wp_enqueue_style( 'font-awesome-4.7.0' ); } @@ -19,8 +19,8 @@ function single_employee_post_content() {
    '; ?>
    @@ -34,21 +34,23 @@ function single_employee_post_content() {
    - '; impa_connected_listings_markup(); echo '
    '; - }?> + } + ?>
    - + if ( $options['impress_agents_custom_wrapper'] && $options['impress_agents_start_wrapper'] ) { + echo $options['impress_agents_start_wrapper']; + } else { + echo '
    '; -} + } // Start the Loop. - while ( have_posts() ) : the_post(); ?> + while ( have_posts() ) : + the_post(); + ?>
    >
    ', '' ); ?> - ','

    '); } ?>
    + + ', '

    ' ); } + ?> +
    - +
    - + if ( $options['impress_agents_custom_wrapper'] && $options['impress_agents_end_wrapper'] ) { + echo $options['impress_agents_end_wrapper']; + } else { + echo '
    '; -} -get_sidebar(); -get_footer(); + } + get_sidebar(); + get_footer(); } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..dbb6871 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,24 @@ + + + + Coding standards from WP Enforcer. + + + phpcs.xml + */tests/* + */vendor/* + + + + 0 + + + + + \ No newline at end of file diff --git a/plugin.php b/plugin.php index bb9bb3b..27beaa3 100755 --- a/plugin.php +++ b/plugin.php @@ -12,7 +12,9 @@ License URI: http://www.opensource.org/licenses/gpl-license.php */ -if ( ! defined( 'ABSPATH' ) ) exit; +if ( ! defined( 'ABSPATH' ) ) { + exit; +} register_activation_hook( __FILE__, 'impress_agents_activation' ); /** @@ -23,12 +25,12 @@ function impress_agents_activation() { /** Flush rewrite rules */ - if ( ! post_type_exists( 'employee' ) ) { - impress_agents_init(); - global $_impress_agents, $_impress_agents_taxonomies; - $_impress_agents->create_post_type(); - $_impress_agents_taxonomies->register_taxonomies(); - } + if ( ! post_type_exists( 'employee' ) ) { + impress_agents_init(); + global $_impress_agents, $_impress_agents_taxonomies; + $_impress_agents->create_post_type(); + $_impress_agents_taxonomies->register_taxonomies(); + } flush_rewrite_rules(); } @@ -63,52 +65,52 @@ function impress_agents_init() { load_plugin_textdomain( 'impress_agents', false, basename( dirname( __FILE__ ) ) . '/languages/' ); /** Includes */ - require_once( dirname( __FILE__ ) . '/includes/helpers.php' ); - require_once( dirname( __FILE__ ) . '/includes/functions.php' ); - require_once( dirname( __FILE__ ) . '/includes/shortcodes.php' ); - require_once( dirname( __FILE__ ) . '/includes/class-agents.php' ); - require_once( dirname( __FILE__ ) . '/includes/class-taxonomies.php' ); - require_once( dirname( __FILE__ ) . '/includes/class-employee-widget.php' ); - require_once( dirname( __FILE__ ) . '/includes/class-agent-import.php' ); - require_once( dirname( __FILE__ ) . '/includes/class-migrate-old-posts.php' ); + require_once dirname( __FILE__ ) . '/includes/helpers.php'; + require_once dirname( __FILE__ ) . '/includes/functions.php'; + require_once dirname( __FILE__ ) . '/includes/shortcodes.php'; + require_once dirname( __FILE__ ) . '/includes/class-agents.php'; + require_once dirname( __FILE__ ) . '/includes/class-taxonomies.php'; + require_once dirname( __FILE__ ) . '/includes/class-employee-widget.php'; + require_once dirname( __FILE__ ) . '/includes/class-agent-import.php'; + require_once dirname( __FILE__ ) . '/includes/class-migrate-old-posts.php'; /** Add theme support for post thumbnails if it does not exist */ - if(!current_theme_supports('post-thumbnails')) { + if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } /** Enqueues impress-agents.css style file if it exists and is not deregistered in settings */ - add_action('wp_enqueue_scripts', 'add_impress_agents_main_styles'); + add_action( 'wp_enqueue_scripts', 'add_impress_agents_main_styles' ); function add_impress_agents_main_styles() { - $options = get_option('plugin_impress_agents_settings'); + $options = get_option( 'plugin_impress_agents_settings' ); /** Register Font Awesome icons but don't enqueue them */ wp_register_style( 'font-awesome-4.7.0', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', array(), '4.7.0' ); - if ( !isset($options['impress_agents_stylesheet_load']) ) { + if ( ! isset( $options['impress_agents_stylesheet_load'] ) ) { $options['impress_agents_stylesheet_load'] = 0; } - if ('1' == $options['impress_agents_stylesheet_load'] ) { + if ( '1' == $options['impress_agents_stylesheet_load'] ) { return; } - if ( file_exists(dirname( __FILE__ ) . '/includes/css/impress-agents.css') ) { - wp_register_style('impress_agents', IMPRESS_AGENTS_URL . 'includes/css/impress-agents.css', '', null, 'all'); - wp_enqueue_style('impress_agents'); - } - } + if ( file_exists( dirname( __FILE__ ) . '/includes/css/impress-agents.css' ) ) { + wp_register_style( 'impress_agents', IMPRESS_AGENTS_URL . 'includes/css/impress-agents.css', '', null, 'all' ); + wp_enqueue_style( 'impress_agents' ); + } + } - /** Add admin scripts and styles */ - function impress_agents_admin_scripts_styles() { - wp_enqueue_style( 'impress_agents_admin_css', IMPRESS_AGENTS_URL . 'includes/css/impress-agents-admin.css' ); + /** Add admin scripts and styles */ + function impress_agents_admin_scripts_styles() { + wp_enqueue_style( 'impress_agents_admin_css', IMPRESS_AGENTS_URL . 'includes/css/impress-agents-admin.css' ); wp_enqueue_script( 'impress-agents-admin', IMPRESS_AGENTS_URL . 'includes/js/admin.js', 'media-views' ); $localize_script = array( - 'title' => __( 'Set Term Image', 'impress_agents' ), - 'button' => __( 'Set term image', 'impress_agents' ) + 'title' => __( 'Set Term Image', 'impress_agents' ), + 'button' => __( 'Set term image', 'impress_agents' ), ); /* Pass custom variables to the script. */ @@ -120,15 +122,15 @@ function impress_agents_admin_scripts_styles() { add_action( 'admin_enqueue_scripts', 'impress_agents_admin_scripts_styles' ); /** Instantiate */ - $_impress_agents = new IMPress_Agents; - $_impress_agents_taxonomies = new IMPress_Agents_Taxonomies; + $_impress_agents = new IMPress_Agents(); + $_impress_agents_taxonomies = new IMPress_Agents_Taxonomies(); add_action( 'widgets_init', 'impress_agents_register_widgets' ); /** Make sure is_plugin_active() can be called */ - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + include_once ABSPATH . 'wp-admin/includes/plugin.php'; - if(is_plugin_active('genesis-agent-profiles/plugin.php')) { + if ( is_plugin_active( 'genesis-agent-profiles/plugin.php' ) ) { add_action( 'wp_loaded', 'impress_agents_migrate' ); } }