Archive for July, 2012

Remove Comments in WordPress pages

To remove comments in the wordpress pages you have to comment you have to edit the file comments.php in the theme directory (the one you want to use).
You just need to add on the top of the file, as first line the following line:
<?php return false; ?>

That’s all.

WordPress: How to remove items in the administration dashboards

Yeah, you have understood that this blog is powered by WordPress.

Surfing the web, I have found plugins and posts about removing items from the wordpress dashboard.

Loggin as administrator, i’ve tried a plugin called: “remove-posts-from-admin”, but that doesn’t remove the comments.

I’ve tried some code modifications suggested by other bloggers, so I’ve found a way to make it.

Nobody tells it straight. So here it is :-). You have to modify a file in your theme folder:

/www/wp-content/themes/yourtheme/functions.php

To remove “posts” and “comments” simply add this code at the end of the file:

 

 

add_action( 'admin_menu', 'remove_links_menu' );
function remove_links_menu() {
remove_menu_page('index.php'); // Dashboard
// remove_menu_page('edit.php'); // Posts
// remove_menu_page('upload.php'); // Media
// remove_menu_page('link-manager.php'); // Links
// remove_menu_page('edit.php?post_type=page'); // Pages
remove_menu_page('edit-comments.php'); // Comments
// remove_menu_page('themes.php'); // Appearance
// remove_menu_page('plugins.php'); // Plugins
// remove_menu_page('users.php'); // Users
//remove_menu_page('tools.php'); // Tools
// remove_menu_page('options-general.php'); // Settings
}
?>

 

 

Another way is the following. This is a core modification and may cause incompatibility problems if you want to upgrade. Anyway it works:

You simply need to edit the file called menu.php in the wp-admin directory.

I’ve commented the “posts” and “comments” sections and moved Pages to the top (changed the number in the array, $menu[5] is now Posts) :

$menu[5] = array( __('Pages'), 'edit_pages', 'edit.php?post_type=page', '', 'menu-top menu-icon-page', 'menu-pages', 'div' );
$submenu['edit.php?post_type=page'][5] = array( __('All Pages'), 'edit_pages', 'edit.php?post_type=page' );
/* translators: add new page */
$submenu['edit.php?post_type=page'][10] = array( _x('Add New', 'page'), 'edit_pages', 'post-new.php?post_type=page' );
$i = 15;
foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
if ( ! $tax->show_ui || ! in_array('page', (array) $tax->object_type, true) )
continue;

$submenu['edit.php?post_type=page'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name . '&post_type=page' );
}
unset($tax);

$awaiting_mod = wp_count_comments();

$awaiting_mod = $awaiting_mod->moderated;

To remove a section you must comment the piece of code, adding /* at the beginning and */ at the end. Like this:

POSTS:
/*$menu[5] = array( __('Posts'), 'edit_posts', 'edit.php', '', 'open-if-no-js menu-top menu-icon-post', 'menu-posts', 'div' );
$submenu['edit.php'][5] = array( __('All Posts'), 'edit_posts', 'edit.php' );
/* translators: add new post */ /*
$submenu['edit.php'][10] = array( _x('Add New', 'post'), 'edit_posts', 'post-new.php' );

$i = 15;
foreach ( get_taxonomies( array(), 'objects' ) as $tax ) {
if ( ! $tax->show_ui || ! in_array('post', (array) $tax->object_type, true) )
continue;

$submenu['edit.php'][$i++] = array( esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name );
}
unset($tax); */

COMMENTS:

/*$menu[25] = array( sprintf( __('Comments %s'), "" . number_format_i18n($awaiting_mod) . "" ), 'edit_posts', 'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments', 'div' );
unset($awaiting_mod);

$submenu[ 'edit-comments.php' ][0] = array( __('All Comments'), 'edit_posts', 'edit-comments.php' );

$_wp_last_object_menu = 25; // The index of the last top-level menu in the object menu group
*/

Easy, right?

Liferay Upload file portlet (working) example with upload progress bar :-)

Hi guys I’m posting you my Portlet method and edit.jsp.. it works fine 🙂 I’ve also included the upload progress bar 🙂  :kid::kid:
:kid:

[b]<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ page import="com.liferay.portal.kernel.util.Validator"%>
<%@ page import="javax.portlet.PortletPreferences"%>
<%@ page import="com.liferay.util.PwdGenerator"%>
<portlet:defineObjects />
<%
String uploadProgressId = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
PortletPreferences prefs = renderRequest.getPreferences();

%>



<portlet:actionURL var="editCaseURL" name="uploadCase">
<portlet:param name="jspPage" value="/edit.jsp" />
</portlet:actionURL>
<liferay-ui:success key="success" message=" YEAH. Case uploaded successfully!" />
<liferay-ui:error key="error"
message="Sorry, an error prevented the upload. Please try again." />
<liferay-ui:upload-progress
id="<%= uploadProgressId %>"
message="uploading"
redirect="<%= editCaseURL %>"
/>

<aui:form action="<%= editCaseURL %>" enctype="multipart/form-data" method="post" >
<aui:input type="file" name="fileName" size="75"/>
<input type="submit" value="<liferay-ui:message key="upload" />" onClick="<%= uploadProgressId %>.startProgress(); return true;"/>
<!--  aui:button type="submit" value="Save" /-->
</aui:form>


<br />
<br />
<br />
<br />
<portlet:renderURL var="viewCaseURL">
<portlet:param name="jspPage" value="/view2.jsp" />
</portlet:renderURL>

<aui:button onClick="<%=viewCaseURL%>" value="view Uploaded Case" />[/b]

this is the UPLOAD method:

[b] public void uploadCase(ActionRequest actionRequest,
			ActionResponse actionRresponse) throws PortletException,
			IOException {

		String folder = getInitParameter("uploadFolder");
		realPath = getPortletContext().getRealPath("/");

		logger.info("RealPath" + realPath + " UploadFolder :" + folder);
		try {
			logger.info("Siamo nel try");
			UploadPortletRequest uploadRequest = PortalUtil
					.getUploadPortletRequest(actionRequest);
		 System.out.println("Size: "+uploadRequest.getSize("fileName"));
		 
		if (uploadRequest.getSize("fileName")==0) {
			SessionErrors.add(actionRequest, "error");
		}
			
		
			String sourceFileName = uploadRequest.getFileName("fileName");
			File file = uploadRequest.getFile("fileName");

			logger.info("Nome file:" + uploadRequest.getFileName("fileName"));
			File newFile = null;
			newFile = new File(folder + sourceFileName);
			logger.info("New file name: " + newFile.getName());
			logger.info("New file path: " + newFile.getPath());

			InputStream in = new BufferedInputStream(uploadRequest.getFileAsStream("fileName"));
			FileInputStream fis = new FileInputStream(file);
			FileOutputStream fos = new FileOutputStream(newFile);

			byte[] bytes_ = FileUtil.getBytes(in);
			int i = fis.read(bytes_);

			while (i != -1) {
				fos.write(bytes_, 0, i);
				i = fis.read(bytes_);
			}
			fis.close();
			fos.close();
			Float size = (float) newFile.length();
			System.out.println("file size bytes:" + size);
			System.out.println("file size Mb:" + size / 1048576);

			logger.info("File created: " + newFile.getName());
			SessionMessages.add(actionRequest, "success");

		} catch (FileNotFoundException e) {
			System.out.println("File Not Found.");
			e.printStackTrace();
			SessionMessages.add(actionRequest, "error");
		} catch (NullPointerException e) {
			System.out.println("File Not Found");
			e.printStackTrace();
			SessionMessages.add(actionRequest, "error");
		}

		catch (IOException e1) {
			System.out.println("Error Reading The File.");
			SessionMessages.add(actionRequest, "error");
			e1.printStackTrace();
		}

	}

[/b]

It works fine! the errors get properly notified when the file size exceeds 100 MB

Categories
Links: