How to use file upload option in WooCommerce payment gateway admin options? - wordpress

I am developing a plugin to integrate a payment gateway in WooCommerce. I have done one before.
But in this one, I need to upload a key file in gateway settings and that is used to hash the data before making payment request to related portal.
I have following code which allows to choose file, but I doubt this is working in the back end.
'sandbox_pvt_key' => array(
'title' => __( 'Test Private Key', 'woocommerce-custom-gateway' ),
'type' => 'file',
'desc_tip' => true,
'description' => __( 'Please upload the test private key file; this is needed in order to test payment.', 'woocommerce-custom-gateway' ),
'default' => '',
),
The output looks like the following:
Can anybody lemme know if this is supported option in the gateway settings? If not, can anybody guide me on how I can customize it via some hook/filters or any other way.

This can be achieved in the process_admin_options()
public function process_admin_options() {
$this->upload_key_files();
$saved = parent::process_admin_options();
return $saved;
}
private function upload_key_files() {
//handle uploads here
}

Related

Drupal 7 Migrate Module shows "No migration groups defined". Why is my Migration Class not registering?

I am trying to migrate content (at this point user accounts specifically) from a legacy site into Drupal 7 using the Drupal Migrate module but for some reason the custom site migration class is not being registered. The only indication that something is wrong is the lack of any output when running drush migrate-status, and the output "No migration groups defined" when visiting http://<drupal_root_url>/admin/content/migrate in a web browser. The migrate, migrate_ui, and pinpics_migration modules have all been enabled via the Drupal 7 admin dashboard. I have tried using drush to clear all caches and register the migration classes, as well as registering the migration classes using the web UI to no avail. drush was run from the folder with the settings.php file /<drupal_root_path>/sites/default/
drush cc all && drush migrate-register && drush migrate-status
I have the following files located in
/<drupal_root_path>/sites/all/modules/custom/pinpics_migration/
pinpics_migration.info
pinpics_migration.migrate.inc
pinpics_migration.module
I have tried placing the file containing the custom migration class implementation pinpics_users.inc in the same directory as the files above, as well as in:
/<drupal_root_path>/includes/
Here are the file contents:
pinpics_migration.info:
<?php
name = "Pinpics Migration"
description = "Module to migrate legacy site to Drupal 7 site"
package = "Migration"
core = 7.x
dependencies[] = migrate
files[] = pinpics_migration.module
files[] = pinpics_users.inc
?>
pinpics_migration.migrate.inc:
<?php
function pinpics_migration_migrate_api() {
$api = array( 'api' => 2 );
return $api;
}
?>
pinpics_migration.module:
<?php
define("SOURCE_DATABASE", "pinpics_db");
?>
pinpics_users.inc: (Stripped of some helper functions, and specific implementation details)
<?php
/// Stripped some helper functions that were used by pinpicsUserMigration::prepareRow() below
class pinpicsUserMigration extends Migration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('user_migration_group'));
$this->description = t('Migrate pinpics.com users');
$source_fields = array(
'uid' => t('User ID'),
'roles' => t('The set of roles assigned to a user.'),
'password' => t('MD5 hash of User Password'),
'email' => t('User email address'),
'name' => t('Username'),
'created' => t('Timestamp that legacy account was created.'),
'status' => t('The staus of the User account'),
'logintime' => t('Timestamp that the User last logged in.')
);
$query = db_select(SOURCE_DATABASE.'.users', 'u')
->fields('u', array('uid', 'roles', 'password', 'email', 'name', 'created', 'logintime', 'status'))
->condition('status', '0', '=')
->condition('inactive', '0', '=')
->condition('email', '', '<>')
->condition('loginip', '', '<>')
->orderBy('uid', 'ASC');
$this->source = new MigrateSourceSQL($query, $source_fields);
$this->destination = new MigrateDestinationUser(array('md5_passwords' => TRUE));
$this->map = new MigrateSQLMap($this->machineName,
array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'non null' => TRUE,
'description' => 'Legacy Unique User ID',
'alias' => 'u',
)
),
MigrateDestinationUser::getKeySchema()
);
$this->addFieldMapping('uid', 'uid');
$this->addFieldMapping('name', 'name');
$this->addFieldMapping('pass', 'password');
/// Many addFieldMapping() statement stripped out for brevity.
}
public function prepareRow($current_row) {
/// Stripped implementation details for massaging data to prepare for Drupal 7.
return TRUE;
}
}
?>
I am new to Drupal, and have been using the following references to implement the migration.
Drupal 6 to Drupal 7 via Migrate 2
Getting started with Migrate
Has anyone encountered this problem before, or know how to go about finding out what is wrong?
Try these steps:
Visit your sites modules page /admin/modules to trigger rebuilding of cached PHP.
Disable and enable your module to get a new class registered.

Facebook Posting using FB API phpSDK

i created my app on fb with permissions ready to publish on users behalf, the thing is, a regular post has Like and Comment links, like buttons on bottom of the post, i want to add my custom link : VOTE NOW, its a poll post
how can i do that?
someone gave an answer but for js sdk not php, n i cant find it on facebook dev documentation
some gave a close enough solution, but ddnt seem to work on php with modifications
FB.ui({
method: "feed",
link: "LINK_URL",
...
actions: [
{ name: "Read Now", link: "URL TO THE READ NOW " }
]
}, function(response) { console.log(response); });
It seems it's working with /me/feed but with my custom /me/xxxxxx:submitted_a_poll/ its not working
When you make a call with the PHP SDK, you also pass a similar set of parameters:
$attachment = array(
'link' => 'http://your-cool-site.com',
'description' => 'This is the description',
...
'actions' => array(
array(
'name' => 'Vote Now!',
'link' => 'http://your-cool-site.com/vote.php'
)
)
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
All you really have to do is add the relevant action settings to your parameters.

Creating a delete confirmation for images using the Wordpress meta box plugin

I am using the Meta Box plugin for Wordpress. I can successfully create fields in the cms for users to upload images. I would like to extend this in two ways:
First, I would like a delete confirmation when users remove an image from the image gallery
Here is the code:
$meta_boxes[] = array(
'id' => 'project_media',
'title' => 'Project Media',
'pages' => array( 'project' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Media Gallery',
'desc' => 'Images should be sized to 983px x 661px',
'id' => $prefix . 'project_media_gallery',
'type' => 'image'
)
);
This creates upload functionality in the custom post type where users can add images to a slideshow. The problem is if the user accidentally clicks the delete button, there is no confirmation to make sure it is deleted. Can I somehow extend the plugin through functions and call an alert when this button is clicked? Something that does not involve editing the WP core?
Second, the base functionality requires the user to upload an image from their local machine. Is there a way to tap into the Media Library for this?
No idea how to even start tackling this one.
To answer the first question
First, I would like a delete confirmation when users remove an image from the image gallery
You can do that by calling a custom script file from the functions.php.
function alert_delete() {
if(is_admin()){
wp_register_script( 'alert_delete', get_bloginfo('template_url'). '/js/alert_delete.js', array('jquery'));
wp_enqueue_script('alert_delete');
}
}
and create a file named alert_delete.js in the js directory of your theme.
alert_delete.js:
// admin delete check
jQuery(document).ready(function(){
jQuery(".rwmb-delete-file").click(function() {
if (!confirm("Are you sure? This process cannot be undone.")){
return false;
}
});
});
In response to the second question...
Second, the base functionality requires the user to upload an image
from their local machine. Is there a way to tap into the Media Library
for this?
Get the latest version of the Meta Box Plugin first.
then change
'type' => 'image'
to
'type' => 'image_advanced'
which will allow you to upload from the existing Media Gallery or a new file from your computer.

Edit mail.inc to enable SMTP server for sending mail

i want to place the following codes into include/mail.inc of Drupal7 so that i can send mail from SourceForge's project web space. Don't ask me to install SMTP Authentication Support, and i don't have access to php.ini , I wonder where should these codes be placed? Thanks in advance!
include('Mail.php');
$recipients = array( 'someone#example.com' ); # Can be one or more emails
$headers = array (
'From' => 'someone#example.com',
'To' => join(', ', $recipients),
'Subject' => 'Testing email from project web',
);
$body = "This was sent via php from project web!\n";
$mail_object =& Mail::factory('smtp',
array(
'host' => 'prwebmail',
'auth' => true,
'username' => 'YOUR_PROJECT_NAME',
'password' => 'PASSWORD', # As set on your project's config page
#'debug' => true, # uncomment to enable debugging
));
$mail_object->send($recipients, $headers, $body);
if this code could success send email without drupal7 (you must make sure it)
then you could do it in three ways:
write a drupal 7 module ,copy mail.php into *.module, and make the rest code as a function,that's the way as the handbook of drupal.
just copy all of the code to you theme/page.tpl.php , and run it directly , a little dirty
hack drupal core , include/mail.inc , just change function drupal_mail_send

Please Explain Drupal schema and drupal_write_record

1) Where is the best place to populate a new database table when a module is first installed, enabled? I need to go and get some data from an external source and want to do it transparently when the user installs/enables my custom module.
I create the schema in {mymodule}_schema(), do drupal_install_schema({tablename}); in hook_install. Then I try to populate the table in hook_enable using drupal_write_record.
I confirmed the table was created, I get no errors when hook_enable executes, but when I query the new table, I get no rows back--it's empty.
Here's one variation of the code I've tried:
/**
* Implementation of hook_schema()
*/
function ncbi_subsites_schema() {
// we know it's MYSQL, so no need to check
$schema['ncbi_subsites_sites'] = array(
'description' => 'The base table for subsites',
'fields' => array(
'site_id' => array(
'description' => 'Primary id for site',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), // end site_id
'title' => array(
'description' => 'The title of the subsite',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
), //end title field
'url' => array(
'description' => 'The URL of the subsite in Production',
'type' => 'varchar',
'length' => 255,
'default' => '',
), //end url field
), //end fields
'unique keys' => array(
'site_id'=> array('site_id'),
'title' => array('title'),
), //end unique keys
'primary_key' => array('site_id'),
); // end schema
return $schema;
}
Here's hook_install:
function ncbi_subsites_install() {
drupal_install_schema('ncbi_subsites');
}
Here's hook_enable:
function ncbi_subsites_enable() {
drupal_get_schema('ncbi_subsites_site');
// my helper function to get data for table (not shown)
$subsites = ncbi_subsites_get_subsites();
foreach( $subsites as $name=>$attrs ) {
$record = new stdClass();
$record->title = $name;
$record->url = $attrs['homepage'];
drupal_write_record( 'ncbi_subsites_sites', $record );
}
}
Can someone tell me what I'm missing?
If ncbi_subsites_get_subsites() is not in the .install file, you need to include whatever file its in with your module. Otherwise, it's returning nothing, in which case try dumping $subsites and exiting.
I think the answer is that drupal_write_record is not meant for install or enable hooks. I think when enabling or installing, you have to write SQL. That is the impression I am getting from reading some posts that mention that the schema is not available in these hooks.
First of all (assuming Drupal 6), drupal_write_record() cannot be called from hook_install() because Drupal would not find the database schema defined from the module, which is still going to be installed, and enabled.
Instead you need to use db_query() function. (the comments are speaking of a way to include default data by prviding it to hook_schema() serialized, but i've found no documentation on this.)
However, would you be using (the development version of) Drupal 7, you want to look at the db_insert() function instead.

Resources