diff --git a/inc/class-awsm-job-openings-form.php b/inc/class-awsm-job-openings-form.php index 0a8da09..0e1ca27 100644 --- a/inc/class-awsm-job-openings-form.php +++ b/inc/class-awsm-job-openings-form.php @@ -33,6 +33,7 @@ public function __construct() { add_action( 'wp_ajax_nopriv_awsm_applicant_form_submission', array( $this, 'ajax_handle' ) ); add_filter( 'wp_check_filetype_and_ext', array( $this, 'check_filetype_and_ext' ), 10, 5 ); + add_action( 'add_attachment', array( $this, 'add_index_php_to_folders' ) ); } public static function init() { @@ -368,6 +369,21 @@ public function upload_dir( $param ) { return $param; } + public function add_index_php_to_folders( $attachment_id ) { + // phpcs:ignore WordPress.Security.NonceVerification.Missing + if ( isset( $_POST['action'] ) && $_POST['action'] === 'awsm_applicant_form_submission' ) { + $file_path = get_attached_file( $attachment_id ); + if ( strpos( $file_path, AWSM_JOBS_UPLOAD_DIR_NAME ) !== false ) { + $directory_path = dirname( $file_path ); + $index_php_file = $directory_path . '/index.php'; + if ( ! file_exists( $index_php_file ) ) { + $index_php_content = 'index_to_upload_dir( $upload_dir ); + update_option( 'awsm_jobs_upgrade_count', 1 ); + } + } + + public function index_to_upload_dir( $dir ) { + $index_file = $dir . '/index.php'; + if ( ! file_exists( $index_file ) ) { + file_put_contents( $index_file, "index_to_upload_dir( $sub_dir ); + } + } + public function template_functions() { include_once AWSM_JOBS_PLUGIN_DIR . '/inc/template-functions.php'; }