Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Tuesday, September 06, 2016

Vital WordPress Questions and Answers

  1. Consider the following code snippet. Briefly explain what changes it will achieve, who can and cannot view its effects, and at what URL WordPress will make it available.
add_action('admin_menu', 'custom_menu');

function custom_menu(){
    add_menu_page('Custom Menu', 'Custom Menu', 'manage_options', 'custom-menu-slug', 'custom_menu_page_display');
}

function custom_menu_page_display(){
    echo '<h1>Hello World</h1>';
    echo '<p>This is a custom page</p>';
}
With default settings and roles, admins can view it and all lower roles can’t. In fact this menu item will only be visible to users who have the privilege to “manage options” or change settings from WordPress admin dashboard.
The admin custom page will be made available at this (relative) URL: “?page=custom-menu-slug”.
 
2. How would you change all the occurrences of “Hello” into “Good Morning” in post/page contents, when viewed before 11AM?
In a plugin or in theme functions file, we must create a function that takes text as input, changes it as needed, and returns it. This function must be added as a filter for “the_content”.
It’s important that we put a little effort to address some details:
  • Only change when we have the full isolate substring “hello”. This will prevent words like “Schellong” from becoming “sgood morningng”. To do that we must use “word boundary” anchors in regular expression, putting the word between a pair of “\b”.
  • Keep consistency with the letter case. An easy way to do that is to make the replace case sensitive.
<?php
function replace_hello($the_content){
    if(current_time('G')<=10){
        $the_content=preg_replace('/\bhello\b/','good morning',$the_content);
        $the_content=preg_replace('/\bHello\b/','Good Morning',$the_content);
    }
    return $the_content;
}
add_filter('the_content', 'replace_hello');
 
3. What is the $wpdb variable in WordPress, and how can you use it to improve the following code?
<?php
function perform_database_action(){
    mysql_query(“INSERT into table_name (col1, col2, col3) VALUES ('$value1','$value2', '$value3');
}
 
$wpdb is a global variable that contains the WordPress database object. It can be used to perform custom database actions on the WordPress database. It provides the safest means for interacting with the WordPress database.
The code above doesn’t follow WordPress best practices which strongly discourages the use of anymysql_query call. WordPress provides easier and safer solutions through $wpdb.
The above code can be modified to be as follows:
<?php
function perform_database_action(){
    global $wpdb;
    $data= array('col1'=>$value1,'col2'=>$value2,'col3'=>$value3);
    $format = array('%s','%s','%s');
    $wpdb->insert('table_name', $data, $format);
}
add_custom_script();
function add_custom_script(){
    wp_enqueue_script( 
        'jquery-custom-script',
        plugin_dir_url( __FILE__ ).'js/jquery-custom-script.js'
    );
}
 
wp_enqueue_script is usually used to inject javascript files in HTML.
The script we are trying to queue will not be added, because “add_custom_script()” is called with no hooks. To make this work properly we must use the wp_enqueue_scripts hook. Some other hooks will also work such as initwp_print_scripts, and wp_head.
Furthermore, since the script seems to be dependent on jQuery, it’s recommended to declare it as such by adding array(‘jquery’) as the 3rd parameter.

Proper use:

add_action(‘wp_enqueue_scripts’, ‘add_custom_script’);
function add_custom_script(){
    wp_enqueue_script( 
        'jquery-custom-script',
        plugin_dir_url( __FILE__ ).'js/jquery-custom-script.js',
        array( 'jquery')
    );
}
 
5. Assuming we have a file named “wp-content/plugins/hello-world.php” with the following content. What is this missing to be called a plugin and run properly?
<?php
add_filter('the_content', 'hello_world');
function hello_world($content){
    return $content . "<h1> Hello World </h1>";
}
 
The file is missing the plugin headers. Every plugin should include at least the plugin name in the header with the following syntax:
<?php
/*
Plugin Name: My hello world plugin
*/
 
6. What is a potential problem in the following snippet of code from a WordPress theme file named “footer.php”?
...
        </section><!—end of body section- ->
        <footer>All rights reserved</footer>
    </body>
</html>
 
All footer files must call the <?php wp_footer() ?> function, ideally right before the</body>tag. This will insert references to all scripts and stylesheets that have been added by plugins, themes, and WordPress itself to the footer.
 
7. What is this code for? How can the end user use it?
function new_shortcode($atts, $content = null) {
    extract(shortcode_atts(array(
        “type” => “warning”
    ), $atts));
    return '
‘.$content.’
';
}
add_shortcode(“warning_box”, “new_shortcode”);
This shortcode allows authors to show an info box in posts or pages where the shortcode itself is added. The HTML code generated is a div with a class name “alert” plus an extra class name by default, “alert-warning”. A parameter can change this second class to change the visual aspect of the alert box.
Those class naming structures are compatible with Bootstrap.
To use this shortcode, the user has to insert the following code within the body of a post or a page:
[warning_box]Warning message[/warning_box]
 
8. Is WordPress safe from brute force login attempts? If not, how can you prevent such an attack vector?
No, WordPress on its own is vulnerable to brute force login attempts.
Some good examples of actions performed to protect a WordPress installation against brute force are:
  • Do not use the “admin” username, and use strong passwords.
  • Password protect “wp-login.php”.
  • Set up some server-side protections (IP-based restrictions, firewall, Apache/Nginx modules, etc.)
  • Install a plugin to add a captcha, or limit login attempts.
 
9. The following line is in a function inside a theme’s “function.php” file. What is wrong with this line of code?
wp_enqueue_script('custom-script', '/js/functions.js');
Assuming that “functions.js” file is in the theme’s “js/” folder, we should use‘get_template_directory_uri()’. '/js/functions.js' or the visitors’ browser will look for the file in the root directory of the website.
 
10. Suppose you have a non-WordPress PHP website with a WordPress instance in the “/blog/” folder. How can you show a list of the last 3 posts in your non-WordPress pages?
One obvious way is to download, parse, and cache the blog’s RSS feeds. However, since the blog and the website are on the same server, you can use all the WordPress power, even outside it.
The first thing to do is to include the “wp-load.php” file. After which you will be able to perform any WP_Query and use any WordPress function such as get_posts,wp_get_recent_posts,query_posts, and so on.
<?php
    require_once('../blog/wp-load.php');
?>
<h2>Recent Posts</h2>
<ul>
<?php
    $recent_posts = wp_get_recent_posts(array(‘numberposts’=>3));
    foreach($recent_posts as $recent){
        echo '<li><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a></li> ';
    }
?>
</ul>

Source: Toptal

Friday, October 23, 2015

Job profiles requirement - Kapil Sharma


Job profiles requirement. 

1). Job Title: Business Analyst 
Job Code: 102015/BA/03
Job Type: Full Time
Job Location: Panchkula/Chandigarh
Experience: Minimum 4+ years’ experience in business analyst role in software domain.
Required Skills:
  • Responsible for system study, requirement gathering, analysis, designing and UAT for project.
  • Managing documentation including SRS, FRS, BRS and writing use cases, help files, user manuals and also performing functional testing.
  • Requirements understanding and system impact analysis, business plan creation and execution.
  • Involved in different activities of project such as information meetings and analysing them.
  • Ensure quality procedures related to the project such as creating BA-Standard Operation Procedure.
  • Regular calls with the onsite team for the status of the work.
  • Interaction with client technical team to ensure that requirements are clear.
  • Coordinated, managed activities within the projects and capture meeting minutes.
  • Proficient with designing and prototyping tools like Mockflow.
  • Mapping business case requirements and work with QA teams.
  
2). Job Title: Sr. PHP Developer 
Job Code: 102015/PHP/01
Job Type: Full Time
Job Location: Panchkula/Chandigarh

Experience: Minimum 4+ years’ experience in coding web based applications in PHP.

Required Skills:
  • Strong concepts working with Object Oriented Programming.
  • Experience working with latest social networking technologies.
  • Ability to write W3C standards compliant, cross browser compatible (Chrome, IE8+, Firefox)
  • Front-end mark-up in HTML/CSS/AJAX/JQuery & JSON
  • Can work with a number of MVC frameworks and write strong, scalable code.
  • Ability to write and performance optimize SQL queries for MySQL (NoSQL a plus)
  • Mobile application development a big plus. (iPhone, Android)
  • Strong work ethic and ability to construct complex projects quickly.
  • An ardent problem-solver.
  • Experience in programming APIs.
  • CMS (Joomla) experience is must, any other CMS exp. is plus
  • Working knowledge of AngularJS is a plus.
Note: Candidate Must have CMS Knowledge mainly in (Joomla, WordPress). 


3). Job Title: PHP Developer 
Job Code: 102015/PHP/02
Job Type: Full Time
Job Location: Panchkula/Chandigarh

Experience: Minimum 2+ years’ experience in coding web based applications in PHP.

Required Skills:
  • Min. 2+ years’ experience coding web based applications in PHP.
  • Strong concepts working with Object Oriented Programming.
  • Experience working with latest social networking technologies.
  • Ability to write W3C standards compliant, cross browser compatible (Firefox, IE8+, Chrome).
  • Front-end mark-up in HTML/CSS/JQuery/JSON.
  • Can work with a number of MVC frameworks and write strong, scalable code
  • Ability to write and performance optimize SQL queries for MySQL
  • Experience in programming APIs
  • Strong work ethic and ability to construct complex projects quickly.
  • An ardent problem-solver. • CMS knowledge is an advantage.
4). Job Title: UI Designer 
Job Code: 102015/UI/04
Job Type: Full Time
Job Location: Panchkula/Chandigarh

Experience: Minimum 2+ years of experience in as a Web / Mobile user interface designer.

 Required Skills:
  • Create impactful power point / word reports from a look and feel / design aspect.
  • Conceptualizing, designing and prototyping new features for our product.
  • Proficient with designing and prototyping tools must. (Photoshop / Illustrator)
  • Deep understanding of typography, colour schemes, platforms and layouts.
  • Front-end programming skills. (Desirable, HTML, CSS, JQuery)
  • Experience working with web responsive design.
  • Ability to work independently, meet strict deadlines and manage client requests with different requirements/specifications.
  • Please include links to your portfolio or attach it along with your resume.

Intrested candidate send there resume with subject code@: careers@hkcl.in

The USB-C Moment for AI: A Student’s Guide to the Model Context Protocol (MCP)

  The USB-C Moment for AI: A Student’s Guide to the Model Context Protocol (MCP) In the rapidly evolving world of Artificial Intelligence, ...