Adding php do_shortcode to array in WordPress - php

I've got this code here:
$defaults = array(
'id' => 'private_message-'.$user_id,
'component' => 'messages',
'must_be_logged_in' => true,
'block_self' => true,
'wrapper_id' => 'send-private-message-'.$user_id,
'wrapper_class' =>'send-private-message',
'link_href' => hibuddy_get_send_private_message_url(),
'link_title' => __( 'Ask the model a question about this item!', 'buddypress' ),
'link_text' => __( 'Send Seller a Private Message', 'buddypress' ),
'link_class' => 'send-message',
);
And I'm trying to change the line that says:
'link_text' => __( 'Send Seller a Private Message', 'buddypress' ),
...to:
'link_text' => __( 'echo do_shortcode('[button]'.Send Seller a Private Message.'[/button]')', 'buddypress' ),
...but it doesnt like it. In a nutshell, I'm trying to change the "Send Seller a Private Message" text to output [button]Send Seller a Private Message[/button] which requires the WordPress do_shortcode.
Thank you!

You can try this, but it probably won't work unless 'link_text' allows HTML instead of plain text:
'link_text' => __( do_shortcode('[button]Send Seller a Private Message[/button]'), 'buddypress' ),

Related

Saving Woocommerce Payment Gateway settings on a custom admin page

I'm trying to create a custom admin page which has Woocommerce Stripe Payment gateway options. Specifically just the Stripe API keys related fields. Reason for this is I need to limit access to Woocommerce settings pages and only want to expose very few things, so bringing just the few things to a custom page seems like the simplest thing.
However, this has been trickier than I expected. I've been trying to do this through extending WC_Payment_Gateway class, but this now seems like the wrong idea. Since I don't think I can extend a specific Gateway's class? I would basically need to rewrite the Stripe plugin I guess.
Also thinking there must be an easier way. Has anyone done this before?
Is it possible to create a settings forms with Woocommerce Settings API outside of the normal WC settings page?
Using this method, I didn't actually even get the form to print out, just the fields (i.e. no Submit button).
class WoocommerceStripeInt extends WC_Payment_Gateway
{
public function __construct () {
$this->id = 'stripe';
$this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' );
/* translators: 1) link to Stripe register page 2) link to Stripe api keys page */
$this->method_description = __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' );
$this->has_fields = true;
// Load the settings fields.
$this->init_form_fields();
// Load the settings.
$this->init_settings();
// Get setting values.
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->instructions = $this->get_option( 'instructions' );
$this->order_status = $this->get_option( 'testmode' );
add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options'));
}
/**
* Initialise Gateway Settings Form Fields
*/
function init_form_fields() {
$this->form_fields = apply_filters(
'wc_stripe_settings', array(
'testmode' => [
'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ),
'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ),
'type' => 'checkbox',
'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ),
'default' => 'yes',
'desc_tip' => true,
],
'test_publishable_key' => [
'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ),
'type' => 'text',
'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_test_" will be saved.', 'woocommerce-gateway-stripe' ),
'default' => '',
'desc_tip' => true,
],
'test_secret_key' => [
'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ),
'type' => 'password',
'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_test_" or "rk_test_" will be saved.', 'woocommerce-gateway-stripe' ),
'default' => '',
'desc_tip' => true,
],
'publishable_key' => [
'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ),
'type' => 'text',
'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "pk_live_" will be saved.', 'woocommerce-gateway-stripe' ),
'default' => '',
'desc_tip' => true,
],
'secret_key' => [
'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ),
'type' => 'password',
'description' => __( 'Get your API keys from your stripe account. Invalid values will be rejected. Only values starting with "sk_live_" or "rk_live_" will be saved.', 'woocommerce-gateway-stripe' ),
'default' => '',
'desc_tip' => true,
],
)
);
}
function admin_options() {
?>
<h2><?php _e('Stripe Settings','woocommerce'); ?></h2>
<table class="form-table">
<?php $this->generate_settings_html(); ?>
</table> <?php
}
}
Any help would be appreciated, thanks.

Changing the array description text without editing plugin's core files with a filter function in wordpress

I have checked many questions from this forum about this solution, but I could not get it at all. I'm learning how to overwrite some text from existing array in plugin without editing it's core files so I will not loose my changes when the core plugin is updated in wordpress.
What I have is this code right from the plugin. There is one string which I can not translate from po.edit. Please get that I'm just learning this solution so I do not know how to really get it at all so that's why I'm asking for your advice.
Core code
/**
* Initialize integration settings form fields.
*
* #return void
*/
public function init_form_fields() {
$this->form_fields = array(
'authorization' => array(
'title' => __( 'Authorization', 'woocommerce-bookings' ),
'type' => 'google_calendar_authorization',
),
'testing' => array(
'title' => __( 'Connect with a custom Google Calendar App', 'woocommerce-bookings' ),
'type' => 'title',
'description' => 'Enter the credentials below to use a custom Google Calendar API app. Disconnect existing connection to enter credentials.',
),
'client_id' => array(
'title' => __( 'Client ID', 'woocommerce-bookings' ),
'type' => 'text',
'description' => __( 'Enter the Google Client ID associated with your Calendar API app.', 'woocommerce-bookings' ),
'disabled' => $this->is_using_wooconnect_method(),
'desc_tip' => true,
'default' => '',
),
'client_secret' => array(
'title' => __( 'Client Secret', 'woocommerce-bookings' ),
'type' => 'text',
'description' => __( 'Enter the Google Client Secret associated with your Calendar API app.', 'woocommerce-bookings' ),
'disabled' => $this->is_using_wooconnect_method(),
'desc_tip' => true,
'default' => '',
),
'custom_authorization' => array(
'title' => __( 'Authorization', 'woocommerce-bookings' ),
'type' => 'custom_google_calendar_authorization',
),
'calendar_connection_settings' => array(
'title' => __( 'Connected Calendar Settings', 'woocommerce-bookings' ),
'type' => 'title',
'display_check' => array( $this, 'display_connection_settings' ),
),
'calendar_id' => array(
'title' => __( 'Calendar', 'woocommerce-bookings' ),
'type' => 'select',
'description' => __( 'Select your Calendar.', 'woocommerce-bookings' ),
'desc_tip' => true,
'default' => '',
'options' => $this->get_calendar_list_options(),
'display_check' => array( $this, 'display_connection_settings' ),
),
'sync_preference' => array(
'type' => 'select',
'title' => __( 'Sync Preference', 'woocommerce-bookings' ),
'options' => array(
'both_ways' => __( 'Sync both ways - between Store and Google', 'woocommerce-bookings' ),
'one_way' => __( 'Sync one way - from Store to Google', 'woocommerce-bookings' ),
),
'description' => __( 'Manage the sync flow between your Store calendar and Google calendar.', 'woocommerce-bookings' ),
'desc_tip' => true,
'default' => 'one_way',
'display_check' => array( $this, 'display_connection_settings' ),
),
'debug' => array(
'title' => __( 'Debug Log', 'woocommerce-bookings' ),
'type' => 'checkbox',
'label' => __( 'Enable logging', 'woocommerce-bookings' ),
'default' => 'no',
/* translators: 1: log file path */
'description' => sprintf( __( 'Log Google Calendar events, such as API requests, inside %s', 'woocommerce-bookings' ), '<code>woocommerce/logs/' . $this->id . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.txt</code>' ),
),
);
}
/**
* Generate Settings HTML.
*
* Extends base class html generation to add 'display_check' parameter to each
* field. 'display_check', is a callable that enables/disables the display of
* the field.
*
* #param array $form_fields (default: array()) Array of form fields.
* #param bool $echo Echo or return.
* #return string the html for the settings
* #since 1.15.0
*/
public function generate_settings_html( $form_fields = array(), $echo = true ) {
if ( empty( $form_fields ) ) {
$form_fields = $this->get_form_fields();
}
foreach ( $form_fields as $index => $field ) {
// Delete fields if they have an "enable_check" function that returns false.
if ( isset( $field['display_check'] ) && ! call_user_func( $field['display_check'] ) ) {
unset( $form_fields[ $index ] );
}
}
return parent::generate_settings_html( $form_fields, $echo );
}
Now there is a testing array in the core code where I need to change its description
'testing' => array(
'title' => __( 'Connect with a custom Google Calendar App', 'woocommerce-bookings' ),
'type' => 'title',
'description' => 'Enter the credentials below to use a custom Google Calendar API app. Disconnect existing connection to enter credentials.',
),
I have tried this but I think its not the right solution for my problem because I can not get it work.
add_filter( 'init_form_fields', 'replace_text', 11, 2 );
function replace_text( $form_fields ) {
$form_fields = array(
'testing'=> array(
'title'=> __( 'Connect with a custom Google Calendar App', 'woocommerce-bookings' ),
'type'=> 'title',
'description' => 'New description',
),
);
return $form_fields;
}
Could you please help me to find a right solution. Thank you

redux framework opt_text not display the value

i tired to fix this
i have problem with redux framework options
options-init.php
Redux::setSection( $opt_name, array(
'title' => __( 'Basic Field', 'redux-framework-demo' ),
'id' => 'basic',
'desc' => __( 'Basic field with no subsections.', 'redux-framework-demo' ),
'icon' => 'el el-home',
'fields' => array(
array(
'id' => 'opt-text',
'type' => 'text',
'title' => __('Text Option - Email Validated', 'redux-framework-demo'),
'subtitle' => __('This is a little space under the Field Title in the Options table, additional info is good in here.', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
'validate' => 'email',
'msg' => 'custom error message',
'default' => 'test#test.com'
)
)
) );
this is my index.php
<h1><?php global $opt_name; echo 'Text value: ' . $opt_name['opt-text']; ?></h1>
i get this error
Warning: Illegal string offset 'opt-text' in C:\xampp\htdocs\wordpress\wp-content\themes\ZoXX\index.php on line 2
Redux hasn't loaded yet. Delay your use of the variable, or run:
Redux::init('OPT_NAME')
Good luck!

How to create simple Offline payment gateway for WooCommerce?

Good afternoon, I want to make simple copy of Cash on Delivery (COD) payment method in my store and rename it to Coupon on Delivery.
How to implement it?
Up
I have tried this code, but it shows error 500 on WC settings page:
<?php
/**
* Plugin Name: My New WooCommerce Gateway
* Plugin URI:
* Description: WooCommerce gateway to ....
* Author: .....
* Version: 1.0
* Author URI: https://example.org/
* Text Domain: woocommerce-my-gateway
* Domain Path: /languages/
*/
add_action( 'plugins_loaded', 'init_my_gateway_class' );
function init_my_gateway_class() {
if ( !class_exists( 'WooCommerce' ) ) return;
class WC_Gateway_COD_Renamed extends WC_Payment_Gateway {
}
}
function add_my_gateway_class( $methods ) {
$methods[] = 'WC_Gateway_my_gateway';
return $methods;
}
add_filter( 'woocommerce_payment_gateways', 'add_my_gateway_class' );
function my_load_textdomain(){
load_plugin_textdomain( 'woocommerce-my-gateway', false, dirname( plugin_dir_path( __FILE__ ) . '/languages/' ) );
}
add_action('plugins_loaded', 'my_load_textdomain');
Source of code
In your main plugin file you can include the class and filter the gateways at the same time:
function add_my_gateway_class( $methods ) {
include( 'class-wc-gateway-cod-renamed.php');
$methods[] = 'WC_Gateway_COD_Renamed';
return $methods;
}
add_filter( 'woocommerce_payment_gateways', 'add_my_gateway_class' );
There's no real need to check if WooCommerce is active this way as woocommerce_payment_gateways only exists if WooCommerce is running.
Then in another file called class-wc-gateway-cod-renamed.php you can define your class:
class WC_Gateway_COD_Renamed extends WC_Gateway_COD {
/**
* Setup general properties for the gateway.
*/
protected function setup_properties() {
$this->id = 'coupon-on-delivery';
$this->icon = apply_filters( 'woocommerce_coupon-on-deliver_icon', '' );
$this->method_title = __( 'Coupon on delivery', 'your-plugin' );
$this->method_description = __( 'Have your customers pay with a coupon upon delivery.', 'your-plugin' );
$this->has_fields = false;
}
/**
* Initialise Gateway Settings Form Fields.
*/
public function init_form_fields() {
$shipping_methods = array();
foreach ( WC()->shipping()->load_shipping_methods() as $method ) {
$shipping_methods[ $method->id ] = $method->get_method_title();
}
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'your-plugin' ),
'label' => __( 'Enable coupon on delivery', 'your-plugin' ),
'type' => 'checkbox',
'description' => '',
'default' => 'no',
),
'title' => array(
'title' => __( 'Title', 'your-plugin' ),
'type' => 'text',
'description' => __( 'Payment method description that the customer will see on your checkout.', 'your-plugin' ),
'default' => __( 'coupon on delivery', 'your-plugin' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Description', 'your-plugin' ),
'type' => 'textarea',
'description' => __( 'Payment method description that the customer will see on your website.', 'your-plugin' ),
'default' => __( 'Pay with coupon upon delivery.', 'your-plugin' ),
'desc_tip' => true,
),
'instructions' => array(
'title' => __( 'Instructions', 'your-plugin' ),
'type' => 'textarea',
'description' => __( 'Instructions that will be added to the thank you page.', 'your-plugin' ),
'default' => __( 'Pay with coupon upon delivery.', 'your-plugin' ),
'desc_tip' => true,
),
'enable_for_methods' => array(
'title' => __( 'Enable for shipping methods', 'your-plugin' ),
'type' => 'multiselect',
'class' => 'wc-enhanced-select',
'css' => 'width: 400px;',
'default' => '',
'description' => __( 'If coupon upon delivery is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'your-plugin' ),
'options' => $shipping_methods,
'desc_tip' => true,
'custom_attributes' => array(
'data-placeholder' => __( 'Select shipping methods', 'your-plugin' ),
),
),
'enable_for_virtual' => array(
'title' => __( 'Accept for virtual orders', 'your-plugin' ),
'label' => __( 'Accept coupon if the order is virtual', 'your-plugin' ),
'type' => 'checkbox',
'default' => 'yes',
),
);
}
}
Extend the WC_Gateway_COD class so that you can inherit methods from it and only override the methods that have to do with the naming of things.
In WooCommerce plugin, you can enable payment gateway COD from admin section:
Admin >> WooCommerce >> Settings >> Checkout >> Cash on delivery.
Check option for enable COD.
Please refer below link for create offline payment gateway.
How to Create A WooCommerce Payment gateway

Notice: Array to string conversion in /var/www/html/mytheme/wp-includes/formatting.php on line 1025

Im trying to add variables instead of custom field IDs in my metaboxes file using this script
I added some options in redux framework to give possibility to change the custom fields.
<?php
/*global from framework*/
global $redux;
/*custom fields options retrieved from redux framework*/
$custom_videourl = $redux['mytheme_videourl'];
$custom_duration = $redux['mytheme_duration'];
$custom_description = $redux['mytheme_desc'];
$fields = array(
array(
'label' => __( 'MP4/FLV & Youtube Url', 'framework' ),
'desc' => __( 'Here you can add videos with mp4 format', 'framework' ),
'id' => $custom_videourl,
'type' => 'text'
),
array(
'label' => __( 'Video Duration', 'framework' ),
'desc' => __( 'Example: 5:20', 'framework' ),
'id' => $custom_duration,
'type' => 'text'
),
array(
'label' => __( 'Video Description', 'framework' ),
'id' => $custom_description,
'desc' => __( 'Here you can write a description', 'framework' ),
'type' => 'editor'
)
);
$my_metaboxes = new custom_add_meta_box( 'mytheme_metaboxes', __( 'Video - Additional Information', 'framework' ), $fields, 'post', true );
But with the above example I got Notice: Array to string conversion in /var/www/html/mytheme/wp-includes/formatting.php on line 1025
So if I add the custom field without variable metaboxes are working fine like below content:
$fields = array(
array(
'label' => __( 'MP4/FLV & Youtube Url', 'framework' ),
'desc' => __( 'Here you can add videos with mp4 format', 'framework' ),
'id' => 'mytheme_videourl',
'type' => 'text'
),
array(
'label' => __( 'Video Duration', 'framework' ),
'desc' => __( 'Example: 5:20', 'framework' ),
'id' => 'mytheme_duration',
'type' => 'text'
),
array(
'label' => __( 'Video Description', 'framework' ),
'id' => 'mytheme_desc',
'desc' => __( 'Here you can write a description', 'framework' ),
'type' => 'editor'
)
);
$my_metaboxes = new custom_add_meta_box( 'mytheme_metaboxes', __( 'Video - Additional Information', 'framework' ), $fields, 'post', true );
I have tried using print_r but metaboxes don't save than. Is there any way to make the first code working? Using variables instead of custom field IDs?
It seems really likely that one of your redux variables contains an Array instead of a String. Knowing that, you just need to figure out which one it is and figure out where the actual piece of data that you are looking for is.
One way you could debug this is to do an explicit conversion of all three of the redux variables to strings. (e.g. 'id' => implode("***", $custom_videourl)). Then, once you've figured out which one (or more than one) is an array, you'll probably know how to access the piece of data you actually want.
If that doesn't do it for you, I would suggest adding this to your wp-config.php file: define( 'WP_DEBUG_LOG', true );
This will create a debug log for you. You can then log out to it (e.g. error_log( print_r( $custom_videourl ) );
I believe it usually stores the debug.log file in the wp-content folder.

Categories