1 | <?php |
||||||||
2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
||||||||
3 | |||||||||
4 | if ( ! defined( 'ABSPATH' ) ) exit; |
||||||||
5 | |||||||||
6 | /** |
||||||||
7 | * Build a sample metabox in editor screen |
||||||||
8 | * |
||||||||
9 | * @author Nirjhar Lo |
||||||||
10 | * @package wp-plugin-framework |
||||||||
11 | */ |
||||||||
12 | if ( ! class_exists( 'Metabox' ) ) { |
||||||||
13 | |||||||||
14 | final class Metabox { |
||||||||
15 | |||||||||
16 | |||||||||
17 | /** |
||||||||
18 | * Add Meetabox |
||||||||
19 | * |
||||||||
20 | * @return Void |
||||||||
21 | */ |
||||||||
22 | public function __construct() { |
||||||||
23 | |||||||||
24 | //Adding the metabox. For custom post type use "add_meta_boxes_posttype" action |
||||||||
25 | add_action( 'add_meta_boxes', array( $this, 'register' ) ); |
||||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||||
26 | add_action( 'save_post', array( $this, 'save' ), 10, 2 ); |
||||||||
27 | } |
||||||||
28 | |||||||||
29 | |||||||||
30 | /** |
||||||||
31 | * Metabox callback |
||||||||
32 | * |
||||||||
33 | * @return Html |
||||||||
0 ignored issues
–
show
The type
NirjharLo\WP_Plugin_Framework\Src\Html was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||||
34 | */ |
||||||||
35 | public function register() { |
||||||||
36 | |||||||||
37 | add_meta_box( |
||||||||
0 ignored issues
–
show
The function
add_meta_box was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
38 | 'meta-box-id', |
||||||||
39 | esc_html__( 'MetaBox Title', 'textdomain' ), |
||||||||
0 ignored issues
–
show
The function
esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
40 | array( $this, 'render' ), |
||||||||
41 | // Declare the post type to show meta box |
||||||||
42 | 'post_type', |
||||||||
43 | 'normal', |
||||||||
44 | 'core' |
||||||||
45 | ); |
||||||||
46 | } |
||||||||
47 | |||||||||
48 | |||||||||
49 | /** |
||||||||
50 | * Metabox render HTML |
||||||||
51 | * |
||||||||
52 | * @return Html |
||||||||
53 | */ |
||||||||
54 | public function render() { |
||||||||
55 | |||||||||
56 | wp_nonce_field( basename( __FILE__ ), 'metabox_name_nonce' ); ?> |
||||||||
0 ignored issues
–
show
The function
wp_nonce_field was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
57 | |||||||||
58 | <p> |
||||||||
59 | <label for="metabox_name"><?php _e( "Custom Text", 'textdomain' ); ?></label> |
||||||||
0 ignored issues
–
show
The function
_e was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
60 | <br /> |
||||||||
61 | <input class="widefat" type="text" name="metabox_field_name" id="metabox_field_name" value="<?php echo esc_attr( get_post_meta( $object->ID, 'metabox_name', true ) ); ?>" /> |
||||||||
0 ignored issues
–
show
The function
get_post_meta was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() Comprehensibility
Best Practice
introduced
by
The function
esc_attr was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
62 | </p> |
||||||||
63 | <?php |
||||||||
64 | } |
||||||||
65 | |||||||||
66 | |||||||||
67 | /** |
||||||||
68 | * Save the Metabox post data |
||||||||
69 | * |
||||||||
70 | * @param Array $atts |
||||||||
71 | * |
||||||||
72 | * @return Html |
||||||||
73 | */ |
||||||||
74 | function save( $post_id, $post ) { |
||||||||
0 ignored issues
–
show
|
|||||||||
75 | |||||||||
76 | //Check if doing autosave |
||||||||
77 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; |
||||||||
0 ignored issues
–
show
|
|||||||||
78 | |||||||||
79 | //Verify the nonce before proceeding. |
||||||||
80 | if ( !isset( $_POST['metabox_name_nonce'] ) || !wp_verify_nonce( $_POST['metabox_name_nonce'], basename( __FILE__ ) ) ) return; |
||||||||
0 ignored issues
–
show
The function
wp_verify_nonce was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
81 | |||||||||
82 | //Get the post type object. |
||||||||
83 | $post_type = get_post_type_object( $post->post_type ); |
||||||||
0 ignored issues
–
show
The function
get_post_type_object was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
84 | |||||||||
85 | //Check if the current user has permission to edit the post. |
||||||||
86 | if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; |
||||||||
0 ignored issues
–
show
The function
current_user_can was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
87 | |||||||||
88 | if ( isset( $_POST['metabox_field_name'] ) ) { |
||||||||
89 | update_post_meta( $post_id, 'metabox_field_name', sanitize_text_field($_POST['metabox_field_name']) ); |
||||||||
0 ignored issues
–
show
The function
sanitize_text_field was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The function
update_post_meta was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
90 | } |
||||||||
91 | } |
||||||||
92 | } |
||||||||
93 | } ?> |
||||||||
94 |