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 16 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
4 changes: 3 additions & 1 deletion archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @package _s
*/

use function WD_S\TemplateTags\display_numeric_pagination;

get_header(); ?>

<main id="main" class="container site-main">
Expand Down Expand Up @@ -34,7 +36,7 @@

endwhile;

_s_display_numeric_pagination();
display_numeric_pagination();

else :
get_template_part( 'template-parts/content', 'none' );
Expand Down
1 change: 1 addition & 0 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* the visitor has not yet entered the password we will
* return early without loading the comments.
*/

if ( post_password_required() ) {
return;
}
Expand Down
10 changes: 7 additions & 3 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @package _s
*/

use function WD_S\TemplateTags\display_copyright_text;
use function WD_S\TemplateTags\display_social_network_links;
use function WD_S\TemplateTags\display_mobile_menu;

?>

<footer class="site-footer">
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 display_copyright_text(); ?>
<?php display_social_network_links(); ?>
</div><!-- .site-info -->

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

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

</body>
Expand Down
36 changes: 21 additions & 15 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@
*
* @author WebDevStudios
*/
function _s_get_theme_include_files() {
return [
'inc/setup.php', // Theme set up. Should be included first.
'inc/compat.php', // Backwards Compatibility.
'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.
];
}
$files = [
'inc/customizer/customizer.php', // Customizer additions.
'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 ( $files as $include ) {
$include = trailingslashit( get_template_directory() ) . $include;

foreach ( _s_get_theme_include_files() as $include ) {
require 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;
}
}
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.

4 changes: 3 additions & 1 deletion inc/customizer/class-text-editor-custom-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* @package _s
*/

namespace WD_S\Customizer;

if ( ! class_exists( 'WP_Customize_Control' ) ) {
return;
}

/**
* Class to create a custom text editor control
*/
final class Text_Editor_Custom_Control extends WP_Customize_Control {
final class Text_Editor_Custom_Control extends \WP_Customize_Control {

/**
* Keep track of if scripts were added.
Expand Down
22 changes: 12 additions & 10 deletions inc/customizer/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,46 @@
* @package _s
*/

namespace WD_S\Customizer;

/**
* Removes default customizer fields that we generally don't use.
*
* @param object $wp_customize The default Customizer settings.
* @author Corey Collins
*/
function _s_remove_default_customizer_sections( $wp_customize ) {
function remove_default_customizer_sections( $wp_customize ) {

// Remove sections.
$wp_customize->remove_section( 'custom_css' );
$wp_customize->remove_section( 'static_front_page' );
$wp_customize->remove_section( 'background_image' );
$wp_customize->remove_section( 'colors' );
}
add_action( 'customize_register', '_s_remove_default_customizer_sections', 15 );
add_action( 'customize_register', __NAMESPACE__ . '\remove_default_customizer_sections', 15 );
jrfoell marked this conversation as resolved.
Show resolved Hide resolved

/**
* Include other customizer files.
*
* @author WebDevStudios
*/
function _s_include_custom_controls() {
function include_custom_controls() {
require get_template_directory() . '/inc/customizer/panels.php';
require get_template_directory() . '/inc/customizer/sections.php';
require get_template_directory() . '/inc/customizer/settings.php';
require get_template_directory() . '/inc/customizer/class-text-editor-custom-control.php';
}
add_action( 'customize_register', '_s_include_custom_controls', -999 );
add_action( 'customize_register', __NAMESPACE__ . '\include_custom_controls', -999 );

/**
* Enqueue customizer related scripts.
*
* @author WebDevStudios
*/
function _s_customize_scripts() {
function customize_scripts() {
wp_enqueue_script( '_s-customize-livepreview', get_template_directory_uri() . '/inc/customizer/assets/scripts/livepreview.js', [ 'jquery', 'customize-preview' ], '1.0.0', true );
}
add_action( 'customize_preview_init', '_s_customize_scripts' );
add_action( 'customize_preview_init', __NAMESPACE__ . '\customize_scripts' );

/**
* Add support for the fancy new edit icons.
Expand All @@ -52,7 +54,7 @@ function _s_customize_scripts() {
* @author WebDevStudios
* @link https://make.wordpress.org/core/2016/02/16/selective-refresh-in-the-customizer/.
*/
function _s_selective_refresh_support( $wp_customize ) {
function selective_refresh_support( $wp_customize ) {

// The <div> classname to append edit icon too.
$settings = [
Expand All @@ -67,7 +69,7 @@ function _s_selective_refresh_support( $wp_customize ) {
$wp_customize->selective_refresh->add_partial( $setting, $args );
}
}
add_action( 'customize_register', '_s_selective_refresh_support' );
add_action( 'customize_register', __NAMESPACE__ . '\selective_refresh_support' );

/**
* Add live preview support via postMessage.
Expand All @@ -79,7 +81,7 @@ function _s_selective_refresh_support( $wp_customize ) {
* @param object $wp_customize Instance of WP_Customize_Class.
* @link https://codex.wordpress.org/Theme_Customization_API#Part_3:_Configure_Live_Preview_.28Optional.29.
*/
function _s_live_preview_support( $wp_customize ) {
function live_preview_support( $wp_customize ) {

// Settings to apply live preview to.
$settings = [
Expand All @@ -105,4 +107,4 @@ function _s_live_preview_support( $wp_customize ) {
$setting->transport = 'postMessage';
}
}
add_action( 'customize_register', '_s_live_preview_support', 999 );
add_action( 'customize_register', __NAMESPACE__ . '\live_preview_support', 999 );
6 changes: 4 additions & 2 deletions inc/customizer/panels.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* @package _s
*/

namespace WD_S\Customizer;

/**
* Add a custom panels to attach sections too.
*
* @author WebDevStudios
*
* @param WP_Customize_Manager $wp_customize Instance of WP_Customize_Class.
*/
function _s_customize_panels( $wp_customize ) {
function customize_panels( $wp_customize ) {
// Register a new panel.
$wp_customize->add_panel(
'site-options',
Expand All @@ -26,4 +28,4 @@ function _s_customize_panels( $wp_customize ) {
);
}

add_action( 'customize_register', '_s_customize_panels' );
add_action( 'customize_register', __NAMESPACE__ . '\customize_panels' );
6 changes: 4 additions & 2 deletions inc/customizer/sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* @package _s
*/

namespace WD_S\Customizer;

/**
* Register the section sections.
*
* @author WebDevStudios
* @param object $wp_customize Instance of WP_Customize_Class.
*/
function _s_customize_sections( $wp_customize ) {
function customize_sections( $wp_customize ) {

// Register additional scripts section.
$wp_customize->add_section(
Expand Down Expand Up @@ -54,4 +56,4 @@ function _s_customize_sections( $wp_customize ) {
]
);
}
add_action( 'customize_register', '_s_customize_sections' );
add_action( 'customize_register', __NAMESPACE__ . '\customize_sections' );
14 changes: 8 additions & 6 deletions inc/customizer/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* @package _s
*/

namespace WD_S\Customizer;

/**
* Register additional scripts.
*
* @author WebDevStudios
*
* @param WP_Customize_Manager $wp_customize Instance of WP_Customize_Manager.
*/
function _s_customize_additional_scripts( $wp_customize ) {
function customize_additional_scripts( $wp_customize ) {
// Register a setting.
$wp_customize->add_setting(
'_s_header_scripts',
Expand Down Expand Up @@ -54,7 +56,7 @@ function _s_customize_additional_scripts( $wp_customize ) {
);
}

add_action( 'customize_register', '_s_customize_additional_scripts' );
add_action( 'customize_register', __NAMESPACE__ . '\customize_additional_scripts' );

/**
* Register a social icons setting.
Expand All @@ -63,7 +65,7 @@ function _s_customize_additional_scripts( $wp_customize ) {
*
* @param WP_Customize_Manager $wp_customize Instance of WP_Customize_Manager.
*/
function _s_customize_social_icons( $wp_customize ) {
function customize_social_icons( $wp_customize ) {
// Create an array of our social links for ease of setup.
$social_networks = [
'facebook',
Expand Down Expand Up @@ -96,7 +98,7 @@ function _s_customize_social_icons( $wp_customize ) {
}
}

add_action( 'customize_register', '_s_customize_social_icons' );
add_action( 'customize_register', __NAMESPACE__ . '\customize_social_icons' );

/**
* Register copyright text setting.
Expand All @@ -105,7 +107,7 @@ function _s_customize_social_icons( $wp_customize ) {
*
* @param WP_Customize_Manager $wp_customize Instance of WP_Customize_Manager.
*/
function _s_customize_copyright_text( $wp_customize ) {
function customize_copyright_text( $wp_customize ) {
// Register a setting.
$wp_customize->add_setting(
'_s_copyright_text',
Expand All @@ -130,4 +132,4 @@ function _s_customize_copyright_text( $wp_customize ) {
);
}

add_action( 'customize_register', '_s_customize_copyright_text' );
add_action( 'customize_register', __NAMESPACE__ . '\customize_copyright_text' );
Loading