Start
This commit is contained in:
13
doc/config/boxes.tex
Normal file
13
doc/config/boxes.tex
Normal file
@@ -0,0 +1,13 @@
|
||||
\tcbset{
|
||||
warningstyle/.style={
|
||||
colback=yellow!10!white,
|
||||
colframe=red!50!black,
|
||||
fonttitle=\bfseries,
|
||||
}
|
||||
}
|
||||
|
||||
\newtcolorbox{warnbox}[1][]{
|
||||
warningstyle,
|
||||
title=\faWarning{} Warning,
|
||||
#1
|
||||
}
|
||||
34
doc/config/commands.tex
Normal file
34
doc/config/commands.tex
Normal file
@@ -0,0 +1,34 @@
|
||||
% Print WordPress name.
|
||||
\NewDocumentCommand{\WP}{ s }{%
|
||||
\IfBooleanTF{#1}{\textsc{wp}\xspace}{WordPress\xspace}%
|
||||
}
|
||||
|
||||
% Print ACF name.
|
||||
\NewDocumentCommand{\acf}{ s }{%
|
||||
\IfBooleanTF{#1}{\textsc{acf}\xspace}{Advanced Custom Fields\xspace}%
|
||||
}
|
||||
|
||||
% Print RHPZ name.
|
||||
\NewDocumentCommand{\rhpz}{ s }{%
|
||||
\IfBooleanTF{#1}{\textsc{RHPZ}\xspace}{Romhack Plaza\xspace}%
|
||||
}
|
||||
|
||||
% Show directory structure.
|
||||
\NewDocumentCommand{\dir}{ s m }{%
|
||||
\textcolor{violet}{\textsl{#2\IfBooleanF{#1}{.php}}}\xspace%
|
||||
}
|
||||
|
||||
\NewDocumentCommand{\sourceargs}{ m }{
|
||||
\textbf{Parameters}: \begin{itemize}%
|
||||
#1%
|
||||
\end{itemize}%
|
||||
}
|
||||
\NewDocumentCommand{\sourcereturn}{ m }{
|
||||
\textbf{Return}: \begin{itemize}%
|
||||
#1%
|
||||
\end{itemize}%
|
||||
}
|
||||
\NewDocumentCommand{\sourceexample}{ m m m }{
|
||||
\textbf{Example}: %
|
||||
\lstinputlisting[firstnumber=1,linerange={#2-#3}]{#1}%
|
||||
}
|
||||
52
doc/config/listings.tex
Normal file
52
doc/config/listings.tex
Normal file
@@ -0,0 +1,52 @@
|
||||
\lstset{
|
||||
language=PHP,
|
||||
alsoletter={\$},
|
||||
basicstyle=\ttfamily,
|
||||
numbers=left,
|
||||
frame=single,
|
||||
breaklines=true,
|
||||
breakatwhitespace=true,
|
||||
columns=flexible,
|
||||
keywordstyle=\color{blue},
|
||||
keywordstyle=[2]\color{teal}, % Var & Useful functions.
|
||||
keywordstyle=[3]\color{purple},
|
||||
commentstyle=\color{lightgray}\itshape,
|
||||
stringstyle=\color{orange},
|
||||
numberstyle=\color{lightgray},
|
||||
showstringspaces=false,
|
||||
morekeywords={
|
||||
require_once,
|
||||
public,
|
||||
protected,
|
||||
private,
|
||||
final,
|
||||
static,
|
||||
function,
|
||||
return,
|
||||
function,
|
||||
namespace,
|
||||
global,
|
||||
defined,
|
||||
class,
|
||||
abstract,
|
||||
interface,
|
||||
new,
|
||||
string,
|
||||
int,
|
||||
}, % PHP Keywords.
|
||||
morekeywords=[2]{
|
||||
\$_romhackplaza,
|
||||
\$_romhackplaza_theme,
|
||||
\$post_id,
|
||||
\$this,
|
||||
\$post_types,
|
||||
\$context,
|
||||
}, % Plugin useful vars.
|
||||
morekeywords=[3]{
|
||||
do_action,
|
||||
add_action,
|
||||
add_filter,
|
||||
apply_filters,
|
||||
CPT
|
||||
} % Plugin & WP useful functions.
|
||||
}
|
||||
50
doc/doc.tex
Normal file
50
doc/doc.tex
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
\documentclass[11pt]{scrreprt}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage{lmodern}
|
||||
\usepackage[a4paper]{geometry}
|
||||
\usepackage{xspace}
|
||||
\usepackage{xparse}
|
||||
\usepackage{xstring}
|
||||
\usepackage{xcolor}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{tabularray}
|
||||
\usepackage{tcolorbox}
|
||||
\usepackage{fontawesome}
|
||||
\usepackage{babel}
|
||||
\usepackage{listings}
|
||||
\usepackage{subcaption}
|
||||
\usepackage{hyperref}
|
||||
\usepackage{hypcap}
|
||||
|
||||
\input{config/listings}
|
||||
\input{config/commands}
|
||||
\input{config/boxes}
|
||||
|
||||
\NewDocumentEnvironment{sourcedef}{ m m m O{false} }{%
|
||||
\StrSubstitute{#1}{../}{}[\sourcepath]%
|
||||
\noindent File location: \dir*{\sourcepath}%
|
||||
\lstinputlisting[label=lst:\sourcepath,includerangemarker=#4,linerange={#2-#3}]{#1}
|
||||
}{%
|
||||
\par
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\title{
|
||||
RHPZ
|
||||
}
|
||||
\author{
|
||||
Test
|
||||
}
|
||||
|
||||
\maketitle
|
||||
\tableofcontents
|
||||
|
||||
\include{hooks}
|
||||
\include{timber}
|
||||
\include{how-to}
|
||||
|
||||
|
||||
\end{document}
|
||||
3
doc/examples/how-to.php
Normal file
3
doc/examples/how-to.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
$post_types['<your_cpt_id>'] = new CPT('<your_cpt_id>', '<your_cpt_singular_name>', <your_cpt_args> );
|
||||
?>
|
||||
2
doc/examples/timber.php
Normal file
2
doc/examples/timber.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
Timber::render( '@plugin/...', $context );
|
||||
5
doc/examples/twig-examples.twig
Normal file
5
doc/examples/twig-examples.twig
Normal file
@@ -0,0 +1,5 @@
|
||||
{{ svg_icon('anchor') }}
|
||||
{{ theme_setting('title_color') }}
|
||||
{% if conditional_tags.is_home %}
|
||||
{# Code... #}
|
||||
{% endif %}
|
||||
1
doc/hooks.tex
Normal file
1
doc/hooks.tex
Normal file
@@ -0,0 +1 @@
|
||||
\chapter{Actions \& Filters}\label{ch:hooks}
|
||||
20
doc/how-to.tex
Normal file
20
doc/how-to.tex
Normal file
@@ -0,0 +1,20 @@
|
||||
\chapter{How to ?}\label{ch:how-to}
|
||||
|
||||
\section[Create a CPT]{Create a custom post type}\label{sec:create-cpt}
|
||||
|
||||
To create a custom post type, you must first register the custom post type as in \WP, then add parameters for the submission page, or even for the \acf fields group.
|
||||
|
||||
\subsection[Register the CPT]{Register the custom post type}\label{subsec:register-cpt}
|
||||
|
||||
First, you need to register the custom post type in the \dir{src/Registrars/Custom\_Post\_Types} file, in the \lstinline|__construct| method.
|
||||
\lstinputlisting[label=lst:create-cpt,linerange={$post_types['reviews']-END_CPT_CREATE}]{../src/Registrars/Custom_Post_Types.php}
|
||||
You must register it like that:
|
||||
|
||||
\lstinputlisting[label=lst:create-cpt-example,linerange={1-2}]{examples/how-to.php}
|
||||
|
||||
With :
|
||||
\begin{itemize}
|
||||
\item \lstinline|<your_cpt_id>|: the ID of your custom post type.
|
||||
\item \lstinline|<your_cpt_singular_name>|: the singular English name of your custom post type\footnote{This field may be removed in a later version.}.
|
||||
\item \lstinline|<your_cpt_args>|: an array like the one on \href{https://developer.wordpress.org/reference/functions/register_post_type/}{\lstinline|register_post_type|}.
|
||||
\end{itemize}
|
||||
72
doc/timber.tex
Normal file
72
doc/timber.tex
Normal file
@@ -0,0 +1,72 @@
|
||||
\chapter{Timber extension}\label{ch:timber}
|
||||
|
||||
From \href{https://timber.github.io/docs/v2/}{Timber documentation}:
|
||||
|
||||
\begin{quotation}
|
||||
Timber helps you create fully-customized WordPress themes faster with more sustainable code.
|
||||
With Timber, you write your HTML with the Twig Template Engine. This cleans up your theme code. Your PHP file can focus on providing the data or logic and your Twig files can focus 100\% on the HTML and display.
|
||||
\end{quotation}
|
||||
|
||||
At Romhack Plaza, we decided to separate the content from the form as much as possible by using Timber templates.
|
||||
We therefore added new features to Timber via our plugin.
|
||||
Most of them can be found in the \dir{src/Extenders/Timber} file.
|
||||
|
||||
\begin{warnbox}
|
||||
Timber is included in \WP via the \emph{\rhpz theme} and not by the plugin! You must enable the \rhpz theme to have access to each of these functions.%
|
||||
\end{warnbox}
|
||||
|
||||
\section{Views}\label{sec:views}
|
||||
|
||||
\rhpz plugin add a new view location folder: \dir*{views} at the root of the plugin folder.
|
||||
\lstinputlisting[label=lst:view-def,includerangemarker=false,linerange={<start_add_views>-<end_add_views>}]{../src/Extenders/Timber.php}
|
||||
|
||||
If you want render a template file from that folder, you can specify the folder with "@plugin":
|
||||
\lstinputlisting[label=lst:view-usage,linerange=2-2]{examples/timber.php}
|
||||
|
||||
\section{Functions}\label{sec:timber-funcs}
|
||||
|
||||
Some functions have been added to use them in a Timber template.
|
||||
|
||||
\subsection{svg\_icon}\label{subsec:svg-icon}
|
||||
\begin{sourcedef}{../src/Extenders/Timber.php}{<start_svg_icon>}{<end_svg_icon>}
|
||||
|
||||
\sourceargs{
|
||||
\item\lstinline|string icon_id|
|
||||
}
|
||||
|
||||
\sourceexample{examples/twig-examples.twig}{1}{1}
|
||||
|
||||
Call the \lstinline|svg_icon| snippet from the \rhpz theme.
|
||||
The SVG icon list is from \href{https://genericons.com/}{genericons neue}.
|
||||
If the theme is not enabled, this callable return an empty string.
|
||||
|
||||
\end{sourcedef}
|
||||
|
||||
\subsection{theme\_setting}\label{subsec:theme_setting}
|
||||
\begin{sourcedef}{../src/Extenders/Timber.php}{<start_theme_setting>}{<end_theme_setting>}
|
||||
|
||||
\sourceargs{
|
||||
\item\lstinline|string option_name|
|
||||
}
|
||||
|
||||
\sourcereturn{
|
||||
\item\lstinline|mixed| If not found, return \lstinline|false|.
|
||||
}
|
||||
|
||||
\sourceexample{examples/twig-examples.twig}{2}{2}
|
||||
|
||||
Call the \lstinline|$_romhackplaza_theme->settings->get()$| from the \rhpz theme.
|
||||
Get a setting registered from the theme\footnote{Every settings linked to Customizer.}.
|
||||
If the theme is not enabled, this callable return an empty string.
|
||||
|
||||
\end{sourcedef}
|
||||
|
||||
\section{Conditional tags}\label{sec:cond-tags}
|
||||
|
||||
Some \href{https://codex.wordpress.org/Conditional_Tags}{conditional tags} are added to the \href{https://timber.github.io/docs/v2/guides/context/}{Timber context}:
|
||||
\lstinputlisting[label=lst:cond-tags,includerangemarker=false,linerange={<start_cond_tags>-<end_cond_tags>}]{../src/Extenders/Timber.php}
|
||||
|
||||
\sourceexample{examples/twig-examples.twig}{3}{5}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user