Forum Replies Created

Viewing 15 replies - 106 through 120 (of 158 total)
  • @gangesh
    I think there’s no way to “persuade” cf7 not to unlink files after mails are sent. This is a security feature as it avoid someone can upload a scritp throug a form and then execute it on your server.
    But you can use the php copy command to make a copy of your file every time you send an email via cf7.

    Suppose you have uploaded a file in a subfolder of your WP uploads folder named master.pdf, and you wanna send a copy of it every time someone fills a form on your site.

    Just add some lines of code to my function above like this:

    add_action( 'wpcf7_before_send_mail', 'create_unique_coupon_and_send_it' );
    function create_unique_coupon_and_send_it( $cf7 ) {
    	//check if this is the right form
    	if ($cf7->id==741){
     		$uploads = wp_upload_dir();
    		//define some constants
    		define ('MY_FILE_PATH',$uploads['path'].'/myfile/');
    
    		//set filenames
    		$master_copy=MY_FILE_PATH.'master.pdf';
    		$copy_to_send=MY-FILE_PATH.'attachment.pdf';
    
    		if ($cf7->mail['use_html']==true)
    			$nl="<br/>";
    		else
    			$nl="\n";
    
    		//make a copy of the master file and attach it
    		if ( copy( $master_copy, $copy_to_send ) ){
    			//Let'go to the file attachment!
    			$cf7->uploaded_files = array ( 'coupon' => $copy_to_send );
    		}
    		//append some text to the outgoing email
    		$message=$nl.$nl.'Blah blah blah.....'.$nl;
     		$message.='So Long, and Thanks for All the Fish!'.$nl;
    		$cf7->mail_2['body'].=$message;
    	}
    }

    You have to insert the code in the functions.php file in your theme folder. If your theme doesn’t have one, create it and copy&paste the code in it (in this case, remeber to add open and close php tags to the code).

    A little addition I’ve coded recently that can be useful: if you have several page template with different styles, this code can auto-include (if it exists) a css relative to every page template in tinymce.

    If page template filename is page-something.php, it looks for TEMPLATEPATH/css/editor-style-page-something.css.
    Obviously it can be extended to take in account taxonomies or particular post ids etc, as it globalizes $post so you can extract all informations you need.
    Here is the code, hope it can be useful:

    /**
     * add_tinymce_custom_styles()
     */
    add_filter( 'mce_css', 'add_tinymce_custom_styles' );
    function add_tinymce_custom_styles( $url ) {
    	global $post;
    	if ( isset( $post->page_template )){
    		$pagetemplate = array_shift( explode( '.php', $post->page_template ) );
    		if ( file_exists( TEMPLATEPATH.'/css/editor-style-'.$pagetemplate.'.css' ) ){
    			if ( !empty($url) ) $url .= ',';
    			$url .= trailingslashit( get_stylesheet_directory_uri() ) . 'css/editor-style-'.$pagetemplate.'.css';
    		}
    	}
    	return $url;
    }

    thanks to Matt and Tyson suggestions here!

    Thread Starter Mad Max

    (@mad_max)

    Happy to hear it has been useful to you!

    Setting the pagination to “1” in the reading settings is the simplest and most immediate working solution I’ve found to this problem, but then you have to set a value for pagination every time you create a new taxonomy/term/cpt etc, and then you have to “scatter” the pagination-setting on several template files.

    My function just groups those settings in one point and allow you to use the value defined in the backend as the default value for every new type of archive/listing.

    Aside from wondering why that problem has not been patched yet, I’d like to find the time to use the function above to create a plugin and so integrate the backend reading settings with a list all paginable items and their specific settings. Maybe in a near future…

    oh, another tip to make some debugging with cf7 forms without getting crazy: use Firefox+Firebug
    HOW
    1) add FirePHP firebug extension to firebug:
    https://addons.mozilla.org/en-US/firefox/addon/6149/
    2) install this wp-firePHP plugin
    http://inchoo.net/wordpress/wordpress-firephp-plugin/
    (download version 0.2 and unzip to your wp plugins folder then activate it)
    3) now use
    fb($whathever_var_or_string);
    to output debugging info to firebug console, even structured one like arrays or objects. For example:
    fb($cf7);
    gives you a print_r like output with all data setted ans used by cf7.

    @veebeeglobal
    1) Have you changed the $cf7->id check using YOUR form-id in code?
    2) Do you get some errors?
    3) Are you sure the file your trying to attach exists and that you are pointing to the right folder?
    2) can you paste the code you are using on pastebin or similar?

    bye

    the solution is to disable plugin one by one, until you find the one causing the warning. Then, find a call like “add_submenu_page” or similar, using a numeric user level instead of a capability name.
    Substitute the numeric user level with a compatible capability or user role and the warning should vanish.

    I’m in the exact same situation. I have a form where a user can request a discount coupon, so I need to create a coupon (pdf file) on the fly with a unique serial number in it, attach the coupon and send it to the user via email.

    I’ve found a working solution, so here it is:

    1) I’ve created a form in the backend and setted all required field in MAIL section.

    2) In the file attachement field on MAIL I’ve inserted
    [coupon]
    N.B: it’s not necessary to really add this field to the form, just in the attchment field.

    3) I Hooked in cf7 via ‘wpcf7_before_send_mail‘ action

    add_action( 'wpcf7_before_send_mail', 'create_unique_coupon_and_send_it' );
    function create_unique_coupon_and_send_it( $cf7 ) {
    	//check if this is the right form
    	if ($cf7->id==741){
     		$uploads = wp_upload_dir();
    		//define some constants
    		define ('COUPON_UPLOAD_PATH',$uploads['path'].'/coupons');
    		// ...
    		// ...
    		if ($cf7->mail['use_html']==true)
    			$nl="<br/>";
    		else
    			$nl="\n";
    		//I omitted all the stuff used to create
    		//the pdf file, you have just to know that
    		//$pdf_filename contains the filename to attach
    		//Let'go to the file attachment!
    
    		$cf7->uploaded_files = array ( 'coupon' => COUPON_UPLOAD_PATH.'/'.$pdf_filename );
    
    		//append some text to the outgoing email
    		$message=$nl.$nl.'Blah blah blah.....'.$nl;
     		$message.='So Long, and Thanks for All the Fish!'.$nl;
    		$cf7->mail_2['body'].=$message;
    	}
    }

    Note that:
    1) you have to change the form id as needed (or avoid the check if you have only one form on your site)
    2) CF7 unlink (delete) the attached file after mail is sent for security reasons, so make a copy of it if you have to send the same file over and over.
    3) make sure the key of the item in this associative array
    array ( ‘coupon’ => COUPON_UPLOAD_PATH.’/’.$pdf_filename );
    matches the name inserted in the form settings, in the attachment file field (see point 2) above the code)
    4) If you are using (like me) the “to-db-extension” plugin, remember to add the action with a priority level lower than 10:
    add_action( ‘wpcf7_before_send_mail’, ‘create_unique_coupon_and_send_it’, 5 );

    to execute your code before the DB plugin gets form data and save them in the db. In the code example above, I can add a field to every record in the db, just altering the $cf7->posted_data array:

    //Add coupon file name in the database
    $cf7->posted_data['coupon_file']=$pdf_filename;

    Hope it can be useful.

    Thread Starter Mad Max

    (@mad_max)

    Great! I’m going to try your plugin asap!

    Please go here. I’ve correct some issues in the explanation and in the code.

    Thanks.

    I’ve found the same exact problem now (9 months later) on WP 3.2.1.
    If you set a posts_per_page value in a template file, lower then the one specified in the backend, you get a 404 error on pagination. If I’m not wrong, the 404 error shows on the last page (the 2nd when you have only few posts).

    After some debugging, I think the problem is that the var posts_per_page get lost going to page 2 and so WP uses the default one to decide if there are posts to show or not.
    Some examples:
    —————————————————————-
    SET A GREATER VALUE
    a) you have 9 posts in a particular category;
    b) you have “5” as posts_per_page setted in the backend;
    c) you specify “7” in your template file;

    First page:
    WP reads the template file, set the var with the new value (7) so it shows posts from 1 to 7

    Second Page:
    when you click on “next page”, WP lost your new posts_per page value and thinks: “ok, I’ve got 9 posts in this category, I’m on page 2 and I have to show 5 post per page, so this page exists for sure and I must load posts from 6 to 9!”
    Then it loads the template file, your var is setted again to 7, page number is 2, so WP loads and shows (correctly) posts 8 and 9.
    No more post to show so you don’t have a next page link to go further.

    SET A LOWER VALUE
    a) you have 9 posts in a particular category
    b) you have “5” as posts_per_page setted in the backend
    c) you specify “3” in your template file

    First page:
    wp reads the template file, set the var with the new value (3) so it shows posts from 1 to 3.

    Second Page:
    when you click on “next page”, WP lost your new posts_per page value and thinks: “ok, I’ve got 9 posts in this category, I’m on page 2 and I have to show 5 post per page, so this page exists for sure and I must load posts from 6 to 9
    Then it loads the template file, your var is setted again to 3, page number is 2, so WP loads and shows (correctly) posts from 4 to 6.

    Third page:
    when you click on “next page”, WP lost (again!) your new posts_per page value and thinks: “ok, I’ve got 9 posts in this category, I’m on page 3 and I have to show 5 post per page, so this page can’t exist!!!”
    Then it loads the 404 template file, your are very angry ang go out for a walk!
    —————————————————————-

    So, if you set a value greather then the one specified in the backend, even if the variable get lost and the default is used, WP calculates (mistaken for excess) thar there are certainly some other posts to show. This is not problematic, as the code on template file corrects it and doesn’t allow to go to next page if all posts are showed.
    If you specify a lower value, WP is “consuming” your remaining posts faster then your template file, that prints a link to next page and you get a 404 error.

    Ok. that’s a funny story. And now? My workaround is:

    function cure_wp_amnesia_on_query_string($query_string) {
    	switch ( $query_string['category_name'] ) {
    		case 'category-slug-1':
    		case 'category-slug-2':
    			$query_string['posts_per_page'] = 5;
    			break;
    		case 'category-slug-3':
    			$query_string['posts_per_page'] = 6;
    			break;
    		case 'category-slug-4':
    			$query_string['posts_per_page'] = 3;
    		//default:
    			break;
    	}
    	if ( isset( $query_string['s'] ) ){//case SEARCH-PAGE
    		$query_string['posts_per_page'] = 5;
    	}
    	return $query_string;
    }
    add_filter('request', 'cure_wp_amnesia_on_query_string');

    Add this function in your functions.php and set here the number of posts you want per category. I’ve not tried it with CPT but I suppose that we can find a specific index in $query_string to test against as I do with ‘category_name’ and ‘s’.

    Hope this can help someone.

    I’ve found this solution working up to wp 3.2.1 and TinyMCE Advanced 3.4.2.1.

    1) Go to Settings -> TinyMCE Advanced and drag&drop the “styles” box over one editor active toolbar, then save changes.

    2) Add a css file in your theme folder, for example:
    css/extra-editor-styles.css

    3) Open your theme functions.php and add code below:

    //load extra-editor-styles.css in tinymce
    add_editor_style('css/extra-editor-styles.css');
    add_filter('tiny_mce_before_init', 'myCustomTinyMCE' );
    /* Custom CSS styles on TinyMCE Editor */
    if ( ! function_exists( 'myCustomTinyMCE' ) ) {
    	function myCustomTinyMCE($init) {
    		$init['theme_advanced_styles'] = 'Style-01-name=css-01-identifier; Style-02-name=css-02-identifier; Style-03-name=css-03-identifier';
    	return $init;
    	}
    }

    where:
    Style-XX-name is one of the option users can choose from in the styles dropdown
    css-XX-identifier is the relative class name that will be added to the selected dom element.
    Obviously you can go further and add as many classes you want, using “;” as separator.

    4) Insert in css/extra-editor-styles.css all css code relative to all classes you have defined at point 3) and all the defined custom styles will be applied directly in the editor textarea and on front-end.

    Hope this can help.

    Bye, Daniele.

    Moogle, add code in 1) on line 220 o wp-smushit.php, just before
    if ( FALSE === strpos($file, WP_CONTENT_DIR) ) {

    and (2) change line 34 of bulk.php, from
    ob_end_flush();
    to
    @ob_end_flush();

    @ char just tell php interpreter not to echo warnings.

    Alex, only another consideration: working on a site with wordpress in debug mode, I’ve found a pair of warnings coming out from your plugin:

    1) an “undefined $file” on line 220 in wp-smush.it.php, during image upload in post edit section; fixed adding
    if (!isset($file)) $file="";

    2) a warning during a bulk smashing “ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush” on line 34 in bulk.php; fixed prepending “@” to ob_end_flush();

    Could you be so kind to include those little patches on your next release of wp-smushit?

    thanks again!

    Bulk smushing works good, thanks!
    It should be cool to have an option in the media library “bulk action” select, to smush only selected images.
    So, if for some reason (someone said “can’t create temp dir error”?!), the bulk smushing doesn’t finish properly, we don’t have to restart and smush same images again and again.
    Or, if it could be simpler, make sure not to process already smushed images when using bulk smush.

    Thank Alex for your great work!

Viewing 15 replies - 106 through 120 (of 158 total)