Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: eShop Mamma Store
- Plugin URI: http://eshopmamma.com
- Description: Totally rad shopping card system for eShopMamma
- Author: Jake Spurlock
- Version: 0.5
- Author URI: http://jakespurlock.com
- */
- /* Copyright 2010
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- $themename = "eShop Momma Store";
- $shortname = "mama";
- add_action( 'init', 'create_my_post_types' );
- function create_my_post_types() {
- register_post_type( 'the_store',
- array(
- 'label' => __( 'Products' ),
- 'singular_label' => __( 'Product' ),
- 'public' => true,
- 'show_ui' => true,
- 'publicly_queryable' => true,
- 'exclude_from_search' => false,
- 'menu_position' => 20,
- 'hierarchical' => false,
- 'query_var' => true,
- 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments' ),
- 'rewrite' => array( 'slug' => 'store', 'with_front' => false ),
- 'permalink_epmask' => EP_PERMALINK,
- )
- );
- register_taxonomy( 'Product Line', 'the_store', array( 'hierarchical' => true, 'label' => __('Product Lines') ) );
- register_taxonomy( 'Product Tags', 'the_store', array( 'hierarchical' => false, 'label' => __('Product Tags'), 'query_var' => 'prod_tags', 'rewrite' => array('slug' => 'product-tags' ) ) );
- }
- add_filter( 'pre_get_posts', 'my_get_posts' );
- function my_get_posts( $query ) {
- if ( is_home() )
- $query->set( 'post_type', array( 'post', 'product', 'the_store', 'attachment' ) );
- return $query;
- }
- //Here is an action to create a custom theme page for displaying content from the store. This will be useful to theme developers.
- // Template selection
- add_action("template_redirect", 'my_template_redirect');
- function my_template_redirect()
- {
- global $wp;
- global $wp_query;
- if ($wp->query_vars["post_type"] == "the_store")
- {
- // Let's look for the property.php template file in the current theme
- if (have_posts())
- {
- include(TEMPLATEPATH . '/store.php');
- die();
- }
- else
- {
- $wp_query->is_404 = true;
- }
- }
- }
- /*Options Page*/
- add_action('admin_menu', 'my_plugin_menu');
- function my_plugin_menu() {
- add_submenu_page('edit.php?post_type=the_store', 'eShop Momma Options', 'Store Options', 'manage_options', 'js_store_options', 'my_plugin_options');
- }
- function my_plugin_options() {
- if (!current_user_can('manage_options')) {
- wp_die( __('You do not have sufficient permissions to access this page.') );
- }
- global $themename, $shortname;
- $options = array (
- array( "name" => "$themename",
- "type" => "title"),
- array( "type" => "open"),
- array( "name" => "PayPal Email",
- "desc" => "Enter your PayPal email here.",
- "id" => $shortname."_paypal",
- "type" => "text",
- "std" => ""),
- array( "name" => "Default Handling",
- "desc" => "Any fee that you want automatically added to every purchase.",
- "id" => $shortname."_handling",
- "type" => "text",
- "std" => "0.00"),
- /*array( "name" => "Footer Stuff",
- "desc" => "Here is where you add stuff to the end of the body tag.",
- "id" => $shortname."_footer_stuff",
- "type" => "radio",
- "std" => ""), */
- array( "type" => "close")
- );
- echo '<div class="wrap">';
- echo '<h2>'; echo $themename; echo ' Settings</h2>'; ?>
- <form method="post">
- <?php foreach ($options as $value) {
- switch ( $value['type'] ) {
- case "open":
- ?>
- <table width="100%" border="0" style="background-color:#eef5fb; padding:10px;">
- <?php break;
- case "close":
- ?>
- </table><br />
- <?php break;
- case "title":
- ?>
- <table width="100%" border="0" style="background-color:#dceefc; padding:5px 10px;"><tr>
- <td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
- </tr>
- <?php break;
- case 'text':
- ?>
- <tr>
- <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
- <td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></td>
- </tr>
- <tr>
- <td><small><?php echo $value['desc']; ?></small></td>
- </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
- <?php
- break;
- case 'textarea':
- ?>
- <tr>
- <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
- <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></td>
- </tr>
- <tr>
- <td><small><?php echo $value['desc']; ?></small></td>
- </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
- <?php
- break;
- case 'select':
- ?>
- <tr>
- <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
- <td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
- </tr>
- <tr>
- <td><small><?php echo $value['desc']; ?></small></td>
- </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
- <?php
- break;
- case "checkbox":
- ?>
- <tr>
- <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
- <td width="80%"><?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
- <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
- </td>
- </tr>
- <tr>
- <td><small><?php echo $value['desc']; ?></small></td>
- </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;"> </td></tr><tr><td colspan="2"> </td></tr>
- <?php break;
- }
- }
- ?>
- <p class="submit">
- <input name="save" type="submit" value="Save changes" />
- <input type="hidden" name="action" value="save" />
- </p>
- </form>
- <form method="post">
- <p class="submit">
- <input name="reset" type="submit" value="Reset" />
- <input type="hidden" name="action" value="reset" />
- </p>
- </form>
- <?php echo '</div>'; ?>
- <?php }
- ?>
- <?php
- $prefix = 'thestore_';
- $meta_box = array(
- 'id' => 'my-meta-box',
- 'title' => 'Store Item Details',
- 'page' => 'the_store',
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'name' => 'Price',
- 'desc' => 'Enter product price here.',
- 'id' => $prefix . 'price',
- 'type' => 'text',
- 'std' => '10.00'
- ),
- array(
- 'name' => 'Shipping',
- 'desc' => 'Enter product shipping here.',
- 'id' => $prefix . 'shipping',
- 'type' => 'text',
- 'std' => '1.00'
- ),
- array(
- 'name' => 'Secondary Shipping',
- 'desc' => 'Enter price to ship a second item. This will be added to every item as the quantity increases',
- 'id' => $prefix . 'shipping2',
- 'type' => 'text',
- 'std' => '0.00'
- ),
- /*array(
- 'name' => 'Display Purchase Link?',
- 'id' => $prefix . 'radio',
- 'type' => 'radio',
- 'options' => array(
- array('name' => 'Yes', 'value' => 'Yes'),
- array('name' => 'No', 'value' => 'No'),
- )
- ),*/
- array(
- 'name' => 'Display PayPal link?',
- 'id' => $prefix . 'display',
- 'type' => 'checkbox'
- )
- )
- );
- add_action('admin_menu', 'mytheme_add_box');
- // Add meta box
- function mytheme_add_box() {
- global $meta_box;
- add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']);
- }
- // Callback function to show fields in meta box
- function mytheme_show_box() {
- global $meta_box, $post;
- // Use nonce for verification
- echo '<input type="hidden" name="mytheme_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
- echo '<table class="form-table">';
- foreach ($meta_box['fields'] as $field) {
- // get current post meta data
- $meta = get_post_meta($post->ID, $field['id'], true);
- echo '<tr>',
- '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
- '<td>';
- switch ($field['type']) {
- case 'text':
- echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',
- '<br />', $field['desc'];
- break;
- case 'textarea':
- echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',
- '<br />', $field['desc'];
- break;
- case 'select':
- echo '<select name="', $field['id'], '" id="', $field['id'], '">';
- foreach ($field['options'] as $option) {
- echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';
- }
- echo '</select>';
- break;
- case 'radio':
- foreach ($field['options'] as $option) {
- echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' />', $option['name'];
- }
- break;
- case 'checkbox':
- echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
- break;
- }
- echo '<td>',
- '</tr>';
- }
- echo '</table>';
- }
- add_action('save_post', 'mytheme_save_data');
- // Save data from meta box
- function mytheme_save_data($post_id) {
- global $meta_box;
- // verify nonce
- if (!wp_verify_nonce($_POST['mytheme_meta_box_nonce'], basename(__FILE__))) {
- return $post_id;
- }
- // check autosave
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $post_id;
- }
- // check permissions
- if ('page' == $_POST['post_type']) {
- if (!current_user_can('edit_page', $post_id)) {
- return $post_id;
- }
- } elseif (!current_user_can('edit_post', $post_id)) {
- return $post_id;
- }
- foreach ($meta_box['fields'] as $field) {
- $old = get_post_meta($post_id, $field['id'], true);
- $new = $_POST[$field['id']];
- if ($new && $new != $old) {
- update_post_meta($post_id, $field['id'], $new);
- } elseif ('' == $new && $old) {
- delete_post_meta($post_id, $field['id'], $old);
- }
- }
- }
- function add_some_stuff($content) {
- global $shortname;
- if (is_post_type('the_store')) {
- $display = get_post_custom_values('thestore_display');
- if($display[0]){
- $item_name = the_title('', '', false);
- $shopping_url = get_permalink();
- $item_number = get_the_ID();
- $amount = get_post_custom_values('thestore_price');
- $amount = $amount[0];
- $shipping = get_post_custom_values('thestore_shipping');
- $shipping = $shipping[0];
- $shipping2 = get_post_custom_values('thestore_shipping2');
- $shipping2 = $shipping2[0];
- $business = get_option($shortname.'_paypal');
- $business = $business[0];
- $handling = get_post_custom_values($shortname.'_handling');
- $handling = $handling[0];
- $paypal = <<<PAYPAL
- <form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="paypal">
- <input type="hidden" name="cmd" value="_cart">
- <input type="hidden" name="business" value="$business">
- <input type="hidden" name="item_name" value="$item_name">
- <input type="hidden" name="shopping_url" value="$shopping_url">
- <input type="hidden" name="item_number" value="$item_number">
- <input type="hidden" name="amount" value="$amount">
- <input type="hidden" name="currency_code" value="USD">
- <input type="hidden" name="shipping" value="$shipping">
- <input type="hidden" name="shipping2" value="$shipping2">
- <input type="hidden" name="handling_cart" value="$handling">
- <input type="hidden" name="bn" value="ButtonFactory.PayPal.001">
- <input type="image" name="add" src="http://www.powersellersunite.com/buttonfactory/sc-but-01.gif">
- </form>
- PAYPAL;
- return $content.$paypal;
- }
- }
- }
- add_action('the_content', 'add_some_stuff');
- ?>
Add Comment
Please, Sign In to add comment