Skip to main content
Tweeted twitter.com/StackWordPress/status/853764353874702336
added 3 characters in body
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

I have a plugin and I am creating a css file in wp_content.

I used this:

$this->content_dir = WP_CONTENT_DIR . "/some_folder";

$path = $this->content_dir . 'options.css';
$css='some string';
global $wp_filesystem; 
if(!$wp_filesystem->put_contents( $path, $css, 0644) ) {
    return __('Failed to create css file');
}

However I get this error:

Fatal error: Call to a member function put_contents() on a non-object

var_dump($css)var_dump($css) return string.

Does put_contents write to an exisitingexisting file or does it create a file like file_put_contentsfile_put_contents does?

I am looking for an equivalent of this:

if(!file_put_contents($path, $css)){
    return __('Failed to create css file');
};

Thank you!

I have a plugin and I am creating a css file in wp_content.

I used this:

$this->content_dir = WP_CONTENT_DIR . "/some_folder";

$path = $this->content_dir . 'options.css';
$css='some string';
global $wp_filesystem; 
if(!$wp_filesystem->put_contents( $path, $css, 0644) ) {
    return __('Failed to create css file');
}

However I get this error:

Fatal error: Call to a member function put_contents() on a non-object

var_dump($css) return string.

Does put_contents write to an exisiting file or does it create a file like file_put_contents does?

I am looking for an equivalent of this:

if(!file_put_contents($path, $css)){
    return __('Failed to create css file');
};

Thank you!

I have a plugin and I am creating a css file in wp_content.

I used this:

$this->content_dir = WP_CONTENT_DIR . "/some_folder";

$path = $this->content_dir . 'options.css';
$css='some string';
global $wp_filesystem; 
if(!$wp_filesystem->put_contents( $path, $css, 0644) ) {
    return __('Failed to create css file');
}

However I get this error:

Fatal error: Call to a member function put_contents() on a non-object

var_dump($css) return string.

Does put_contents write to an existing file or does it create a file like file_put_contents does?

I am looking for an equivalent of this:

if(!file_put_contents($path, $css)){
    return __('Failed to create css file');
};

Thank you!

added 29 characters in body
Source Link
Toniq
  • 447
  • 6
  • 15

I have a plugin and I am creating a css file in wp_content.

I used this:

$this->content_dir = WP_CONTENT_DIR . "/some_folder";

$path = $this->content_dir . 'options.css';
$css='some string';
global $wp_filesystem; 
if(!$wp_filesystem->put_contents( $path, $css, 0644) ) {
    return __('Failed to create css file');
}

However I get this error:

Fatal error: Call to a member function put_contents() on a non-object

var_dump($css) return string.

Does put_contents write to an exisiting file or does it create a file like file_put_contents does?

I am looking for an equivalent of this:

if(!file_put_contents($path, $css)){
    return __('Failed to create css file');
};

Thank you!

I have a plugin and I am creating a css file in wp_content.

I used this:

$this->content_dir = WP_CONTENT_DIR . "/some_folder";

$path = $this->content_dir . 'options.css';
$css='some string';
if(!$wp_filesystem->put_contents( $path, $css, 0644) ) {
    return __('Failed to create css file');
}

However I get this error:

Fatal error: Call to a member function put_contents() on a non-object

var_dump($css) return string.

Does put_contents write to an exisiting file or does it create a file like file_put_contents does?

I am looking for an equivalent of this:

if(!file_put_contents($path, $css)){
    return __('Failed to create css file');
};

Thank you!

I have a plugin and I am creating a css file in wp_content.

I used this:

$this->content_dir = WP_CONTENT_DIR . "/some_folder";

$path = $this->content_dir . 'options.css';
$css='some string';
global $wp_filesystem; 
if(!$wp_filesystem->put_contents( $path, $css, 0644) ) {
    return __('Failed to create css file');
}

However I get this error:

Fatal error: Call to a member function put_contents() on a non-object

var_dump($css) return string.

Does put_contents write to an exisiting file or does it create a file like file_put_contents does?

I am looking for an equivalent of this:

if(!file_put_contents($path, $css)){
    return __('Failed to create css file');
};

Thank you!

Source Link
Toniq
  • 447
  • 6
  • 15

Call to a member function put_contents() on a non-object

I have a plugin and I am creating a css file in wp_content.

I used this:

$this->content_dir = WP_CONTENT_DIR . "/some_folder";

$path = $this->content_dir . 'options.css';
$css='some string';
if(!$wp_filesystem->put_contents( $path, $css, 0644) ) {
    return __('Failed to create css file');
}

However I get this error:

Fatal error: Call to a member function put_contents() on a non-object

var_dump($css) return string.

Does put_contents write to an exisiting file or does it create a file like file_put_contents does?

I am looking for an equivalent of this:

if(!file_put_contents($path, $css)){
    return __('Failed to create css file');
};

Thank you!