Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

kazuyoshida on "How to modify a part of a plugin"

$
0
0

Hi,

I am totally new to hooks and was hoping someone can tell me how do the following. I have read on hooks, but to be honest, a real life example, I believe will make it a lot easier for me to understand how this all works.

Here is a code from a plugin where I just want to replace one line. Can you tell me how I could do this, so I do not need to make the same changes each time the plugin gets updated?

I would like to change
$end_date = get_gmt_from_date( date( 'Y-m-d H:i:s', $end_date ) );
to
$end_date = get_date_from_gmt( date( 'Y-m-d H:i:s', $end_date ) );

If you can tell me what exactly I need to add to my functions.php, I would really appreciate it.

<?php
/**
 * Campaigns
 *
 * All things to do with campaigns as a whole.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 */

class ATCF_Campaigns {

	/**
	 * Start things up.
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @return void
	 */
	public function __construct() {
		add_action( 'init', array( $this, 'setup' ), -1 );
	}

	/**
	 * Some basic tweaking.
	 *
	 * Set the archive slug, and remove formatting from prices.
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @return void
	 */
	function setup() {
		add_filter( 'edd_download_labels', array( $this, 'download_labels' ) );
		add_filter( 'edd_default_downloads_name', array( $this, 'download_names' ) );
		add_filter( 'edd_download_supports', array( $this, 'download_supports' ) );

		do_action( 'atcf_campaigns_actions' );

		if ( ! is_admin() )
			return;

		add_filter( 'edd_price_options_heading', 'atcf_edd_price_options_heading' );
		add_filter( 'edd_variable_pricing_toggle_text', 'atcf_edd_variable_pricing_toggle_text' );

		add_filter( 'manage_edit-download_columns', array( $this, 'dashboard_columns' ), 11, 1 );
		add_filter( 'manage_download_posts_custom_column', array( $this, 'dashboard_column_item' ), 11, 2 );

		add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 11 );
		add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );

		add_filter( 'edd_metabox_fields_save', array( $this, 'meta_boxes_save' ) );
		add_filter( 'edd_metabox_save_campaign_end_date', 'atcf_campaign_save_end_date' );

		remove_action( 'edd_meta_box_fields', 'edd_render_product_type_field', 10 );

		add_action( 'edd_download_price_table_head', 'atcf_pledge_limit_head', 9 );
		add_action( 'edd_download_price_table_row', 'atcf_pledge_limit_column', 9, 3 );

		add_action( 'edd_after_price_field', 'atcf_after_price_field' );

		add_action( 'wp_insert_post', array( $this, 'update_post_date_on_publish' ) );

		do_action( 'atcf_campaigns_actions_admin' );
	}

	/**
	 * Download labels. Change it to "Campaigns".
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @param array $labels The preset labels
	 * @return array $labels The modified labels
	 */
	function download_labels( $labels ) {
		$labels =  apply_filters( 'atcf_campaign_labels', array(
			'name' 				=> __( 'Campaigns', 'atcf' ),
			'singular_name' 	=> __( 'Campaign', 'atcf' ),
			'add_new' 			=> __( 'Add New', 'atcf' ),
			'add_new_item' 		=> __( 'Add New Campaign', 'atcf' ),
			'edit_item' 		=> __( 'Edit Campaign', 'atcf' ),
			'new_item' 			=> __( 'New Campaign', 'atcf' ),
			'all_items' 		=> __( 'All Campaigns', 'atcf' ),
			'view_item' 		=> __( 'View Campaign', 'atcf' ),
			'search_items' 		=> __( 'Search Campaigns', 'atcf' ),
			'not_found' 		=> __( 'No Campaigns found', 'atcf' ),
			'not_found_in_trash'=> __( 'No Campaigns found in Trash', 'atcf' ),
			'parent_item_colon' => '',
			'menu_name' 		=> __( 'Campaigns', 'atcf' )
		) );

		return $labels;
	}

	/**
	 * Further change "Download" & "Downloads" to "Campaign" and "Campaigns"
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @param array $labels The preset labels
	 * @return array $labels The modified labels
	 */
	function download_names( $labels ) {
		$cpt_labels = $this->download_labels( array() );

		$labels = array(
			'singular' => $cpt_labels[ 'singular_name' ],
			'plural'   => $cpt_labels[ 'name' ]
		);

		return $labels;
	}

	/**
	 * Add excerpt support for downloads.
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @param array $supports The post type supports
	 * @return array $supports The modified post type supports
	 */
	function download_supports( $supports ) {
		$supports[] = 'excerpt';
		$supports[] = 'comments';
		$supports[] = 'author';

		if ( ! atcf_theme_supports( 'campaign-featured-image' ) ) {
			if ( ( $key = array_search( 'thumbnail', $supports ) ) !== false ) {
				unset( $supports[$key]);
			}
		}

		return $supports;
	}

	/**
	 * Download Columns
	 *
	 * Add "Amount Funded" and "Expires" to the main campaign table listing.
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @param array $supports The post type supports
	 * @return array $supports The modified post type supports
	 */
	function dashboard_columns( $columns ) {
		$columns = apply_filters( 'atcf_dashboard_columns', array(
			'cb'                => '<input type="checkbox"/>',
			'title'             => __( 'Name', 'atcf' ),
			'type'              => __( 'Type', 'atcf' ),
			'backers'           => __( 'Backers', 'atcf' ),
			'funded'            => __( 'Amount Funded', 'atcf' ),
			'expires'           => __( 'Days Remaining', 'atcf' )
		) );

		return $columns;
	}

	/**
	 * Download Column Items
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @param array $supports The post type supports
	 * @return array $supports The modified post type supports
	 */
	function dashboard_column_item( $column, $post_id ) {
		$campaign = atcf_get_campaign( $post_id );

		switch ( $column ) {
			case 'funded' :
				printf( _x( '%s of %s', 'funded of goal', 'atcf' ), $campaign->current_amount(true), $campaign->goal(true) );

				break;
			case 'expires' :
				echo $campaign->is_endless() ? '&mdash;' : $campaign->days_remaining();

				break;
			case 'type' :
				echo ucfirst( $campaign->type() );

				break;
			case 'backers' :
				echo $campaign->backers_count();

				break;
			default :
				break;
		}
	}

	/**
	 * Remove some metaboxes that we don't need to worry about. Sales
	 * and download stats, aren't really important.
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @return void
	 */
	function remove_meta_boxes() {
		$boxes = array(
			'edd_file_download_log' => 'normal',
			'edd_purchase_log'      => 'normal',
			'edd_product_stats'     => 'side'
		);

		foreach ( $boxes as $box => $context ) {
			remove_meta_box( $box, 'download', $context );
		}
	}

	/**
	 * Add our custom metaboxes.
	 *
	 * - Collect Funds
	 * - Campaign Stats
	 * - Campaign Video
	 *
	 * As well as some other information plugged into EDD in the Download Configuration
	 * metabox that already exists.
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @return void
	 */
	function add_meta_boxes() {
		add_meta_box( 'atcf_campaign_stats', __( 'Campaign Stats', 'atcf' ), '_atcf_metabox_campaign_stats', 'download', 'side', 'high' );
		add_meta_box( 'atcf_campaign_updates', __( 'Campaign Updates', 'atcf' ), '_atcf_metabox_campaign_updates', 'download', 'normal', 'high' );

		if ( atcf_theme_supports( 'campaign-video' ) )
			add_meta_box( 'atcf_campaign_video', __( 'Campaign Video', 'atcf' ), '_atcf_metabox_campaign_video', 'download', 'normal', 'high' );

		add_action( 'edd_meta_box_fields', '_atcf_metabox_campaign_info', 5 );
	}

	/**
	 * Campaign Information
	 *
	 * Hook in to EDD and add a few more things that will be saved. Use
	 * this so we are already cleared/validated.
	 *
	 * @since Astoundify Crowdfunding 0.1-alpha
	 *
	 * @param array $fields An array of fields to save
	 * @return array $fields An updated array of fields to save
	 */
	function meta_boxes_save( $fields ) {
		$fields[] = '_campaign_featured';
		$fields[] = '_campaign_physical';
		$fields[] = 'campaign_goal';
		$fields[] = 'campaign_contact_email';
		$fields[] = 'campaign_end_date';
		$fields[] = 'campaign_endless';
		$fields[] = 'campaign_norewards';
		$fields[] = 'campaign_video';
		$fields[] = 'campaign_location';
		$fields[] = 'campaign_author';
		$fields[] = 'campaign_type';
		$fields[] = 'campaign_updates';

		return $fields;
	}

	/**
	 * When a campaign is published, reset the campaign end date based
	 * on the original number of days set when submitting.
	 *
	 * @since Astoundify Crowdfunding 1.6
	 *
	 * @return void
	 */
	public function update_post_date_on_publish() {
		global $post;

		if ( ! isset ( $post ) )
			return;

		if ( 'pending' != $post->post_status )
			return $post;

		$length = $post->campaign_length;

		$end_date = strtotime( sprintf( '+%d days', $length ) );
		$end_date = get_gmt_from_date( date( 'Y-m-d H:i:s', $end_date ) );

		update_post_meta( $post->ID, 'campaign_end_date', sanitize_text_field( $end_date ) );
	}
}

new ATCF_Campaigns;

/**
 * Filter the expiration date for a campaign.
 *
 * A hidden/fake input field so the filter is triggered, then
 * add all the other date fields together to create the MySQL date.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 *
 * @param string $date
 * @return string $end_date Formatted date
 */
function atcf_campaign_save_end_date( $new ) {
	global $post;

	if ( ! isset( $_POST[ 'end-aa' ] ) ) {
		if ( $_POST[ 'campaign_endless' ] == 0 ) {
			delete_post_meta( $post->ID, 'campaign_endless' );
		}

		return;
	}

	$aa = $_POST['end-aa'];
	$mm = $_POST['end-mm'];
	$jj = $_POST['end-jj'];
	$hh = $_POST['end-hh'];
	$mn = $_POST['end-mn'];
	$ss = $_POST['end-ss'];

	$aa = ($aa <= 0 ) ? date('Y') : $aa;
	$mm = ($mm <= 0 ) ? date('n') : $mm;
	$jj = ($jj > 31 ) ? 31 : $jj;
	$jj = ($jj <= 0 ) ? date('j') : $jj;

	$hh = ($hh > 23 ) ? $hh -24 : $hh;
	$mn = ($mn > 59 ) ? $mn -60 : $mn;
	$ss = ($ss > 59 ) ? $ss -60 : $ss;

	$end_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );

	$valid_date = wp_checkdate( $mm, $jj, $aa, $end_date );

	if ( ! $valid_date ) {
		return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.', 'atcf' ) );
	}

	if ( mysql2date( 'G', $end_date ) > current_time( 'timestamp' ) ) {
		delete_post_meta( $post->ID, '_campaign_expired' );
	}

	return $end_date;
}

/**
 * Price row head
 *
 * @since Astoundify Crowdfunding 0.9
 *
 * @return void
 */
function atcf_pledge_limit_head() {
?>
	<th style="width: 30px"><?php _e( 'Limit', 'atcf' ); ?></th>
	<th style="width: 30px"><?php _e( 'Backers', 'atcf' ); ?></th>
<?php
}

/**
 * Price row columns
 *
 * @since Astoundify Crowdfunding 0.9
 *
 * @return void
 */
function atcf_pledge_limit_column( $post_id, $key, $args ) {
?>
	<td>
		<input type="text" class="edd_repeatable_name_field" name="edd_variable_prices[<?php echo $key; ?>][limit]" id="edd_variable_prices[<?php echo $key; ?>][limit]" value="<?php echo isset ( $args[ 'limit' ] ) ? $args[ 'limit' ] : null; ?>" style="width:100%" />
	</td>
	<td>
		<input type="text" class="edd_repeatable_name_field" name="edd_variable_prices[<?php echo $key; ?>][bought]" id="edd_variable_prices[<?php echo $key; ?>][bought]" value="<?php echo isset ( $args[ 'bought' ] ) ? $args[ 'bought' ] : null; ?>" style="width:100%" />
	</td>
<?php
}

/**
 * Price row fields
 *
 * @since Astoundify Crowdfunding 0.9
 *
 * @return void
 */
function atcf_price_row_args( $args, $value ) {
	$args[ 'limit' ] = isset( $value[ 'limit' ] ) ? $value[ 'limit' ] : '';
	$args[ 'bought' ] = isset( $value[ 'bought' ] ) ? $value[ 'bought' ] : 0;

	return $args;
}
add_filter( 'edd_price_row_args', 'atcf_price_row_args', 10, 2 );

/**
 * Campaign Stats Box
 *
 * These are read-only stats/info for the current campaign.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 *
 * @return void
 */
function _atcf_metabox_campaign_stats() {
	global $post;

	$campaign = atcf_get_campaign( $post );

	do_action( 'atcf_metabox_campaign_stats_before', $campaign );
?>
	<p>
		<strong><?php _e( 'Current Amount:', 'atcf' ); ?></strong>
		<?php echo $campaign->current_amount(); ?> &mdash; <?php echo $campaign->percent_completed(); ?>
	</p>

	<p>
		<strong><?php _e( 'Backers:' ,'atcf' ); ?></strong>
		<?php echo $campaign->backers_count(); ?>
	</p>

	<?php if ( ! $campaign->is_endless() ) : ?>
	<p>
		<strong><?php _e( 'Days Remaining:', 'atcf' ); ?></strong>
		<?php echo $campaign->days_remaining(); ?>
	</p>
	<?php endif; ?>
<?php
	do_action( 'atcf_metabox_campaign_stats_after', $campaign );
}

/**
 * Campaign Video Box
 *
 * oEmbed campaign video.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 *
 * @return void
 */
function _atcf_metabox_campaign_video() {
	global $post;

	$campaign = atcf_get_campaign( $post );

	do_action( 'atcf_metabox_campaign_video_before', $campaign );
?>
	<input type="text" name="campaign_video" id="campaign_video" class="widefat" value="<?php echo esc_url( $campaign->video() ); ?>" />
	<p class="description"><?php _e( 'oEmbed supported video links.', 'atcf' ); ?></p>
<?php
	do_action( 'atcf_metabox_campaign_video_after', $campaign );
}

/**
 * Campaign Updates Box
 *
 * @since Astoundify Crowdfunding 0.9
 *
 * @return void
 */
function _atcf_metabox_campaign_updates() {
	global $post;

	$campaign = atcf_get_campaign( $post );

	do_action( 'atcf_metabox_campaign_updates_before', $campaign );
?>
	<textarea name="campaign_updates" rows="4" class="widefat"><?php echo esc_textarea( $campaign->updates() ); ?></textarea>
	<p class="description"><?php _e( 'Notes and updates about the campaign.', 'atcf' ); ?></p>
<?php
	do_action( 'atcf_metabox_campaign_updates_after', $campaign );
}

/**
 * Campaign Configuration
 *
 * Hook into EDD Download Information and add a bit more stuff.
 * These are all things that can be updated while the campaign runs/before
 * being published.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 *
 * @return void
 */
function _atcf_metabox_campaign_info() {
	global $post, $edd_options, $wp_locale;

	/** Verification Field */
	wp_nonce_field( 'cf', 'cf-save' );

	$campaign = atcf_get_campaign( $post );

	$end_date = $campaign->end_date();

	if ( ! $end_date && ! $campaign->is_endless() ) {
		$min = isset ( $edd_options[ 'atcf_campaign_length_min' ] ) ? $edd_options[ 'atcf_campaign_length_min' ] : 14;
		$max = isset ( $edd_options[ 'atcf_campaign_length_max' ] ) ? $edd_options[ 'atcf_campaign_length_max' ] : 48;

		$start = apply_filters( 'atcf_shortcode_submit_field_length_start', round( ( $min + $max ) / 2 ) );

		$end_date = date( 'Y-m-d h:i:s', time() + ( $start * 86400 ) );
	}

	$jj = mysql2date( 'd', $end_date );
	$mm = mysql2date( 'm', $end_date );
	$aa = mysql2date( 'Y', $end_date );
	$hh = mysql2date( 'H', $end_date );
	$mn = mysql2date( 'i', $end_date );
	$ss = mysql2date( 's', $end_date );

	do_action( 'atcf_metabox_campaign_info_before', $campaign );

	$types = atcf_campaign_types();
?>
	<p>
		<label for="_campaign_featured">
			<input type="checkbox" name="_campaign_featured" id="_campaign_featured" value="1" <?php checked( 1, $campaign->featured() ); ?> />
			<?php _e( 'Featured campaign', 'atcf' ); ?>
		</label>
	</p>

	<p>
		<label for="_campaign_physical">
			<input type="checkbox" name="_campaign_physical" id="_campaign_physical" value="1" <?php checked( 1, $campaign->needs_shipping() ); ?> />
			<?php _e( 'Collect shipping information on checkout', 'atcf' ); ?>
		</label>
	</p>

	<p>
		<strong><?php _e( 'Funding Type:', 'atcf' ); ?></strong>
	</p>

	<p>
		<?php foreach ( atcf_campaign_types_active() as $key => $desc ) : ?>
		<label for="campaign_type[<?php echo esc_attr( $key ); ?>]"><input type="radio" name="campaign_type" id="campaign_type[<?php echo esc_attr( $key ); ?>]" value="<?php echo esc_attr( $key ); ?>" <?php checked( $key, $campaign->type() ); ?> /> <strong><?php echo $types[ $key ][ 'title' ]; ?></strong> &mdash; <?php echo $types[ $key ][ 'description' ]; ?></label><br />
		<?php endforeach; ?>
	</p>

	<p>
		<label for="campaign_goal"><strong><?php _e( 'Goal:', 'atcf' ); ?></strong></label><br />
		<?php if ( ! isset( $edd_options[ 'currency_position' ] ) || $edd_options[ 'currency_position' ] == 'before' ) : ?>
			<?php echo edd_currency_filter( '' ); ?><input type="text" name="campaign_goal" id="campaign_goal" value="<?php echo edd_format_amount( $campaign->goal(false) ); ?>" style="width:80px" />
		<?php else : ?>
			<input type="text" name="campaign_goal" id="campaign_goal" value="<?php echo edd_format_amount($campaign->goal(false) ); ?>" style="width:80px" /><?php echo edd_currency_filter( '' ); ?>
		<?php endif; ?>
	</p>

	<p>
		<label for="campaign_location"><strong><?php _e( 'Location:', 'atcf' ); ?></strong></label><br />
		<input type="text" name="campaign_location" id="campaign_location" value="<?php echo esc_attr( $campaign->location() ); ?>" class="regular-text" />
	</p>

	<p>
		<label for="campaign_author"><strong><?php _e( 'Author:', 'atcf' ); ?></strong></label><br />
		<input type="text" name="campaign_author" id="campaign_author" value="<?php echo esc_attr( $campaign->author() ); ?>" class="regular-text" />
	</p>

	<p>
		<label for="campaign_email"><strong><?php _e( 'Contact Email:', 'atcf' ); ?></strong></label><br />
		<input type="text" name="campaign_contact_email" id="campaign_contact_email" value="<?php echo esc_attr( $campaign->contact_email() ); ?>" class="regular-text" />
	</p>

	<style>#end-aa { width: 3.4em } #end-jj, #end-hh, #end-mn { width: 2em; }</style>

	<p>
		<strong><?php _e( 'End Date:', 'atcf' ); ?></strong><br />

		<select id="end-mm" name="end-mm">
			<?php for ( $i = 1; $i < 13; $i = $i + 1 ) : $monthnum = zeroise($i, 2); ?>
				<option value="<?php echo $monthnum; ?>" <?php selected( $monthnum, $mm ); ?>>
				<?php printf( '%1$s-%2$s', $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ); ?>
				</option>
			<?php endfor; ?>
		</select>

		<input type="text" id="end-jj" name="end-jj" value="<?php echo esc_attr( $jj ); ?>" size="2" maxlength="2" autocomplete="off" />,
		<input type="text" id="end-aa" name="end-aa" value="<?php echo esc_attr( $aa ); ?>" size="4" maxlength="4" autocomplete="off" /> @
		<input type="text" id="end-hh" name="end-hh" value="<?php echo esc_attr( $hh ); ?>" size="2" maxlength="2" autocomplete="off" /> :
		<input type="text" id="end-mn" name="end-mn" value="<?php echo esc_attr( $mn ); ?>" size="2" maxlength="2" autocomplete="off" />
		<input type="hidden" id="end-ss" name="end-ss" value="<?php echo esc_attr( $ss ); ?>" />
		<input type="hidden" id="campaign_end_date" name="campaign_end_date" value="1" />
	</p>

	<p>
		<label for="campaign_endless">
			<input type="checkbox" name="campaign_endless" id="campaign_endless" value="1" <?php checked( 1, $campaign->is_endless() ); ?>> <?php printf( __( 'This %s never ends', 'atcf' ), strtolower( edd_get_label_singular() ) ); ?>
		</label>
	</p>
<?php
	do_action( 'atcf_metabox_campaign_info_after', $campaign );
}

function atcf_after_price_field() {
	global $post;

	$campaign = atcf_get_campaign( $post );
?>
	<p>
		<label for="campaign_norewards">
			<input type="checkbox" name="campaign_norewards" id="campaign_norewards" value="1" <?php checked( 1, $campaign->is_donations_only() ); ?>> <?php printf( __( 'This %s is donations only (no rewards)', 'atcf' ), strtolower( edd_get_label_singular() ) ); ?>
		</label>
	</p>
<?php
}

/**
 * Goal Save
 *
 * Sanitize goal before it is saved, to remove commas.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 *
 * @return string $price The formatted price
 */
add_filter( 'edd_metabox_save_campaign_goal', 'edd_sanitize_price_save' );

/**
 * Updates Save
 *
 * EDD trys to escape this data, and we don't want that.
 *
 * @since Astoundify Crowdfunding 0.9
 */
function atcf_sanitize_campaign_updates( $updates ) {
	$updates = $_POST[ 'campaign_updates' ];
	$updates = wp_kses_post( $updates );

	return $updates;
}
add_filter( 'edd_metabox_save_campaign_updates', 'atcf_sanitize_campaign_updates' );

/**
 * Updates Save
 *
 * EDD trys to escape this data, and we don't want that.
 *
 * @since Astoundify Crowdfunding 0.9
 */
function atcf_save_variable_prices_norewards( $prices ) {
	$norewards = isset ( $_POST[ 'campaign_norewards' ] ) ? true : false;

	if ( ! $norewards )
		return $prices;

	if ( isset( $prices[0][ 'name' ] ) )
		return $prices;

	$prices = array();

	$prices[0] = array(
		'name'   => apply_filters( 'atcf_default_no_rewards_name', __( 'Donation', 'atcf' ) ),
		'amount' => apply_filters( 'atcf_default_no_rewards_price', 0 ),
		'limit'  => null,
		'bought' => 0
	);

	return $prices;
}
add_filter( 'edd_metabox_save_edd_variable_prices', 'atcf_save_variable_prices_norewards' );

/**
 * Load Admin Scripts
 *
 * @since Astoundify Crowdfunding 1.3
 *
 * @return void
 */
function atcf_load_admin_scripts( $hook ) {
	global $pagenow, $typenow;

	if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) )
		return;

	if ( 'download' != $typenow )
		return;

	$crowdfunding = crowdfunding();

	wp_enqueue_script( 'atcf-admin-scripts', $crowdfunding->plugin_url . '/assets/js/crowdfunding-admin.js', array( 'jquery', 'edd-admin-scripts' ) );
}

ced1870 on "Best way to have a Pro version of a plugin"

$
0
0

Hi
I'm developping some plugins and I would like to have a Pro version for each one that allows to have advanced feature in it.
My question is what is the best way to do that ?
1/ I have a free basic version in the plugin repository
2/ if I make a pro version with the same name it will be deleted with the updates of the free plugin
3/ if I create it with another name it will not use the update notification from the repository and needs 2 plugins to be maintained (free+pro)

The best way for me would be to deliver just the additional files, but how to manage this so that it is the easiest for the user ? :)

Any suggestion would be welcome
Thank you
CEd

gianficaro on "max character help"

$
0
0

on the home page i have the max characters limited for design reasons to keep everything at a same level design so some post are not longer then others but its not counting the white spaces as a character and it makes other posts longer

i have this in functions

/* set max characters in articles and posts. */

function get_excerpt($count){
$permalink = get_permalink($post->ID);
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));

return $excerpt;
}

and this in index

<?php echo get_excerpt(250); ?>

igogra on "Custom Ordering Post Link Functions"

$
0
0

Hi,

I'm using a custom post type to hold products, each product holds a name via a custom field. When I display the product via its singular template it would be nice to have a next & previous link to go through those products, but it should go through them in order of their name. Currently that’s not possible as they would be ordered by their publishing dates.

So I added the following code in functions.php, but it's not working, I don't know if this has to be made in a different way:

if(is_singular('products')) {
	add_filter('get_previous_post_join', 'rt_post_join');
	add_filter('get_next_post_join', 'rt_post_join');
	add_filter('get_previous_post_where', 'rt_prev_post_where');
	add_filter('get_next_post_where', 'rt_next_post_where');
	add_filter('get_previous_post_sort', 'rt_prev_post_sort');
	add_filter('get_next_post_sort', 'rt_next_post_sort');
}

function rt_post_join($join, $isc, $ec) {
	global $wpdb;

	$join = " INNER JOIN $wpdb->postmeta AS pm ON pm.post_id = p.ID";
	return $join;
}

function rt_prev_post_where($w) {
	global $wpdb, $post;

	$prd = get_post_meta($post->ID, 'data_product_name_product', true);
	$w = $wpdb->prepare(" WHERE pm.meta_key = 'data_product_name_product' AND pm.meta_value < '$prd' AND p.post_type = 'products' AND p.post_status = 'publish'");
	return $w;
}

function rt_next_post_where($w) {
	global $wpdb, $post;

	$prd = get_post_meta($post->ID, 'data_product_name_product', true);
	$w = $wpdb->prepare(" WHERE pm.meta_key = 'data_product_name_product' AND pm.meta_value > '$prd' AND p.post_type = 'products' AND p.post_status = 'publish'");
	return $w;
}

function rt_prev_post_sort($o) {
	$o = "ORDER BY pm.meta_value DESC LIMIT 1";
	return $o;
}
function rt_next_post_sort($o) {
	$o = "ORDER BY pm.meta_value ASC LIMIT 1";
	return $o;
}

And in my single page of products (single-products.php) I added the following code to display the pagination links:

<?php next_post_link('%link', 'Next product'); ?>
<?php previous_post_link('%link','Previous product'); ?>

Thanks.

buckdanny on "Custom Post Template: How to get the name of the post-template on index.php?"

$
0
0

Hey,
I am using the Custom Post Template Plugin (http://wordpress.org/plugins/custom-post-template/) to style different posts with different layouts. My question is, how can I get the name of the post-template in the loop on my index.php or somewhere else (outside of singleXX.php)? I want to loop threw all my posts and to style them differently according to their template.

Thank you!!

sh090 on "Replacing regular form in php"

$
0
0

Hi Guys

I am looking to make some changes to my site which uses appthemes's jobroller theme. Please help me as to what changes should i make to the below php code to call gravity forms instead of the current one when "Apply Online" is clicked:

<?php
				// load up theme-actions.php and display the apply form
				do_action('job_footer');
				?>
				<ul class="section_footer" style="display:none;">

					<?php if ($url = get_post_meta($post->ID, 'job_url', true)) : ?>
						<li class="apply"><a href="<?php echo $url; ?>" <?php
							 if ($onmousedown = get_post_meta($post->ID, 'onmousedown', true)) :
							 	echo 'onmousedown="'.$onmousedown.'"';
							 endif;
						?> target="_blank" rel="nofollow"><?php _e('View & Apply Online',APP_TD); ?></a></li>
					<?php else :?>
						<li class="apply"><a href="#apply_form" class="apply_online"><?php _e('Apply Online',APP_TD); ?></a></li>
					<?php endif; ?>

					<?php if (is_user_logged_in() && current_user_can('can_submit_resume')) : $starred = (array) get_user_meta(get_current_user_id(), '_starred_jobs', true); ?>
						<?php if (!in_array($post->ID, $starred)) : ?>
							<li class="star"><a href="<?php echo add_query_arg( 'star', 'true', get_permalink() ); ?>" class="star"><?php _e('Star Job',APP_TD); ?></a></li>
						<?php else : ?>
							<li class="star"><a href="<?php echo add_query_arg( 'star', 'false', get_permalink() ); ?>" class="star"><?php _e('Un-star Job',APP_TD); ?></a></li>
						<?php endif; ?>
					<?php endif; ?>

Any help would be greatly appreciated !!!

[Moderator Note: No bumping. If it's that urgent after waiting just 45 minutes, consider hiring someone instead.]

Snaphaan on "Running jquery inside plugin admin page"

$
0
0

This is a simple piece of jqeury I have picked up from JSFiddle:

$('.sample').on('click', function () {

    console.log(this);
    var choice = $(this);

    if (choice.is(":checked")) {
        $('#choices').append(choice.val() + " is checked!");
    }
});

Here is the html:

<div id="top-menu">
    <input type="checkbox" class="sample" value="a">A</input>
    <input type="checkbox" class="sample" value="b">B</input>
    <input type="checkbox" class="sample" value="c">C</input>
</div>
<label>Choices</label>
<div id="choices"></div>

And this is how I enqued jquery in my functions.php:

function load_jquery() {
    wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_script', 'load_jquery' );

But nothing works! I'v tried a number of other simple scripts for instance:

jQuery(document).ready(function(){

    alert("Hello");
});

.. and still nothing.

Any help would be greatly appreciated.

Thank you

bossbowser on "Get post ids by category name"

$
0
0

Hi there,

For the life of me I can't work out how to do this one. If anyone can help I will be very very appreciative! Thanks in advance.

I have two arrays each containing category names as values so for instance

Array1 ( [0] => cheap [1] => cheap [2] => average )
Array2 ( [0] => hiphop [1] => charthits [2] => partybangers )

These arrays change each time the page is reloaded to create a more random variation to display to the user

The keys for each array match, so I need to get a list of all post id's for any post tagged in both:
0 > cheap & hiphop
1 > cheap & charthits
2 > average & partybangers

But how would I retrieve an array containing the post id's?? wp_query?

Many thanks in advance.


Pat on "Custom Title on Multi-page posts"

$
0
0

Many list sites seem to have this feature where the first page of a paged post is the original title. Let's say it's "10 Reasons Why We Love Wordpress."

Then after a short intro, you hit "next page" and go onto the countdown. Page 2 of the same post will be title "10. Customization."

The post title is replaced with a unique title that describes that section better.

How can that be implemented?

grantdailey on "Help With Conditional Background Image, Based on Page/Parent"

$
0
0

Could use a little help with this functions.php hack.

I am running a Genesis theme, Agency Pro. I have the following code pasted into functions:

// Grant's Conditional BKGRND Images!
	if (is_page('53') || 53 == $post->post_parent ) :
	wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => 		get_stylesheet_directory_uri() .'/images/bkgrd-softball.jpg' ) );
	elseif (is_page(57) || '57' == $post->post_parent ) :
	wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-soccer.jpg' ) );
	elseif (is_page(59) || '59' == $post->post_parent ) :
	wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-kickball.jpg' ) );
	elseif (is_page(63) || '63' == $post->post_parent ) :
	wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-flag.jpg' ) );
	elseif (is_page(55) || '55' == $post->post_parent ) :
	wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-volleyball.jpg' ) );
	elseif (is_page(61) || '61' == $post->post_parent ) :
	wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-baketball.jpg' ) );
	else :
wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_background_image() ) );
	endif;

}

The idea is to change Agency's background image depending on what page is loaded. If none of the pages are loaded, it displays the default image. Half of my code works. It displays the appropriate image on the specified page (is_page()) but fails to do so when a sub page of the identified page is loaded. Any insight would be greatly appreciated.

Example of page that works: http://www.tennsports.com/softball/

Example of subpage that doesn't (but should!): http://www.tennsports.com/softball/sample-schedule/

Ultic on "Nextgen - Galleries and thumbnails simulatanously"

$
0
0

Hello!

I'm using Nextgen Gallery version 2.0.65.
I have my albums/galleries displayed in the sidebar with the help from a short code. When I click on a gallery, the sidebar is replaced by the corresponding thumbnails, what is standard behavior.

What I would like to accomplish, is that when I click on a gallery in the sidebar, the thumbnails are displayed in the main page(instead of in the sidebar), and that the sidebars galleries remain as galleries(doesn't turn into thumbnails).

Any help will be appreciated.

All the best, cheers!

SirCharo on "Custom WooCommerce payment gateway redirection issue"

$
0
0

Hello,
I'm developing a custom payment gateway for WooCommerce to process payments through NetCommerce (a local visa and credit card gateway).
1- Collecting customer information is Working fine
2- Sending the information to the gateway website is Working fine
3- Transactions are being made successfully on the gateway website and they successfully send us a message back with the transaction status if accepted or rejected.
The problem i'm facing is that whenever i receive the message from them i'm having errors changing the order status to "Processing" if the transaction was successful, and an error displaying the message received in the signature whenever the transaction is failing to go through.
The redirection is right i assume since I always get back to checkout whenever i'm done from the payment gateway website with a message saying "Thank you for Shopping".
I'm not sure whats wrong with the final step of the file, i checked many other gateways and i think i did the same.
Does anyone have idea about this issue?
The php file can be found here: http://goldeneagleadv.com/NetCommerce_Gateway.php (Right click + Save target as)
Thank you.

spacibo on "Properties Webportal Datafeed"

$
0
0

Hi Everyone:

Im trying to design a solution for estate agents where they can showcase their properties as they come but at the same time I was thinking how make a channel for the datafeed so that at a given time it will be automatically be populated in their accounts in different properties management portals.

I am new in this area and haven't got a vivid picture of the workflow and how to achieve this, can any give me a heads-up?

thanks

nixonnotes on "Category checklist in post admin"

$
0
0

Can anyone tell me what to change to make the checklist sub-categories not be indented so far to the right? I am using WP 3.9.1 and the Simple Taxonomies plugin.

I noticed the problem back when the big interface change came in the WP admin. I waited awhile thinking the plugin would catch up and it would get fixed. But apparently the plugin hasn't been updated in 2 years. I would like to just fix it myself (either in the plugin or in the WP admin css, but I can't find where to change it. Nothing I do seems to work.

This link is an image showing what it looks like: http://obrerofiel.com/wp-content/uploads/2014/05/categorychecklist.jpg

Any suggestions?

jahmin on "Editing Header.php in Pictorico Theme"

$
0
0

Hi,

I'm looking for some help on editing the header.php in the Pictorico Theme so as to insert an image in site-branding.div. By default the theme inserts the site name as text. The .php is below, any suggestions on what I need to do would be most welcome!!

Thanks

Laurie

<?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="content">
 *
 * @package Pictorico
 */
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">

<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div id="page" class="hfeed site">

	<header id="masthead" class="site-header" role="banner">
		<div class="site-header-inner">
			<div class="site-branding">
				<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
				<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
			</div>
			<nav id="site-navigation" class="main-navigation" role="navigation">
				<h1 class="menu-toggle"><span class="screen-reader-text"><?php _e( 'Menu', 'pictorico' ); ?></span></h1>
				<a class="skip-link screen-reader-text" href="#content"><?php _e( 'Skip to content', 'pictorico' ); ?></a>

				<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
			</nav><!-- #site-navigation -->
			<div class="header-search">
				<?php get_search_form(); ?>
			</div>
		</div>
	</header><!-- #masthead -->
	<?php if ( is_home() && pictorico_has_featured_posts( 1 ) ) : ?>
		<?php get_template_part( 'content', 'featured' ); ?>
	<?php elseif ( get_header_image() && ( is_home() || is_archive() || is_search() ) ) : ?>
		<div class="hentry has-thumbnail">
			<div class="entry-header">
				<div class="header-image" style="background-image: url(<?php header_image(); ?>)">
					<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><span class="screen-reader-text"><?php bloginfo( 'name' ); ?></span></a>
				</div>
			</div>
		</div>
	<?php endif; ?>
	<div id="content" class="site-content">

aronk on "Setting custom link image as default"

$
0
0

How can I set a specific custom link image as default, so I dont need to change every time and write the url that I want.

Thanks in advance

jacksghost on "List Child Pages of Current Page with get_posts"

$
0
0

Hi all,
I'm having some trouble displaying the Child Pages of the Current Page in our Sidebar Menu. We have a hierarchy on our site like this:

Classrooms (main menu link)
> First Grade
> Introduction
> Second Grade
> Special Activities
> Third Grade
> Introduction
> Homework

When a user clicks the 'Classrooms' link, the sidebar menu displays the Child Pages fine like this:
First Grade
Second Grade
Third Grade

However, when the user clicks the 'Third Grade' link, we want it to show its own Child Pages, but instead it shows the same list of pages: First Grade, Second Grade, Third Grade list as the 'Classrooms' link above.

When the user clicks the 'Homework' link (child of Third Grade), the sidebar menu lists the Third Grade child pages, which we like, fine like this:
Introduction
Homework

Here is the code we currently have in our sidebar:
$children_pages = get_pages( array( 'child_of' => $child_of, 'parent' => $child_of, 'sort_column' => 'ID', 'sort_order' => 'ASC' ) );

So the problem lies in the 'Third Grade' level link. We want to change this so when the user clicks the 'Third Grade' link, the sidebar menu displays the 'Third Grade' Child Pages (ie: Introduction & Homework) and not list First Grade, Second Grade, Third Grade.

I tried changing $child_of, 'parent' to $child_of, 'current page', but displays all of the child pages and their sub-pages together like this:
First Grade
Introduction
Second Grade
Special Activities
Third Grade
Introduction
Homework

Here is where you can view it: http://www.stagnesavon.org/classroom-pages/

Can anyone share how I can accomplish this?

arkdestro on "someone hacked and changed my admin details"

$
0
0

hello admins i am having a big issue, i run a development company.
one of my worker used to work in a website named vineyardindia.org
he left the company and changed the admin email and the password
i have the old ones but doesn't know how to use them to login to my WordPress admin area, is it possible if i provide the old details and credentials i can recover my admin.
since its a clients work,, asking him for the cpanel details and getting into the database is out of the question.

nnnswordfish on "Update add_image_size() function"

$
0
0

I want to dynamicaly update this function - add_image_size() when value of this variable ( $image_size ) is changed, as in example below. I can achieve that with 'Regenerate Thumbnails' plugin, but I want to do without that.

` if ( $image_size === '200x200' ) {
add_image_size( 'portfolio-isotope-200x200', 200,200,true );
} elseif ( $image_size === '700x700' ) {
add_image_size( 'portfolio-isotope-700x700', 700,700, true );
}
`

B on "Change media URLs on upload"

$
0
0

I'm looking to, programmatically on upload, change the URL of a media file to its URL on a CDN. I.e. modify site.com/wp-content/uploads/file.jpg to be cdn.site.com/wp-content/uploads/file.jpg.

Essentially what I'm asking is: which hook should I tie into? If anybody has more code help, that's great, but I think hook is the big question.

People before seem to have been wondering this, so I think it'll be helpful to resolve. Note also: I'm aware that W3 Total Cache and other plugins do this; I'd actually like it changed in the database (not just filtered on post render/output), and need to use some of my own logic, so I need to code snippet in my code.

Many thanks.

Viewing all 8245 articles
Browse latest View live




Latest Images