New module added in SAK4WP

Posted by on Jul 25, 2014 in News, Tutorials | 0 comments

We've made another update to our Swiss Army Knife for WordPress (SAK4WP ) project. We've added a new module called PostMeta. The PostMeta module retrieves meta information for a given post/page or multiple posts, pages separated by comma. The search can also be done using post/page slug. The meta information also contains post and author info. Here is a demo. Do you use test/staging sites? Visit qSandbox for more...

Read More

How to Make an Ajax Request When Twitter Bootstrap Alert is Dismissed

Posted by on Jul 23, 2014 in Tutorials | 0 comments

How to Make an Ajax Request when Twitter Bootstrap Alert is Dismissed Twitter Bootstrap is an awesome CSS framework which speeds the UI development a lot. I worked on one of my products (qSandbox.com) this weekend. I wanted to notify the user that their account has been upgraded. I wanted the message to be shown in the control panel. That's in addition to the email confirmation. I save the user specific message in a folder and if that file exist it is shown to the user. The message will expire within 24hours but I wanted if the user dismissed the message so it is deleted. That way the user won't be bother with the message again. The project uses Twitter Bootstrap 3.x so I used the dismissible alert which when clicked makes an ajax request to remove the message. Here is a link to a working demo: https://gist.github.com/lordspace/d950dfbd81b4a7f7213a <?php echo 'Ok'; <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Example: How to Make an Ajax Request when Twitter Bootstrap Alert is Dismissed</title> <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!--[if lt IE 9]> <script src="//oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="//oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> <!-- Optional theme --> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" /> </head> <body> <div class="row"> <div class="col-md-6"> <h1>Hello, world!</h1> <div> This example code shows you how you can call JavaScript (ajax) when an alert is dismissed so you can make sure the message doesn't bug the user again. </div> <div> Here is a link to the <a href='http://slavi.ca/tutorials/make-ajax-request-twitter-bootstrap-alert-dismissed/' target='_blank'>blog post</a> </div> <br/> <div class="alert alert-warning alert-dismissible" role="alert" data-id="100" data-user_id="500"> <button type="button" class="close" data-dismiss="alert"> <span aria-hidden="true">&times;</span><span class="__sr-only">Close</span> </button> <strong>Warning!</strong> Start coding, you're missing the fun! </div> </div> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <!-- Latest compiled and minified JavaScript --> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script> $(document).ready(function($) { // This handles when the user clicks on an X button of an alert message. // We need to call ajax to make sure the message is deleted so it doesn't bug the user again. $('.alert-dismissible').bind('closed.bs.alert', function () { var id = $(this).data('id') || 0; var user_id = $(this).data('user_id') || 0; $.get('ajax.php?cmd=dismiss_alert&user_id=' + escape(user_id) + '&id=' + escape(id)); }); }); </script> </body> </html> Related http://stackoverflow.com/questions/17128665/ajax-request-on-dismissal-of-twitter-bootstrap-alerts     Do you use test/staging sites? Visit qSandbox for more...

Read More

How to Map an Associative Array to HTML Element (Data) Attributes?

Posted by on Jul 21, 2014 in Tutorials | 0 comments

If you're a developer (you are reading this so you are) you've used jQuery to access different elements from a page. It is super convenient to set data attributes to given HTML elements. For example: You can use jQuery to loop through all of the containers with 'app_container' class but how are you going to tell which one you're currently processing? yes, you can use element's ID for that but if we want to put more data into that element we can achieve id using data attributes which can be accessed like so: var id = $('app_container').prop('id'); var type = $('app_container').data('type'); Here is a PHP class that allows you to create HTML attributes from a php array. If you pass the second parameter the key will be prefixed with 'data-' prefix so they can be access via jQuery later. Here is a link to the gist: https://gist.github.com/lordspace/fcc733e7e2a53ef427c3 Class HTML_Util { /** * Usage: HTML_Util::array2attribs(); * @param array $attributes * @param bool $make_them_data will prefix each key with 'data-' prefix so it's acessible via $('#elem').data(); * @return string * @see http://stackoverflow.com/questions/18081625/how-do-i-map-an-associative-array-to-html-element-attributes */ public static function array2attribs($attributes = array(), $make_them_data = 0) { $pairs = array(); foreach ($attributes as $name => $value) { if ($make_them_data) { $name = 'data-' . $name; // prefix the keys with data- prefix so it's accessible later. } $name = htmlentities($name, ENT_QUOTES, 'UTF-8'); $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); if (is_bool($value)) { if ($value) { $pairs[] = $name; } } else { $pairs[] = sprintf('%s="%s"', $name, $value); } } return join(' ', $pairs); }...

Read More

This version of Evernote Web Clipper is no longer compatible with Evernote Service

Posted by on Jul 20, 2014 in Tutorials | 0 comments

Today I opened my chrome browser and was greeted by an annoying alert box from Evernote's Web Clipper Google Chrome Extension. I've tried clicking OK and also ticking the "Prevent this page from creating additional dialogs" checkbox but still no success. I had to simultaneously be pressing ESC key and right clicking on the Web Cliper's icon. I created a video how to remove Evernote's Web Clipper from Chrome while seeing error: "This version of Evernote Web Clipper is no longer compatible with Evernote Service"...

Read More

How to Hook into Contact Form 7 WordPress Plugin Before Sending an Email

Posted by on Jul 3, 2014 in Howto, Tutorials, Web Development | 0 comments

Great WordPress plugins allow other developers to easily hook into their functionality without modifying the original plugin's source code. This is very important because any future plugin updates will override your changes   One of the hooks you'd want to hook into is wpcf7_mail_components filter. It receives 2 parameters that you can read and modify. The first one is an associative array with keys such as 'subject', 'body' (shown below), and a form obj. You must return the $mail_params array.   add_filter( 'wpcf7_mail_components', 'app_100_handle_cf7_mail_components', 50, 2 ); function app_100_handle_cf7_mail_components($mail_params, $form = null) { return $mail_params; } The filter is located in: wp-content/plugins/contact-form-7/includes/classes.php The $mail_params looks like this. array ( 'subject' => 'Test', 'sender' => ':)', 'body' => ':) -- This e-mail was sent from a contact form on My Sandbox Site (http://orbutm.qsandbox.com) ----------------------------------------------------- Orbisius UTM Total Visit(s): 3 ', 'recipient' => 'whatever_recipient@isconfigured.com', 'additional_headers' => '', 'attachments' => array ( ), ) the $form looks like this. WPCF7_ContactForm::__set_state(array( 'initial' => false, 'id' => 10, 'name' => 'contact-form-1', 'title' => 'Contact form 1', 'unit_tag' => NULL, 'responses_count' => 0, 'scanned_form_tags' => array ( 0 => array ( 'type' => 'text*', 'basetype' => 'text', 'name' => 'your-name', 'options' => array ( ), 'raw_values' => array ( ), 'values' => array ( ), 'pipes' => WPCF7_Pipes::__set_state(array( 'pipes' => array ( ), )), 'labels' => array ( ), 'attr' => '', 'content' => '', ), 1 => array ( 'type' => 'submit', 'basetype' => 'submit', 'name' => '', 'options' => array ( ), 'raw_values' => array ( 0 => 'Send', ), 'values' => array ( 0 => 'Send', ), 'pipes' => WPCF7_Pipes::__set_state(array( 'pipes' => array ( 0 => WPCF7_Pipe::__set_state(array( 'before' => 'Send', 'after' => 'Send', )), ), )), 'labels' => array ( 0 => 'Send', ), 'attr' => '', 'content' => '', ), ), 'posted_data' => array ( '_wpcf7' => '10', '_wpcf7_version' => '3.8.1', '_wpcf7_locale' => 'en_US', '_wpcf7_unit_tag' => 'wpcf7-f10-p11-o1', '_wpnonce' => '09572933d3', 'your-name' => ':)', '_wpcf7_is_ajax_call' => '1', ), 'uploaded_files' => array ( ), 'skip_mail' => false, 'form' => 'Your Name (required) [text* your-name] [submit "Send"]', 'mail' => array ( 'subject' => 'Test', 'sender' => '[your-name]', 'body' => '[your-name] -- This e-mail was sent from a contact form on My Sandbox Site (http://orbutm.qsandbox.com)', 'recipient' => 'whatever_recipient@isconfigured.com', 'additional_headers' => '', 'attachments' => '', 'use_html' => false, ), 'mail_2' => array ( 'active' => false, 'subject' => '[your-subject]', 'sender' => '[your-name] ', 'body' => 'Message Body: [your-message] -- This e-mail was sent from a contact form on My Sandbox Site (http://orbutm.qsandbox.com)', 'recipient' => '[your-email]', 'additional_headers' => '', 'attachments' => '', 'use_html' => false, ), 'messages' => array ( 'mail_sent_ok' => 'Your message was sent successfully. Thanks.', 'mail_sent_ng' => 'Failed to send your message. Please try...

Read More