-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissuepage.php
More file actions
100 lines (87 loc) · 2.62 KB
/
issuepage.php
File metadata and controls
100 lines (87 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Plugin Name: issuepage
* Description: Example block written with ESNext standard and JSX support – build step required.
* Version: 0.1.0
* Author: The WordPress Contributors
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: issuepage
*
* @package siejmy
*/
require_once dirname(__FILE__) . '/metaboxes/issuepage_metabox_html.php';
function issuepage_register_post_fields() {
register_post_meta( 'post', 'issuepage_issue_no', array(
'description' => 'Numer i miesiąc wydania (tekst wyświetlany nad tytułem)',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
) );
register_post_meta( 'post', 'issuepage_download_url', array(
'description' => 'Url pobierania numeru',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
) );
}
function issuepage_save_post($post_id) {
if ( array_key_exists( 'issuepage_issue_no', $_POST ) ) {
update_post_meta(
$post_id,
'issuepage_issue_no',
$_POST['issuepage_issue_no']
);
}
if ( array_key_exists( 'issuepage_download_url', $_POST ) ) {
update_post_meta(
$post_id,
'issuepage_download_url',
$_POST['issuepage_download_url']
);
}
}
function issuepage_add_metaboxes() {
add_meta_box(
'issuepage_metabox', // Unique ID
'Strona pobierania wydania', // Box title
'issuepage_metabox_html', // Content callback, must be of type callable
'post' // Post type
);
}
function issuepage_plugin_init() {
$dir = dirname( __FILE__ );
$script_asset_path = "$dir/build/index.asset.php";
if ( ! file_exists( $script_asset_path ) ) {
throw new Error(
'You need to run `npm start` or `npm run build` for the "siejmy/issuepage" block first.'
);
}
$index_js = 'build/index.js';
$script_asset = require( $script_asset_path );
wp_register_script(
'siejmy-issuepage-block-editor',
plugins_url( $index_js, __FILE__ ),
$script_asset['dependencies'],
$script_asset['version']
);
$editor_css = 'build/index.css';
wp_register_style(
'siejmy-issuepage-block-editor',
plugins_url( $editor_css, __FILE__ ),
array(),
filemtime( "$dir/$editor_css" )
);
$style_css = 'build/style-index.css';
wp_register_style(
'siejmy-issuepage-block',
plugins_url( $style_css, __FILE__ ),
array(),
filemtime( "$dir/$style_css" )
);
wp_enqueue_style('siejmy-issuepage-block');
issuepage_register_post_fields();
}
add_action( 'init', 'issuepage_plugin_init' );
add_action( 'add_meta_boxes', 'issuepage_add_metaboxes' );
add_action( 'save_post', 'issuepage_save_post' );