I have been trying to use the collivery package with laravel. However when i try use it i get the error in the title. How will I call the class non statically.
This is what i am trying to call.
public function getTowns( $country = "ZAF", $province = null )
{
if ( ( $this->check_cache == 2 ) && is_null( $province ) && $this->cache->has( 'collivery.towns.'. $country ) ) {
return $this->cache->get( 'collivery.towns.'.$country );
} elseif ( ( $this->check_cache == 2 ) && ! is_null( $province ) && $this->cache->has( 'collivery.towns.'. $country .'.'. $province ) ) {
return $this->cache->get( 'collivery.towns.'.$country.'.'.$province );
} else {
try {
$result = $this->client()->get_towns( $this->token, $country, $province );
} catch ( SoapFault $e ) {
$this->catchSoapFault( $e );
return false;
}
if ( isset( $result['towns'] ) ) {
if ( is_null( $province ) ) {
if ( $this->check_cache != 0 ) $this->cache->put( 'collivery.towns.'. $country, $result['towns'], 60*24 );
} else {
if ( $this->check_cache != 0 ) $this->cache->put( 'collivery.towns.'. $country .'.'. $province, $result['towns'], 60*24 );
}
return $result['towns'];
} else {
if ( isset( $result['error_id'] ) )
$this->setError( $result['error_id'], $result['error'] );
else
$this->setError( 'result_unexpected', 'No result returned.' );
return false;
}
}
}
You need to create instance of the Collivery class to access in your controller. You can try the below code
$config = array(
'app_name' => 'Default App Name', // Application Name
'app_version' => '0.0.1', // Application Version
'app_host' => '', // Framework/CMS name and version, eg 'Wordpress 3.8.1 WooCommerce 2.0.20' / 'Joomla! 2.5.17 VirtueMart 2.0.26d'
'app_url' => '', // URL your site is hosted on
'user_email' => 'demo#collivery.co.za',
'user_password' => 'demo',
'demo' => false,
);
$collivery = new \Mds\Collivery( $config );
$towns = $collivery->getTowns();
dump( $towns );`
Related
This is the plugin that generates a profile photo upload button:
https://github.com/ultimatemember/Extended/blob/main/um-profile-photo/um-profile-photo.php
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Add new predefined field "Profile Photo" in UM Form Builder.
*
* #param array $arr field array settings.
*/
function um_predefined_fields_hook_profile_photo( $arr ) {
$arr['register_profile_photo'] = array(
'title' => __( 'Profile Photo', 'ultimate-member' ),
'metakey' => 'register_profile_photo',
'type' => 'image',
'label' => __('Change your profile photo','ultimate-member' ),
'upload_text' => __( 'Upload your photo here', 'ultimate-member' ),
'icon' => 'um-faicon-camera',
'crop' => 1,
'editable' => 1,
'max_size' => ( UM()->options()->get('profile_photo_max_size') ) ? UM()->options()->get('profile_photo_max_size') : 999999999,
'min_width' => str_replace('px','',UM()->options()->get('profile_photosize')),
'min_height' => str_replace('px','',UM()->options()->get('profile_photosize')),
);
return $arr;
}
add_filter( 'um_predefined_fields_hook', 'um_predefined_fields_hook_profile_photo', 99999, 1 );
/**
* Multiply Profile Photo with different sizes
*
* #param integer $user_id the user ID.
*/
function um_registration_set_profile_photo( $user_id, $args ) {
if( isset( $args['form_id'] )) $req = 'register_profile_photo-' . $args['form_id'];
else $req = 'register_profile_photo';
if( ! isset( $_REQUEST[$req] ) ) return;
//if ( strpos( $_REQUEST['register_profile_photo'], '_temp.') <= -1 ) {
//return;
//}
if( is_user_logged_in() ) {
UM()->files()->delete_core_user_photo( $user_id, 'profile_photo' );
}
$user_basedir = UM()->uploader()->get_upload_user_base_dir( $user_id, true );
$temp_dir = UM()->uploader()->get_core_temp_dir() . DIRECTORY_SEPARATOR;
$temp_profile_photo = array_slice( scandir( $temp_dir ), 2);
$temp_profile_id = isset( $_COOKIE['um-register-profile-photo'] ) ? $_COOKIE['um-register-profile-photo'] : null;
if( empty( $temp_profile_photo ) ) return;
foreach( $temp_profile_photo as $i => $p ){
if ( strpos($p, "_photo_{$temp_profile_id}_temp") !== false ) {
$profile_p = $p;
}
}
if( empty( $profile_p ) ) return;
$temp_image_path = $temp_dir . DIRECTORY_SEPARATOR . $profile_p;
$new_image_path = $user_basedir . DIRECTORY_SEPARATOR . $profile_p;
$image = wp_get_image_editor( $temp_image_path );
$file_info = wp_check_filetype_and_ext( $temp_image_path, $profile_p );
$ext = $file_info['ext'];
$new_image_name = str_replace( $profile_p, "profile_photo.{$ext}", $new_image_path );
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
$quality = UM()->options()->get( 'image_compression' );
if ( ! is_wp_error( $image ) ) {
$image->save( $new_image_name );
$image->set_quality( $quality );
$sizes_array = array();
foreach( $sizes as $size ) {
$sizes_array[ ] = array ( 'width' => $size );
}
$image->multi_resize( $sizes_array );
delete_user_meta( $user_id, 'synced_profile_photo' );
update_user_meta( $user_id, 'profile_photo', "profile_photo.{$ext}" );
update_user_meta( $user_id, 'register_profile_photo', "profile_photo.{$ext}" );
#unlink( $temp_image_path );
}
}
add_action( 'um_after_user_account_updated', 'um_registration_set_profile_photo', 1, 2 );
add_action( 'um_registration_set_extra_data', 'um_registration_set_profile_photo', 1, 2 );
/**
* Set Temporary user id
*/
function um_register_profile_photo_set_temp_user_id() {
$temp_profile_id = isset( $_COOKIE['um-register-profile-photo'] ) ? $_COOKIE['um-register-profile-photo'] : null;
if ( ! $temp_profile_id ) {
setcookie( 'um-register-profile-photo', md5( time() ), time() + 3600, COOKIEPATH, COOKIE_DOMAIN );
}
}
add_action( 'template_redirect', 'um_register_profile_photo_set_temp_user_id' );
/**
* Set handler callback for filename
*/
function um_register_profile_photo_upload_handler( $override_handler ) {
if ( 'stream_photo' == UM()->uploader()->upload_image_type && 'register_profile_photo' == UM()->uploader()->field_key ) {
$override_handler['unique_filename_callback'] = 'um_register_profile_photo_name';
}
return $override_handler;
}
add_filter( 'um_image_upload_handler_overrides__register_profile_photo', 'um_register_profile_photo_upload_handler', 99999 );
/**
* Change filename
*/
function um_register_profile_photo_name( $dir, $filename, $ext ) {
$temp_profile_id = isset( $_COOKIE['um-register-profile-photo'] ) ? $_COOKIE['um-register-profile-photo'] : null;
return "profile_photo_{$temp_profile_id}_temp{$ext}";
}
/**
* Support profile photo uploader in Account form
*/
function um_register_display_profile_photo_in_account( $field_atts, $key, $data ) {
if ( 'register_profile_photo' == $key && um_is_core_page( 'account' ) ) {
$profile_photo = UM()->uploader()->get_upload_base_url() . um_user( 'ID' ) . DIRECTORY_SEPARATOR . um_profile( 'profile_photo' ) . '?ts=' . current_time( 'timestamp' );
$field_atts['data-profile_photo'] = array( $profile_photo );
}
return $field_atts;
}
add_filter( 'um_field_extra_atts', 'um_register_display_profile_photo_in_account', 10, 3 );
/**
* Clear profile photo cache
*/
function um_register_display_profile_photo_script() {
if( ! um_is_core_page( 'account' ) ) return;
?>
<script type="text/javascript">
jQuery(document).on("ready", function(){
setTimeout(() => {
var register_profile_photo = jQuery("div[data-key='register_profile_photo']");
register_profile_photo.find(".um-field-area").find(".um-single-image-preview").find("img").attr("src", register_profile_photo.data("profile_photo"));
}, 1000);
var account_small_avatar = jQuery(".um-account-meta-img-b").find("a").find("img");
account_small_avatar.attr("src", account_small_avatar.attr("src") + "?ts=" + Math.floor(Date.now() / 1000) );
jQuery(document).ajaxSuccess(function(event, xhr, settings) {
if( typeof settings.data.indexOf !== "undefined" ){
if (settings.data.indexOf("action=um_resize_image") > -1) {
jQuery(".um-account .um-form form").submit();
}
}
});
});
</script>
<?php
}
add_action( 'wp_footer', 'um_register_display_profile_photo_script' );
/**
* Delete profile photo viam the account form
*/
function um_register_delete_profile_photo_from_account() {
if( isset( $_REQUEST['mode'] ) && "account" == $_REQUEST['mode'] ) {
UM()->files()->delete_core_user_photo( get_current_user_id(), 'profile_photo' );
}
wp_send_json_success();
}
add_action( 'wp_ajax_um_remove_file', 'um_register_delete_profile_photo_from_account', 1 );
When uploading the profile photo from the registration form with the 1:1 crop, it does not allow uploading a photo smaller than 600px, since it is not linked to the ultimate member settings.
This lock at 600px is located at line 1799 in the path ultimatemember/includes/core/class-fields.php
https://github.com/ultimatemember/ultimatemember/blob/master/includes/core/class-fields.php
if ( $array['min_width'] == '' && $array['crop'] == 1 ) {
$array['min_width'] = 600;
}
if ( $array['min_height'] == '' && $array['crop'] == 1 ) {
$array['min_height'] = 600;
}
if ( $array['min_width'] == '' && $array['crop'] == 3 ) {
$array['min_width'] = 600;
}
if ( $array['min_height'] == '' && $array['crop'] == 3 ) {
$array['min_height'] = 600;
Let's see if you can help me in the first code to unlock that 600px value and if you can, link it with the Ultimate Member profile photo settings.
Thank you very much for everything and greetings to the community.
I have a lot of posts which have a particular shortcode like [rest massage=""][/rest] and a text in between, and also the text is unique that mean in all the site its not used, only in this shortcode. the shortcode doesn't have any class or id assigned. now I want to assign a css class to it so that i can design it. how can i do it with php or jquery.
I founded this in the shortcode.php
function rcp_restrict_shortcode( $atts, $content = null ) {
$atts = shortcode_atts( array(
'userlevel' => 'none',
'message' => '',
'paid' => false,
'level' => 0,
'subscription' => ''
), $atts, 'restrict' );
global $rcp_options, $user_ID;
if ( strlen( $atts['message'] ) > 0 ) {
$teaser = $atts['message'];
} else {
$teaser = rcp_get_restricted_content_message( ! empty( $atts['paid'] ) );
}
$subscriptions = array_map( 'trim', explode( ',', $atts['subscription'] ) );
$has_access = false;
$classes = 'rcp_restricted';
$customer = rcp_get_customer(); // currently logged in customer
$is_active = rcp_user_has_active_membership();
$has_access_level = rcp_user_has_access( get_current_user_id(), $atts['level'] );
if( $atts['paid'] ) {
if ( rcp_user_has_paid_membership() && $has_access_level ) {
$has_access = true;
}
$classes = 'rcp_restricted rcp_paid_only';
} elseif ( $has_access_level ) {
$has_access = true;
}
if ( ! empty( $subscriptions ) && ! empty( $subscriptions[0] ) ) {
if ( $is_active && ! empty( $customer ) && count( array_intersect( rcp_get_customer_membership_level_ids( $customer->get_id() ), $subscriptions ) ) ) {
$has_access = true;
} else {
$has_access = false;
}
}
if ( $atts['userlevel'] === 'none' && ! is_user_logged_in() ) {
$has_access = false;
}
if( 'none' != $atts['userlevel'] ) {
$roles = array_map( 'trim', explode( ',', $atts['userlevel'] ) );
foreach ( $roles as $role ) {
if ( current_user_can( strtolower( $role ) ) ) {
$has_access = true;
break;
} else {
$has_access = false;
}
}
}
plz help.
I'm trying to change the function inside the handler class for uploading user image from front end using the the code which mostly works in situations like this one:
class Custom_Class extends Main_Class {
function __construct() {
remove_action('default_action', array($this));
add_action('new_action', array($this));
}
/* custom code from here on */
}
new Custom_Class
The goal is to change the $image->resize value to 320px, but I can not even remove the action, and the original code looks like this:
class UR_Form_Handler {
/**
* Hook in methods.
*/
public static function init() {
add_action( 'template_redirect', array( __CLASS__, 'redirect_reset_password_link' ) );
add_action( 'template_redirect', array( __CLASS__, 'save_profile_details' ) );
add_action( 'template_redirect', array( __CLASS__, 'save_change_password' ) );
add_action( 'wp_loaded', array( __CLASS__, 'process_login' ), 20 );
add_action( 'wp_loaded', array( __CLASS__, 'process_lost_password' ), 20 );
add_action( 'wp_loaded', array( __CLASS__, 'process_reset_password' ), 20 );
add_action( 'user_registration_before_customer_login_form', array( __CLASS__, 'export_confirmation_request' ) );
}
/**
* Save/update a profile fields if the form was submitted through the user account page.
*
* #return mixed
*/
public function save_profile_details() {
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
return;
}
if ( empty( $_POST['action'] ) || 'save_profile_details' !== $_POST['action'] || empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'save_profile_details' ) ) {
return;
}
$user_id = get_current_user_id();
if ( $user_id <= 0 ) {
return;
}
if ( has_action( 'uraf_profile_picture_buttons' ) ) {
if ( isset( $_POST['profile_pic_url'] ) && ! empty( $_POST['profile_pic_url'] ) ) {
update_user_meta( $user_id, 'user_registration_profile_pic_url', $_POST['profile_pic_url'] );
}
} else {
if ( isset( $_FILES['profile-pic'] ) && $_FILES['profile-pic']['size'] ) {
if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
$upload = $_FILES['profile-pic'];
$upload_overrides = array(
'action' => 'save_profile_details',
);
$uploaded = wp_handle_upload( $upload, $upload_overrides );
if ( $uploaded && ! isset( $uploaded['error'] ) ) {
$image = wp_get_image_editor( $uploaded['file'] );
if ( ! is_wp_error( $image ) ) {
$image->resize( 150, 150, true );
$image->save( $uploaded['file'] );
}
update_user_meta( $user_id, 'user_registration_profile_pic_url', $uploaded['url'] );
} else {
ur_add_notice( $uploaded['error'], 'error' );
}
} elseif ( UPLOAD_ERR_NO_FILE !== $_FILES['profile-pic']['error'] ) {
switch ( $_FILES['profile-pic']['error'] ) {
case UPLOAD_ERR_INI_SIZE:
ur_add_notice( __( 'File size exceed, please check your file size.', 'user-registration' ), 'error' );
break;
default:
ur_add_notice( __( 'Something went wrong while uploading, please contact your site administrator.', 'user-registration' ), 'error' );
break;
}
} elseif ( empty( $_POST['profile-pic-url'] ) ) {
$upload_dir = wp_upload_dir();
$profile_url = get_user_meta( $user_id, 'user_registration_profile_pic_url', true );
// Check if profile already set?
if ( $profile_url ) {
// Then delete file and user meta.
$profile_url = $upload_dir['basedir'] . explode( '/uploads', $profile_url )[1];
if ( ! empty( $profile_url ) && file_exists( $profile_url ) ) {
#unlink( $profile_url );
}
delete_user_meta( $user_id, 'user_registration_profile_pic_url' );
}
}
}
$form_id_array = get_user_meta( $user_id, 'ur_form_id' );
$form_id = 0;
if ( isset( $form_id_array[0] ) ) {
$form_id = $form_id_array[0];
}
$profile = user_registration_form_data( $user_id, $form_id );
foreach ( $profile as $key => $field ) {
if ( ! isset( $field['type'] ) ) {
$field['type'] = 'text';
}
// Get Value.
switch ( $field['type'] ) {
case 'checkbox':
if ( isset( $_POST[ $key ] ) && is_array( $_POST[ $key ] ) ) {
$_POST[ $key ] = $_POST[ $key ];
} else {
$_POST[ $key ] = (int) isset( $_POST[ $key ] );
}
break;
default:
$_POST[ $key ] = isset( $_POST[ $key ] ) ? ur_clean( $_POST[ $key ] ) : '';
break;
}
// Hook to allow modification of value.
$_POST[ $key ] = apply_filters( 'user_registration_process_myaccount_field_' . $key, $_POST[ $key ] );
$disabled = false;
if ( isset( $field['custom_attributes'] ) && isset( $field['custom_attributes']['readonly'] ) && isset( $field['custom_attributes']['disabled'] ) ) {
if ( 'readonly' === $field['custom_attributes']['readonly'] || 'disabled' === $field['custom_attributes']['disabled'] ) {
$disabled = true;
}
}
if ( ! empty( $_POST[ $key ] ) ) {
// Validation rules.
if ( ! empty( $field['validate'] ) && is_array( $field['validate'] ) ) {
foreach ( $field['validate'] as $rule ) {
switch ( $rule ) {
case 'email':
$_POST[ $key ] = strtolower( $_POST[ $key ] );
if ( ! is_email( $_POST[ $key ] ) ) {
ur_add_notice( sprintf( __( '%s is not a valid email address.', 'user-registration' ), '<strong>' . $field['label'] . '</strong>' ), 'error' );
}
break;
}
}
}
}
}// End foreach().
do_action( 'user_registration_after_save_profile_validation', $user_id, $profile );
if ( 0 === ur_notice_count( 'error' ) ) {
$user_data = array();
foreach ( $profile as $key => $field ) {
$new_key = str_replace( 'user_registration_', '', $key );
if ( in_array( $new_key, ur_get_user_table_fields() ) ) {
if ( $new_key === 'display_name' ) {
$user_data['display_name'] = $_POST[ $key ];
} else {
$user_data[ $new_key ] = $_POST[ $key ];
}
} else {
$update_key = $key;
if ( in_array( $new_key, ur_get_registered_user_meta_fields() ) ) {
$update_key = str_replace( 'user_', '', $new_key );
}
$disabled = isset( $field['custom_attributes']['disabled'] ) ? $field['custom_attributes']['disabled'] : '';
if ( $disabled !== 'disabled' ) {
update_user_meta( $user_id, $update_key, $_POST[ $key ] );
}
}
}
if ( count( $user_data ) > 0 ) {
$user_data['ID'] = get_current_user_id();
wp_update_user( $user_data );
}
do_action( 'user_registration_save_profile_details', $user_id, $form_id );
wp_safe_redirect( ur_get_endpoint_url( 'edit-profile', '', ur_get_page_permalink( 'myaccount' ) ) );
exit;
}
}
}
Either I get Fatal error: Cannot make static method UR_Form_Handler::save_profile_details() non static in class Custom_UR_Form_Handler, or the override doesn't work at all, I'm not sure if I'm even doing this the right way, maybe there's no need to override the entire function, but I'm stuck with this, any help or idea would be much appreciated, thanks.
I have some themes from WooThemes I bought about a year ago and now I'm getting around to using them. I keep getting the "illegal string offset" error. Code posted. Please advise. Thanks.
Error Messages:
Warning: Illegal string offset 'version' in C:\xampp\apps\wordpress\htdocs\wp-content\themes\flashnews\functions\admin-interface.php on line 1613
Warning: Illegal string offset 'version' in C:\xampp\apps\wordpress\htdocs\wp-content\themes\flashnews\functions\admin-interface.php on line 1659
Lines 1612 - 1659:
//Check if version is the latest - assume standard structure x.x.x
$pieces_rss = explode( '.', $latest_version_via_rss['version'] );
$pieces_local = explode( '.', $local_version );
//account for null values in second position x.2.x
if( isset( $pieces_rss[0] ) && $pieces_rss[0] != 0 ) {
if ( ! isset( $pieces_rss[1] ) )
$pieces_rss[1] = '0';
if ( ! isset( $pieces_local[1] ) )
$pieces_local[1] = '0';
//account for null values in third position x.x.3
if ( ! isset( $pieces_rss[2] ) )
$pieces_rss[2] = '0';
if ( ! isset( $pieces_local[2] ) )
$pieces_local[2] = '0';
//do the comparisons
$version_sentinel = false;
$status = 'bugfix';
// Setup update statuses
$statuses = array(
'new_version' => __( 'New Version', 'woothemes' ),
'new_feature' => __( 'New Feature', 'woothemes' ),
'bugfix' => __( 'Bugfix', 'woothemes' )
);
// New version
if ( $pieces_rss[0] > $pieces_local[0] ) {
$version_sentinel = true;
$status = 'new_version';
}
// New feature
if ( ( $pieces_rss[1] > $pieces_local[1] ) && ( $version_sentinel == false ) && ( $pieces_rss[0] == $pieces_local[0] ) ) {
$version_sentinel = true;
$status = 'new_feature';
}
// Bugfix
if ( ( $pieces_rss[2] > $pieces_local[2] ) && ( $version_sentinel == false ) && ( $pieces_rss[0] == $pieces_local[0] ) && ( $pieces_rss[1] == $pieces_local[1] ) ) {
$version_sentinel = true;
$status = 'bugfix';
}
return array( 'is_update' => $version_sentinel, 'version' => $latest_version_via_rss['version'], 'status' => $statuses[$status], 'theme_name' => $theme_name );
if ( !$bad_input ) {
$user_id = bb_new_user( $user_login, $_POST['user_email'], $_POST['user_url'] );
if ( is_wp_error( $user_id ) ) { // error
foreach ( $user_id->get_error_codes() as $code )
$bb_register_error->add( $code, $user_id->get_error_message( $code ) );
if ( $bb_register_error->get_error_message( 'user_login' ) )
$user_safe = false;
} elseif ( $user_id ) { // success
foreach( $profile_info_keys as $key => $label )
if ( strpos($key, 'user_') !== 0 && $$key !== '' )
bb_update_usermeta( $user_id, $key, $$key );
do_action('register_user', $user_id);
//HERE I WANT TO LOAD A HTML PAGE
exit;
} // else failure
}
I am trying to modify bbPress php file. This handles registration and I want to load another HTML file stored in local machine after user finish the registration.
include()
http://php.net/manual/en/function.include.php
Yep, try the old include function.
if ( !$bad_input ) {
$user_id = bb_new_user( $user_login, $_POST['user_email'], $_POST['user_url'] );
if ( is_wp_error( $user_id ) ) { // error
foreach ( $user_id->get_error_codes() as $code )
$bb_register_error->add( $code, $user_id->get_error_message( $code ) );
if ( $bb_register_error->get_error_message( 'user_login' ) )
$user_safe = false;
} elseif ( $user_id ) { // success
foreach( $profile_info_keys as $key => $label )
if ( strpos($key, 'user_') !== 0 && $$key !== '' )
bb_update_usermeta( $user_id, $key, $$key );
do_action('register_user', $user_id);
include('path/to/file.html');
exit;
} // else failure
}