Jump to content

Recommended Posts

So i've bought two themes but need to transplant one function to the other (both are very similar) and i'm trying to get my head around whats required and what does what... So apart from the basic CSS these are the related files i've found 

 

The main code

<?php
/**
 * Job Listing: Business Hours
 *
 * @since Listify 1.0.0
 */
class Listify_Widget_Listing_Business_Hours extends Listify_Widget {

    public function __construct() {
        $this->widget_description = __( 'Display the business hours of the listing.', 'listify' );
        $this->widget_id          = 'listify_widget_panel_listing_business_hours';
        $this->widget_name        = __( 'Listify - Listing: Business Hours', 'listify' );
        $this->settings           = array(
            'title' => array(
                'type'  => 'text',
                'std'   => '',
                'label' => __( 'Title:', 'listify' )
            ),
            'icon' => array(
                'type'    => 'text',
                'std'     => 'ion-clock',
                'label'   => '<a href="http://ionicons.com/">' . __( 'Icon Class:', 'listify' ) . '</a>'
            )
        );

        parent::__construct();
    }

    function widget( $args, $instance ) {
        global $job_manager;

        extract( $args );

        $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
        $icon = isset( $instance[ 'icon' ] ) ? $instance[ 'icon' ] : null;

        if ( $icon ) {
            if ( strpos( $icon, 'ion-' ) !== false ) {
                $before_title = sprintf( $before_title, $icon );
            } else {
                $before_title = sprintf( $before_title, 'ion-' . $icon );
            }
        }

        $hours = get_post()->_job_hours;

        if ( ! $hours ) {
            return;
        }

        global $wp_locale;

        $numericdays = listify_get_days_of_week();

        foreach ( $numericdays as $key => $i ) {
            $day = $wp_locale->get_weekday( $i );
            $start = isset( $hours[ $i ][ 'start' ] ) ? $hours[ $i ][ 'start' ] : false;
            $end = isset( $hours[ $i ][ 'end' ] ) ? $hours[ $i ][ 'end' ] : false;

            if ( ! ( $start && $end ) ) {
                continue;
            }

            $days[ $day ] = array( $start, $end );
        }

        if ( empty( $days ) ) {
            return;
        }

        ob_start();

        echo $before_widget;

        if ( $title ) {
            echo $before_title . $title . $after_title;
        }

        do_action( 'listify_widget_job_listing_hours_before' );
?>

<?php foreach ( $days as $day => $hours ) : ?>
    <p class="business-hour" itemprop="openingHours" content="<?php echo $day; ?> <?php echo date_i18n( 'Ga', strtotime( $hours[0] ) ); ?>-<?php echo date( 'Ga', strtotime( $hours[1] ) ); ?>">
        <span class="day"><?php echo $day ?></span>
        <span class="business-hour-time">
            <?php if ( __( 'Closed', 'listify' ) == $hours[0] ) : ?>
                <?php _e( 'Closed', 'listify' ); ?>
            <?php else : ?>
                <span class="start"><?php echo $hours[0]; ?></span> – <span class="end"><?php echo $hours[1]; ?></span>
            <?php endif; ?>
        </span>
    </p>
<?php endforeach; ?>

<?php
        do_action( 'listify_widget_job_listing_hours_after' );

        echo $after_widget;

        $content = ob_get_clean();

        echo apply_filters( $this->widget_id, $content );
    }
}

I guess it's calling this for the styling and formatting information for the table?

<?php
/**
 *
 */

global $wp_locale;

if ( is_admin() ) {
	global $field;
}

$days = listify_get_days_of_week();
?>

<table>
	<tr>
		<th width="40%"> </th>
		<th align="left"><?php _e( 'Open', 'listify' ); ?></th>
		<th align="left"><?php _e( 'Close', 'listify' ); ?></th>
	</tr>

	<?php foreach ( $days as $key => $i ) : ?>
		<tr>
			<td align="left"><?php echo $wp_locale->get_weekday( $i ); ?></td>
			<td align="left" class="business-hour"><input type="text" class="timepicker" name="job_hours[<?php echo $i;
			?>][start]" value="<?php echo isset( $field[ 'value' ][ $i ] ) && isset( $field[ 'value' ][ $i ][ 'start' ] ) ? $field[ 'value' ][ $i ][ 'start' ] : ''; ?>" class="regular-text" /></td>
			<td align="left" class="business-hour"><input type="text" class="timepicker" name="job_hours[<?php echo $i;
			?>][end]" value="<?php echo isset( $field[ 'value' ][ $i ] ) && isset( $field[ 'value' ][ $i ][ 'end' ] )
			?$field[ 'value' ][ $i ][ 'end' ] : ''; ?>" class="regular-text" /></td>
		</tr>
	<?php endforeach; ?>
</table>

and lastly this...

<?php

class Listify_WP_Job_Manager_Business_Hours extends Listable_Integration {

	public function __construct() {
		$this->includes = array();
		$this->integration = 'wp-job-manager';

		parent::__construct();
	}

	public function setup_actions() {
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );

		// save [front, back]
		add_action( 'job_manager_update_job_data', array( $this, 'job_manager_update_job_data' ), 10, 2 );
		add_action( 'job_manager_save_job_listing', array( $this, 'job_manager_update_job_data' ), 10, 2 );

		// add to frontend
		add_filter( 'submit_job_form_fields', array( $this, 'submit_job_form_fields' ) );
	
		// custom input
		add_action( 'job_manager_input_business_hours', array( $this, 'job_manager_input_business_hours' ), 10, 2 );
		
		// get current value
		add_filter( 'submit_job_form_fields_get_job_data', array( $this, 'get_job_data' ), 10, 2 );

		// output in admin
		add_action( 'listify_writepanels_business_hours', array( $this, 'output_admin' ) );
	}

	public function admin_enqueue_scripts() {
		global $pagenow;

		if ( ! ( in_array( $pagenow, array( 'post-new.php', 'post.php'  )) && get_post_type() == 'job_listing' ) ) {
			return;
		}

		wp_enqueue_script( 'timepicker', Listable_Integration::get_url() . 'js/vendor/jquery.timepicker.min.js' );
		wp_enqueue_style( 'timepicker', get_template_directory_uri() . '/css/vendor/jquery.timepicker.css' );
	}

	public function submit_job_form_fields( $fields ) {
		$fields[ 'job' ][ 'job_hours' ] = array(
			'label'       => __( 'Hours of Operation', 'listify' ),
			'type'        => 'business-hours',
			'required'    => false,
			'placeholder' => '',
			'priority'    => 4.9,
			'default'     => ''
		);

		return $fields;
	}

	public function job_manager_update_job_data( $job_id, $values ) {
		if ( ! isset( $_POST[ 'job_hours' ] ) ) {
			return;
		}

		update_post_meta( $job_id, '_job_hours', stripslashes_deep( $_POST[ 'job_hours' ] ) );
	}

	public function get_job_data( $fields, $job ) {
		$hours = get_post_meta( $job->ID, '_job_hours', true );

		if ( ! $hours ) {
			return $fields;
		}

		$fields[ 'job' ][ 'job_hours' ][ 'value' ] = $hours;
		
		return $fields;
	}

	public function job_manager_input_business_hours( $key, $field ) {
		global $wp_locale, $post, $thepostid;

		$thepostid = $post->ID;
	?>

	<div class="form-field" style="position: relative;">

		<?php if ( ! is_admin() ) : ?>
		<label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ) ; ?>:</label>
		<?php endif; ?>

		<?php
			global $field;

			if ( empty( $field[ 'value' ] ) ) {
				$field[ 'value' ] = get_post_meta( $thepostid, '_job_hours', true );
			}

			get_job_manager_template( 'form-fields/business-hours-field.php' );
		?>

		<script>
			(function($) {
				$( '.timepicker' ).timepicker({
					timeFormat: '<?php echo str_replace( '\\', '\\\\', get_option( 'time_format' ) ); ?>',
					noneOption: {
						label: '<?php _e( 'Closed', 'listify' ); ?>',
						value: '<?php _e( 'Closed', 'listify' ); ?>' 
					}
				});
			})(jQuery);
		</script>

	</div>

	<?php
	}

	public function output_admin() {
		do_action( 'job_manager_input_business_hours', '_job_hours', array(
			'label' => __( 'Hours of Operation', 'listify' ),
			'type' => 'business_hours',
			'placeholder' => '',
			'priority' => 99
		) );
	}
}

Do i need to manually create the mysql tables or are they already being created? Is there more files i should be looking for? Absolutely clueless despite watching lots of tutorials on  youtube, having a PHP & Mysql for dummies book beside me... 

Edited by Evolutionsic

Maybe should be looking at the developers site and also wordpress related.

 

If this was made as a plugin everything should be included to work, possibly they require a special custom theme to work right.

 

 

To try and make this simple, adding functions to theme itself or use as a plugin that injects into themes.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.