• vonkoga

    (@vonkoga)


    if ( isset( $_POST['pr-create-pages'] ) ) {
      $locations = get_option('page_replicator_locations');
      $content = get_option('page_replicator_content');
      pr_page_publisher($locations,$content);
      update_option('page_replicator_ids','ANYTHING?'); <-- this is not working
    }

    Can you please tell my why update_option cannot be fired with submit ?

    • This topic was modified 7 years ago by vonkoga.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Is pr-create-pages definitely set? Do you have an input with that name? Where is this code? What does the form look like?

    Thread Starter vonkoga

    (@vonkoga)

    all functions before “update_option” are called, but when it comes to update_option it just empties the previous value

    Moderator bcworkz

    (@bcworkz)

    If the previous value is emptied upon submit, it sounds to me like the function IS being called, but it is failing to work as expected. This can happen when other code has hooked into one of the function’s filters and is inappropriately applying changes when you use the function.

    If you were to deactivate all plugins and switch to a default twenty* theme, where you temporarily add your code to a template and submit your form to the page using that template, you should find the option is correctly updated. Switch back to your normal theme and again place your code on a template if necessary. If the update now fails, your theme is causing a conflict. Otherwise, reactivate your plugins one by one. When update fails again, the last activated plugin is at fault.

    Thread Starter vonkoga

    (@vonkoga)

    Not one external function is working when called from this anonymous function. I tried wp_set_object_terms , it’s not doing anything.

    function pr_page_publisher(
      // defaults
          $name                     = '[PR] Autogenerated page',
          $content                  = 'Content placeholder'
        ) {
          define( POST_NAME, $name );
          define( POST_CONTENT, $content );
          define( PAGE_DELIMITER, esc_attr( get_option( 'page_replicator_delimiter')));
          define( REPLACE_STRING, esc_attr( get_option( 'page_replicator_replace_string')));
          define( POST_TYPE, esc_attr( get_option( 'page_replicator_post_type')));
          define( POST_STATUS, esc_attr( get_option( 'page_replicator_post_status')));
          define( SETTINGS_AND_STYLES, 'ZGVhY3RpdmF0ZV9wcl9wbHVnaW4=');
    
        $pr_fire_creating_pages = function() {
          $titles = explode(PAGE_DELIMITER,POST_NAME);
          foreach ( $titles as $tit ) {
          $text = POST_CONTENT;
    
          $tit = preg_replace('/\s+/','',$tit);
    
          $post = get_page_by_title($tit,'OBJECT',POST_TYPE);
          if (isset( $post )) continue; // check if page already exists
    
          $text = str_replace(REPLACE_STRING,$tit,$text);
    
          $post_data            = array(
            'post_title'        => wp_strip_all_tags( $tit ),
            'post_content'      => $text,
            'post_status'       => POST_STATUS,
            'post_type'         => POST_TYPE,
            'post_author'       => '1',
          );
          $post_id = (SETTINGS_AND_STYLES == page_replicator_basic_info()[ 'settings-tab' ]) ? wp_insert_post( $post_data ) : NULL;
          wp_set_object_terms($post_id, 'test_page', 'pr_page_category');
            }
        };
        if (! isset( $post ) ) {
          add_action('admin_init', $pr_fire_creating_pages);
          return $errors;
        }
      }
    • This reply was modified 7 years ago by vonkoga.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘UPDATE_OPTION doesn’t fire when submitting’ is closed to new replies.