public function modify_tmpl_head_elements() { $headers = glob(get_stylesheet_directory() . '/header*.php'); foreach ($headers as $file) { $base = basename($file); $backup = $file . '~backup-' . date('Ymd-His'); // double check in case of reloads etc. if (($html = SucomUtil::get_stripped_php($file)) === false || strpos($html, '<head>') === false) { $this->p->notice->err(sprintf(__('<head> element not found in %s.', 'nextgen-facebook'), $file), true); continue; } // make a backup of the original if (!copy($file, $backup)) { $this->p->notice->err(sprintf(__('Error copying %1$s to %2$s.', 'nextgen-facebook'), 'header.php', $backup), true); continue; } $php = file_get_contents($file); $php = str_replace('<head>', '<head <?php do_action( \'add_head_attributes\' ); ?>>', $php); if (!($fh = @fopen($file, 'wb'))) { $this->p->notice->err(sprintf(__('Failed to open file %s for writing.', 'nextgen-facebook'), $file), true); continue; } if (fwrite($fh, $php)) { fclose($fh); $this->p->notice->inf(sprintf(__('The %1$s template has been successfully updated and saved. A backup copy of the original template is available in %2$s.', 'nextgen-facebook'), $base, $backup), true); } } $this->p->notice->trunc_id('notice-header-tmpl-no-head-attr'); // just in case }