Gistpens – sMyles Plugins https://plugins.smyl.es WordPress and WHMCS Plugins Mon, 21 Oct 2024 14:38:40 +0000 en-US hourly 1 https://wordpress.org/?v=4.6.29 Require package for Administrators on frontend with WP Job Manager Packages https://plugins.smyl.es/gistpens/require-package-for-administrators-on-frontend-with-wp-job-manager-packages/ Sat, 28 Jan 2017 19:01:34 +0000 https://plugins.smyl.es/gistpens/require-package-for-administrators-on-frontend-with-wp-job-manager-packages/

functions.php

add_filter( 'job_manager_packages_admin_required_packages_frontend', 'smyles_packages_demo_admin_require_packages' );

function smyles_packages_demo_admin_require_packages(){
	return true;
}
]]>
How to use a non-standard/hidden meta field for custom permalinks https://plugins.smyl.es/gistpens/how-to-use-a-non-standardhidden-meta-field-for-custom-permalinks/ Sat, 28 Jan 2017 00:44:49 +0000 https://plugins.smyl.es/?post_type=gistpen&p=125473

functions.php

// assuming the non-standard meta key is `job_import_id` (this filter is for Admin Side)
add_filter( 'job_manager_visibility_permalink_get_field_value_job_import_id_is_hidden_meta', 'smyles_job_import_id_permalink_not_hidden' );

function smyles_job_import_id_permalink_not_hidden(){
    return false;
}

// This is for frontend handling
add_filter( 'job_manager_visibility_permalink_frontend_get_field_value_job_import_id', 'smyles_job_import_id_frontend', 10, 4 );

/**
 * Fontend Handling
 * 
 * @var $value          The value that is going to be returned and used for the permalink
 * @var $all_fields     All field configurations in array format
 * @var $values         All values in array format passed by core WP Job Manager plugin after validations
 * @var $field_value    Same as $value, unless unable to determine how to pull value, $value will be empty string and this will be the actual value
 * 
 * @return string
 */
function smyles_job_import_id_frontend( $value, $all_fields, $values, $field_value ){
    
    // It's up to you to return whatever value you want.  Mainly because if the value was submitted via the form
    // there would be no need to use this filter, as the plugin already handles it.  This filter would be used to
    // customize a value, or to return your own custom value.
    
    return 'somecustomvalue';
}
]]>
Allow empty Listing Description (job_description) field in WP Job Manager (to prevent white screen of death) https://plugins.smyl.es/gistpens/allow-empty-listing-description-job_description-field-in-wp-job-manager-to-prevent-white-screen-of-death/ Fri, 23 Dec 2016 18:13:43 +0000 https://plugins.smyl.es/gistpens/allow-empty-listing-description-job_description-field-in-wp-job-manager-to-prevent-white-screen-of-death/

functions.php

<?php
// ^ there should only be one of these at the very top of your functions.php file.
// Omit the <?php above if adding this code to the bottom of your functions.php file (and one exists already at the top)

// Add one filter before Field Editor to make sure required shows as disabled in list table
add_filter( 'submit_job_form_fields', 'smyles_set_job_description_not_required', 99 );
// Add another one to actually set the value after Field Editor updates fields
add_filter( 'submit_job_form_fields', 'smyles_set_job_description_not_required', 101 );

function smyles_set_job_description_not_required( $fields ){
	
	if( is_array( $fields ) && ! empty( $fields['job'] ) ){
		
		if( ! empty( $fields['job']['job_description'] ) ){
			$fields['job']['job_description']['required'] = false;
		}
		
	}

	return $fields;
}

// This filter handles preventing fatal error from empty value in post_content
add_filter( 'submit_job_form_save_job_data', 'submit_listing_allow_empty_job_description', 99999, 5 );

/**
 * Allow empty Listing Description (job_description) field in WP Job Manager
 *
 * If you're using the Field Editor plugin, and want to configure the Description (job_description meta key) field
 * to only show for specific packages, you will need this code to prevent a white screen of death, as the core
 * WP Job Manager plugin requires this value to not be NULL.  This function will filter the core WP Job Manager
 * job data, and set the post_content (used for job_description meta key) to an empty string, instead of NULL.
 *
 *
 * @param $job_data
 * @param $post_title
 * @param $post_content
 * @param $status
 * @param $values
 *
 * @return mixed
 */
function submit_listing_allow_empty_job_description( $job_data, $post_title, $post_content, $status, $values ){

	/**
	 * If we disabled the job_description meta key field, the post_content value will be NULL,
	 * so we set it to an empty string to prevent any fatal PHP errors.
	 */
	if( $job_data['post_content'] === NULL ) {
		$job_data['post_content'] = '';
	}

	return $job_data;
}
]]>
Example WP Job Manager Emails code to add custom email templates (for developers) https://plugins.smyl.es/gistpens/example-wp-job-manager-emails-code-to-add-custom-email-templates-for-developers/ Thu, 22 Dec 2016 21:09:54 +0000 https://plugins.smyl.es/gistpens/example-wp-job-manager-emails-code-to-add-custom-email-templates-for-developers/

functions.php

/**
 * Filter to add Custom Theme, or Plugin templates
 *
 * If you want to add custom templates, this is the hook you should use.
 * Custom templates should follow the pattern below.  Templates should be placed inside the 'templates' array key
 * which is an array of non-key arrays.
 *
 * For the email template post content, you should NOT use HTML as this will be stripped if the user sets the email type
 * to plain text.  Instead, you should use new line breaks (n), which will be converted to HTML <br> automatically.
 *
 * Supported shortcodes (NOT WordPress shortcodes, this plugins shortcodes) can be used in almost every field (to, subject, post_content),
 * except post_title.  If you want to add custom shortcodes, @see WP_Job_Manager_Emails_Shortcodes
 *
 * The `action` value in the template array of arrays should be the action to associate the template with.
 * This is the key of the action/hook, defined in this class, or extending classes @see init_ps_actions() @see init_actions()
 *
 * @see https://plugins.smyl.es/docs-kb/adding-custom-plugin-or-theme-email-templates/
 *
 * @since 2.0.0
 *
 * @param array $templates    Array of templates based on active/available hooks
 * @param array $ps_actions   Array of Post Status actions/hooks
 * @param array $core_actions Array of Core actions/hooks
 * @param class $this         Access to $this current object
 */
add_filter( 'job_manager_emails_hook_templates', 'smyles_test_email_templates', 10, 4 );

function smyles_test_email_templates( $templates, $ps_actions, $core_actions, $that ){

	$singular = 'Listify Listing';

	$content = '';
	$content .= __( 'Hello' ) . "n" . "n";
	$content .= sprintf( __( 'A new %1$s has just been submitted by *%2$s*.  The details are as follows:' ), $singular, '[company_name]' ) . "n" . "n";
	$content .= __( 'This is a custom email template just for the Listify theme!  Plugin and theme developers can easily add their own templates! ') . "n" . "n";
	$content .= "
" . "n" . "n"; $content .= "[job_description]" . "n" . sprintf( __( 'The %s description is as follows:' ), $singular ) . "n" . "[/job_description]" . "n" . "n"; $content .= sprintf( __( 'You can view this %1$s here: %2$s' ), $singular, '[view_job_url]' ) . "n"; $content .= sprintf( __( 'You can view/edit this %1$s in the backend by clicking here: %2$s' ), $singular, '[view_job_url_admin]' ) . "n" . "n"; $templates['listify'] = array( 'label' => __( 'Listify Theme Templates' ), // Header text when viewing tab 'tab' => __( 'Listify' ), // Text used for tab .. KEEP THIS SHORT!! 'desc' => __( 'Themes and plugins can add their own custom templates!' ), // Description shown under header text 'templates' => array( array( 'label' => __( 'New Listify Listing Submitted' ), 'desc' => __( 'This is a custom template specifically for the Listify theme integrated easily with only a few lines of code!' ), 'action' => 'job_manager_job_submitted', 'attachments' => array('company_logo'), 'defaults' => array( 'to' => '[admin_email]', 'post_content' => $content, 'subject' => __( 'New Listify Submission, [job_title]' ), 'post_title' => __( 'New Listify Listing Submitted' ), ) ) ) ); return $templates; }
]]>
How to output value/separator for multiple (inc taxonomy) fields when not using full or value wrapper in WP Job Manager Field Editor https://plugins.smyl.es/gistpens/how-to-output-valueseparator-for-multiple-inc-taxonomy-fields-when-not-using-full-or-value-wrapper-in-wp-job-manager-field-editor/ https://plugins.smyl.es/gistpens/how-to-output-valueseparator-for-multiple-inc-taxonomy-fields-when-not-using-full-or-value-wrapper-in-wp-job-manager-field-editor/#respond Sun, 11 Dec 2016 03:03:06 +0000 https://plugins.smyl.es/gistpens/how-to-output-valueseparator-for-multiple-inc-taxonomy-fields-when-not-using-full-or-value-wrapper-in-wp-job-manager-field-editor/

functions.php

<?php

/**
 * If you are using shortcode, or auto output and do not have the full AND value wrapper being output (output as value only),
 * you can use this code below to use something different than the regular <br /> that is output by default
 */

add_filter('field_editor_output_no_wrap_after', 'smyles_custom_no_wrap_after', 10, 6);

function smyles_custom_no_wrap_after( $output, $meta_key, $listing_id, $field_values, $args, $single_value ){
  
  // Array indexes start at 0, to get the last we need to minus 1 from total
  $last_value_index = ( count( $field_values ) - 1 );
  // Get where our current value output is at
  $current_index = array_search( $single_value, $field_values);
  
  // Return empty string if this is the last value
  if( $last_value_index === $current_index ){
	return '';	
  }
  
  // Return ", and " for second to last value
  if( $current_index === ( $last_value_index -1 ) ){
	return ', and ';
  }
  
  // Return comma instead of <br /> for "job_region" meta key
  if( $meta_key === 'job_region' ){
	return ', ';
  }
  
  // OR check for taxonomy and output comma
  if( array_key_exists( 'taxonomy', $args ) && $args['taxonomy'] === 'job_listing_region' ){
	return ', ';
  }
  
  return $output;
}
]]>
https://plugins.smyl.es/gistpens/how-to-output-valueseparator-for-multiple-inc-taxonomy-fields-when-not-using-full-or-value-wrapper-in-wp-job-manager-field-editor/feed/ 0
Allow featured_image to be set as admin only field https://plugins.smyl.es/gistpens/allow-featured_image-to-be-set-as-admin-only-field/ Tue, 22 Nov 2016 20:02:50 +0000 https://plugins.smyl.es/gistpens/allow-featured_image-to-be-set-as-admin-only-field/

functions.php

add_filter( 'job_manager_field_editor_js_conf_meta_keys', 'smyles_allow_featured_image_admin_only' );

/**
 * Allow featured_image to be set as admin only
 */
function smyles_allow_featured_image_admin_only( $config ){
    
    // Make sure admin_only_0 is in disabled fields first (_0 added for any checkboxes)
    if( isset( $config['featured_image'], $config['featured_image']['disable_fields'] ) ){
		// Flip values to array keys so we can unset admin_only_0 and still retain other values
	  	$flipped = array_flip( $config['featured_image']['disable_fields'] );
	    // Remove admin_only_0 from array
	  	unset( $flipped['admin_only_0'] );
	    // Flip back to values
	  	$unflipped = array_flip( $flipped );
	    // Set modified values
	  	$config['featured_image']['disable_fields'] = $unflipped;
    } 
    
    return $config;
    
}
]]>
Disable parent categories from being selected in taxonomy chosen dropdown for WP Job Manager Field Editor https://plugins.smyl.es/gistpens/disable-parent-categories-from-being-selected-in-taxonomy-chosen-dropdown-for-wp-job-manager-field-editor/ https://plugins.smyl.es/gistpens/disable-parent-categories-from-being-selected-in-taxonomy-chosen-dropdown-for-wp-job-manager-field-editor/#respond Thu, 17 Nov 2016 16:12:09 +0000 https://plugins.smyl.es/gistpens/disable-parent-categories-from-being-selected-in-taxonomy-chosen-dropdown-for-wp-job-manager-field-editor/

script.js

jQuery( function($){
	
	// To use for field other than job_region, change job_region to the meta
	// key of the field
	$( '#job_region > .level-0' ).each( function ( index ) {
		$( this ).prop( 'disabled', 'disabled' );
	});

	$( '#job_region' ).trigger( 'chosen:updated' );

});
]]>
https://plugins.smyl.es/gistpens/disable-parent-categories-from-being-selected-in-taxonomy-chosen-dropdown-for-wp-job-manager-field-editor/feed/ 0
Set featured image from first Gallery Image in Listify when using WP Job Manager Field Editor https://plugins.smyl.es/gistpens/set-featured-image-from-first-gallery-image-in-listify-when-using-wp-job-manager-field-editor/ https://plugins.smyl.es/gistpens/set-featured-image-from-first-gallery-image-in-listify-when-using-wp-job-manager-field-editor/#respond Wed, 16 Nov 2016 22:34:12 +0000 https://plugins.smyl.es/gistpens/set-featured-image-from-first-gallery-image-in-listify-when-using-wp-job-manager-field-editor/

functions.php

<?php
// This must be ran on priority 15 as Listify updates gallery images and featured image @ priority 12
add_action( 'job_manager_update_job_data', 'smyles_listify_featured_image_from_gallery', 15, 2 );

function smyles_listify_featured_image_from_gallery( $job_id, $values ){
	
	if ( ! isset( $values[ 'job' ][ 'gallery_images' ] ) ) {
		return;
	}
	
	$images = $values[ 'job' ][ 'gallery_images' ];
	
	// If gallery images removed or not set, try and remove featured image
	if ( ! isset( $images ) || empty( $images ) || empty( $images[0] ) ) {
		return delete_post_thumbnail( $job_id );
	}
	
	// Set featured image from first image in array
	$featured_image = $images[0];
	// Convert URL to attachment ID
	$attach_id = attachment_url_to_postid( $featured_image );
	
	// If different attachment ID (than currently set one), set featured image
	if ( $attach_id != get_post_thumbnail_id( $job_id ) ) {
		set_post_thumbnail( $job_id, $attach_id );
	}
	
}
]]>
https://plugins.smyl.es/gistpens/set-featured-image-from-first-gallery-image-in-listify-when-using-wp-job-manager-field-editor/feed/ 0
Set a custom placeholder for WP Job Manager taxonomy dropdown field https://plugins.smyl.es/gistpens/set-a-custom-placeholder-for-wp-job-manager-taxonomy-dropdown-field/ https://plugins.smyl.es/gistpens/set-a-custom-placeholder-for-wp-job-manager-taxonomy-dropdown-field/#respond Wed, 16 Nov 2016 20:48:40 +0000 https://plugins.smyl.es/gistpens/set-a-custom-placeholder-for-wp-job-manager-taxonomy-dropdown-field/

functions.php

<?php

add_filter( 'job_manager_term_select_field_wp_dropdown_categories_args', 'smyles_set_tax_dropdown_placeholder' );

function smyles_set_tax_dropdown_placeholder( $args ){
	
	$taxonomy = $args['taxonomy'];
	
	switch ($taxonomy){
		// Set your custom taxonomy here
		case 'mycustomtaxonomy':
			// Set your custom taxonomy placeholder here
			$args['show_option_none'] = __( 'Custom taxonomy placeholder 1' );
			$args['option_none_value'] = '';
			break;
		case 'mycustomtaxonomy2':
			$args['show_option_none'] = __( 'Custom taxonomy placeholder 2' );
			$args['option_none_value'] = '';
			break;
	}
	
	return $args;
}
]]>
https://plugins.smyl.es/gistpens/set-a-custom-placeholder-for-wp-job-manager-taxonomy-dropdown-field/feed/ 0
Create/Add an auto incrementing field whenever a new Job Listing is posted (for WP Job Manager) https://plugins.smyl.es/gistpens/createadd-an-auto-incrementing-field-whenever-a-new-job-listing-is-posted-for-wp-job-manager/ https://plugins.smyl.es/gistpens/createadd-an-auto-incrementing-field-whenever-a-new-job-listing-is-posted-for-wp-job-manager/#respond Wed, 09 Nov 2016 22:00:17 +0000 https://plugins.smyl.es/gistpens/createadd-an-auto-incrementing-field-whenever-a-new-job-listing-is-posted-for-wp-job-manager/

functions.php

<?php

add_action( 'job_manager_update_job_data', 'smyles_add_auto_increment_field', 10, 2);

function smyles_add_auto_increment_field( $job_id, $values ){

	$meta_key = '_my_increment_field';
	$inc_option = 'smyles_job_auto_increment';
	
	$already_set = get_post_meta( $job_id, $meta_key, true);
	$last_num = get_option( $inc_option, 0 );
	
	if( ! $already_set ){
		$next_num = (int) $last_num + 1;
		update_post_meta( $job_id, $meta_key, $next_num );
		update_option( $inc_option, $next_num );
	}

}
]]>
https://plugins.smyl.es/gistpens/createadd-an-auto-incrementing-field-whenever-a-new-job-listing-is-posted-for-wp-job-manager/feed/ 0