Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions checks/class-directories-macosx-check.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Check if Macosx directory is included
*
* @package Theme Check
*/

/**
* Check if Macosx directory is included.
*
* Check if Macosx directory is included. If it is, require it to be removed.
*/
class Directories_Macosx_Check implements themecheck {
/**
* Error messages, warnings and info notices.
*
* @var array $error
*/
protected $error = array();

/**
* Theme context.
*
* @var WP_Theme $theme
*/
protected $theme;

/**
* Set check context.
*
* @param array $data Context data.
*/
function set_context( $data ) {
if ( isset( $data['theme'] ) ) {
$this->theme = $data['theme'];
}
}

/**
* Check that return true for good/okay/acceptable, false for bad/not-okay/unacceptable.
*
* @param array $php_files File paths and content for PHP files.
* @param array $css_files File paths and content for CSS files.
* @param array $other_files Folder names, file paths and content for other files.
*/
public function check( $php_files, $css_files, $other_files ) {

$excluded_directories = array(
'__MACOSX',
);

$ret = true;

$theme_dir = $this->theme->get_stylesheet_directory();
$directories = scandir( $theme_dir );

if ( false === $directories ) {
return true;
}

foreach ( $directories as $dir ) {
checkcount();

if ( in_array( $dir, $excluded_directories, true ) ) {
$this->error[] = sprintf(
'<span class="tc-lead tc-required">%s</span>: %s',
__( 'REQUIRED', 'theme-check' ),
__( 'Please remove any extraneous directories like <strong>__MACOSX</strong> from the ZIP file before uploading it.', 'theme-check' )
);
$ret = false;
}
}

return $ret;
}

/**
* Get error messages from the checks.
*
* @return array Error message.
*/
public function getError() {
return $this->error;
}
}

$themechecks[] = new Directories_Macosx_Check();
Loading