Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds namespacing and makes function naming more consistent. #773

Merged
merged 69 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9ddb976
Reorganizes the template tags functions
batesweb Oct 13, 2021
bfe5a43
Breaks all of the functions in inc/ files out into individual files
batesweb Oct 13, 2021
6b1d8aa
Replaced underscores with hyphens in filenames
batesweb Oct 13, 2021
a4be81a
Added doc block comments
batesweb Oct 14, 2021
66c8822
Added readme to inc/
batesweb Oct 14, 2021
88ec92a
Working on adding namespaces...
batesweb Oct 15, 2021
7c34cb0
More namespacing updates....
batesweb Oct 15, 2021
caf0239
More namespacing updates...
batesweb Oct 18, 2021
6c7452c
Fix SVG namespacing
batesweb Oct 18, 2021
81ba4ce
Fixes function comments
batesweb Oct 18, 2021
fa22b9d
Adds .gitkeep file to force creation of empty post-types directory
batesweb Oct 19, 2021
20794f5
Changed function namespace imports
batesweb Oct 19, 2021
37489b3
Fixed page template namespacing
batesweb Oct 19, 2021
7c4dca7
Added namespace magic constant
batesweb Oct 25, 2021
668668f
Fixed return_custom_logo_url namespace
batesweb Oct 25, 2021
96e86db
Missed a few __NAMESPACE__ constants
batesweb Dec 30, 2021
e6c847b
changed namespace to WebDevStudios/wd_s
nickyiie May 19, 2022
f3c35ca
changed namespace
nickyiie May 19, 2022
64bff34
renaming of functions/files
nickyiie May 19, 2022
bc276f7
fixed typo on __return_false
nickyiie May 19, 2022
816cf05
pulling main
nickyiie May 19, 2022
2bae77f
Fixes some JS linting issues
coreymcollins May 19, 2022
11c5999
Replaces old namespacing
coreymcollins May 19, 2022
4f07a86
Use single namespace throughout theme
batesweb May 20, 2022
266d63d
Renames theme get_the_title function
batesweb May 20, 2022
e38cacb
Cleans up namespacing in template tags
batesweb May 20, 2022
e9eda23
More function and namespace updates...
batesweb May 20, 2022
e7eeba3
Renames the title and excerpt functions
batesweb May 20, 2022
606b40b
Merge branch 'main' into feature/#769-function-naming
oliverharrison May 27, 2022
22c90ff
Updated to use either namespaces or functions as appropriate
oliverharrison May 27, 2022
19bc1f5
Updated package lock
oliverharrison May 27, 2022
0f6228e
Add 'use function' instead of declaring the namespace again; remove n…
oliverharrison May 30, 2022
f01213e
Change 'get_the_content' function to 'get_post_content' to avoid conf…
oliverharrison May 30, 2022
b939e00
Add missing namespaces
asharirfan May 30, 2022
f68f1cb
Fix spacing issues
asharirfan May 30, 2022
fbdb5e1
Remove namespace from backward compatibility function
asharirfan May 30, 2022
c5555cc
Add missing nav function for scaffolding
asharirfan May 30, 2022
db8101f
Add missing namespace
asharirfan May 30, 2022
b8f735e
Fix attribute escape function
asharirfan May 31, 2022
0c601aa
Fix spacing issues
asharirfan May 31, 2022
0869b0d
Remove non-required namespace function declarations
asharirfan May 31, 2022
5f4d5d3
Add namespace function declaration
asharirfan May 31, 2022
cbeee85
Fix namespace declaration
asharirfan May 31, 2022
ddb6fb8
Update text domains and package names
oliverharrison May 31, 2022
6558e7c
Update text domain
oliverharrison May 31, 2022
9b77614
Update spacing
oliverharrison Jun 2, 2022
9d157a7
Update prettier config to handle wp-scripts format correctly
oliverharrison Jun 2, 2022
0ee9837
Fix scaffolding expand/collapse sections
oliverharrison Jun 24, 2022
347c4fe
Fix scaffolding nav
oliverharrison Jun 24, 2022
3b4037f
Update phpcs rule to capture namespacing
oliverharrison Jun 24, 2022
01d6531
Update handle prefixes
oliverharrison Jun 24, 2022
2958f81
update _s.pot -> wd_s.pot for consistency
oliverharrison Jun 24, 2022
92f3852
Removed the old post_date function AGAIN
batesweb Jun 24, 2022
9f92a6f
Updates excerpt function name
batesweb Jun 24, 2022
f8e4892
Include all files with a function using namespacing
oliverharrison Jun 24, 2022
4d0e32e
Define function prefix for functions in global namespace
oliverharrison Jun 24, 2022
7b322c6
Cleans up prefixes
batesweb Jun 24, 2022
b4174e6
Update function and filename for clarity
oliverharrison Jun 24, 2022
77cf667
Update _wd_s_ -> wd_s_
oliverharrison Jun 24, 2022
7c782d2
Fixes ability to save content in Copyright field in theme customizer
Jul 18, 2022
8fafaad
Fixes functions for printing customizer header and footer scripts to …
Jul 18, 2022
4bb68a4
Updates comments about find and replace to refer to readme file.
Jul 19, 2022
f58bc3d
Updates readme with complete find and replace list
Jul 19, 2022
9ecc413
Update tested up to version
oliverharrison Jul 22, 2022
9f51d44
Remove backwards-compat wp_body_open() since wd_s specifies WP 5.6+
jrfoell Jul 22, 2022
b889e47
Merge branch 'main' into feature/#769-function-naming
jrfoell Jul 22, 2022
fbb011a
Fix script handle prefix
asharirfan Jul 29, 2022
fc1cd0f
Update version from 2.1.0 -> 3.0.0
oliverharrison Jul 29, 2022
bf74c36
Re-add version to package.json
oliverharrison Jul 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 404.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @link https://codex.wordpress.org/Creating_an_Error_404_Page
*
* @package _s
* @package wd_s
*/

get_header(); ?>
Expand All @@ -13,12 +13,12 @@

<section class="error-404 not-found">
<header class="page-header">
<h1 class="page-title"><?php esc_html_e( "Sorry, this page doesn't exist.", '_s' ); ?></h1>
<h1 class="page-title"><?php esc_html_e( "Sorry, this page doesn't exist.", 'wd_s' ); ?></h1>
</header><!-- .page-header -->

<div class="page-content">

<p><?php esc_html_e( "It seems we can't find what you're looking for. Perhaps searching can help.", '_s' ); ?></p>
<p><?php esc_html_e( "It seems we can't find what you're looking for. Perhaps searching can help.", 'wd_s' ); ?></p>

<?php get_search_form(); ?>

Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ If you want to set me up manually:

2. Find & Replace

You'll need to change all instances of the names: `_s`.

- Search for: `'_s'` and replace with: `'project-name'` (inside single quotations) to capture the text domain
- Search for: `"_s"` and replace with: `"project-name"` (inside double quotations) to capture the text domain
- Search for: `_s_` and replace with: `project-name_` to capture all the function names
- Search for: `Text Domain: _s` and replace with: `Text Domain: project-name` in style.css
- Search for (and include the leading space): ` _s` and replace with: ` Project Name` (with a space before it) to capture DocBlocks
- Search for: `_s-` and replace with: `project-name-` to capture prefixed handles
- Search for `_s.pot` and replace with: `project-name.pot` to capture translation files
You'll need to change all instances of the name: `wd_s`.

- Search for: `@package wd_s` and replace with: `@package project_name` to capture the package name
- Update `"WebDevStudios\wd_s,wd_s"` to: `"CompanyName\project_name,project_name"` (with double quotes) in phpcs.xml.dist
- Search for: `WebDevStudios\wd_s` and replace with: `CompanyName\project_name` to capture the namespaces
- Update `"webdevstudios/wd_s"` to `"companyname/project_name"` (with double quotes) in composer.json
- Search for: `, 'wd_s'` and replace with: `, 'project_name'` (inside backticks) to capture the text domain
- Update `Text Domain: wd_s` to: `Text Domain: project_name` in style.css
- Update `"wd_s"` to: `"project_name"` (with double quotes) in phpcs.xml.dist and package.json
- Update `'wd_s'` to: `'project_name'` (with single quotes) in inc/setup/setup.php
- Search for: `wd_s_` and replace with: `project_name_` to capture all the function names
- Search for: `'wd_s-` and replace with: `'project_name-` to capture prefixed handles
- Search for `wd_s.pot` and replace with: `project_name.pot` to capture translation files
- Search for `wdunderscores.test` and replace with: `project_name.test` to match your local development URL
- Edit the theme information in the header of style.scss to meet your needs

## Setup
Expand Down
41 changes: 22 additions & 19 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,46 @@
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package _s
* @package wd_s
*/

use function WebDevStudios\wd_s\print_numeric_pagination;

get_header(); ?>

<main id="main" class="container site-main">
<main id="main" class="container site-main">

<?php if ( have_posts() ) : ?>
<?php if ( have_posts() ) : ?>

<header class="page-header">
<?php
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="archive-description">', '</div>' );
?>
</header><!-- .page-header -->
?>
</header><!-- .page-header -->

<?php
<?php
/* Start the Loop */
while ( have_posts() ) :
the_post();
while ( have_posts() ) :
the_post();

/**
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
/**
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );

endwhile;

_s_display_numeric_pagination();
print_numeric_pagination();

else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>

</main><!-- #main -->
</main><!-- #main -->

<?php get_footer(); ?>
<?php get_footer();
?>
21 changes: 11 additions & 10 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package _s
* @package wd_s
*/

/**
* If the current post is protected by a password and
* the visitor has not yet entered the password we will
* return early without loading the comments.
*/

if ( post_password_required() ) {
return;
}
?>

<div id="comments" class="container comments-area">
<h2 class="screen-reader-text"><?php esc_html_e( 'Comment section', '_s' ); ?></h2>
<h2 class="screen-reader-text"><?php esc_html_e( 'Comment section', 'wd_s' ); ?></h2>

<?php
// You can start editing here -- including this comment!
Expand All @@ -31,7 +32,7 @@
<?php
printf(
/* translators: the number of comments */
esc_html( _nx( '%1$s thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'comments title', '_s' ) ),
esc_html( _nx( '%1$s thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', get_comments_number(), 'comments title', 'wd_s' ) ),
number_format_i18n( get_comments_number() ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- XSS OK.
'<span>' . wp_kses_post( get_the_title() ) . '</span>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- XSS OK.
);
Expand All @@ -42,11 +43,11 @@
if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through?
?>
<nav id="comment-nav-above" class="navigation comment-navigation" role="navigation">
<h3 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', '_s' ); ?></h3>
<h3 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'wd_s' ); ?></h3>
<div class="nav-links">

<div class="nav-previous"><?php previous_comments_link( esc_html__( 'Older Comments', '_s' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( esc_html__( 'Newer Comments', '_s' ) ); ?></div>
<div class="nav-previous"><?php previous_comments_link( esc_html__( 'Older Comments', 'wd_s' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( esc_html__( 'Newer Comments', 'wd_s' ) ); ?></div>

</div><!-- .nav-links -->
</nav><!-- #comment-nav-above -->
Expand All @@ -68,11 +69,11 @@
if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through?
?>
<nav id="comment-nav-below" class="navigation comment-navigation" role="navigation">
<h2 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', '_s' ); ?></h2>
<h2 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'wd_s' ); ?></h2>
<div class="nav-links">

<div class="nav-previous"><?php previous_comments_link( esc_html__( 'Older Comments', '_s' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( esc_html__( 'Newer Comments', '_s' ) ); ?></div>
<div class="nav-previous"><?php previous_comments_link( esc_html__( 'Older Comments', 'wd_s' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( esc_html__( 'Newer Comments', 'wd_s' ) ); ?></div>

</div><!-- .nav-links -->
</nav><!-- #comment-nav-below -->
Expand All @@ -84,7 +85,7 @@
// If comments are closed and there are comments, let's leave a little note, shall we?
if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
?>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', '_s' ); ?></p>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'wd_s' ); ?></p>
<?php endif; ?>

<?php
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"scripts": {
"format": "phpcbf --report=summary,source",
"lint": "phpcs --report=summary,source",
"pot": "wp i18n make-pot . build/languages/_s.pot --exclude=node_modules,vendor,build --allow-root"
"pot": "wp i18n make-pot . build/languages/wd_s.pot --exclude=node_modules,vendor,build --allow-root"
}
}
14 changes: 9 additions & 5 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package _s
* @package wd_s
*/

use function WebDevStudios\wd_s\print_copyright_text;
use function WebDevStudios\wd_s\print_social_network_links;
use function WebDevStudios\wd_s\print_mobile_menu;

?>

<footer class="site-footer">

<nav id="site-footer-navigation" class="footer-navigation navigation-menu" aria-label="<?php esc_attr_e( 'Footer Navigation', '_s' ); ?>">
<nav id="site-footer-navigation" class="footer-navigation navigation-menu" aria-label="<?php esc_attr_e( 'Footer Navigation', 'wd_s' ); ?>">
<?php
wp_nav_menu(
[
Expand All @@ -29,13 +33,13 @@
</nav><!-- #site-navigation-->

<div class="container site-info">
<?php _s_display_copyright_text(); ?>
<?php _s_display_social_network_links(); ?>
<?php print_copyright_text(); ?>
<?php print_social_network_links(); ?>
</div><!-- .site-info -->

</footer><!-- .site-footer container-->

<?php _s_display_mobile_menu(); ?>
<?php print_mobile_menu(); ?>
<?php wp_footer(); ?>

</body>
Expand Down
40 changes: 26 additions & 14 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,40 @@
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package _s
* @package wd_s
*/

namespace WebDevStudios\wd_s;

/**
* Get all the include files for the theme.
*
* @author WebDevStudios
*/
function _s_get_theme_include_files() {
return [
'inc/setup.php', // Theme set up. Should be included first.
'inc/compat.php', // Backwards Compatibility.
function include_inc_files() {
$files = [
'inc/customizer/customizer.php', // Customizer additions.
'inc/extras.php', // Custom functions that act independently of the theme templates.
'inc/hooks.php', // Load custom filters and hooks.
'inc/security.php', // WordPress hardening.
'inc/scaffolding.php', // Scaffolding.
'inc/scripts.php', // Load styles and scripts.
'inc/template-tags.php', // Custom template tags for this theme.
'inc/functions/', // Custom functions that act independently of the theme templates.
'inc/hooks/', // Load custom filters and hooks.
'inc/post-types/', // Load custom post types.
'inc/scaffolding/', // Scaffolding.
'inc/setup/', // Theme setup.
'inc/shortcodes/', // Load shortcodes.
'inc/template-tags/', // Custom template tags for this theme.
];
}

foreach ( _s_get_theme_include_files() as $include ) {
require trailingslashit( get_template_directory() ) . $include;
foreach ( $files as $include ) {
$include = trailingslashit( get_template_directory() ) . $include;

// Allows inclusion of individual files or all .php files in a directory.
if ( is_dir( $include ) ) {
foreach ( glob( $include . '*.php' ) as $file ) {
require $file;
}
} else {
require $include;
}
}
}

include_inc_files();
14 changes: 7 additions & 7 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package _s
* @package wd_s
*/

?>
Expand All @@ -28,7 +28,7 @@

<?php wp_body_open(); ?>

<a class="skip-link screen-reader-text" href="#main"><?php esc_html_e( 'Skip to content', '_s' ); ?></a>
<a class="skip-link screen-reader-text" href="#main"><?php esc_html_e( 'Skip to content', 'wd_s' ); ?></a>

<header class="site-header">

Expand All @@ -46,21 +46,21 @@

<?php

$description = get_bloginfo( 'description', 'display' );
if ( $description || is_customize_preview() ) :
$wd_s_description = get_bloginfo( 'description', 'display' );
if ( $wd_s_description || is_customize_preview() ) :
?>
<p class="site-description"><?php echo esc_html( $description ); ?></p>
<p class="site-description"><?php echo esc_html( $wd_s_description ); ?></p>
jrfoell marked this conversation as resolved.
Show resolved Hide resolved
<?php endif; ?>

</div><!-- .site-branding -->

<?php if ( has_nav_menu( 'primary' ) || has_nav_menu( 'mobile' ) ) : ?>
<button type="button" class="off-canvas-open" aria-expanded="false" aria-label="<?php esc_attr_e( 'Open Menu', '_s' ); ?>"></button>
<button type="button" class="off-canvas-open" aria-expanded="false" aria-label="<?php esc_attr_e( 'Open Menu', 'wd_s' ); ?>"></button>
<?php endif; ?>

</div><!-- .container -->

<nav id="site-navigation" class="main-navigation navigation-menu" aria-label="<?php esc_attr_e( 'Main Navigation', '_s' ); ?>">
<nav id="site-navigation" class="main-navigation navigation-menu" aria-label="<?php esc_attr_e( 'Main Navigation', 'wd_s' ); ?>">
<?php
wp_nav_menu(
[
Expand Down
27 changes: 27 additions & 0 deletions inc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Included `PHP` Files

Use the `/inc` directory to declare any theme functionality. All files in this directory are imported inside of `functions.php`.

## Directories

The `/inc` directory is organized into sub-directories based on the functionality/purpose of the code. These directories can be modified as needed, but the following structure is recommended:

```text
inc/
└─── customizer/ (functions relating to the theme customizer)
└─── functions/ (general functions that don't fit into any other directory)
└─── hooks/ (theme hooks)
└─── post-types/ (theme post type registrations & functions)
└─── scaffolding/ (theme scaffolding functions)
└─── setup/ (functions relating to the theme setup)
└─── shortcodes/ (shortcode registrations)
└─── template-tags/ (functions that render markup for use in theme templates)
└─── README.md
```

## Filenames

As a general rule, each `.php` file should contain a single function/action which should match the name of the file (replacing underscores with hyphens in the filename).

For example, `function demo_function() {...}` would be declared in a file named `demo-function.php` and stored inside an appropriate `/inc` sub-directory.

27 changes: 0 additions & 27 deletions inc/compat.php

This file was deleted.

Loading