hooks(); } public function hooks() { add_action( 'apppresser_add_settings', array( $this, 'download_settings' ) ); add_filter( 'apppresser_field_override_media_post_types', array( $this, 'media_post_types' ), 10, 4 ); add_action( 'add_meta_boxes', array( $this, 'media_url_meta_box' ) ); add_action( 'save_post', array( $this, 'media_url_save' ), 10, 2 ); } public function media_url_meta_box() { global $post; $post_types = appp_get_setting( 'media_post_types' ); if( empty( $post_types ) ) { return; } if( in_array( $post->post_type, $post_types ) ) { add_meta_box( 'appp_media_url_meta_box', __( 'AppPresser Media URL', 'apppresser' ), array( $this, 'media_url_meta_box_render' ) ); } } public function media_url_meta_box_render( $post ) { wp_nonce_field( 'appp_media_url_meta_box', 'appp_media_url_meta_box_nonce' ); $value = get_post_meta( $post->ID, 'appp_media_url', true ); ?>

post_type, $post_types ) ) { return $post_id; } // Check if our nonce is set. if ( ! isset( $_POST['appp_media_url_meta_box_nonce'] ) ) { return $post_id; } $nonce = $_POST['appp_media_url_meta_box_nonce']; // Verify that the nonce is valid. if ( ! wp_verify_nonce( $nonce, 'appp_media_url_meta_box' ) ) { return $post_id; } /* * If this is an autosave, our form has not been submitted, * so we don't want to do anything. */ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } // Check the user's permissions. if ( ! current_user_can( 'edit_post', $post_id ) ) { return $post_id; } /* OK, it's safe for us to save the data now. */ // Sanitize the user input. $url = sanitize_text_field( $_POST['appp_media_url'] ); // Update the meta field. update_post_meta( $post_id, 'appp_media_url', $url ); } /** * Add download settings * @since 1.0.0 */ public function download_settings( $appp ) { $appp->add_setting_label( __( 'Media Settings', 'apppresser' ), array( 'subtab' => 'general', ) ); $appp->add_setting( 'enable_media_urls', __( 'Media post types', 'apppresser' ), array( 'type' => 'media_post_types', 'subtab' => 'general', 'helptext' => __( 'Check post types to use with the app media list. Next, go to each post and add media urls to the meta box.', 'apppresser' ) ) ); } public function media_post_types( $field, $key, $value, $args ) { $post_types = get_post_types( array('public' => true ), 'objects' ); $saved = appp_get_setting( 'media_post_types' ); foreach ( $post_types as $post_type => $object ) { $checked = ''; if( $saved ) { $setting = is_array( $saved ) && in_array( $post_type, $saved, true ); $checked = checked( $setting, 1, 0 ); } $field .= '
'."\n"; } return $field; } } AppPresser_Media_Settings::run();