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.
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 '@@ -113,10 +145,14 @@ function form( $instance ) { echo ''; echo ''; echo '
'; @@ -124,40 +160,40 @@ function form( $instance ) { ?>- -
- - + +
-
-
-
-
%s
@@ -494,8 +525,9 @@ function impress_agents_edit_term_image_field( $term ) {
%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 .= '
%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 ''; } } @@ -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 = ''; @@ -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 .= 'Price: ', get_post_meta($listing->ID, '_listing_price', true), '
-Beds: ', get_post_meta($listing->ID, '_listing_bedrooms', true), '
Baths: ', get_post_meta($listing->ID, '_listing_bathrooms', true),'
+Price: ', get_post_meta( $listing->ID, '_listing_price', true ), '
+Beds: ', get_post_meta( $listing->ID, '_listing_bedrooms', true ), '
Baths: ', get_post_meta( $listing->ID, '_listing_bathrooms', true ),'
-
+