Before going to into the details of WordPress Coding Standards, you need to know the purpose of the coding standards & why you need to have coding standards.
In this blog, we will focus on part 1 – WordPress Coding Standards For PHP & HTML and in the next blog, we will focus on part 2 – WordPress Coding Standards For CSS & JS.
PHP is one of the simplest server-side languages out there, and it was designed primarily for web development. Learning PHP is good not only because it adds ...
PHP string function helps us to manipulate string in various ways. There are various types of string function available. Here we discuss some important functions and its use with examples.
The slides for introducing Python to beginner. This is a complimentary class made in Wekanta's Soft Launch in Universities within Malaysia.
Slides Overview:
• Python Background
• Syntax
• Variables
• Data Structure
• Comparison
• Control Flow
• Function
PHP is one of the simplest server-side languages out there, and it was designed primarily for web development. Learning PHP is good not only because it adds ...
PHP string function helps us to manipulate string in various ways. There are various types of string function available. Here we discuss some important functions and its use with examples.
The slides for introducing Python to beginner. This is a complimentary class made in Wekanta's Soft Launch in Universities within Malaysia.
Slides Overview:
• Python Background
• Syntax
• Variables
• Data Structure
• Comparison
• Control Flow
• Function
TOPS Technologies provides PHP training in Ahmedabad, for MCA Students PHP live project training as per GTU project guidelines. Get more info @ http://www.tops-int.com/, 903 Samedh Complex, Next to Associated Petrol Pump, CG Road, Ahmedabad 380009.
Covered some of the Best Practices.
Reference:
http://www.brandonsavage.net/essential-ini-settings/
http://shiflett.org/blog/2005/feb/my-top-two-php-security-practices
http://www.php.net/manual/en/security.php
Securing IoT Data With Blockchain - A New Age InnovationeSparkBiz
Everyone has heard all of the terms such as blockchain, security, secure IoT data, cryptocurrency, etc. But the popularity of these technologies has been on the rise and will continue to be an issue in the future. But, how can blockchain help secure IoT data? Blockchain was earlier associated only with cryptocurrencies. Now blockchain technology is being used for many purposes.
Part 2 in depth guide on word-press coding standards for css & js bigeSparkBiz
Every programming language has its own coding standards which need to be followed by any WordPress Development Company in order to enhance the readability of the code. The same is the case with WordPress, where there are coding standards for PHP, HTML, CSS & JS.
Here, we have tried to provide you with an in-depth guide on WordPress Coding Standards For CSS & JS which will help you in future when you’re working with WordPress.
12 innovative ways to utilize forms on word press websiteeSparkBiz
There are many ways through which forms can be used on your WordPress website in order to grow your business. In this blog, we’re going to provide you with a list of 12 such innovative ways through which you can use the form in an effective manner.
13 Misunderstanding about HubSpot COS Development Platform & HubSpot COS Temp...eSparkBiz
Choose the Perfect HubSpot COS Templates for your business can not only save you a lot of time and improve your ROI but also attract more customers.
COS models are ideal for those who have less experience with the developers. The HubSpot editor allows creation and customization. If you want to deepen, design certification course is excellent.
The best method that helps HubSpot website designer to be expert in hubspot coseSparkBiz
HubSpot Website Designer helps to get best results in Hubspot COS Web designing site, letting you focus on your marketing content and performance, not on cobbling together different tools.
The developer of HubSpot cos has recently gained a great name and fame in the design and development of a program on the new COS system and has launched our website reactive in the new content optimization platform. Learn more about our custom COS web development.
Let eSparkBiz develop your new Hubspot COS website. From web design to COS web development, we have the expertise you need at affordable rate as per you want.
Website redesign process | Website Design & Development Company in USAeSparkBiz
Our guide of things to consider before you plan to redesign your website with Website Design Company . Website Re-Design is a Process to promote success for your business with Targeted Customers and Improve ROI
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
Welcome to the first live UiPath Community Day Dubai! Join us for this unique occasion to meet our local and global UiPath Community and leaders. You will get a full view of the MEA region's automation landscape and the AI Powered automation technology capabilities of UiPath. Also, hosted by our local partners Marc Ellis, you will enjoy a half-day packed with industry insights and automation peers networking.
📕 Curious on our agenda? Wait no more!
10:00 Welcome note - UiPath Community in Dubai
Lovely Sinha, UiPath Community Chapter Leader, UiPath MVPx3, Hyper-automation Consultant, First Abu Dhabi Bank
10:20 A UiPath cross-region MEA overview
Ashraf El Zarka, VP and Managing Director MEA, UiPath
10:35: Customer Success Journey
Deepthi Deepak, Head of Intelligent Automation CoE, First Abu Dhabi Bank
11:15 The UiPath approach to GenAI with our three principles: improve accuracy, supercharge productivity, and automate more
Boris Krumrey, Global VP, Automation Innovation, UiPath
12:15 To discover how Marc Ellis leverages tech-driven solutions in recruitment and managed services.
Brendan Lingam, Director of Sales and Business Development, Marc Ellis
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfPeter Spielvogel
Building better applications for business users with SAP Fiori.
• What is SAP Fiori and why it matters to you
• How a better user experience drives measurable business benefits
• How to get started with SAP Fiori today
• How SAP Fiori elements accelerates application development
• How SAP Build Code includes SAP Fiori tools and other generative artificial intelligence capabilities
• How SAP Fiori paves the way for using AI in SAP apps
In-Depth Guide On WordPress Coding Standards For PHP & HTML
1. In-Depth Guide On WordPress Coding Standards For
PHP, HTML
“ANY FOOL CAN WRITE A CODE THAT COMPUTER CAN UNDERSTAND. GOOD
PROGRAMMERS WRITE CODE THAT HUMAN CAN UNDERSTAND.”
- JOHN JOHNSON
This quote is good enough to understand the importance of standards as far as the coding is
concerned. Every programming language has its own rules and regulations for the coding which is
also known as the coding standards.
Each programmer should follow these coding standards in order to inherit the best practices in
his/her professional career. Coding standards are not the syntax that strictly needs to be followed,
they are more of coding conventions that if followed by the programmer can help them to enhance
their coding style.
The same applies to the case of WordPress where it has its own coding standards which every
developer should have the knowledge of. Taking this into consideration, we have developed a
two-part series on WordPress Coding Standards which will help you to know the coding standards
for PHP, HTML, CSS, & JS.
Here’s how we will progress right through the WordPress Coding Standards series:
2. Part 1: In-Depth Guide On WordPress Coding Standards For PHP & HTML
Part 2: In-Depth Guide On WordPress Coding Standards For CSS & JS
In this blog, we will focus on part 1 - WordPress Coding Standards For PHP & HTML and in the
next blog, we will focus on part 2 - WordPress Coding Standards For CSS & JS.
Before going to into the details of WordPress Coding Standards, you need to know the purpose of
the coding standards & why you need to have coding standards.
What Is The Purpose Of WordPress Coding Standards?
The sole purpose of the WordPress Coding Standards is to create a base for collaboration and
review within the various aspects of WordPress open-source project & community right from the
core part to the themes and plugins.
Why You Need Coding Standards?
Coding standards help you to avoid common errors, simplify the modification process & most
importantly assists you in improving the readability of your code.
In addition to all these, the coding standards ensure that all files within one project appear as if
they’re created by a single person.
Another major advantage you get by following the coding standards is that anyone will be able to
understand your code and also modify it, without contacting you.
So, if you’re planning to develop a website in WordPress, you should know the coding standards.
Now, let’s dive deep into the core part & understand the various coding standards.
3. Part 1: In-Depth Guide On WordPress Coding
Standards For PHP & HTML:-
WordPress Coding Standards For PHP
1. Using Single & Double Quotes
If you’re someone who is working in a Custom WordPress Development Company, then you
must be knowing that appropriate use of single and double quotes is necessary.
As per the standard convention if you’re not evaluating anything in the string, then you should use
the single quotes. Otherwise, you should always prefer using the double quotes for the string value
while writing PHP code for the WordPress platform.
Example:
echo '<a href="www.url.com" title="Contact">Contact Us</a>';
echo "<a href='$cta_link' title='$cta_title'>$cta_label</a>";
Here, we have used double quotes for displaying the “Contact” as it is a value for the title attribute,
while we have used a single quote for ‘$cta_title’ as we’re not evaluating its value.
2. Indentation
Another very important thing that you need to remember while writing the code in PHP is the
proper use of indentation. The reason behind that is, it always reflects the logical structure of your
code. Always use tabs for indentation instead of space, as it improves readability.
However, there is one exception: If you've got a block of code which looks more readable if the
code is written in an aligned manner, then you can use space for that purpose.
Example:
[tab]'demo' => 'demovalue';
[tab]'demo1' => 'demovalue1’;
[tab]'demo2' => 'demovalue2';
[tab]'demo3' => 'demovalue3';
For associative arrays, each item should start on a new line when the array contains more than one
item:
4. Example:
$key_value_array = array(
[tab]'demo' => 'demovalue',
[tab]'demo1' => 'demovalue1',
[tab]'demo2' => 'demovalue2',
[tab]'demo3' => 'demovalue3',
);
Here, you may have noted a comma after the last item. This is recommended by the WordPress as
it makes it easier for you to change the order of an array.
Example:
[tab]'demo3' => 'demovalue3',
[tab]'demo1' => 'demovalue1',
[tab]'demo' => 'demovalue',
[tab]'demo2' => 'demovalue2',
);
For the switch structures, the case should be indented one tab from the switch statement and
break should be one tab from the case statement.
Example:
switch ( $condition ) {
[tab]case 'value':
[tab][tab]demo_function();
[tab][tab]break;
[tab]case 'value2':
[tab][tab]demo_function1();
[tab][tab]break;
}
As a thumb rule, Tabs should be used at the beginning of the line for indentation and Space should
be used for the mid-line alignment.
3. Brace Style
Braces should be used for all the blocks as shown in the snippet below:
Example:
5. if ( condition ) {
function();
function2();
} elseif ( condition2 && condition3 ) {
function3();
function4();
} else {
defaul_function();
}
In case, you have a really long block, it can be broken into 2 or more shorter blocks to reduce
complexity and improve readability.
Example:
if ( condition ) {
function();
function2();
} elseif ( condition2 && condition3 ) {
function3();
function4();
} else {
defaul_function();
}
foreach ( $data as $data_key => $data_value ) {
echo $data_value;
}
One thing that should be noted here is that the use of braces is to avoid single-statement inline
control structures. You’re free to use the alternative syntax for control structure, especially when
the PHP code is embedded into the HTML.
Example:
<?php if ( !empty( $data ) ) { ?>
<div class="test">
<?php foreach ( $data as $data_key => $data_value ) { ?>
<div id="data-<?php echo $data_key; ?>">
<!-- Other Content -->
</div>
<?php } ?>
</div>
<?php } ?>
6. 4. Use elseif, Not else if
else if is not compatible with the colon-based syntax for if|elseif blocks. Therefore, you should
always use elseif instead of using else if.
5. Multiline Function Calls
As a WordPress developer, when you split the function call over the multiple lines, always
remember to keep each parameter on a separate line.
Each parameter should not consume more than one line and multiline parameter values must be
assigned to a variable, so you just need to pass that variable to the function call.
Example:
```
$bar = array(
'use_this' => true,
'meta_key' => 'field_name',
);
$baz = sprintf(
/* translators: %s: Friend's name */
esc_html__( 'Hello, %s!', 'yourtextdomain' ),
$friend_name
);
$a = foo(
$bar,
$baz,
/* translators: %s: cat */
sprintf( __( 'The best pet is a %s.' ), 'cat' )
);
6. Regular Expressions
Always use Perl compatible regular expressions (PCRE) with the reference to their POSIX
counterparts. Never use the /e switch, use preg_replace_callback instead. In addition to all these,
you should always use single-quoted strings for the regular expressions.
7. Opening & Closing PHP Tags
When you’re embedding multiline PHP snippets within an HTML block, the PHP open and close
tags must be on a line by themselves.
7. Example: (multiline)
function test_function() {
?>
<div>
<?php
echo '<a href="www.url.com" title="Contact">Contact Us</a>';
?>
</div>
<?php
}
Example: (single line)
<input type="text" name="<?php echo $name ; ?>" />
8. No Shorthand PHP Tags
Never use shorthand PHP tags, always use full PHP tags.
Example: (Incorrect)
```
<? ... ?>
<?= $var ?>
Example: (Correct)
```
<?php ... ?>
<?php echo $var; ?>
9. Remove Trailing Spaces
Always remember to remove the trailing whitespaces at the end of your each coding line. You
should omit the PHP tag at the end of the file. However, if you’re using the tag, then don’t forget to
remove the trailing whitespace.
10. Proper Usage Of Space
Always put space after every comma and also on both sides of logical, comparison, string and
assignment operators.
Example:
8. y == 2
foo && bar
! foo
array( 1, 2, 3 )
$baz . '-4'
$term .= 'Z'
Remember to put spaces on both sides opening and closing parentheses of if, elseif, foreach, for,
and switch blocks.
Example:
```
foreach ( $foo as $bar ) { …
Also, follow this rule while defining a function.
Example:
function dummy( $param1 = 'foo', $param2 = 'bar' ) { ...
function my_dummy_function1() { ...
When you’re calling any function, you need to follow the rule mentioned above.
Example:
first_function1( $param1, func_param( $param2 ) );
my_dummy_function();
For logical comparisons, the same rule applies.
Example:
```
if ( ! $foo ) { ...
When you’re performing typecasting, the above rule is also valid.
Example:
```
foreach ( (array) $foo as $bar ) { ...
9. $foo = (boolean) $bar;
When referring to array items, include a space around the index only if it’s variable.
Example:
$x = $foo['bar']; // correct
$x = $foo[ 'bar' ]; // incorrect
$x = $foo[0]; // correct
$x = $foo[ 0 ]; // incorrect
$x = $foo[ $bar ]; // correct
$x = $foo[$bar]; // incorrect
For a switch block, there should be any space before the colon for a case statement.
Example:
```
switch ( $foo ) {
case 'bar': // correct
case 'ba' : // incorrect
}
Similarly, there should be no space before the colon on the return type declaration.
Example:
```
function sum( $a, $b ): float {
return $a + $b;
}
11. Formatting SQL Statements
When you’re formatting any SQL statement, you should break it into several lines and indent if it’s
sufficiently complex. Always capitalize the SQL parts of the statements such as WHERE or
UPDATE.
Functions that update the database should expect their parameters to lack SQL slash escaping
when passed. For that purpose, escaping should be done by using $wpdb->prepare().
$wpdb->prepare() is a method that handles escaping, quoting and int-casting for SQL queries.
10. Example:
<?php
// set the meta_key to the appropriate custom field meta key
$meta_key = 'miles';
$allmiles = $wpdb->get_var( $wpdb->prepare(
"
SELECT sum(meta_value)
FROM $wpdb->postmeta
WHERE meta_key = %s
",
$meta_key
) );
echo "<p>Total miles is {$allmiles}</p>";
?>
Here, %s is used for string placeholders and %d is used for integer placeholders. Note that they
are not ‘quoted’! $wpdb->prepare() will take care of escaping and quoting for us. This is the
benefit you get if you utilize this function.
12. Database Queries
Always avoid touching the database in a direct manner. Utilize the functions for extracting the data
whenever possible. The reason behind that is, Database Abstraction (using functions in place of
queries) helps you to keep your code forward-compatible.
13. Naming Conventions
Always use lowercase for a variable, action/filter, and function names. Separate the words by
using underscore. In addition to that, choose a name which is unambiguous & self-documenting.
Example:
function some_name( $some_variable ) { [...] }
For class name, you should use capitalize words which are separated by underscores.
Example:
```
class Walk_Categorization extends Walk { [...] }
All the constants should be in upper-case with words being separated by underscores.
11. Example:
```
define( 'PI', true );
The file should be named descriptively by using the lowercase and for separating the words you
should utilize hyphen.
My-new-theme.php
For class file name should be based on the class name i.e. class- followed by a hyphen.
Example:
If the class name is class Walk_Categorization, then the class file name should be
class-walk-categroization.php
There is one exception in the class file name for three files: class.wp-dependencies.php,
class.wp-scripts.php, class.wp-styles.php. These files are ported into Backpress and therefore,
they are prepended with class. instead of a hyphen.
14. Self-Explanatory Flag Values for Function Arguments
Always prefer using true & false for the string values when you're calling a function.
Example:
// Incorrect
function eat( $what, $slowly = true ) {
...
}
eat( 'wheat', true );
eat( 'rice', false );
Now, PHP doesn’t support flag arguments and therefore, sometimes the values of flags are
meaningless as it is in our example shown above. So, for that type of scenario, you should make
your code readable by utilizing descriptive string values instead of booleans.
Example:
// Correct
function eat( $what, $slowly = ‘slowly’) {
...
}
12. eat( 'wheat', ‘slowly’ );
eat( 'rice', ‘quickly’ );
15. Interpolation for Naming Dynamic Hooks
For naming the dynamic hooks, you should utilize the interpolation methodology rather than using
the concatenation for readability purpose. Dynamic hooks are the one which includes dynamic
values in their tag name - {$new_status}_{$post->post_type} (publish_post).
Always include the variables of your hook tags inside the curly braces {} and the outer tag name
should be wrapped in double quotes. The reason behind following this methodology is to ensure
that PHP can correctly parse the variable types with interpolated string:
Example:
```
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
16. Ternary Operator
For using the ternary operator, always have them test if the statement is true, not false. Otherwise,
it can create a massive confusion in the future.
Example:
```
$musictype = ( 'jazz' == $music ) ? 'cool' : 'blah';
17. Yoda Conditions
When you’re doing the logical comparisons which include variables, always put the variable on
the right-hand side & constants, literals, or function calls on the left-hand side. If neither side has a
variable, then the order is not that important.
Example:
```
if ( true == $the_force ) {
$victorious = you_will( $be );
}
Here, if you omit an equals sign (=), then you will get a parse error, as you can’t assign a value to
constant like true. Instead of that, if you’ve written ( $the_force = true ), the assignment would be
13. perfect and you won’t get an error. This is known as the Yoda Condition and it applies to ==, !=,
===, !==, <, >, <= or >= operators.
18. Clever Coding
For coding, readability is more important than cleverness.
Example:
```
isset( $var ) || $var = some_function();
This might look clever, but it has low readability. Instead of that, if you write:
if ( ! isset( $var ) ) {
$var = some_function();
}
Then, the readability improves drastically.
In the case of a switch statement, it’s ok to have multiple cases in a common block. However, if a
case contains a block, the falls through to the next block, then this should be explicitly commented
as shown in the snippet below:
switch ( $foo ) {
case 'bar': // Correct, an empty case can fall through without comment.
case 'baz':
echo $foo; // Incorrect, a case with a block must break, return, or
have a comment.
case 'cat':
echo 'mouse';
break; // Correct, a case with a break does not require a comment.
case 'dog':
echo 'horse';
// no break // Correct, a case can have a comment to explicitly mention
the fall-through.
case 'fish':
echo 'bird';
break;
}
WordPress Coding Standards For HTML
1. Validation
14. All the HTML pages should be verified with the help of the W3C Validator to ensure that markup
is well-formed. Although this is not the only indicator of good coding, it helps to solve the
problems that are to be tested via the automation process. The manual code review cannot be as
effective as this one and that’s why it is recommended that you should validate your code.
2. Self-Enclosing Elements
All tags must be properly closed. Howver, for the tags that are self-enclosing, the forward slash
should have once space preceding it.
Example:
```
<br /> //Correct
<br/> //Incorrect
3. Attributes & Tags
All the tags, as well as their attributes, must be written in lowercase. In addition to that, attribute
values should be in lowercase when the purpose of the text is just to be interpreted by a machine.
However, when an attribute value is going be read by a human, proper capitalization should
follow:
Example:
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> // For
Machine
<a href="http://abc.com/" title="Content Writer">ABC.com</a> // For Human
4. Quotes
As per the W3C specification for XHTML, all the attributes must have a value & must be wrapped
inside single or double quotes.
Example:
```
<input type="text" name="ABC" disabled="disabled" /> //Correct
<input type='text' name=’ABC’ disabled='disabled' /> //Correct
<input type=text name=email disabled>//Incorrect
15. Howver, in HTML all attributes do not have to have values & they do not have to be quoted. But
you should follow these conventions to avoid any kind of security vulnerabilities.
5. Indentation
Like PHP, HTML indentation should always reflect logical structure. So always use tabs and not
spaces. If you’re mixing PHP & HTML, then indent PHP blocks to match the HTML code.
Example:
?php if ( ! have_posts() ) : ?>
<div id="post-1" class="post">
<h1 class="entry-title">Not Found</h1>
<div class="entry-content">
<p>Apologies, but no results were found.</p>
<?php get_search_form(); ?>
</div>
</div>
<?php endif; ?>
Final Thoughts…
Every programming language has its own coding standards which need to be followed by the
programmer in order to enhance the readability of the code. The same is the case with WordPress,
where there are coding standards for PHP, HTML, CSS & JS.
Here, we have tried to provide you with an in-depth guide on WordPress Coding Standards For
PHP & HTML which will help you in future when you're developing something in WordPress.
If you’ve any question or suggestion regarding this subject, then do mention them in our comment
section. Thank You!
Originally Published at esparkinfo.com