Advertisement
multibids

MY Custom WP Job Manager

May 8th, 2015
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 20.99 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: WP Job Manager - My Custom Content
  4.  * Description: Loads my custom content to WP Job Manager
  5.  * Author:      Adam Hurlebaus
  6.  * Version:     1.1.0
  7.  * Text Domain: multidigmjm
  8.  */
  9.  
  10. // Exit if accessed directly
  11. if ( ! defined( 'ABSPATH' ) ) exit;
  12.  
  13. if ( ! class_exists( 'WP_Job_Manager' ) ) {
  14.     include( ABSPATH . 'wp-content/plugins/wp-job-manager/includes/abstracts/abstract-wp-job-manager-form.php' );
  15. }
  16.  
  17. class My_Custom_Job_Manager_Content extends WP_Job_Manager_Form{
  18.  
  19.     /**
  20.      * @var $instance
  21.      */
  22.     private static $instance;
  23.  
  24.     /**
  25.      * Make sure only one instance is only running.
  26.      */
  27.     public static function instance() {
  28.         if ( ! isset ( self::$instance ) ) {
  29.             self::$instance = new self;
  30.         }
  31.  
  32.         return self::$instance;
  33.     }
  34.  
  35.     /**
  36.      * Start things up.
  37.      *
  38.      * @since 1.0
  39.      */
  40.     public function __construct() {
  41.  
  42.         define( 'CUSTOM_JOB_MANAGER_PLUGIN_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
  43.         define( 'CUSTOM_JOB_MANAGER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
  44.  
  45.         $this->setup_globals();
  46.         $this->setup_actions();
  47.     }
  48.  
  49.     /**
  50.      * Set some smart defaults to class variables. Allow some of them to be
  51.      * filtered to allow for early overriding.
  52.      *
  53.      * @since 1.0
  54.      *
  55.      * @return void
  56.      */
  57.     private function setup_globals() {
  58.         $this->file         = __FILE__;
  59.  
  60.         $this->basename     = apply_filters( 'multidigmjm_plugin_basenname', plugin_basename( $this->file ) );
  61.         $this->plugin_dir   = apply_filters( 'multidigmjm_plugin_dir_path',  plugin_dir_path( $this->file ) );
  62.         $this->plugin_url   = apply_filters( 'multidigmjm_plugin_dir_url',   plugin_dir_url ( $this->file ) );
  63.  
  64.         $this->lang_dir     = apply_filters( 'multidigmjm_lang_dir',     trailingslashit( $this->plugin_dir . 'languages' ) );
  65.  
  66.         $this->domain       = 'multidigmjm';
  67.     }
  68.  
  69.     /**
  70.      * Setup the default hooks and actions for editing cutsom taxonomies and custom fields
  71.      *
  72.      * @since 1.0
  73.      *
  74.      * @return void
  75.      */
  76.     private function setup_actions() {
  77.         add_action( 'init', array( $this, 'register_post_taxonomy' ) );
  78.         add_filter( 'submit_job_form_fields', array( $this, 'form_fields' ) );
  79.         add_action( 'job_manager_update_job_data', array( $this, 'update_job_data' ), 10, 2 );
  80.         add_filter( 'submit_job_form_fields_get_job_data', array( $this, 'form_fields_get_job_data' ), 10, 2 );
  81.         add_filter( 'submit_job_form_fields_get_user_data', array( $this, 'form_fields_get_user_data' ) );
  82.         add_filter( 'job_manager_job_listing_data_fields', array( $this, 'job_listing_data_fields' ) );
  83.         add_action( 'single_job_listing_meta_end', array( $this, 'display_custom_property_type' ) );
  84.         add_action( 'submit_job_form_job_fields_end', array( $this, 'add_property_fields_to_submit' ) );
  85.         add_filter( 'submit_job_form_validate_fields', array( $this, 'custom_job_form_validate_fields' ), 10, 3 );
  86.         add_action( 'wp_enqueue_scripts', array( $this, 'my_script_method' ) );
  87.         add_filter( 'job_manager_locate_template', array( $this, 'custom_field_job_manager_locate_template' ), 10, 3 );
  88.  
  89.         $this->load_textdomain();
  90.     }
  91.  
  92.     /**
  93.      * Create the `job_listing_property_type` taxonomy.
  94.      *
  95.      * @since 1.0
  96.      */
  97.     public function register_post_taxonomy() {
  98.         $admin_capability = 'manage_job_listings';
  99.  
  100.         $singular  = __( 'Property Type', 'multidigmjm' );
  101.         $plural    = __( 'Property Types', 'multidigmjm' );
  102.  
  103.         if ( current_theme_supports( 'job-manager-templates' ) ) {
  104.             $rewrite     = array(
  105.                 'slug'         => _x( 'property-type', 'Property type slug - resave permalinks after changing this', 'multidigmjm' ),
  106.                 'with_front'   => false,
  107.                 'hierarchical' => false
  108.             );
  109.         } else {
  110.             $rewrite = false;
  111.         }
  112.  
  113.         register_taxonomy( 'job_listing_property_type',
  114.             array( 'job_listing' ),
  115.             array(
  116.                 'hierarchical'          => true,
  117.                 'update_count_callback' => '_update_post_term_count',
  118.                 'label'                 => $plural,
  119.                 'labels' => array(
  120.                     'name'              => $plural,
  121.                     'singular_name'     => $singular,
  122.                     'search_items'      => sprintf( __( 'Search %s', 'multidigmjm' ), $plural ),
  123.                     'all_items'         => sprintf( __( 'All %s', 'multidigmjm' ), $plural ),
  124.                     'parent_item'       => sprintf( __( 'Parent %s', 'multidigmjm' ), $singular ),
  125.                     'parent_item_colon' => sprintf( __( 'Parent %s:', 'multidigmjm' ), $singular ),
  126.                     'edit_item'         => sprintf( __( 'Edit %s', 'multidigmjm' ), $singular ),
  127.                     'update_item'       => sprintf( __( 'Update %s', 'multidigmjm' ), $singular ),
  128.                     'add_new_item'      => sprintf( __( 'Add New %s', 'multidigmjm' ), $singular ),
  129.                     'new_item_name'     => sprintf( __( 'New %s Name', 'multidigmjm' ),  $singular )
  130.                 ),
  131.                 'show_ui'               => true,
  132.                 'query_var'             => true,
  133.                 'has_archive'           => true,
  134.                 'capabilities'          => array(
  135.                     'manage_terms'      => $admin_capability,
  136.                     'edit_terms'        => $admin_capability,
  137.                     'delete_terms'      => $admin_capability,
  138.                     'assign_terms'      => $admin_capability,
  139.                 ),
  140.                 'rewrite'               => $rewrite,
  141.             )
  142.         );
  143.     }
  144.  
  145.     /**
  146.      * Get the value of a repeated fields (e.g. property contacts)
  147.      * @param  array $fields
  148.      * @return array
  149.      */
  150.     public function get_repeated_field( $field_prefix, $fields ) {
  151.         $items       = array();
  152.         $field_keys  = array_keys( $fields );
  153.         $first_field = current( $field_keys );
  154.  
  155.         if ( ! empty( $_POST[ $field_prefix . '_' . $first_field ] ) && is_array( $_POST[ $field_prefix . '_' . $first_field ] ) ) {
  156.             $keys = array_keys( $_POST[ $field_prefix . '_' . $first_field ] );
  157.             foreach ( $keys as $posted_key ) {
  158.                 $item = array();
  159.                 foreach ( $fields as $key => $field ) {
  160.                     switch ( $field['type'] ) {
  161.                         case 'textarea' :
  162.                             $item[ $key ] = wp_kses_post( stripslashes( $_POST[ $field_prefix . '_' . $key ][ $posted_key ] ) );
  163.                         break;
  164.                         default :
  165.                             if ( is_array( $_POST[ $field_prefix . '_' . $key ][ $posted_key ] ) ) {
  166.                                 $item[ $key ] = array_filter( array_map( 'sanitize_text_field', array_map( 'stripslashes', $_POST[ $field_prefix . '_' . $key ][ $posted_key ] ) ) );
  167.                             } else {
  168.                                 $item[ $key ] = sanitize_text_field( stripslashes( $_POST[ $field_prefix . '_' . $key ][ $posted_key ] ) );
  169.                             }
  170.                         break;
  171.                     }
  172.                     if ( empty( $item[ $key ] ) && ! empty( $field['required'] ) ) {
  173.                         continue 2;
  174.                     }
  175.                 }
  176.                 $items[] = $item;
  177.             }
  178.         }
  179.         return $items;
  180.     }
  181.  
  182.     /**
  183.      * Get the value of a posted file field
  184.      * @param  string $key
  185.      * @param  array $field
  186.      * @return string
  187.      */
  188.     public function get_posted_contact_field( $key, $field ) {
  189.         return apply_filters( 'submit_job_form_fields_get_contact_data', $this->get_repeated_field( $key, $field['fields'] ) );
  190.     }
  191.  
  192.     /**
  193.      * Get the value of a posted file field
  194.      * @param  string $key
  195.      * @param  array $field
  196.      * @return string
  197.      */
  198.     public function get_posted_location_field( $key, $field ) {
  199.         return apply_filters( 'submit_job_form_fields_get_location_data', $this->get_repeated_field( $key, $field['fields'] ) );
  200.     }
  201.  
  202.     /**
  203.      * Filter plugin specific templates via the 'job_manager_locate_template' filter
  204.      *
  205.      * @since 1.0
  206.      */
  207.     function custom_field_job_manager_locate_template( $template, $template_name, $template_path ) {
  208.         if ( 'form-fields/location-field.php' === $template_name || 'form-fields/contact-field.php' === $template_name ) {
  209.             return CUSTOM_JOB_MANAGER_PLUGIN_DIR . '/templates/' . $template_name;
  210.         }
  211.         return $template;
  212.     }
  213.  
  214.     // Script to include datepicker
  215.     function my_script_method () {
  216.         wp_enqueue_script('wp-job-manager-custom', plugin_dir_url( __FILE__ ) . '/js/custom-wp-job-manager.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable' ));
  217.         wp_localize_script( 'wp-job-manager-custom', 'job_manager_job_submission', array(
  218.             'i18n_navigate'       => __( 'If you wish to edit the posted details use the "edit job" button instead, otherwise changes may be lost.', 'wp-job-manager' ),
  219.             'i18n_confirm_remove' => __( 'Are you sure you want to remove this item?', 'wp-job-manager' ),
  220.             'i18n_remove'         => __( 'remove', 'wp-job-manager' )
  221.         ) );
  222.         wp_enqueue_style('jquery-style', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
  223.     }
  224.  
  225.     /**
  226.      * Add custom fields to the submission form.
  227.      *
  228.      * @since 1.0
  229.      */
  230.     function form_fields( $fields ) {
  231.        
  232.         // Modify default fields
  233.         unset($fields['job']['job_location']);
  234.         unset($fields['company']['company_logo']);
  235.         unset($fields['company']['company_video']);
  236.         unset($fields['company']['company_twitter']);
  237.         $fields['job']['job_start'] = array(
  238.             'label'       => __( 'Project start date', 'wp-job-manager' ),
  239.             'type'        => 'text',
  240.             'placeholder' => 'Click to select date',
  241.             'required'    => false,
  242.             'priority'    => 10
  243.         );
  244.         $fields['job']['job_end'] = array(
  245.             'label'       => __( 'Project end date', 'wp-job-manager' ),
  246.             'type'        => 'text',
  247.             'placeholder' => 'Click to select date',
  248.             'required'    => false,
  249.             'priority'    => 11
  250.         );
  251.  
  252.         // Add custom "Property" fields
  253.  
  254.         $fields['property'] = array();
  255.  
  256.         $fields['property']['property_type'] = array(
  257.             'label'       => __( 'Property type', 'wp-job-manager' ),
  258.             'type'        => 'select',
  259.             'options'     => multidigmjm_get_properties_simple(),
  260.             'required'    => true,
  261.             'priority'    => '1'
  262.         );
  263.         $fields[ 'property' ][ 'property_name' ] = array(
  264.             'label'       => __( 'Name of property', 'wp-job-manager' ),
  265.             'type'        => 'text',
  266.             'required'    => false,
  267.             'placeholder' => __( 'Enter the name of the building or complex', 'wp-job-manager' ),
  268.             'priority'    => 2
  269.         );
  270.         $fields[ 'property' ][ 'property_size' ] = array(
  271.             'label'       => __( 'Size of property', 'wp-job-manager' ),
  272.             'type'        => 'text',
  273.             'required'    => true,
  274.             'placeholder' => __( 'Enter number of units on property', 'wp-job-manager' ),
  275.             'priority'    => 3
  276.         );
  277.         $fields[ 'property' ][ 'property_year' ] = array(
  278.             'label'       => __( 'Year built', 'wp-job-manager' ),
  279.             'type'        => 'text',
  280.             'required'    => true,
  281.             'placeholder' => __( 'What year was your property built (numbers only)', 'wp-job-manager' ),
  282.             'priority'    => 4
  283.         );
  284.         $fields[ 'property' ][ 'property_contact' ] = array(
  285.             'label'       => __( 'Point of contact', 'wp-job-manager'),
  286.             'type'        => 'contact',
  287.             'required'    => false,
  288.             'placeholder' => '',
  289.             'priority'    => 5,
  290.             'fields'      => array(
  291.                 'name' => array(
  292.                     'label'       => __( 'Name', 'wp-job-manager' ),
  293.                     'type'        => 'text',
  294.                     'required'    => true,
  295.                     'placeholder' => ''
  296.                 ),
  297.                 'title' => array(
  298.                     'label'       => __( 'Title', 'wp-job-manager' ),
  299.                     'type'        => 'text',
  300.                     'required'    => true,
  301.                     'placeholder' => ''
  302.                 ),
  303.                 'email' => array(
  304.                     'label'       => __( 'Email address', 'wp-job-manager' ),
  305.                     'type'        => 'text',
  306.                     'required'    => true,
  307.                     'placeholder' => ''
  308.                 ),
  309.                 'phone' => array(
  310.                     'label'       => __( 'Phone number', 'wp-job-manager' ),
  311.                     'type'        => 'textarea',
  312.                     'required'    => true,
  313.                     'placeholder' => ''
  314.                 )
  315.             )
  316.         );
  317.         $fields[ 'property' ][ 'property_location' ] = array(
  318.             'label'       => __( 'Property location', 'wp-job-manager'),
  319.             'type'        => 'location',
  320.             'required'    => false,
  321.             'placeholder' => '',
  322.             'priority'    => 6,
  323.             'fields'      => array(
  324.                 'street' => array(
  325.                     'label'       => __( 'Street address', 'wp-job-manager' ),
  326.                     'type'        => 'text',
  327.                     'required'    => true,
  328.                     'placeholder' => ''
  329.                 ),
  330.                 'street_two' => array(
  331.                     'label'       => __( 'Street address 2', 'wp-job-manager' ),
  332.                     'type'        => 'text',
  333.                     'required'    => false,
  334.                     'placeholder' => ''
  335.                 ),
  336.                 'city' => array(
  337.                     'label'       => __( 'City', 'wp-job-manager' ),
  338.                     'type'        => 'text',
  339.                     'required'    => true,
  340.                     'placeholder' => ''
  341.                 ),
  342.                 'state' => array(
  343.                     'label'       => __( 'State', 'wp-job-manager' ),
  344.                     'type'        => 'select',
  345.                     'options'     => array ('Alabama'=>"AL", 'Alaska'=>"AK", 'Arizona'=>"AZ", 'Arkansas'=>"AR", 'California'=>"CA", 'Colorado'=>"CO", 'Connecticut'=>"CT", 'Delaware'=>"DE", 'District Of Columbia'=>"DC", 'Florida'=>"FL", 'Georgia'=>"GA", 'Hawaii'=>"HI", 'Idaho'=>"ID", 'Illinois'=>"IL", 'Indiana'=>"IN", 'Iowa'=>"IA", 'Kansas'=>"KS", 'Kentucky'=>"KY", 'Louisiana'=>"LA", 'Maine'=>"ME", 'Maryland'=>"MD", 'Massachusetts'=>"MA", 'Michigan'=>"MI", 'Minnesota'=>"MN", 'Mississippi'=>"MS", 'Missouri'=>"MO", 'Montana'=>"MT", 'Nebraska'=>"NE", 'Nevada'=>"NV", 'New Hampshire'=>"NH", 'New Jersey'=>"NJ", 'New Mexico'=>"NM", 'New York'=>"NY", 'North Carolina'=>"NC", 'North Dakota'=>"ND", 'Ohio'=>"OH", 'Oklahoma'=>"OK", 'Oregon'=>"OR", 'Pennsylvania'=>"PA", 'Rhode Island'=>"RI", 'South Carolina'=>"SC", 'South Dakota'=>"SD", 'Tennessee'=>"TN", 'Texas'=>"TX", 'Utah'=>"UT", 'Vermont'=>"VT", 'Virginia'=>"VA", 'Washington'=>"WA", 'West Virginia'=>"WV", 'Wisconsin'=>"WI", 'Wyoming'=>"WY"),
  346.                     'required'    => true,
  347.                     'placeholder' => __( '-', 'wp-job-manager' )
  348.                 ),
  349.                 'zip' => array(
  350.                     'label'       => __( 'Zip code', 'wp-job-manager' ),
  351.                     'type'        => 'text',
  352.                     'required'    => true,
  353.                     'placeholder' => ''
  354.                 )
  355.             )
  356.         );
  357.  
  358.         return $fields;
  359.  
  360.     }
  361.  
  362.     /**
  363.      * Get the current value for the property type. We can't rely
  364.      * on basic meta value getting, instead we need to find the term.
  365.      *
  366.      * @since 1.0
  367.      */
  368.     function form_fields_get_job_data( $fields, $job ) {
  369.  
  370.         $fields['property']['property_type']['value'] = current( wp_get_object_terms( $job->ID, 'job_listing_property_type', array( 'fields' => 'slugs' ) ) );
  371.  
  372.         return $fields;
  373.     }
  374.  
  375.     /**
  376.      * Get the user data.
  377.      *
  378.      * @since 1.0
  379.      */
  380.     function form_fields_get_user_data( $fields ) {
  381.         if ( is_user_logged_in() && empty( $_POST['submit_job'] ) ) {
  382.             if ( ! empty( $fields['property'] ) ) {
  383.                 foreach ( $fields['property'] as $key => $field ) {
  384.                     $fields['property'][ $key ]['value'] = get_user_meta( get_current_user_id(), '_' . $key, true );
  385.                 }
  386.             }
  387.  
  388.         return $fields;
  389.        
  390.         }
  391.     }
  392.  
  393.  
  394.     /**
  395.      * When the form is submitted, update the data.
  396.      *
  397.      * @since 1.0
  398.      */
  399.     function update_job_data( $job_id, $values ) {
  400.        
  401.         // Loop fields and save meta and term data
  402.         foreach ( $this->fields as $group_key => $group_fields ) {
  403.             foreach ( $group_fields as $key => $field ) {
  404.                 update_post_meta( $job_id, '_' . $key, $values[ $group_key ][ $key ] );
  405.             }
  406.         }
  407.  
  408.         if ( is_user_logged_in() ) {
  409.             update_user_meta( get_current_user_id(), '_property_name', isset( $values['property']['property_name'] ) ? $values['property']['property_name'] : '' );
  410.             update_user_meta( get_current_user_id(), '_property_size', isset( $values['property']['property_size'] ) ? $values['property']['property_size'] : '' );
  411.             update_user_meta( get_current_user_id(), '_property_year', isset( $values['property']['property_year'] ) ? $values['property']['property_year'] : '' );
  412.         }
  413.  
  414.         $property = isset ( $values[ 'property' ][ 'property_type' ] ) ? $values[ 'property' ][ 'property_type' ] : null;
  415.  
  416.         if ( ! $property )
  417.             return;
  418.  
  419.         $term   = get_term_by( 'slug', $property, 'job_listing_property_type' );
  420.  
  421.         wp_set_post_terms( $job_id, array( $term->term_id ), 'job_listing_property_type', false );
  422.  
  423.     }
  424.  
  425.     /**
  426.      * Create Admin write panels for custom content.
  427.      *
  428.      * @since 1.0
  429.      */
  430.     function job_listing_data_fields( $fields ) {
  431.  
  432.         unset($fields['_job_location']);
  433.        
  434.         $fields['_property_name'] = array(
  435.                 'label' => __( 'Property name', 'wp-job-manager' ),
  436.                 'placeholder' => __( '' ),
  437.                 'description' => __( 'Leave this blank if there is no name', 'wp-job-manager' )
  438.             );
  439.         $fields['_property_size'] = array(
  440.                 'label'       => __( 'Property size', 'wp-job-manager' ),
  441.                 'placeholder' => __( '', 'wp-job-manager' ),
  442.                 'description' => __( 'Number of units on property (numbers only)', 'wp-job-manager' )
  443.             );
  444.         $fields['_property_year'] = array(
  445.                 'label'       => __( 'Year built', 'wp-job-manager' ),
  446.                 'placeholder' => __( '', 'wp-job-manager' ),
  447.                 'description' => __( 'What year was your property built (numbers only)', 'wp-job-manager' )
  448.             );
  449.  
  450.         return $fields;
  451.     }
  452.  
  453.  
  454.     /**
  455.      * Validate custom fields
  456.      *
  457.      * @since 1.0
  458.      */
  459.     function custom_job_form_validate_fields($success, $fields, $values) {
  460.         $check_size = $values['property']['property_size'];
  461.         $cleaned_size = preg_replace('/[^[:digit:]]/', '', $check_size);
  462.         if ($check_size != $cleaned_size) {
  463.             return new WP_Error( 'validation-error', 'Please only enter numbers for Property Size' );
  464.         }
  465.         $check_year = $values['property']['property_year'];
  466.         $cleaned_year = preg_replace('/[^[:digit:]]/', '', $check_year);
  467.         if ($check_year != $cleaned_year) {
  468.             return new WP_Error( 'validation-error', 'Please only enter numbers for Year Built' );
  469.         }
  470.         return $success;
  471.     }
  472.  
  473.     /**
  474.      * On a singular job page, display the property type.
  475.      *
  476.      * @since 1.0
  477.      */
  478.     function display_custom_property_type() {
  479.  
  480.         global $post;
  481.  
  482.         /**$terms = wp_get_post_terms( $post->ID, 'job_listing_property_type' );
  483.  
  484.         if ( is_wp_error( $terms ) || empty( $terms ) )
  485.             exit;
  486.  
  487.         $property = $terms[0];
  488.         $propertyname  = $property->name;
  489.  
  490.         if ( $property )
  491.             echo '<li>' . $propertyname . '</li>';*/
  492.             echo '<li>' . get_the_term_list( $post->ID, 'job_listing_property_type', '', ', ', '' ) . '</li>';
  493.     }
  494.  
  495.     function add_property_fields_to_submit( $fields ) {
  496.        
  497.         global $post;
  498.  
  499.         if (strpos($post->post_content, 'submit') !== false){
  500.             $form_fields = WP_Job_Manager_Form_Submit_Job::instance();
  501.             $property_fields = $form_fields->get_fields( 'property' );
  502.         } else {
  503.             $form_fields = WP_Job_Manager_Form_Edit_Job::instance();
  504.             $property_fields = $form_fields->get_fields( 'property' );
  505.         }
  506.  
  507.         if ( $property_fields ) : ?>
  508.             <h2><?php _e( 'Property Details', 'wp-job-manager' ); ?></h2>
  509.  
  510.             <?php foreach ( $property_fields as $key => $field ) : ?>
  511.                 <fieldset class="fieldset-<?php esc_attr_e( $key ); ?>">
  512.                     <label for="<?php esc_attr_e( $key ); ?>"><?php echo $field['label'] . apply_filters( 'submit_job_form_required_label', $field['required'] ? '' : ' <small>' . __( '(optional)', 'wp-job-manager' ) . '</small>', $field ); ?></label>
  513.                     <div class="field <?php echo $field['required'] ? 'required-field' : ''; ?>">
  514.                         <?php
  515.                             if ($field['type'] == ('contact' || 'location')){
  516.                                 get_job_manager_template( 'form-fields/' . $field['type'] . '-field.php', array( 'key' => $key, 'field' => $field, 'class' => $this  ) );
  517.                             }
  518.                             else get_job_manager_template( 'form-fields/' . $field['type'] . '-field.php', array( 'key' => $key, 'field' => $field ) );
  519.                         ?>
  520.                     </div>
  521.                 </fieldset>
  522.             <?php endforeach;
  523.         endif;
  524.     }
  525.  
  526.     /**
  527.      * Loads the plugin language files
  528.      *
  529.      * @since 1.0
  530.      */
  531.     public function load_textdomain() {
  532.         // Traditional WordPress plugin locale filter
  533.         $locale        = apply_filters( 'plugin_locale', get_locale(), $this->domain );
  534.         $mofile        = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
  535.  
  536.         // Setup paths to current locale file
  537.         $mofile_local  = $this->lang_dir . $mofile;
  538.         $mofile_global = WP_LANG_DIR . '/' . $this->domain . '/' . $mofile;
  539.  
  540.         // Look in global /wp-content/languages/multidigmjm folder
  541.         if ( file_exists( $mofile_global ) ) {
  542.             return load_textdomain( $this->domain, $mofile_global );
  543.  
  544.         // Look in local /wp-content/plugins/multidigmjm/languages/ folder
  545.         } elseif ( file_exists( $mofile_local ) ) {
  546.             return load_textdomain( $this->domain, $mofile_local );
  547.         }
  548.  
  549.         return false;
  550.     }
  551. }
  552.  
  553. /**
  554.  * Start things up.
  555.  *
  556.  * Use this function instead of a global.
  557.  *
  558.  * $multidigmjm = multidigmjm();
  559.  *
  560.  * @since 1.0
  561.  */
  562. function multidigmjm() {
  563.     return My_Custom_Job_Manager_Content::instance();
  564. }
  565.  
  566. multidigmjm();
  567.  
  568. /**
  569.  * Get properties (terms) helper.
  570.  *
  571.  * @since 1.0
  572.  */
  573. function multidigmjm_get_properties() {
  574.     $properties = get_terms( 'job_listing_property_type', apply_filters( 'multidigmjm_get_property_args', array( 'hide_empty' => 0 ) ) );
  575.  
  576.     return $properties;
  577. }
  578.  
  579. /**
  580.  * Create a key => value pair of term ID and term name.
  581.  *
  582.  * @since 1.0
  583.  */
  584. function multidigmjm_get_properties_simple() {
  585.     $properties = multidigmjm_get_properties();
  586.     $simple    = array();
  587.  
  588.     foreach ( $properties as $property ) {
  589.         $simple[ $property->slug ] = $property->name;
  590.     }
  591.  
  592.     return apply_filters( 'multidigmjm_get_properties_simple', $simple );
  593. }
  594.  
  595. /**
  596.  * Custom widgets
  597.  *
  598.  * @since 1.1
  599.  */
  600. function multidigmjm_widgets_init() {
  601.     if ( ! class_exists( 'Custom_Property_Widget' ) )
  602.         return;
  603.  
  604.     $multidigmjm = multidigmjm();
  605.  
  606.     include_once( $multidigmjm->plugin_dir . '/widgets.php' );
  607.  
  608.     register_widget( 'My_Custom_Job_Manager_Content_Widget' );
  609. }
  610. add_action( 'after_setup_theme', 'multidigmjm_widgets_init', 11 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement