/** * Check if the muut directory exists under the wp-content/uploads directory, and if not then create it. * * @param string $sub_dir A subdirectory or path to check beneath the main Muut uploads directory. * @return bool Whether the directory exists or not (or was created if it previously didn't). * @author Paul Hughes * @since 3.0.2 */ public static function checkMuutUploadsDirectory($sub_dir = '') { $wp_upload_dir = wp_upload_dir(); $dir_path = trailingslashit($wp_upload_dir['basedir']) . self::UPLOADS_DIR_NAME; $sub_path = trailingslashit($dir_path) . $sub_dir; // If the uploads directory (and specified subdirectory) do not exist, create them with proper permissions. if (!file_exists($sub_path)) { if (@(!mkdir($sub_path, 0755, true))) { return false; } } // Verify that the directory is writeable. if (!is_writable($sub_path)) { return false; } // Store the directory path. self::$uploads_path = $dir_path; return true; }
/** * Prints the widget JS stuff (mostly, the array of latest comments items). * * @return void * @author Paul Hughes * @since 3.0.2 */ public function printWidgetJs() { global $post; if (is_active_widget(false, false, $this->id_base, true) && !is_admin() && isset($post)) { $poll_time = apply_filters('muut_latest_comments_poll_updates', '0'); $json = $content = json_encode(array('latest_comments_posts' => $this->getLatestCommentsData())); echo '<script type="text/javascript">'; echo 'var muut_latest_comments_poll_time = "' . $poll_time . '";'; echo 'var muut_latest_comments_json = ' . $json . ';'; echo 'var muut_latest_comments_request_endpoint = "' . trailingslashit(Muut_Files_Utility::getUploadsUrl()) . 'cache/' . self::LATEST_COMMENTS_JSON_FILE_NAME . '";'; $user_obj = new stdClass(); $user_obj->path = '%USER_PATH%'; $user_obj->displayname = '%USER_DISPLAYNAME%'; $user_obj->img = '%USER_IMAGEURL%'; echo 'var muut_latest_comments_row_template = \'' . $this->getRowMarkup('%POSTID%', '%TIMESTAMP%', $user_obj) . '\';'; echo '</script>'; } }
/** * Displays a dismissible admin notice if the Muut uploads directory is not writeable. * * @return void * @author Paul Hughes * @since 3.0.4 */ public function maybeShowUploadsDirectoryFailureNotice() { $dismissed_notices = muut()->getOption('dismissed_notices', array()); if ((!isset($dismissed_notices['uploads_dir_fail_notice']) || !$dismissed_notices['uploads_dir_fail_notice']) && !Muut_Files_Utility::checkMuutUploadsDirectory('/')) { $wp_upload_dir = wp_upload_dir(); $muut_uploads_dir = trailingslashit($wp_upload_dir['basedir']) . Muut_Files_Utility::UPLOADS_DIR_NAME; echo '<div class="updated muut_admin_notice" id="muut_uploads_dir_fail_notice">'; wp_nonce_field('muut_dismiss_notice', 'dismiss_nonce'); echo '<span class="dismiss_notice_button"><a href="#" class="dismiss_notice">X</a></span>'; echo '<p>' . sprintf(__('The %sMuut Plugin%s has some advanced functionality that requires your uploads directory be writeable. You should create a directory with permissions 755 at %s, or change the permissions of the main uploads directory to 755. There are instrucitons on how to do that %shere%s.', 'muut'), '<b>', '</b>', $muut_uploads_dir, '<a href="http://codex.wordpress.org/Changing_File_Permissions">', '</a>') . '</p>'; echo '</div>'; } }