Skip to content

Commit c6fe3d2

Browse files
committed
first commit
0 parents  commit c6fe3d2

File tree

26 files changed

+1476
-0
lines changed

26 files changed

+1476
-0
lines changed

Assets.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace cw\wp;
4+
5+
class Assets{
6+
use \cw\php\core\traits\Singleton;
7+
8+
public function theme(){
9+
return Theme::getInstance();
10+
}
11+
12+
public function scripts(){
13+
return assets\Scripts::getInstance();
14+
}
15+
16+
public function styles(){
17+
return assets\Styles::getInstance();
18+
}
19+
20+
public function expand($uri){
21+
if(strpos($uri, '://') !== false
22+
|| strpos($uri, '//') === 0)
23+
return $uri;
24+
25+
return get_stylesheet_directory_uri() . '/' . $uri;
26+
}
27+
}

Helper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace cw\wp;
4+
5+
class Helper{
6+
public static function isLoginPage() {
7+
return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
8+
}
9+
10+
public static function isAdmin() {
11+
return is_admin();
12+
}
13+
}

Menus.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace cw\wp;
4+
5+
class Menus{
6+
public $menus = [];
7+
8+
public function __construct(){
9+
$this->bootstrap();
10+
}
11+
12+
protected function bootstrap(){
13+
add_action( 'init', [$this, 'registerMenus'] );
14+
}
15+
16+
public function registerMenus(){
17+
register_nav_menus(
18+
$this->menus
19+
);
20+
}
21+
22+
public function addMenu($name, $translationKey = null){
23+
if($translationKey == null)
24+
$translationKey = $name;
25+
26+
$this->menus[$name] = __($translationKey);
27+
28+
return $this;
29+
}
30+
}

Post.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace cw\wp;
4+
5+
class Post{
6+
public $post;
7+
8+
public function __construct(\WP_Post $post){
9+
$this->post = $post;
10+
}
11+
12+
public function title(){
13+
return $this->post->post_title;
14+
}
15+
16+
public function permalink(){
17+
return get_permalink($this->post);
18+
}
19+
20+
public function terms($termId){
21+
if(is_a($termId, '\cw\wp\custom\Taxanomy'))
22+
$termId = $termId->id;
23+
24+
$terms = wp_get_post_terms($this->post->ID, $termId, [
25+
'orderby' => 'name',
26+
'order' => 'ASC'
27+
]);
28+
29+
return array_map(function($term){
30+
return new \cw\wp\custom\Term($term);
31+
}, $terms);
32+
}
33+
}

README.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# creative-workflow/lib-wordpress
2+
3+
### Setup
4+
```
5+
git submodule add https://github.com/creative-workflow/lib-wp.git ./wordpress/wp-content/themes/child/lib/cw/wp
6+
git submodule add https://github.com/creative-workflow/lib-php.git ./wordpress/wp-content/themes/child/lib/cw/php
7+
git submodule add https://github.com/creative-workflow/lib-sass.git ./wordpress/wp-content/themes/child/lib/cw/sass
8+
```
9+
10+
### functions.php
11+
```php
12+
<?php
13+
14+
define('CW_LIB_FOLDER', __DIR__ . '/lib');
15+
define('CW_DIVI_MODULES_FOLDER', __DIR__ . '/modules');
16+
define('CW_WP_SHORTCODES_FOLDER', __DIR__ . '/shortcodes');
17+
18+
foreach(glob(__DIR__ . '/initializers/*.php') as $file)
19+
require $file;
20+
21+
```
22+
23+
### initializers/
24+
##### 01_autoload.php
25+
```php
26+
<?php
27+
28+
require CW_LIB_FOLDER.'/cw/php/core/Autoloader.php';
29+
30+
cw\php\core\Autoloader::registerNamespaceLoader(
31+
CW_LIB_FOLDER,
32+
CW_DIVI_MODULES_FOLDER
33+
);
34+
35+
36+
```
37+
38+
##### 03_options.php
39+
```php
40+
<?php
41+
42+
global $wpOptions;
43+
44+
$wpOptions = new \cw\wp\admin\Options('child_options');
45+
46+
$wpOptions->adminBarName('Page-Options')
47+
->typeText('global_footer_post_id',
48+
'ID des Footer-Posts (Divi-Bibliothek)')
49+
50+
->typePlain('color_info',
51+
'Farbinfo',
52+
'<div class="theme-color green">
53+
<div class="color-monitor" style="background-color: #72ac4d"></div>
54+
<b>hex:</b> #72ac4d <br>
55+
<b>rgb:</b> rgba(114, 172, 77, 1)
56+
</div>');
57+
58+
```
59+
60+
##### 04_assets.php
61+
```php
62+
<?php
63+
64+
global $wpOptions, $jQuery, $wpAssets;
65+
66+
$jQuery = \cw\php\js\jQuery::getInstance();
67+
$wpAssets = \cw\wp\Assets::getInstance();
68+
69+
$wpAssets->scripts()
70+
->add('main-js', 'js/main.js', ['jquery'], 1, true)
71+
->inline('main-js', $wpOptions->toJs())
72+
->jqReady(
73+
$jQuery->getScript(
74+
$wpAssets->expand('js/app/loader.js')
75+
)
76+
)
77+
->replaceJquery('//ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js')
78+
->removeEmojiScript()
79+
->remove(
80+
'google-maps-api',
81+
'divi-fitvids',
82+
'waypoints',
83+
'magnific-popup',
84+
'hashchange',
85+
'salvattore',
86+
'easypiechart',
87+
'magnific-popup',
88+
'wp-embed'
89+
);
90+
91+
92+
$wpAssets->styles()
93+
->addParent()
94+
->addAdmin('eve-admin-css', 'admin.css')
95+
->conditional(function($wpAssests){
96+
if(!current_user_can( 'update_core' )) // no admin
97+
$wpAssests->remove('dashicons');
98+
});
99+
100+
$wpAssets->theme()
101+
->touchAfterPostUpdated() // can be used for browser-sync reload
102+
->addFooterContent($jQuery); // when will render onReady content when __toString is called
103+
104+
```
105+
106+
##### 06_menu.php
107+
```php
108+
<?php
109+
$childMenu = new \cw\wp\Menus();
110+
111+
$childMenu->addMenu('footer-1-menu')
112+
->addMenu('footer-2-menu')
113+
->addMenu('footer-3-menu');
114+
```
115+
116+
##### 07_custom_post_types.php
117+
```php
118+
<?php
119+
120+
$postType = new \cw\wp\custom\PostType('job_post');
121+
$postType->typePage()
122+
->isPublic()
123+
->slug('jobs')
124+
->hasArchive(false)
125+
->isHierarchical(false)
126+
->isPubliclyQueryable()
127+
->showInUi()
128+
->showInMenu()
129+
->supportsTitle()
130+
->supportsEditor()
131+
->supportsThumbnail()
132+
->supportsRevisions()
133+
->supportsPageAttributes()
134+
->supportsPostFormats()
135+
->menuPositionBelowPosts()
136+
->name('Job-Board')
137+
->singularName('Stellenanzeige')
138+
->menuName('Job-Board')
139+
->labelAddNew('Anzeige erstellen')
140+
->adminBarName('Job-Board')
141+
->addMetaBox(
142+
(new \cw\wp\custom\MetaBox('task'))
143+
->title('Aufgaben')
144+
->typeHtml()
145+
)
146+
->publish();
147+
148+
$taxanomy = new \cw\wp\custom\Taxanomy('job_place');
149+
$taxanomy->setObjectType($postType)
150+
->isHierarchical(false)
151+
->showInUi()
152+
->showAdminColumn()
153+
->queryVar(true)
154+
->slug('place')
155+
->name('Standorte')
156+
->publish();
157+
158+
$taxanomy = new \cw\wp\custom\Taxanomy('job_category');
159+
$taxanomy->setObjectType($postType)
160+
->isHierarchical(false)
161+
->showInUi()
162+
->showAdminColumn()
163+
->queryVar(true)
164+
->slug('category')
165+
->name('Kategorien')
166+
->publish();
167+
168+
$taxanomy = new \cw\wp\custom\Taxanomy('job_position');
169+
$taxanomy->setObjectType($postType)
170+
->isHierarchical(false)
171+
->showInUi()
172+
->showAdminColumn()
173+
->queryVar(true)
174+
->slug('position')
175+
->name('Positionen')
176+
->publish();
177+
```
178+
179+
##### hallo-world/css/module.sass
180+
```sass
181+
@import "variables"
182+
183+
@import "mixins/css/css3"
184+
@import "mixins/css/positioning"
185+
@import "mixins/helper/helper"
186+
187+
@import "mixins/grid/mediaqueries"
188+
@import "mixins/grid/grid"
189+
190+
@import "mixins/wordpress/divi"
191+
@import "mixins/wordpress/post"
192+
193+
194+
+custom-divi-module('cw-module-hallo-world')
195+
.image
196+
display: none
197+
+min-width-sm
198+
+block
199+
+absolute
200+
right: -40px
201+
bottom: 0
202+
203+
.content-wrapper
204+
[...]
205+
```

Theme.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace cw\wp;
4+
5+
class Theme{
6+
use \cw\php\core\traits\Singleton;
7+
8+
public $header='';
9+
public $footer='';
10+
11+
public function touchAfterPostUpdated($file = 'functions.php'){
12+
$file = get_stylesheet_directory() . '/' . $file;
13+
14+
add_action( 'post_updated', function() use($file){
15+
touch($file);
16+
}, 10, 3 );
17+
18+
return $this;
19+
}
20+
21+
public function addBodyClass($class){
22+
add_filter( 'body_class', function($classes) use($class){
23+
$classes[] = $class;
24+
return $classes;
25+
} );
26+
27+
return $this;
28+
}
29+
30+
function addFooterContent($input) {
31+
if(is_subclass_of($input, '\cw\php\js\expression\AbstractExpression'))
32+
$input = new \cw\php\js\expression\Wrapper($input);
33+
34+
add_action( 'wp_footer', function() use($input){
35+
echo $input;
36+
}, 101 );
37+
}
38+
39+
public function pageTemplate(){
40+
return get_query_template('page');
41+
}
42+
43+
public function postTemplate(){
44+
return get_query_template('single');
45+
}
46+
47+
public function parentTemplate($which){
48+
return get_template_directory() . '/' .$which;
49+
}
50+
51+
public function header($header=null){
52+
if($header === null)
53+
return $this->header;
54+
55+
$this->header = $header;
56+
return $this;
57+
}
58+
59+
public function footer($footer=null){
60+
if($footer === null)
61+
return $this->footer;
62+
63+
$this->footer = $footer;
64+
return $this;
65+
}
66+
}

0 commit comments

Comments
 (0)