editing wordpress custom header php file - php

I am using an open source theme for a wordpress website. While most of the site is done, I am having trouble adding a second slogan area to our site.
Additionally, I am attempting to modify customer_header.php to make the front page showcase appear on all pages as well.
Currently the home page is the only page displaying the header showcase and only has two lines of text. The following is the php:
<?php
/**
* Sample implementation of the Custom Header feature.
*
* #link http://codex.wordpress.org/Custom_Headers
*
* #package refur
*/
class refur_custom_header {
/**
* A reference to an instance of this class.
*
* #var object
*/
private static $instance = null;
/**
* Default header settings array
*
* #var array
*/
public $default_settings = array();
/**
* Holder for active showcase trigger
*
* #var bool
*/
public $is_showcase = null;
function __construct() {
add_filter( 'body_class', array( $this, 'add_body_classes' ) );
add_action( 'after_setup_theme', array( $this, 'custom_header_setup' ) );
add_action( 'refur_header_showcase', array( $this, 'public_callback' ) );
add_action( 'customize_register', array( $this, 'header_settings' ) );
$this->default_settings = array(
'header_mask_color' => '#000000',
'header_mask_fill' => 50,
'header_slogan_title' => __( 'Your Awesome Blog', 'refur' ),
'header_slogan_text' => __( 'Just a few words why you blog is so awesome', 'refur' ),
'header_button_text' => __( 'Call to action', 'refur' ),
'header_button_url' => '#'
);
}
/**
* Set up the WordPress core custom header feature.
*
* #uses refur_header_style()
* #uses refur_admin_header_style()
* #uses refur_admin_header_image()
*/
function custom_header_setup() {
add_theme_support( 'custom-header', apply_filters( 'refur_custom_header_args', array(
'default-image' => get_template_directory_uri() . '/images/header-image.png',
'default-text-color' => 'ffffff',
'width' => 2000,
'height' => 765,
'flex-height' => true,
'wp-head-callback' => array( $this, 'header_style' ),
'admin-head-callback' => array( $this, 'admin_header_style' ),
'admin-preview-callback' => array( $this, 'admin_header_image' ),
) ) );
}
/**
* Register additional setting for header section
*
* #param object $wp_customize customizer object
* #return void
*/
function header_settings( $wp_customize ) {
$wp_customize->add_setting('refur[header_mask_color]', array(
'default' => $this->default_settings['header_mask_color'],
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_hex_color',
));
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'refur_header_mask_color', array(
'label' => __( 'Image Mask Color', 'refur' ),
'section' => 'header_image',
'settings' => 'refur[header_mask_color]',
)));
$wp_customize->add_setting( 'refur[header_mask_fill]', array(
'default' => $this->default_settings['header_mask_fill'],
'type' => 'theme_mod',
'sanitize_callback' => 'refur_sanitize_num',
) );
$wp_customize->add_control( 'refur_header_mask_fill', array(
'label' => __( 'Image mask fill level', 'refur' ),
'section' => 'header_image',
'settings' => 'refur[header_mask_fill]',
'type' => 'number',
'input_attrs' => array(
'min' => 0,
'max' => 100,
'step' => 1,
),
) );
$wp_customize->add_setting( 'refur[header_slogan_title]', array(
'default' => $this->default_settings['header_slogan_title'],
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'refur_header_slogan_title', array(
'label' => __( 'Header slogan title', 'refur' ),
'section' => 'header_image',
'settings' => 'refur[header_slogan_title]',
'type' => 'text',
) );
$wp_customize->add_setting( 'refur[header_slogan_text]', array(
'default' => $this->default_settings['header_slogan_text'],
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'refur_header_slogan_text', array(
'label' => __( 'Header slogan description', 'refur' ),
'section' => 'header_image',
'settings' => 'refur[header_slogan_text]',
'type' => 'text',
) );
$wp_customize->add_setting( 'refur[header_button_text]', array(
'default' => $this->default_settings['header_button_text'],
'type' => 'theme_mod',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'refur_header_button_text', array(
'label' => __( 'Header button text (leave empty to remove button)', 'refur' ),
'section' => 'header_image',
'settings' => 'refur[header_button_text]',
'type' => 'text',
) );
$wp_customize->add_setting( 'refur[header_button_url]', array(
'default' => $this->default_settings['header_button_url'],
'type' => 'theme_mod',
'sanitize_callback' => 'refur_sanitize_url',
) );
$wp_customize->add_control( 'refur_header_button_url', array(
'label' => __( 'Header button URL', 'refur' ),
'section' => 'header_image',
'settings' => 'refur[header_button_url]',
'type' => 'text',
) );
}
/**
* Custom header image markup displayed on the Appearance > Header admin panel.
*
* #see custom_header_setup().
*/
function admin_header_image() {
?>
<div id="headimg">
<h1 class="displaying-header-text">
<a id="name" style="<?php echo esc_attr( 'color: #' . get_header_textcolor() ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a>
</h1>
<div class="displaying-header-text" id="desc" style="<?php echo esc_attr( 'color: #' . get_header_textcolor() ); ?>"><?php bloginfo( 'description' ); ?></div>
<?php if ( get_header_image() ) : ?>
<img src="<?php header_image(); ?>" alt="">
<?php endif; ?>
</div>
<?php
}
/**
* Public output for header image
*
* #return void
*/
public function public_callback() {
$custom_callback = apply_filters( 'refur_custom_header_showcase_callback', false );
if ( false !== $custom_callback ) {
echo $custom_callback;
return true;
}
$this->open_image_wrap();
$this->show_image();
$this->show_slogan();
$this->close_image_wrap();
}
/**
* Open HTML wrapper for header image block
*
* #return void
*/
public function open_image_wrap() {
$subpage = '';
if ( ! $this->is_showcase() ) {
$subpage = ' is-subpage';
}
echo '<div class="header-showcase' . $subpage . '">';
}
public function show_image() {
$image = get_header_image();
$data = get_custom_header();
$alt = get_bloginfo( 'name' );
if ( ! $image ) {
return;
}
printf(
'<img src="%s" class="header-showcase_img" alt="%s" width="%s" height="%s">',
$image, $alt, $data->width, $data->height
);
}
/**
* Show header showcase content
*
* #return void
*/
public function show_slogan() {
if ( ! $this->is_showcase() ) {
return;
}
$title = refur_get_option( 'header_slogan_title', $this->default_settings['header_slogan_title'] );
$text = refur_get_option( 'header_slogan_text', $this->default_settings['header_slogan_text'] );
?>
<div class="header-showcase_content">
<div class="container">
<?php if ( $title || $text ) : ?>
<div class="header-showcase_slogan">
<?php if ( $title ) : ?>
<div class="header-showcase_title"><?php
echo wp_kses( $title, wp_kses_allowed_html( 'post' ) );
?></div>
<?php endif; ?>
<?php if ( $text ) : ?>
<div class="header-showcase_text"><?php
echo wp_kses( $text, wp_kses_allowed_html( 'post' ) );
?></div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php $this->show_button(); ?>
</div>
</div>
<?php
}
/**
* Show header showcase call to action button
*
* #return void
*/
public function show_button() {
$text = refur_get_option( 'header_button_text', $this->default_settings['header_button_text'] );
$url = refur_get_option( 'header_button_url', $this->default_settings['header_button_url'] );
if ( ! $text ) {
return;
}
printf( '%1$s', esc_textarea( $text ), esc_url( $url ) );
}
/**
* Close HTML wrapper for header image block
*
* #return void
*/
public function close_image_wrap() {
echo '</div>';
}
/**
* Is showcase area visible on current page
*
* #return boolean
*/
public function is_showcase() {
if ( null !== $this->is_showcase ) {
return $this->is_showcase;
}
$this->is_showcase = ( is_front_page() && ! is_paged() ) ? true : false;
return $this->is_showcase;
}
/**
* Styles the header image and text displayed on the blog
*
* #see custom_header_setup().
*/
function header_style() {
// If we get this far, we have custom styles. Let's do this.
?>
<style type="text/css">
<?php
$mask_bg = refur_get_option( 'header_mask_color', $this->default_settings['header_mask_color'] );
$mask_opacity = refur_get_option( 'header_mask_fill', $this->default_settings['header_mask_fill'] );
$mask_opacity = absint( esc_attr( $mask_opacity ) ) / 100;
?>
.header-showcase:after {
background: <?php echo esc_attr( $mask_bg ); ?>;
opacity: <?php echo $mask_opacity; ?>;
}
</style>
<?php
}
/**
* Styles the header image displayed on the Appearance > Header admin panel.
*
* #see custom_header_setup().
*/
function admin_header_style() {
?>
<style type="text/css">
.appearance_page_custom-header #headimg {
border: none;
}
#headimg h1,
#desc {
}
#headimg h1 {
}
#headimg h1 a {
}
#desc {
}
#headimg img {
}
</style>
<?php
}
/**
* Header-related body classes
*
* #param array $classes
*/
public function add_body_classes( $classes ) {
if ( ! get_header_image() ) {
$classes[] = 'static-header';
}
if ( $this->is_showcase() ) {
$classes[] = 'showcase-active';
}
return $classes;
}
/**
* Returns the instance.
*
* #return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance )
self::$instance = new self;
return self::$instance;
}
}
refur_custom_header::get_instance();

For part one: I'm not going to write all the code for you, but you can basically just find all the places in that file where you find header_slogan_title, header_slogan_text, and header_button_text and duplicate them judiciously.
For part two: you're going to want to hack this code in the file you linked to in your question:
/**
* Is showcase area visible on current page
*
* #return boolean
*/
public function is_showcase() {
if ( null !== $this->is_showcase ) {
return $this->is_showcase;
}
$this->is_showcase = ( is_front_page() && ! is_paged() ) ? true : false;
return $this->is_showcase;
}
Most likely you will want to change
$this->is_showcase = ( is_front_page() && ! is_paged() ) ? true : false;
to
$this->is_showcase = is_page();
or some other combination of template tags that produces true for the pages you want it to show for and false for the others.

Related

Woocommerce custom payment gateway redirect back to woocommerce

I have a custom gateway, I am new to the custom plugins for woocommerce, now my problem I have is that I am able to redirect to my payment gateway but in my payment gateway (HTML) how do I redirect back after payment was made? I don't understand the whole process as yet, I know once payment is selected then I can redirect to my custom payment gateway but the confusing part is returning from payment gateway to woocommerce to say it was a success or not
<?php
/**
* Plugin Name: Woocommerce CloudCart Payment Gateway
* Plugin URI: http://cloudcart.online
* Description: Payment Gateway to use CloudCart points.
* Author: Cornelis Kuijpers
* Author URI: http://kuijpersconsulting.co.za
* Version: 1.0.1
*
*/
add_action('plugins_loaded', 'init_Cloudcart', 0);
function init_Cloudcart() {
if ( ! class_exists( 'WC_Payment_Gateway' ) ) return;
class woocommerce_Cloudcart extends WC_Payment_Gateway {
public function __construct() {
global $woocommerce;
$this->id = 'Cloudcart';
$this->method_title = __('Cloudcart', 'Cloudcart-chearaan-woo');
$this->icon = plugins_url( 'Cloudcart.png', __FILE__ );
$this->has_fields = false;
$this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'woocommerce_Cloudcart', home_url( '/' ) ) );
// Load the form fields.
$this->init_form_fields();
// Load the settings.
$this->init_settings();
// Define user set variables
$this->Cloudcarturl = $this->settings['Cloudcarturl'];
$this->title = $this->settings['title'];
$this->description = $this->settings['description'];
$this->merchantid = $this->settings['merchantid'];
$this->hashKey = $this->settings['hashKey'];
$this->transactionDate = date('Y-m-d H:i:s O');
$this->woo_version = $this->get_woo_version();
// Actions
add_action('init', array(&$this, 'successful_request'));
add_action('woocommerce_api_woocommerce_Cloudcart', array( &$this, 'successful_request' ));
add_action('woocommerce_receipt_Cloudcart', array(&$this, 'receipt_page'));
if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) {
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ));
} else {
add_action('woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ));
}
}
/**
* Initialise Gateway Settings Form Fields
*/
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable:', 'Cloudcart-chearaan-woo' ),
'type' => 'checkbox',
'label' => __( 'Enable Cloudcart', 'Cloudcart-chearaan-woo' ),
'default' => 'yes'
),
'Cloudcarturl' => array(
'title' => __( 'Test/Production:', 'Cloudcart-chearaan-woo' ),
'type' => 'checkbox',
'label' => __( 'Test', 'Cloudcart-chearaan-woo' ),
'default' => 'yes'
),
'title' => array(
'title' => __( 'Title:', 'Cloudcart-chearaan-woo' ),
'type' => 'text',
'description' => __( 'The title which the user sees during checkout.', 'Cloudcart-chearaan-woo' ),
'default' => __( 'Cloudcart Online Payment Gateway', 'Cloudcart-chearaan-woo' )
),
'description' => array(
'title' => __( 'Description:', 'Cloudcart-chearaan-woo' ),
'type' => 'textarea',
'description' => __( 'Description which the user sees during checkout.', 'Cloudcart-chearaan-woo' ),
'default' => __('Pay securely through Cloudcart\'s Secure Servers.', 'Cloudcart-chearaan-woo')
),
'merchantid' => array(
'title' => __( 'Merchant ID:', 'Cloudcart-chearaan-woo' ),
'type' => 'text',
'description' => __( 'Please enter your Merchant ID as provided by Cloudcart.', 'Cloudcart-chearaan-woo' ),
'default' => ''
),
'hashKey' => array(
'title' => __( 'Merchant hashKey:', 'Cloudcart-chearaan-woo' ),
'type' => 'text',
'description' => __( 'Please enter your Merchant hashKey as provided by Cloudcart.', 'Cloudcart-chearaan-woo' ),
'default' => ''
)
);
}
public function admin_options() {
?>
<h3>Cloudcart</h3>
<p><?php _e('Cloudcart works by sending the user to Cloudcart to enter their payment information.', 'Cloudcart-chearaan-woo'); ?></p>
<table class="form-table">
<?php
// Generate the HTML For the settings form.
$this->generate_settings_html();
?>
</table><!--/.form-table-->
<?php
} // End admin_options()
/**
* There are no payment fields, but we want to show the description if set.
**/
function payment_fields() {
if ($this->description) echo wpautop(wptexturize($this->description));
}
/**
* Generate the button link
**/
public function generate_Cloudcart_form( $order_id ) {
global $woocommerce;
$order = new WC_Order( $order_id );
if ($this->Cloudcarturl == "yes"){
$Cloudcart_adr = "https://ckconsulting.ddns.net/API/CloudCart/";
}else{
$Cloudcart_adr = "https://ckconsulting.ddns.net/API/CloudCart/";
}
$sHash = strtoupper(hash('sha256', $this->hashKey."Continue".str_pad($this->merchantid, 10, '0', STR_PAD_LEFT).str_pad($order->id, 20, '0', STR_PAD_LEFT).str_pad(($order->order_total*100), 12, '0', STR_PAD_LEFT)));
$Cloudcart_args = array(
'secureHash' => $sHash,
'mid' => str_pad($this->merchantid, 10, '0', STR_PAD_LEFT),
'invno' => str_pad($order->id, 20, '0', STR_PAD_LEFT),
'amt' => str_pad(($order->order_total*100), 12, '0', STR_PAD_LEFT),
'desc' => str_pad("Order No ".$order_id, 255, ' ', STR_PAD_RIGHT),
'postURL' => $this->notify_url,
'phone' => $order->billing_phone,
'email' => $order->billing_email,
'param' => 'WC|V1'
);
$Cloudcart_args_array = array();
foreach ($Cloudcart_args as $key => $value) {
$Cloudcart_args_array[] = '<input type="hidden" name="'.$key.'" value="'. $value .'" /><br>';
}
wc_enqueue_js('
jQuery(function(){
jQuery("body").block(
{
message: "<img src=\"'.$woocommerce->plugin_url().'/images/uploading.gif\" alt=\"Redirecting…\" style=\"float:left; margin-right: 10px;\" />'.__('Thank you for your order. We are now redirecting you to Cloudcart to make payment.', 'Cloudcart-chearaan-woo').'",
overlayCSS:
{
background: "#fff",
opacity: 0.5
},
css: {
padding: 18,
textAlign: "center",
color: "#555",
border: "2px solid #aaa",
backgroundColor:"#fff",
cursor: "wait",
lineHeight: "30px"
}
});
jQuery("#submit_Cloudcart_payment_form").click();
});
');
return '<form action="'.$Cloudcart_adr.'" method="post">
' . implode('', $Cloudcart_args_array) . '
<input type="submit" class="button-alt" id="submit_Cloudcart_payment_form" value="'.__('Pay via Cloudcart', 'Cloudcart-chearaan-woo').'" /> <a class="button cancel" href="'.$order->get_cancel_order_url().'">'.__('Cancel order & restore cart', 'Cloudcart-chearaan-woo').'</a>
</form>';
}
/**
* Process the payment and return the result
**/
function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
echo get_permalink(get_option('woocommerce_pay_page_id'));
if($this->woo_version >= 2.1){
$redirect = $order->get_checkout_payment_url( true );
}else if( $this->woo_version < 2.1 ){
$redirect = add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id'))));
}else{
$redirect = add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id'))));
}
return array(
'result' => 'success',
'redirect' => $redirect
);
}
/**
* receipt_page
**/
function receipt_page( $order ) {
echo '<p>'.__('Please click the button below to pay with Cloudcart.', 'Cloudcart-chearaan-woo').'</p>';
echo $this->generate_Cloudcart_form( $order );
}
/**
* Server callback was valid, process callback (update order as passed/failed etc).
**/
function successful_request($Cloudcart_response) {
global $woocommerce;
echo 'Hello from the other side';
if (isset($_GET['wc-api']) && $_GET['wc-api'] == 'woocommerce_Cloudcart') {
/** need to trim from result **/
$Url_result = $_GET['result'];
$order = new WC_Order( (int) substr($Url_result,7,20) );
$tranID = (int)substr($Url_result,1,6);
if (substr($Url_result,0,1) == '0'){
$r_status = 0;
}else{
$r_status = 33;
}
/*
$order = new WC_Order( (int) $_POST['invno'] );
$r_status = (int) $_POST['result'];
*/
if ($r_status == '0' ){
$order->payment_complete();
$order->add_order_note('Cloudcart Payment was SUCCESSFUL '.'<br>AuthCode is ' . $tranID);
wp_redirect( $this->get_return_url($order) ); exit;
//wp_redirect( $this->order->get_checkout_order_received_url() ); exit;
}else{
$order->update_status('failed', sprintf(__('Cloudcart Payment Failed. Error Communicating with Bank.', 'Cloudcart-chearaan-woo') ) );
wp_redirect($order->get_cancel_order_url()); exit;
}
}
}
function get_woo_version() {
// If get_plugins() isn't available, require it
if ( ! function_exists( 'get_plugins' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Create the plugins folder and file variables
$plugin_folder = get_plugins( '/woocommerce' );
$plugin_file = 'woocommerce.php';
// If the plugin version number is set, return it
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
return $plugin_folder[$plugin_file]['Version'];
} else {
// Otherwise return null
return NULL;
}
}
}
}
/**
* Add the gateway to WooCommerce
**/
function add_Cloudcart( $methods ) {
$methods[] = 'woocommerce_Cloudcart'; return $methods;
}
add_filter('woocommerce_payment_gateways', 'add_Cloudcart' );

Fatal error: Class 'wp_bootstrap_navwalker' not found in

I was working on a website and somehow broke it. I did not create this website but was working to update the SEO and a few minor items. This is a bit out of my depth to be honest.
I'm not sure what I did but now I'm getting:
Fatal error: Class 'wp_bootstrap_navwalker' not found in /home/content/92/11969592/html/wp-content/themes/kim/header.php on line 82
I've searched everything I can find on here and on every website I can find, but I can't seem to fix it. This is the code after trying to make changes according to this topic https://stackoverflow.com/questions/45445283/fatal-error-class-wp-bootstrap-navwalker-not-found-in
Can anyone help me?
Thank you for any help you can provide!
functions.php
<?php
/**
* For more information on hooks, actions, and filters,
* {#link https://developer.wordpress.org/plugins/}
*
* #package WordPress
* #subpackage Twenty_Sixteen
* #since Twenty Sixteen 1.0
*/
/**
* Twenty Sixteen only works in WordPress 4.4 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
}
if ( ! function_exists( 'twentysixteen_setup' ) ) :
*
* #since Twenty Sixteen 1.0
*/
function twentysixteen_setup() {
load_theme_textdomain( 'twentysixteen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'title-tag' );
add_theme_support(
'custom-logo',
array(
'height' => 240,
'width' => 240,
'flex-height' => true,
)
);
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1200, 9999 );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'twentysixteen' ),
'social' => __( 'Social Links Menu', 'twentysixteen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'script',
'style',
)
);
/*
* Enable support for Post Formats.
*
* See: https://wordpress.org/support/article/post-formats/
*/
add_theme_support(
'post-formats',
array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'status',
'audio',
'chat',
)
);
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', twentysixteen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Add support for custom color scheme.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Dark Gray', 'twentysixteen' ),
'slug' => 'dark-gray',
'color' => '#1a1a1a',
),
array(
'name' => __( 'Medium Gray', 'twentysixteen' ),
'slug' => 'medium-gray',
'color' => '#686868',
),
array(
'name' => __( 'Light Gray', 'twentysixteen' ),
'slug' => 'light-gray',
'color' => '#e5e5e5',
),
array(
'name' => __( 'White', 'twentysixteen' ),
'slug' => 'white',
'color' => '#fff',
),
array(
'name' => __( 'Blue Gray', 'twentysixteen' ),
'slug' => 'blue-gray',
'color' => '#4d545c',
),
array(
'name' => __( 'Bright Blue', 'twentysixteen' ),
'slug' => 'bright-blue',
'color' => '#007acc',
),
array(
'name' => __( 'Light Blue', 'twentysixteen' ),
'slug' => 'light-blue',
'color' => '#9adffd',
),
array(
'name' => __( 'Dark Brown', 'twentysixteen' ),
'slug' => 'dark-brown',
'color' => '#402b30',
),
array(
'name' => __( 'Medium Brown', 'twentysixteen' ),
'slug' => 'medium-brown',
'color' => '#774e24',
),
array(
'name' => __( 'Dark Red', 'twentysixteen' ),
'slug' => 'dark-red',
'color' => '#640c1f',
),
array(
'name' => __( 'Bright Red', 'twentysixteen' ),
'slug' => 'bright-red',
'color' => '#ff675f',
),
array(
'name' => __( 'Yellow', 'twentysixteen' ),
'slug' => 'yellow',
'color' => '#ffef8e',
),
)
);
add_action('after_setup_theme','wpb_theme_setup');
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif; // twentysixteen_setup()
add_action( 'after_setup_theme', 'twentysixteen_setup' );
/**
* Sets the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* #global int $content_width
*
* #since Twenty Sixteen 1.0
*/
function twentysixteen_content_width() {
$GLOBALS['content_width'] = apply_filters( 'twentysixteen_content_width', 840 );
}
add_action( 'after_setup_theme', 'twentysixteen_content_width', 0 );
/**
* Add preconnect for Google Fonts.
*
* #since Twenty Sixteen 1.6
*
* #param array $urls URLs to print for resource hints.
* #param string $relation_type The relation type the URLs are printed.
* #return array $urls URLs to print for resource hints.
*/
function twentysixteen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentysixteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentysixteen_resource_hints', 10, 2 );
/**
* Registers a widget area.
*
* #link https://developer.wordpress.org/reference/functions/register_sidebar/
*
* #since Twenty Sixteen 1.0
*/
function twentysixteen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'twentysixteen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Content Bottom 1', 'twentysixteen' ),
'id' => 'sidebar-2',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Content Bottom 2', 'twentysixteen' ),
'id' => 'sidebar-3',
'description' => __( 'Appears at the bottom of the content on posts and pages.', 'twentysixteen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentysixteen_widgets_init' );
if ( ! function_exists( 'twentysixteen_fonts_url' ) ) :
/**
* Register Google fonts for Twenty Sixteen.
*
* Create your own twentysixteen_fonts_url() function to override in a child theme.
*
* #since Twenty Sixteen 1.0
*
* #return string Google fonts URL for the theme.
*/
function twentysixteen_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/*
* translators: If there are characters in your language that are not supported
* by Merriweather, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
}
/*
* translators: If there are characters in your language that are not supported
* by Montserrat, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Montserrat:400,700';
}
/*
* translators: If there are characters in your language that are not supported
* by Inconsolata, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'twentysixteen' ) ) {
$fonts[] = 'Inconsolata:400';
}
if ( $fonts ) {
$fonts_url = add_query_arg(
array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
'display' => urlencode( 'fallback' ),
),
'https://fonts.googleapis.com/css'
);
}
return $fonts_url;
}
endif;
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* #since Twenty Sixteen 1.0
*/
function twentysixteen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );
/**
* Enqueues scripts and styles.
*
* #since Twenty Sixteen 1.0
*/
function twentysixteen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );
// Theme stylesheet.
wp_enqueue_style( 'twentysixteen-style', get_stylesheet_uri(), array(), '20190507' );
// Theme block stylesheet.
wp_enqueue_style( 'twentysixteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentysixteen-style' ), '20190102' );
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentysixteen-style' ), '20170530' );
wp_style_add_data( 'twentysixteen-ie', 'conditional', 'lt IE 10' );
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie8', get_template_directory_uri() . '/css/ie8.css', array( 'twentysixteen-style' ), '20170530' );
wp_style_add_data( 'twentysixteen-ie8', 'conditional', 'lt IE 9' );
// Load the Internet Explorer 7 specific stylesheet.
wp_enqueue_style( 'twentysixteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentysixteen-style' ), '20170530' );
wp_style_add_data( 'twentysixteen-ie7', 'conditional', 'lt IE 8' );
// Load the html5 shiv.
wp_enqueue_script( 'twentysixteen-html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3' );
wp_script_add_data( 'twentysixteen-html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentysixteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20170530', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'twentysixteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20170530' );
}
wp_enqueue_script( 'twentysixteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20181217', true );
wp_localize_script(
'twentysixteen-script',
'screenReaderText',
array(
'expand' => __( 'expand child menu', 'twentysixteen' ),
'collapse' => __( 'collapse child menu', 'twentysixteen' ),
)
);
}
add_action( 'wp_enqueue_scripts', 'twentysixteen_scripts' );
/**
* Enqueue styles for the block-based editor.
*
* #since Twenty Sixteen 1.6
*/
function twentysixteen_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'twentysixteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20190102' );
// Add custom fonts.
wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );
}
add_action( 'enqueue_block_editor_assets', 'twentysixteen_block_editor_styles' );
/**
* Adds custom classes to the array of body classes.
*
* #since Twenty Sixteen 1.0
*
* #param array $classes Classes for the body element.
* #return array (Maybe) filtered body classes.
*/
function twentysixteen_body_classes( $classes ) {
// Adds a class of custom-background-image to sites with a custom background image.
if ( get_background_image() ) {
$classes[] = 'custom-background-image';
}
// Adds a class of group-blog to sites with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Adds a class of no-sidebar to sites without active sidebar.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
return $classes;
}
add_filter( 'body_class', 'twentysixteen_body_classes' );
/**
* Converts a HEX value to RGB.
*
* #since Twenty Sixteen 1.0
*
* #param string $color The original color, in 3- or 6-digit hexadecimal form.
* #return array Array containing RGB (red, green, and blue) values for the given
* HEX code, empty array otherwise.
*/
function twentysixteen_hex2rgb( $color ) {
$color = trim( $color, '#' );
if ( strlen( $color ) === 3 ) {
$r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) );
$g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) );
$b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) );
} elseif ( strlen( $color ) === 6 ) {
$r = hexdec( substr( $color, 0, 2 ) );
$g = hexdec( substr( $color, 2, 2 ) );
$b = hexdec( substr( $color, 4, 2 ) );
} else {
return array();
}
return array(
'red' => $r,
'green' => $g,
'blue' => $b,
);
}
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images
*
* #since Twenty Sixteen 1.0
*
* #param string $sizes A source size value for use in a 'sizes' attribute.
* #param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* #return string A source size value for use in a content image 'sizes' attribute.
*/
function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 840 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
}
if ( 'page' === get_post_type() ) {
if ( 840 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
} else {
if ( 840 > $width && 600 <= $width ) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
} elseif ( 600 > $width ) {
$sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentysixteen_content_image_sizes_attr', 10, 2 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails
*
* #since Twenty Sixteen 1.0
*
* #param array $attr Attributes for the image markup.
* #param int $attachment Image attachment ID.
* #param array $size Registered image size or flat array of height and width dimensions.
* #return array The filtered attributes for the image markup.
*/
function twentysixteen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( 'post-thumbnail' === $size ) {
if ( is_active_sidebar( 'sidebar-1' ) ) {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px';
} else {
$attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 88vw, 1200px';
}
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentysixteen_post_thumbnail_sizes_attr', 10, 3 );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* #since Twenty Sixteen 1.1
*
* #param array $args Arguments for tag cloud widget.
* #return array The filtered arguments for tag cloud widget.
*/
function twentysixteen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentysixteen_widget_tag_cloud_args' );
header.php
<?php
/**
* The template for displaying the header
*
* Displays all of the head element and everything up until the "site-content" div.
*
* #package WordPress
* #subpackage Twenty_Sixteen
* #since Twenty Sixteen 1.0
*/
?><!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js" style="margin-top: 0px !important;">
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php if(is_home()) { echo bloginfo("name"); echo " | "; echo bloginfo("description"); } else { echo wp_title(" | ", false, right); echo bloginfo("name"); } ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11">
<?php if ( is_singular() && pings_open( get_queried_object() ) ) : ?>
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php endif; ?>
<?php wp_head(); ?>
<style>
.search .blog_page_content .b-title h3 a{color: #75c3d5;font-family: "futura-mediumregular";font-size: 35px;letter-spacing: 2px;}
.search .blog_page_content .b-title h3 a:hover{text-decoration: none;color:#351561;}
.search .blog_page_content .b-title h3{clear: unset; margin-top: 0px;}
</style>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-44104510-1', 'auto');
ga('send', 'pageview');
</script>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('.social_menu_footer a, .social-slider-icons a, .social-icons a').each(function() {
if ($(this).attr('href') == 'https://www.linkedin.com/in/kimberley-cochrane-ma-diptirp-cec-capt-079a3b1?trk=nav_responsive_tab_profile') {
$(this).attr('href', 'https://www.linkedin.com/in/kimberley-cochrane-registered-psychotherapist-079a3b1/');
}
});
});
</script>
</head>
<body <?php body_class(); ?>>
<div class="<?php if(get_field('banner')) { echo "banner"; } else {echo "no-banner";}?>">
<header>
<div class="header-main navbar-fixed-top">
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<div class="logo text-center">
<img src="<?php echo get_template_directory_uri() .'/img/logo.png';?>" alt="Kim Cochrane" title="Kim Cochrane" />
</div>
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'navbar',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
</div>
<div class="col-md-8">
<div class="desktop-menu">
<nav class="navbar navbar-default" role="navigation">
<div class="collapse navbar-collapse" id="main-menu">
</div>
</nav>
</div>
</div>
</div>
</div>
</div>
<div id="menu2"></div>
<?php
$classes = get_body_class();
if(is_front_page()) { ?>
<div class="header-slider">
<?php echo do_shortcode("[metaslider id=25]"); ?>
</div>
<div class="social-slider-icons">
<?php dynamic_sidebar('social_icon_widget');?>
</div>
<?php } elseif(is_singular( 'post' ) || is_singular( 'event' ) || is_search()) {
if(get_field('banner')) { ?>
<div class="banner-section">
<img src="<?php echo get_field('banner');?>" />
</div>
<div class="social-slider-icons">
<?php dynamic_sidebar('social_icon_widget');?>
</div>
<?php } } elseif(is_tax( 'event-categories' )) {
if(get_field('banner')) { ?>
<div class="banner-section">
<img src="<?php echo get_field('banner');?>" />
<div class="banner-text">
<div class="container">
<div class="row">
<div class="col-md-11">
<h1><?php echo single_cat_title();?></h1>
</div>
</div>
</div>
</div>
</div>
<div class="social-slider-icons">
<?php dynamic_sidebar('social_icon_widget');?>
</div>
<?php } } else { ?>
<?php if(get_field('banner')) { ?>
<div class="banner-section">
<img src="<?php echo get_field('banner');?>" />
<div class="banner-text">
<div class="container">
<div class="row">
<div class="col-md-11">
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title();?></h1>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
</div>
<div class="social-slider-icons">
<?php dynamic_sidebar('social_icon_widget');?>
</div>
<?php } ?>
<?php } ?>
</header>
in /functions.php check if this lines of code are there otherwise add them
/**
* Register Custom Navigation Walker
*/
function register_navwalker(){
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
}
add_action( 'after_setup_theme', 'register_navwalker' );
and then in /header check if this line of code are then if not add them
wp_nav_menu( array(
'theme_location' => 'primary',
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'navbar-nav mr-auto',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker(),
) );

Change Panel Image Size Wordpress 2017 Theme

I have a wordpress site using the 2017 Theme that has sections where you can embed one of your other pages. The Header Image size for my Blog page is HUGE, but when I go to the Blog page it is truncated by the theme to a nice banner. So on the home page section, you have to scroll through the huge image.
I'd like to show the truncated size in the section on the home page. How do I (I assume) modify the theme to do this?
When I inspect the element, it is
<div class="panel-image" style="background-image: url(image_url);">
<div class="panel-image-prop" style="padding-top: 100%"></div>
</div>
FYI, the theme Functions.php is below.
<?php
/**
* Twenty Seventeen functions and definitions
*
* #link https://developer.wordpress.org/themes/basics/theme-functions/
*
* #package WordPress
* #subpackage Twenty_Seventeen
* #since 1.0
*/
/**
* Twenty Seventeen only works in WordPress 4.7 or later.
*/
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '<' ) ) {
require get_template_directory() . '/inc/back-compat.php';
return;
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function twentyseventeen_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyseventeen
* If you're building a theme based on Twenty Seventeen, use a find and replace
* to change 'twentyseventeen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'twentyseventeen' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* #link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );
add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
// Set the default content width.
$GLOBALS['content_width'] = 525;
// This theme uses wp_nav_menu() in two locations.
register_nav_menus(
array(
'top' => __( 'Top Menu', 'twentyseventeen' ),
'social' => __( 'Social Links Menu', 'twentyseventeen' ),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support(
'post-formats',
array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'audio',
)
);
// Add theme support for Custom Logo.
add_theme_support(
'custom-logo',
array(
'width' => 250,
'height' => 250,
'flex-width' => true,
)
);
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, and column width.
*/
add_editor_style( array( 'assets/css/editor-style.css', twentyseventeen_fonts_url() ) );
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Load default block styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Define and register starter content to showcase the theme on new sites.
$starter_content = array(
'widgets' => array(
// Place three core-defined widgets in the sidebar area.
'sidebar-1' => array(
'text_business_info',
'search',
'text_about',
),
// Add the core-defined business info widget to the footer 1 area.
'sidebar-2' => array(
'text_business_info',
),
// Put two core-defined widgets in the footer 2 area.
'sidebar-3' => array(
'text_about',
'search',
),
),
// Specify the core-defined pages to create and add custom thumbnails to some of them.
'posts' => array(
'home',
'about' => array(
'thumbnail' => '{{image-sandwich}}',
),
'contact' => array(
'thumbnail' => '{{image-espresso}}',
),
'blog' => array(
'thumbnail' => '{{image-coffee}}',
),
'homepage-section' => array(
'thumbnail' => '{{image-espresso}}',
),
),
// Create the custom image attachments used as post thumbnails for pages.
'attachments' => array(
'image-espresso' => array(
'post_title' => _x( 'Espresso', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/espresso.jpg', // URL relative to the template directory.
),
'image-sandwich' => array(
'post_title' => _x( 'Sandwich', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/sandwich.jpg',
),
'image-coffee' => array(
'post_title' => _x( 'Coffee', 'Theme starter content', 'twentyseventeen' ),
'file' => 'assets/images/coffee.jpg',
),
),
// Default to a static front page and assign the front and posts pages.
'options' => array(
'show_on_front' => 'page',
'page_on_front' => '{{home}}',
'page_for_posts' => '{{blog}}',
),
// Set the front page section theme mods to the IDs of the core-registered pages.
'theme_mods' => array(
'panel_1' => '{{homepage-section}}',
'panel_2' => '{{about}}',
'panel_3' => '{{blog}}',
'panel_4' => '{{contact}}',
),
// Set up nav menus for each of the two areas registered in the theme.
'nav_menus' => array(
// Assign a menu to the "top" location.
'top' => array(
'name' => __( 'Top Menu', 'twentyseventeen' ),
'items' => array(
'link_home', // Note that the core "home" page is actually a link in case a static front page is not used.
'page_about',
'page_blog',
'page_contact',
),
),
// Assign a menu to the "social" location.
'social' => array(
'name' => __( 'Social Links Menu', 'twentyseventeen' ),
'items' => array(
'link_yelp',
'link_facebook',
'link_twitter',
'link_instagram',
'link_email',
),
),
),
);
/**
* Filters Twenty Seventeen array of starter content.
*
* #since Twenty Seventeen 1.1
*
* #param array $starter_content Array of starter content.
*/
$starter_content = apply_filters( 'twentyseventeen_starter_content', $starter_content );
add_theme_support( 'starter-content', $starter_content );
}
add_action( 'after_setup_theme', 'twentyseventeen_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* #global int $content_width
*/
function twentyseventeen_content_width() {
$content_width = $GLOBALS['content_width'];
// Get layout.
$page_layout = get_theme_mod( 'page_layout' );
// Check if layout is one column.
if ( 'one-column' === $page_layout ) {
if ( twentyseventeen_is_frontpage() ) {
$content_width = 644;
} elseif ( is_page() ) {
$content_width = 740;
}
}
// Check if is single post and there is no sidebar.
if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) {
$content_width = 740;
}
/**
* Filter Twenty Seventeen content width of the theme.
*
* #since Twenty Seventeen 1.0
*
* #param int $content_width Content width in pixels.
*/
$GLOBALS['content_width'] = apply_filters( 'twentyseventeen_content_width', $content_width );
}
add_action( 'template_redirect', 'twentyseventeen_content_width', 0 );
/**
* Register custom fonts.
*/
function twentyseventeen_fonts_url() {
$fonts_url = '';
/*
* Translators: If there are characters in your language that are not
* supported by Libre Franklin, translate this to 'off'. Do not translate
* into your own language.
*/
$libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
if ( 'off' !== $libre_franklin ) {
$font_families = array();
$font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i';
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
/**
* Add preconnect for Google Fonts.
*
* #since Twenty Seventeen 1.0
*
* #param array $urls URLs to print for resource hints.
* #param string $relation_type The relation type the URLs are printed.
* #return array $urls URLs to print for resource hints.
*/
function twentyseventeen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentyseventeen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 );
/**
* Register widget area.
*
* #link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentyseventeen_widgets_init() {
register_sidebar(
array(
'name' => __( 'Blog Sidebar', 'twentyseventeen' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Footer 1', 'twentyseventeen' ),
'id' => 'sidebar-2',
'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => __( 'Footer 2', 'twentyseventeen' ),
'id' => 'sidebar-3',
'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'twentyseventeen_widgets_init' );
/**
* Replaces "[...]" (appended to automatically generated excerpts) with ... and
* a 'Continue reading' link.
*
* #since Twenty Seventeen 1.0
*
* #param string $link Link to single post/page.
* #return string 'Continue reading' link prepended with an ellipsis.
*/
function twentyseventeen_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
$link = sprintf(
'<p class="link-more">%2$s</p>',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), get_the_title( get_the_ID() ) )
);
return ' … ' . $link;
}
add_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* #since Twenty Seventeen 1.0
*/
function twentyseventeen_javascript_detection() {
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action( 'wp_head', 'twentyseventeen_javascript_detection', 0 );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function twentyseventeen_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">' . "\n", esc_url( get_bloginfo( 'pingback_url' ) ) );
}
}
add_action( 'wp_head', 'twentyseventeen_pingback_header' );
/**
* Display custom color CSS.
*/
function twentyseventeen_colors_css_wrap() {
if ( 'custom' !== get_theme_mod( 'colorscheme' ) && ! is_customize_preview() ) {
return;
}
require_once( get_parent_theme_file_path( '/inc/color-patterns.php' ) );
$hue = absint( get_theme_mod( 'colorscheme_hue', 250 ) );
$customize_preview_data_hue = '';
if ( is_customize_preview() ) {
$customize_preview_data_hue = 'data-hue="' . $hue . '"';
}
?>
<style type="text/css" id="custom-theme-colors" <?php echo $customize_preview_data_hue; ?>>
<?php echo twentyseventeen_custom_colors_css(); ?>
</style>
<?php
}
add_action( 'wp_head', 'twentyseventeen_colors_css_wrap' );
/**
* Enqueues scripts and styles.
*/
function twentyseventeen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
// Theme stylesheet.
wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri() );
// Theme block stylesheet.
wp_enqueue_style( 'twentyseventeen-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'twentyseventeen-style' ), '1.1' );
// Load the dark colorscheme.
if ( 'dark' === get_theme_mod( 'colorscheme', 'light' ) || is_customize_preview() ) {
wp_enqueue_style( 'twentyseventeen-colors-dark', get_theme_file_uri( '/assets/css/colors-dark.css' ), array( 'twentyseventeen-style' ), '1.0' );
}
// Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer.
if ( is_customize_preview() ) {
wp_enqueue_style( 'twentyseventeen-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'twentyseventeen-style' ), '1.0' );
wp_style_add_data( 'twentyseventeen-ie9', 'conditional', 'IE 9' );
}
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'twentyseventeen-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'twentyseventeen-style' ), '1.0' );
wp_style_add_data( 'twentyseventeen-ie8', 'conditional', 'lt IE 9' );
// Load the html5 shiv.
wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '3.7.3' );
wp_script_add_data( 'html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'twentyseventeen-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '1.0', true );
$twentyseventeen_l10n = array(
'quote' => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ),
);
if ( has_nav_menu( 'top' ) ) {
wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '1.0', true );
$twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' );
$twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' );
$twentyseventeen_l10n['icon'] = twentyseventeen_get_svg(
array(
'icon' => 'angle-down',
'fallback' => true,
)
);
}
wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true );
wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'twentyseventeen_scripts' );
/**
* Enqueues styles for the block-based editor.
*
* #since Twenty Seventeen 1.8
*/
function twentyseventeen_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'twentyseventeen-block-editor-style', get_theme_file_uri( '/assets/css/editor-blocks.css' ), array(), '1.1' );
// Add custom fonts.
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
}
add_action( 'enqueue_block_editor_assets', 'twentyseventeen_block_editor_styles' );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images.
*
* #since Twenty Seventeen 1.0
*
* #param string $sizes A source size value for use in a 'sizes' attribute.
* #param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* #return string A source size value for use in a content image 'sizes' attribute.
*/
function twentyseventeen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 740 <= $width ) {
$sizes = '(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px';
}
if ( is_active_sidebar( 'sidebar-1' ) || is_archive() || is_search() || is_home() || is_page() ) {
if ( ! ( is_page() && 'one-column' === get_theme_mod( 'page_options' ) ) && 767 <= $width ) {
$sizes = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 );
/**
* Filter the `sizes` value in the header image markup.
*
* #since Twenty Seventeen 1.0
*
* #param string $html The HTML image tag markup being filtered.
* #param object $header The custom header object returned by 'get_custom_header()'.
* #param array $attr Array of the attributes for the image tag.
* #return string The filtered header image HTML.
*/
function twentyseventeen_header_image_tag( $html, $header, $attr ) {
if ( isset( $attr['sizes'] ) ) {
$html = str_replace( $attr['sizes'], '100vw', $html );
}
return $html;
}
add_filter( 'get_header_image_tag', 'twentyseventeen_header_image_tag', 10, 3 );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for post thumbnails.
*
* #since Twenty Seventeen 1.0
*
* #param array $attr Attributes for the image markup.
* #param int $attachment Image attachment ID.
* #param array $size Registered image size or flat array of height and width dimensions.
* #return array The filtered attributes for the image markup.
*/
function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( is_archive() || is_search() || is_home() ) {
$attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
} else {
$attr['sizes'] = '100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
/**
* Use front-page.php when Front page displays is set to a static page.
*
* #since Twenty Seventeen 1.0
*
* #param string $template front-page.php.
*
* #return string The template to be used: blank if is_home() is true (defaults to index.php), else $template.
*/
function twentyseventeen_front_page_template( $template ) {
return is_home() ? '' : $template;
}
add_filter( 'frontpage_template', 'twentyseventeen_front_page_template' );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size
* and use list format for better accessibility.
*
* #since Twenty Seventeen 1.4
*
* #param array $args Arguments for tag cloud widget.
* #return array The filtered arguments for tag cloud widget.
*/
function twentyseventeen_widget_tag_cloud_args( $args ) {
$args['largest'] = 1;
$args['smallest'] = 1;
$args['unit'] = 'em';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_args' );
/**
* Get unique ID.
*
* This is a PHP implementation of Underscore's uniqueId method. A static variable
* contains an integer that is incremented with each call. This number is returned
* with the optional prefix. As such the returned value is not universally unique,
* but it is unique across the life of the PHP process.
*
* #since Twenty Seventeen 2.0
* #see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
*
* #staticvar int $id_counter
*
* #param string $prefix Prefix for the returned ID.
* #return string Unique ID.
*/
function twentyseventeen_unique_id( $prefix = '' ) {
static $id_counter = 0;
if ( function_exists( 'wp_unique_id' ) ) {
return wp_unique_id( $prefix );
}
return $prefix . (string) ++$id_counter;
}
/**
* Implement the Custom Header feature.
*/
require get_parent_theme_file_path( '/inc/custom-header.php' );
/**
* Custom template tags for this theme.
*/
require get_parent_theme_file_path( '/inc/template-tags.php' );
/**
* Additional features to allow styling of the templates.
*/
require get_parent_theme_file_path( '/inc/template-functions.php' );
/**
* Customizer additions.
*/
require get_parent_theme_file_path( '/inc/customizer.php' );
/**
* SVG icons functions and filters.
*/
require get_parent_theme_file_path( '/inc/icon-functions.php' );
Maybe this is more useful, panel template php:
<?php
/**
* Template part for displaying pages on front page
*
* #package WordPress
* #subpackage Twenty_Seventeen
* #since 1.0
* #version 1.0
*/
global $twentyseventeencounter;
?>
<article id="panel<?php echo $twentyseventeencounter; ?>" <?php post_class( 'twentyseventeen-panel ' ); ?> >
<?php
if ( has_post_thumbnail() ) :
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'twentyseventeen-featured-image' );
// Calculate aspect ratio: h / w * 100%.
$ratio = $thumbnail[2] / $thumbnail[1] * 100;
?>
<div class="panel-image" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>);">
<div class="panel-image-prop" style="padding-top: <?php echo esc_attr( $ratio ); ?>%"></div>
</div><!-- .panel-image -->
<?php endif; ?>
<div class="panel-content">
<div class="wrap">
<header class="entry-header">
<?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
<?php twentyseventeen_edit_link( get_the_ID() ); ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php
/* translators: %s: Name of current post */
the_content(
sprintf(
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ),
get_the_title()
)
);
?>
</div><!-- .entry-content -->
<?php
// Show recent blog posts if is blog posts page (Note that get_option returns a string, so we're casting the result as an int).
if ( get_the_ID() === (int) get_option( 'page_for_posts' ) ) :
?>
<?php
// Show three most recent posts.
$recent_posts = new WP_Query(
array(
'posts_per_page' => 3,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
?>
<?php if ( $recent_posts->have_posts() ) : ?>
<div class="recent-posts">
<?php
while ( $recent_posts->have_posts() ) :
$recent_posts->the_post();
get_template_part( 'template-parts/post/content', 'excerpt' );
endwhile;
wp_reset_postdata();
?>
</div><!-- .recent-posts -->
<?php endif; ?>
<?php endif; ?>
</div><!-- .wrap -->
</div><!-- .panel-content -->
</article><!-- #post-<?php the_ID(); ?> -->
Pretty simple fix in CSS. Just changed:
.panel-image {
height: 100vh;
max-height: 1200px;
}
to
.panel-image {
height: 165px;
max-height: 1200px;
}

Woocommerce Custom Payment Gateway Not Redirecting

I have a WC payment gateway which was build and working until WP version 4.1. Today I started testing it on WP 4.9.8 and WC 3.5.1.
When I try to complete purchase the payment gateway is not taking me to the payment screen to fill credit card details. It get stuck on redirection state.
Hope someone can help me out to solve this.
Below the image reference and the code I am using:
<?php
/**
* Plugin Name: CustomPaymentGateway
*/
add_action('plugins_loaded', 'init_mpay', 0);
function init_mpay() {
if ( ! class_exists( 'WC_Payment_Gateway' ) ) return;
class woocommerce_mpay extends WC_Payment_Gateway {
public function __construct() {
global $woocommerce;
$this->id = 'mpay';
$this->method_title = __('MPay', 'mpay-chearaan-woo');
$this->icon = plugins_url( 'mpay.png', __FILE__ );
$this->has_fields = false;
$this->notify_url = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'woocommerce_mpay', home_url( '/' ) ) );
// Load the form fields.
$this->init_form_fields();
// Load the settings.
$this->init_settings();
// Define user set variables
$this->mpayurl = $this->settings['mpayurl'];
$this->title = $this->settings['title'];
$this->description = $this->settings['description'];
$this->merchantid = $this->settings['merchantid'];
$this->hashKey = $this->settings['hashKey'];
$this->transactionDate = date('Y-m-d H:i:s O');
$this->woo_version = $this->get_woo_version();
// Actions
add_action('init', array(&$this, 'successful_request'));
add_action('woocommerce_api_woocommerce_mpay', array( &$this, 'successful_request' ));
add_action('woocommerce_receipt_mpay', array(&$this, 'receipt_page'));
if ( version_compare( WOOCOMMERCE_VERSION, '2.0.0', '>=' ) ) {
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array( &$this, 'process_admin_options' ));
} else {
add_action('woocommerce_update_options_payment_gateways', array( &$this, 'process_admin_options' ));
}
}
/**
* Initialise Gateway Settings Form Fields
*/
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable:', 'mpay-chearaan-woo' ),
'type' => 'checkbox',
'label' => __( 'Enable MPay', 'mpay-chearaan-woo' ),
'default' => 'yes'
),
'mpayurl' => array(
'title' => __( 'UAT/Production:', 'mpay-chearaan-woo' ),
'type' => 'checkbox',
'label' => __( 'UAT', 'mpay-chearaan-woo' ),
'default' => 'yes'
),
'title' => array(
'title' => __( 'Title:', 'mpay-chearaan-woo' ),
'type' => 'text',
'description' => __( 'The title which the user sees during checkout.', 'mpay-chearaan-woo' ),
'default' => __( 'MPay Online Payment Gateway', 'mpay-chearaan-woo' )
),
'description' => array(
'title' => __( 'Description:', 'mpay-chearaan-woo' ),
'type' => 'textarea',
'description' => __( 'Description which the user sees during checkout.', 'mpay-chearaan-woo' ),
'default' => __('Pay securely through MPay\'s Secure Servers.', 'mpay-chearaan-woo')
),
'merchantid' => array(
'title' => __( 'Merchant ID:', 'mpay-chearaan-woo' ),
'type' => 'text',
'description' => __( 'Please enter your Merchant ID as provided by MPay.', 'mpay-chearaan-woo' ),
'default' => ''
),
'hashKey' => array(
'title' => __( 'Merchant hashKey:', 'mpay-chearaan-woo' ),
'type' => 'text',
'description' => __( 'Please enter your Merchant hashKey as provided by MPay.', 'mpay-chearaan-woo' ),
'default' => ''
)
);
}
public function admin_options() {
?>
<h3>MPay</h3>
<p><?php _e('MPay works by sending the user to MPay to enter their payment information.', 'mpay-chearaan-woo'); ?></p>
<table class="form-table">
<?php
// Generate the HTML For the settings form.
$this->generate_settings_html();
?>
</table><!--/.form-table-->
<?php
} // End admin_options()
/**
* There are no payment fields, but we want to show the description if set.
**/
function payment_fields() {
if ($this->description) echo wpautop(wptexturize($this->description));
}
/**
* Generate the button link
**/
public function generate_mpay_form( $order_id ) {
global $woocommerce;
$order = new WC_Order( $order_id );
if ($this->mpayurl == "yes"){
$mpay_adr = "https://pcimdex.mpay.my/mdex2/payment/eCommerce";
}else{
$mpay_adr = "https://www.mdex.my/mdex/payment/eCommerce";
}
$sHash = strtoupper(hash('sha256', $this->hashKey."Continue".str_pad($this->merchantid, 10, '0', STR_PAD_LEFT).str_pad($order->id, 20, '0', STR_PAD_LEFT).str_pad(($order->order_total*100), 12, '0', STR_PAD_LEFT)));
$mpay_args = array(
'secureHash' => $sHash,
'mid' => str_pad($this->merchantid, 10, '0', STR_PAD_LEFT),
'invno' => str_pad($order->id, 20, '0', STR_PAD_LEFT),
'amt' => str_pad(($order->order_total*100), 12, '0', STR_PAD_LEFT),
'desc' => str_pad("Order No ".$order_id, 255, ' ', STR_PAD_RIGHT),
'postURL' => $this->notify_url,
'phone' => $order->billing_phone,
'email' => $order->billing_email,
'param' => 'WC|V1'
);
$mpay_args_array = array();
foreach ($mpay_args as $key => $value) {
$mpay_args_array[] = '<input type="hidden" name="'.$key.'" value="'. $value .'" /><br>';
}
wc_enqueue_js('
jQuery(function(){
jQuery("body").block(
{
message: "<img src=\"'.$woocommerce->plugin_url().'/images/uploading.gif\" alt=\"Redirecting…\" style=\"float:left; margin-right: 10px;\" />'.__('Thank you for your order. We are now redirecting you to MPay to make payment.', 'mpay-chearaan-woo').'",
overlayCSS:
{
background: "#fff",
opacity: 0.5
},
css: {
padding: 18,
textAlign: "center",
color: "#555",
border: "2px solid #aaa",
backgroundColor:"#fff",
cursor: "wait",
lineHeight: "30px"
}
});
jQuery("#submit_mpay_payment_form").click();
});
');
return '<form action="'.$mpay_adr.'" method="post">
' . implode('', $mpay_args_array) . '
<input type="submit" class="button-alt" id="submit_mpay_payment_form" value="'.__('Pay via MPay', 'mpay-chearaan-woo').'" /> <a class="button cancel" href="'.$order->get_cancel_order_url().'">'.__('Cancel order & restore cart', 'mpay-chearaan-woo').'</a>
</form>';
}
/**
* Process the payment and return the result
**/
function process_payment( $order_id ) {
$order = new WC_Order( $order_id );
if($this->woo_version >= 2.1){
$redirect = $order->get_checkout_payment_url( true );
}else if( $this->woo_version < 2.1 ){
$redirect = add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id'))));
}else{
$redirect = add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id'))));
}
return array(
'result' => 'success',
'redirect' => $redirect
);
}
/**
* receipt_page
**/
function receipt_page( $order ) {
echo '<p>'.__('Please click the button below to pay with MPay.', 'mpay-chearaan-woo').'</p>';
echo $this->generate_mpay_form( $order );
}
/**
* Server callback was valid, process callback (update order as passed/failed etc).
**/
function successful_request($mpay_response) {
global $woocommerce;
if (isset($_GET['wc-api']) && $_GET['wc-api'] == 'woocommerce_mpay') {
/** need to trim from result **/
$Url_result = $_GET['result'];
$order = new WC_Order( (int) substr($Url_result,7,20) );
$tranID = (int)substr($Url_result,1,6);
if (substr($Url_result,0,1) == '0'){
$r_status = 0;
}else{
$r_status = 33;
}
/*
$order = new WC_Order( (int) $_POST['invno'] );
$r_status = (int) $_POST['result'];
*/
if ($r_status == '0' ){
$order->payment_complete();
$order->add_order_note('MPay Payment was SUCCESSFUL '.'<br>AuthCode is ' . $tranID);
wp_redirect( $this->get_return_url($order) ); exit;
//wp_redirect( $this->order->get_checkout_order_received_url() ); exit;
}else{
$order->update_status('failed', sprintf(__('MPay Payment Failed. Error Communicating with Bank.', 'mpay-chearaan-woo') ) );
wp_redirect($order->get_cancel_order_url()); exit;
}
}
}
function get_woo_version() {
// If get_plugins() isn't available, require it
if ( ! function_exists( 'get_plugins' ) )
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Create the plugins folder and file variables
$plugin_folder = get_plugins( '/woocommerce' );
$plugin_file = 'woocommerce.php';
// If the plugin version number is set, return it
if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
return $plugin_folder[$plugin_file]['Version'];
} else {
// Otherwise return null
return NULL;
}
}
}
}
/**
* Add the gateway to WooCommerce
**/
function add_mpay( $methods ) {
$methods[] = 'woocommerce_mpay'; return $methods;
}
add_filter('woocommerce_payment_gateways', 'add_mpay' );

twitter oAuth for developers wordpress - can't output tweets

I am using a great script called twitter oAuth for developers to create a twitter feed plugin for my wordpress site. The aim is to create a widget where the user can enter their username and number of tweets to display, and that shows in the clients site.
Twitter oAuth for developers creates the following function that is used to display tweets:
getTweets($number_of_tweets, $twitter_screenname_to_load);
Since I am allowing the user to change the username and no. of tweets, I have changed it to this:
$no_of_tweets = $widget['no_of_tweets'];
$twitter_username = $widget['twitter_username'];
$tweets = getTweets($no_of_tweets, ''.$twitter_username.'');
Where $widget['no_of_tweets'] and $widget['twitter_username'] are parameters specified by the user.
I have set defaults for this plugin as follows:
/* Setup Widget Defaults */
$this->defaults = array (
...
'twitter_username' => 'skizzar_sites',
'no_of_tweets' => 3,
...
)
);
So when I load up my plugin, it shows the latest 3 tweets from skizzar_sites - as it should. However, when the user change the number or username, the widget outputs a single random tweet from a random user.
Is there something obviously wrong with the way I have written the function:
$tweets = getTweets($no_of_tweets, ''.$twitter_username.'');
Here is my full widget code for reference:
<?php /**
* Layers Twitter Widget
*
* This file is used to register and display the Layers widget.
* http://docs.layerswp.com/development-tutorials-layers-builder-widgets/
*
* #package Layers
* #since Layers 1.0.0
*/
if( !class_exists( 'Layers_Twitter_Widget' ) && class_exists( 'Layers_Widget' ) ) {
// http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#widget-class
class Layers_Twitter_Widget extends Layers_Widget {
/**
* 1 - Widget construction
* http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#1-widget-construction
*/
function Layers_Twitter_Widget(){
$this->widget_title = __( 'Tweets' , 'layerswp' );
$this->widget_id = 'tweets';
$this->post_type = '';
$this->taxonomy = '';
$this->checkboxes = array();
/* Widget settings. */
$widget_ops = array(
'classname' => 'obox-layers-' . $this->widget_id .'-widget',
'description' => __( 'This widget is used to display your Tweets', 'layerswp')
);
/* Widget control settings. */
$control_ops = array(
'width' => '660',
'height' => NULL,
'id_base' => 'layers-widget-' . $this->widget_id
);
/* Create the widget. */
parent::__construct( 'layers' . '-widget-' . $this->widget_id , $this->widget_title, $widget_ops, $control_ops );
/* Setup Widget Defaults */
$this->defaults = array (
'title' => __( 'Twitter Feed', 'layerswp' ),
'excerpt' => __( 'Display a list of your most recent tweets', 'layerswp' ),
'twitter_username' => 'skizzar_sites',
'no_of_tweets' => 3,
'design' => array(
'layout' => 'layout-boxed',
'textalign' => 'text-left',
'background' => array(
'position' => 'center',
'repeat' => 'no-repeat'
),
'fonts' => array(
'align' => 'text-left',
'size' => 'medium',
'color' => NULL,
'shadow' => NULL
)
)
);
} // END main function
/**
* 2 - Widget form
* http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#2-widget-form
* We use regulage HTML here, it makes reading the widget much easier
* than if we used just php to echo all the HTML out.
*
*/
function form( $instance ){
// $instance Defaults
$instance_defaults = $this->defaults;
// If we have information in this widget, then ignore the defaults
if( !empty( $instance ) ) $instance_defaults = array();
// Parse $instance
$instance = wp_parse_args( $instance, $instance_defaults );
extract( $instance, EXTR_SKIP );
// Design Bar Components
$design_bar_components = apply_filters(
'layers_' . $this->widget_id . '_widget_design_bar_components' ,
array(
'layout',
'fonts',
'background',
'advanced'
)
);
// Instantiate the Deisgn Bar
$this->design_bar(
'side', // CSS Class Name
array(
'name' => $this->get_field_name( 'design' ),
'id' => $this->get_field_id( 'design' ),
), // Widget Object
$instance, // Widget Values
$design_bar_components // Standard Components
);
// Build Content Form
// http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#content-options-form
?>
<div class="layers-container-large">
<?php
$this->form_elements()->header(
array(
'title' => __( 'Tweets' , 'layerswp' ),
'icon_class' => 'post'
)
);
?>
<section class="layers-accordion-section layers-content">
<div class="layers-row layers-push-bottom">
<p>In order for the twitter widget to work, you will need to set up a twitter app and add your API credentials to the dashboard. Click here to enter your API details.</p>
<p class="layers-form-item">
<?php echo $this->form_elements()->input(
array(
'type' => 'text',
'name' => $this->get_field_name( 'title' ) ,
'id' => $this->get_field_id( 'title' ) ,
'placeholder' => __( 'Enter title here' , 'layerswp' ),
'value' => ( isset( $title ) ) ? $title : NULL ,
'class' => 'layers-text layers-large'
)
); ?>
</p>
<p class="layers-form-item">
<?php echo $this->form_elements()->input(
array(
'type' => 'rte',
'name' => $this->get_field_name( 'excerpt' ) ,
'id' => $this->get_field_id( 'excerpt' ) ,
'placeholder' => __( 'Short Excerpt' , 'layerswp' ),
'value' => ( isset( $excerpt ) ) ? $excerpt : NULL ,
'class' => 'layers-textarea layers-large'
)
); ?>
</p>
<p class="layers-form-item">
<?php
echo $this->form_elements()->input(
array(
'type' => 'text',
'name' => $this->get_field_name( 'twitter_username' ) ,
'id' => $this->get_field_id( 'twitter_username' ) ,
'placeholder' => __( 'Twitter username' , 'layerswp' ),
'value' => ( isset( $twitter_username ) ) ? $twitter_username : NULL ,
'class' => 'layers-text layers-large'
)
); ?>
</p>
<p class="layers-form-item">
<?php
echo __( 'Number of tweets to show' , 'layerswp' );
echo $this->form_elements()->input(
array(
'type' => 'number',
'name' => $this->get_field_name( 'no_of_tweets' ) ,
'id' => $this->get_field_id( 'no_of_tweets' ) ,
'value' => ( isset( $no_of_tweets ) ) ? $no_of_tweets : NULL ,
'min' => '1',
'max' => '20'
)
); ?>
</p>
</div>
</section>
</div>
<?php
} // Form
/**
* 3 - Update Options
* http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#3-update-controls
*/
function update($new_instance, $old_instance) {
if ( isset( $this->checkboxes ) ) {
foreach( $this->checkboxes as $cb ) {
if( isset( $old_instance[ $cb ] ) ) {
$old_instance[ $cb ] = strip_tags( $new_instance[ $cb ] );
}
} // foreach checkboxes
} // if checkboxes
return $new_instance;
}
/**
* 4 - Widget front end display
* http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#4-widget-front-end
*/
function widget( $args, $instance ) {
// Turn $args array into variables.
extract( $args );
// $instance Defaults
$instance_defaults = $this->defaults;
// If we have information in this widget, then ignore the defaults
if( !empty( $instance ) ) $instance_defaults = array();
// Parse $instance
$widget = wp_parse_args( $instance, $instance_defaults );
// Apply Styling
// http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#colors-and-font-settings
layers_inline_styles( '#' . $widget_id, 'background', array( 'background' => $widget['design'][ 'background' ] ) );
layers_inline_styles( '#' . $widget_id, 'color', array( 'selectors' => array( '.section-title h3.heading' , '.section-title div.excerpt' ) , 'color' => $widget['design']['fonts'][ 'color' ] ) );
// Apply the advanced widget styling
$this->apply_widget_advanced_styling( $widget_id, $widget );
// Generate the widget container class
// Do not edit
$widget_container_class = array();
$widget_container_class[] = 'widget row content-vertical-massive';
$widget_container_class[] = $this->check_and_return( $widget , 'design', 'advanced', 'customclass' );
$widget_container_class[] = $this->get_widget_spacing_class( $widget );
$widget_container_class = implode( ' ', apply_filters( 'layers_post_widget_container_class' , $widget_container_class ) );
/**
* Widget Markup
* http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#widget-html
*/
?>
<section class=" <?php echo $widget_container_class; ?>" id="<?php echo $widget_id; ?>">
<?php if( '' != $this->check_and_return( $widget , 'title' ) ||'' != $this->check_and_return( $widget , 'excerpt' ) ) { ?>
<div class="container clearfix">
<?php
// Generate the Section Title Classes
$section_title_class = array();
$section_title_class[] = 'section-title clearfix';
$section_title_class[] = $this->check_and_return( $widget , 'design', 'fonts', 'size' );
$section_title_class[] = $this->check_and_return( $widget , 'design', 'fonts', 'align' );
$section_title_class[] = ( $this->check_and_return( $widget, 'design', 'background' , 'color' ) && 'dark' == layers_is_light_or_dark( $this->check_and_return( $widget, 'design', 'background' , 'color' ) ) ? 'invert' : '' );
$section_title_class = implode( ' ', $section_title_class ); ?>
<div class="<?php echo $section_title_class; ?>">
<?php if( '' != $widget['title'] ) { ?>
<h3 class="heading"><?php echo esc_html( $widget['title'] ); ?></h3>
<?php } ?>
<?php if( '' != $widget['excerpt'] ) { ?>
<div class="excerpt"><?php echo $widget['excerpt']; ?></div>
<?php } ?>
</div>
</div>
<?php }
// Begin Post Structure ?>
<div class="row <?php echo $this->get_widget_layout_class( $widget ); ?> <?php echo $this->check_and_return( $widget , 'design', 'liststyle' ); ?>">
<?php //start Twitter output
// draft sample display for array returned from oAuth Twitter Feed for Developers WP plugin
// http://wordpress.org/extend/plugins/oauth-twitter-feed-for-developers/
$no_of_tweets = $widget['no_of_tweets'];
$twitter_username = $widget['twitter_username'];
$tweets = getTweets($no_of_tweets, ''.$twitter_username.'');
if(is_array($tweets)){
// to use with intents
echo '<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>';
foreach($tweets as $tweet){
if($tweet['text']){
$the_tweet = $tweet['text'];
// i. User_mentions must link to the mentioned user's profile.
if(is_array($tweet['entities']['user_mentions'])){
foreach($tweet['entities']['user_mentions'] as $key => $user_mention){
$the_tweet = preg_replace(
'/#'.$user_mention['screen_name'].'/i',
'#'.$user_mention['screen_name'].'',
$the_tweet);
}
}
// ii. Hashtags must link to a twitter.com search with the hashtag as the query.
if(is_array($tweet['entities']['hashtags'])){
foreach($tweet['entities']['hashtags'] as $key => $hashtag){
$the_tweet = preg_replace(
'/#'.$hashtag['text'].'/i',
'#'.$hashtag['text'].'',
$the_tweet);
}
}
// iii. Links in Tweet text must be displayed using the display_url
// field in the URL entities API response, and link to the original t.co url field.
if(is_array($tweet['entities']['urls'])){
foreach($tweet['entities']['urls'] as $key => $link){
$the_tweet = preg_replace(
'`'.$link['url'].'`',
''.$link['url'].'',
$the_tweet);
}
}
echo $the_tweet;
// 3. Tweet Actions
// Reply, Retweet, and Favorite action icons must always be visible for the user to interact with the Tweet. These actions must be implemented using Web Intents or with the authenticated Twitter API.
// No other social or 3rd party actions similar to Follow, Reply, Retweet and Favorite may be attached to a Tweet.
// get the sprite or images from twitter's developers resource and update your stylesheet
echo '
<ul class="twitter_intents">
<li><a class="reply" href="https://twitter.com/intent/tweet?in_reply_to='.$tweet['id_str'].'"><i class="fa fa-reply"></i>R</a></li>
<li><a class="retweet" href="https://twitter.com/intent/retweet?tweet_id='.$tweet['id_str'].'"><i class="fa fa-retweet"></i>R</a></li>
<li><a class="favorite" href="https://twitter.com/intent/favorite?tweet_id='.$tweet['id_str'].'"><i class="fa fa-heart"></i>F</a></li>
</ul>';
// 4. Tweet Timestamp
// The Tweet timestamp must always be visible and include the time and date. e.g., “3:00 PM - 31 May 12”.
// 5. Tweet Permalink
// The Tweet timestamp must always be linked to the Tweet permalink.
echo '
<p class="timestamp">
<a href="https://twitter.com/YOURUSERNAME/status/'.$tweet['id_str'].'" target="_blank">
'.date('h:i A M d',strtotime($tweet['created_at']. '- 8 hours')).'
</a>
</p>';// -8 GMT for Pacific Standard Time
} else {
echo '
<br /><br />
Click here to read YOURUSERNAME\'S Twitter feed';
}
}
}
// end Twitter output ?>
</div>
</section>
<?php }
} // Class
// Register our widget
// http://docs.layerswp.com/development-tutorials-layers-builder-widgets/#register-and-initialize
register_widget('Layers_Twitter_Widget');
}
Aha! Just figured this out - remembered from a few years back having a similar problem and it was because the no_of_tweets and _username paramteres in the function are documented the wrong way round.
Instead of
getTweets($number_of_tweets, $twitter_screenname_to_load);
its:
getTweets($twitter_screenname_to_load, $number_of_tweets);

Categories