← All changes
|
inc/admin/views/meta-boxes/class-lp-meta-box.php
+136
-136
4.3.8
→
4.4.9
View file →
| @@ -1,136 +1,136 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * LP Admin Metabox | |
| 5 | - * | |
| 6 | - * @author Nhamdv | |
| 7 | - * @version 4.0.0 | |
| 8 | - */ | |
| 9 | -abstract class LP_Meta_Box { | |
| 10 | - | |
| 11 | - private static $saved_meta_boxes = false; | |
| 12 | - | |
| 13 | - public $post_type = LP_COURSE_CPT; | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * LP_Meta_Box constructor. | |
| 17 | - */ | |
| 18 | - public function __construct() { | |
| 19 | - $this->includes(); | |
| 20 | - | |
| 21 | - // @since 4.0.0 | |
| 22 | - add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) ); | |
| 23 | - // @since 4.2.7 | |
| 24 | - add_action( 'add_meta_boxes', array( $this, '_do_add_meta_boxes' ), 10, 2 ); | |
| 25 | - add_action( 'save_post', array( $this, 'save_meta_boxes' ), 100, 2 ); | |
| 26 | - add_action( 'learnpress_save_' . $this->post_type . '_metabox', array( $this, 'save' ) ); | |
| 27 | - | |
| 28 | - //add_action( 'learnpress_save_lp_course_metabox', 'LP_Meta_Box_Course::save_eduma_child_metabox_v3', 10 ); | |
| 29 | - } | |
| 30 | - | |
| 31 | - // Include fields. | |
| 32 | - public function includes() { | |
| 33 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/class-lp-meta-box-fields.php'; | |
| 34 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/text.php'; | |
| 35 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/duration.php'; | |
| 36 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/checkbox.php'; | |
| 37 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/textarea.php'; | |
| 38 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/file.php'; | |
| 39 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/radio.php'; | |
| 40 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/select.php'; | |
| 41 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/extra.php'; | |
| 42 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/extra-faq.php'; | |
| 43 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/date.php'; | |
| 44 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/wysiwyg.php'; | |
| 45 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/repeater.php'; | |
| 46 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/autocomplete.php'; | |
| 47 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/materials.php'; | |
| 48 | - include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/lp-meta-box-functions.php'; | |
| 49 | - } | |
| 50 | - | |
| 51 | - public function add_meta_box() { | |
| 52 | - // Implement from child | |
| 53 | - } | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * Handle call method add meta boxes | |
| 57 | - * | |
| 58 | - * @param $post_type | |
| 59 | - * @param $post | |
| 60 | - * | |
| 61 | - * @return void | |
| 62 | - * @since 4.2.7 | |
| 63 | - */ | |
| 64 | - final public function _do_add_meta_boxes( $post_type, $post ) { | |
| 65 | - if ( $post_type !== $this->post_type ) { | |
| 66 | - return; | |
| 67 | - } | |
| 68 | - | |
| 69 | - $this->add_meta_boxes( $post ); | |
| 70 | - } | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * Method for add meta boxes | |
| 74 | - * | |
| 75 | - * @param $post | |
| 76 | - * | |
| 77 | - * @return void | |
| 78 | - * @since 4.2.7 | |
| 79 | - */ | |
| 80 | - public function add_meta_boxes( $post ) { | |
| 81 | - // Implement from child | |
| 82 | - } | |
| 83 | - | |
| 84 | - | |
| 85 | - public function metabox( $post_id ) { | |
| 86 | - return array(); | |
| 87 | - } | |
| 88 | - | |
| 89 | - public function output( $post ) { | |
| 90 | - wp_nonce_field( 'learnpress_save_meta_box', 'learnpress_meta_box_nonce' ); | |
| 91 | - } | |
| 92 | - | |
| 93 | - public function save( $post_id ) { | |
| 94 | - if ( ! empty( $this->metabox( $post_id ) ) ) { | |
| 95 | - foreach ( $this->metabox( $post_id ) as $key => $object ) { | |
| 96 | - if ( is_a( $object, 'LP_Meta_Box_Field' ) ) { | |
| 97 | - $object->id = $key; | |
| 98 | - $object->save( $post_id ); | |
| 99 | - } | |
| 100 | - } | |
| 101 | - } | |
| 102 | - } | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * @param id $post_id | |
| 106 | - * @param WP_Post $post | |
| 107 | - */ | |
| 108 | - public function save_meta_boxes( $post_id = 0, $post = null ) { | |
| 109 | - $post_id = absint( $post_id ); | |
| 110 | - | |
| 111 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { | |
| 112 | - return; | |
| 113 | - } | |
| 114 | - | |
| 115 | - if ( empty( $_POST['learnpress_meta_box_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['learnpress_meta_box_nonce'] ), 'learnpress_save_meta_box' ) ) { | |
| 116 | - return; | |
| 117 | - } | |
| 118 | - | |
| 119 | - if ( empty( $_POST['post_ID'] ) || absint( $_POST['post_ID'] ) !== $post_id ) { | |
| 120 | - return; | |
| 121 | - } | |
| 122 | - | |
| 123 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
| 124 | - return; | |
| 125 | - } | |
| 126 | - | |
| 127 | - self::$saved_meta_boxes = true; | |
| 128 | - | |
| 129 | - //TODO: Not apply for course, | |
| 130 | - // but on theme custom fields course is using this hook. Need change how to hook on theme. | |
| 131 | - /*if ( $post->post_type === LP_COURSE_CPT ) { | |
| 132 | - return; | |
| 133 | - }*/ | |
| 134 | - do_action( 'learnpress_save_' . $post->post_type . '_metabox', $post_id, $post ); | |
| 135 | - } | |
| 136 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * LP Admin Metabox | |
| 5 | + * | |
| 6 | + * @author Nhamdv | |
| 7 | + * @version 4.0.0 | |
| 8 | + */ | |
| 9 | +abstract class LP_Meta_Box { | |
| 10 | + | |
| 11 | + private static $saved_meta_boxes = false; | |
| 12 | + | |
| 13 | + public $post_type = LP_COURSE_CPT; | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * LP_Meta_Box constructor. | |
| 17 | + */ | |
| 18 | + public function __construct() { | |
| 19 | + $this->includes(); | |
| 20 | + | |
| 21 | + // @since 4.0.0 | |
| 22 | + add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) ); | |
| 23 | + // @since 4.2.7 | |
| 24 | + add_action( 'add_meta_boxes', array( $this, '_do_add_meta_boxes' ), 10, 2 ); | |
| 25 | + add_action( 'save_post', array( $this, 'save_meta_boxes' ), 100, 2 ); | |
| 26 | + add_action( 'learnpress_save_' . $this->post_type . '_metabox', array( $this, 'save' ) ); | |
| 27 | + | |
| 28 | + //add_action( 'learnpress_save_lp_course_metabox', 'LP_Meta_Box_Course::save_eduma_child_metabox_v3', 10 ); | |
| 29 | + } | |
| 30 | + | |
| 31 | + // Include fields. | |
| 32 | + public function includes() { | |
| 33 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/class-lp-meta-box-fields.php'; | |
| 34 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/text.php'; | |
| 35 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/duration.php'; | |
| 36 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/checkbox.php'; | |
| 37 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/textarea.php'; | |
| 38 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/file.php'; | |
| 39 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/radio.php'; | |
| 40 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/select.php'; | |
| 41 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/extra.php'; | |
| 42 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/extra-faq.php'; | |
| 43 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/date.php'; | |
| 44 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/wysiwyg.php'; | |
| 45 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/repeater.php'; | |
| 46 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/autocomplete.php'; | |
| 47 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/fields/materials.php'; | |
| 48 | + include_once LP_PLUGIN_PATH . 'inc/admin/views/meta-boxes/lp-meta-box-functions.php'; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public function add_meta_box() { | |
| 52 | + // Implement from child | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Handle call method add meta boxes | |
| 57 | + * | |
| 58 | + * @param $post_type | |
| 59 | + * @param $post | |
| 60 | + * | |
| 61 | + * @return void | |
| 62 | + * @since 4.2.7 | |
| 63 | + */ | |
| 64 | + final public function _do_add_meta_boxes( $post_type, $post ) { | |
| 65 | + if ( $post_type !== $this->post_type ) { | |
| 66 | + return; | |
| 67 | + } | |
| 68 | + | |
| 69 | + $this->add_meta_boxes( $post ); | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Method for add meta boxes | |
| 74 | + * | |
| 75 | + * @param $post | |
| 76 | + * | |
| 77 | + * @return void | |
| 78 | + * @since 4.2.7 | |
| 79 | + */ | |
| 80 | + public function add_meta_boxes( $post ) { | |
| 81 | + // Implement from child | |
| 82 | + } | |
| 83 | + | |
| 84 | + | |
| 85 | + public function metabox( $post_id ) { | |
| 86 | + return array(); | |
| 87 | + } | |
| 88 | + | |
| 89 | + public function output( $post ) { | |
| 90 | + wp_nonce_field( 'learnpress_save_meta_box', 'learnpress_meta_box_nonce' ); | |
| 91 | + } | |
| 92 | + | |
| 93 | + public function save( $post_id ) { | |
| 94 | + if ( ! empty( $this->metabox( $post_id ) ) ) { | |
| 95 | + foreach ( $this->metabox( $post_id ) as $key => $object ) { | |
| 96 | + if ( is_a( $object, 'LP_Meta_Box_Field' ) ) { | |
| 97 | + $object->id = $key; | |
| 98 | + $object->save( $post_id ); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 104 | + /** | |
| 105 | + * @param id $post_id | |
| 106 | + * @param WP_Post $post | |
| 107 | + */ | |
| 108 | + public function save_meta_boxes( $post_id = 0, $post = null ) { | |
| 109 | + $post_id = absint( $post_id ); | |
| 110 | + | |
| 111 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { | |
| 112 | + return; | |
| 113 | + } | |
| 114 | + | |
| 115 | + if ( empty( $_POST['learnpress_meta_box_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['learnpress_meta_box_nonce'] ), 'learnpress_save_meta_box' ) ) { | |
| 116 | + return; | |
| 117 | + } | |
| 118 | + | |
| 119 | + if ( empty( $_POST['post_ID'] ) || absint( $_POST['post_ID'] ) !== $post_id ) { | |
| 120 | + return; | |
| 121 | + } | |
| 122 | + | |
| 123 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
| 124 | + return; | |
| 125 | + } | |
| 126 | + | |
| 127 | + self::$saved_meta_boxes = true; | |
| 128 | + | |
| 129 | + //TODO: Not apply for course, | |
| 130 | + // but on theme custom fields course is using this hook. Need change how to hook on theme. | |
| 131 | + /*if ( $post->post_type === LP_COURSE_CPT ) { | |
| 132 | + return; | |
| 133 | + }*/ | |
| 134 | + do_action( 'learnpress_save_' . $post->post_type . '_metabox', $post_id, $post ); | |
| 135 | + } | |
| 136 | +} | |